Skip to content

Commit

Permalink
Merge pull request #524 from gruelbox/r2dbc-abandon-refactor
Browse files Browse the repository at this point in the history
Move secondary modules into their own package namespace (leaving deprecation shims in place and all tests directed at the shims)
  • Loading branch information
badgerwithagun authored Dec 21, 2023
2 parents f427bf2 + ca5d9ec commit 88d0493
Show file tree
Hide file tree
Showing 49 changed files with 749 additions and 319 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
jdk: [11,17,21]
os: [ ubuntu-latest ]
jdk: [ 11,17,21 ]
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand All @@ -22,4 +22,4 @@ jobs:
java-version: ${{ matrix.jdk }}

- name: Build with Maven
run: mvn -Pconcise -B package -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
run: mvn -Pconcise -B fmt:check package -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gruelbox.transactionoutbox;

import com.gruelbox.transactionoutbox.spi.Utils;
import java.sql.Connection;
import javax.sql.DataSource;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
@AllArgsConstructor
@Getter
@Beta
public enum Dialect {
MY_SQL_5(
false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gruelbox.transactionoutbox;

import static com.gruelbox.transactionoutbox.Utils.uncheckedly;
import static com.gruelbox.transactionoutbox.spi.Utils.uncheckedly;

import java.sql.Connection;
import java.sql.DriverManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gruelbox.transactionoutbox;

import com.gruelbox.transactionoutbox.spi.Utils;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gruelbox.transactionoutbox;

import com.gruelbox.transactionoutbox.spi.AbstractFullyQualifiedNameInstantiator;
import java.util.function.Function;
import lombok.experimental.SuperBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* outbox.schedule(MyClass.class).myMethod("foo", context));
* </pre>
*/
@Beta
public interface ParameterContextTransactionManager<T> extends TransactionManager {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gruelbox.transactionoutbox;

import com.gruelbox.transactionoutbox.spi.AbstractFullyQualifiedNameInstantiator;
import com.gruelbox.transactionoutbox.spi.Utils;
import java.lang.reflect.Constructor;
import lombok.experimental.SuperBuilder;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.gruelbox.transactionoutbox;

import com.gruelbox.transactionoutbox.spi.AbstractThreadLocalTransactionManager;
import com.gruelbox.transactionoutbox.spi.SimpleTransaction;
import com.gruelbox.transactionoutbox.spi.Utils;
import java.sql.Connection;
import java.sql.SQLException;
import lombok.experimental.SuperBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.gruelbox.transactionoutbox;

import com.gruelbox.transactionoutbox.spi.ProxyFactory;
import com.gruelbox.transactionoutbox.spi.SimpleTransaction;
import com.gruelbox.transactionoutbox.spi.Utils;
import java.sql.Connection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand All @@ -22,7 +25,6 @@ public class StubParameterContextTransactionManager<C>
* @param contextClass The class that represents the context. Must support equals/hashCode.
* @param contextFactory Generates context instances when transactions are started.
*/
@Beta
public StubParameterContextTransactionManager(Class<C> contextClass, Supplier<C> contextFactory) {
this.contextClass = contextClass;
this.contextFactory = contextFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.gruelbox.transactionoutbox;

import com.gruelbox.transactionoutbox.spi.AbstractThreadLocalTransactionManager;
import com.gruelbox.transactionoutbox.spi.ProxyFactory;
import com.gruelbox.transactionoutbox.spi.SimpleTransaction;
import com.gruelbox.transactionoutbox.spi.Utils;
import java.sql.Connection;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -11,7 +15,6 @@
public class StubThreadLocalTransactionManager
extends AbstractThreadLocalTransactionManager<SimpleTransaction> {

@Beta
public StubThreadLocalTransactionManager() {
// Nothing to do
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.gruelbox.transactionoutbox;

import static com.gruelbox.transactionoutbox.Utils.uncheck;
import static com.gruelbox.transactionoutbox.Utils.uncheckedly;
import static com.gruelbox.transactionoutbox.spi.Utils.uncheck;
import static com.gruelbox.transactionoutbox.spi.Utils.uncheckedly;

import java.lang.reflect.Method;
import javax.sql.DataSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.gruelbox.transactionoutbox;

import static com.gruelbox.transactionoutbox.Utils.logAtLevel;
import static com.gruelbox.transactionoutbox.Utils.uncheckedly;
import static com.gruelbox.transactionoutbox.spi.Utils.logAtLevel;
import static com.gruelbox.transactionoutbox.spi.Utils.uncheckedly;
import static java.time.temporal.ChronoUnit.MILLIS;
import static java.time.temporal.ChronoUnit.MINUTES;

import com.gruelbox.transactionoutbox.spi.ProxyFactory;
import com.gruelbox.transactionoutbox.spi.Utils;
import java.lang.reflect.InvocationTargetException;
import java.time.Clock;
import java.time.Duration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.gruelbox.transactionoutbox;
package com.gruelbox.transactionoutbox.spi;

import static com.gruelbox.transactionoutbox.Utils.uncheckedly;
import static com.gruelbox.transactionoutbox.spi.Utils.uncheckedly;

import com.gruelbox.transactionoutbox.Instantiator;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import lombok.extern.slf4j.Slf4j;

/**
* Abstract {@link Instantiator} implementation which simplifies the creation of implementations
* which instantiate based on the clazz FQN.
*/
@Slf4j
@SuperBuilder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
abstract class AbstractFullyQualifiedNameInstantiator implements Instantiator {
public abstract class AbstractFullyQualifiedNameInstantiator implements Instantiator {

@Override
public final String getName(Class<?> clazz) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gruelbox.transactionoutbox;
package com.gruelbox.transactionoutbox.spi;

import com.gruelbox.transactionoutbox.*;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Optional;
Expand All @@ -11,7 +12,7 @@
@Slf4j
@SuperBuilder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
abstract class AbstractThreadLocalTransactionManager<TX extends SimpleTransaction>
public abstract class AbstractThreadLocalTransactionManager<TX extends SimpleTransaction>
implements ThreadLocalContextTransactionManager {

private final ThreadLocal<Deque<TX>> transactions = ThreadLocal.withInitial(LinkedList::new);
Expand Down Expand Up @@ -43,20 +44,20 @@ public <T, E extends Exception> T requireTransactionReturns(
return work.doWork(peekTransaction().orElseThrow(NoTransactionActiveException::new));
}

final TX pushTransaction(TX transaction) {
public final TX pushTransaction(TX transaction) {
transactions.get().push(transaction);
return transaction;
}

final TX popTransaction() {
public final TX popTransaction() {
TX result = transactions.get().pop();
if (transactions.get().isEmpty()) {
transactions.remove();
}
return result;
}

Optional<TX> peekTransaction() {
public Optional<TX> peekTransaction() {
return Optional.ofNullable(transactions.get().peek());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gruelbox.transactionoutbox;
package com.gruelbox.transactionoutbox.spi;

import com.gruelbox.transactionoutbox.MissingOptionalDependencyException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
Expand Down Expand Up @@ -52,7 +53,7 @@ private ObjenesisStd setupObjenesis() {
}

@SuppressWarnings({"unchecked", "cast"})
<T> T createProxy(Class<T> clazz, BiFunction<Method, Object[], T> processor) {
public <T> T createProxy(Class<T> clazz, BiFunction<Method, Object[], T> processor) {
if (clazz.isInterface()) {
// Fastest - we can just proxy an interface directly
return (T)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.gruelbox.transactionoutbox;
package com.gruelbox.transactionoutbox.spi;

import static com.gruelbox.transactionoutbox.Utils.safelyClose;
import static com.gruelbox.transactionoutbox.Utils.uncheck;
import static com.gruelbox.transactionoutbox.spi.Utils.safelyClose;
import static com.gruelbox.transactionoutbox.spi.Utils.uncheck;

import com.gruelbox.transactionoutbox.Transaction;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
Expand All @@ -15,31 +16,31 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@AllArgsConstructor(access = AccessLevel.PROTECTED)
class SimpleTransaction implements Transaction, AutoCloseable {
@AllArgsConstructor(access = AccessLevel.PUBLIC)
public final class SimpleTransaction implements Transaction, AutoCloseable {

private final List<Runnable> postCommitHooks = new ArrayList<>();
private final Map<String, PreparedStatement> preparedStatements = new HashMap<>();
private final Connection connection;
private final Object context;

@Override
public final Connection connection() {
public Connection connection() {
return connection;
}

@Override
public final void addPostCommitHook(Runnable runnable) {
public void addPostCommitHook(Runnable runnable) {
postCommitHooks.add(runnable);
}

@Override
public final PreparedStatement prepareBatchStatement(String sql) {
public PreparedStatement prepareBatchStatement(String sql) {
return preparedStatements.computeIfAbsent(
sql, s -> Utils.uncheckedly(() -> connection.prepareStatement(s)));
}

final void flushBatches() {
public void flushBatches() {
if (!preparedStatements.isEmpty()) {
log.debug("Flushing batches");
for (PreparedStatement statement : preparedStatements.values()) {
Expand All @@ -48,18 +49,18 @@ final void flushBatches() {
}
}

final void processHooks() {
public void processHooks() {
if (!postCommitHooks.isEmpty()) {
log.debug("Running post-commit hooks");
postCommitHooks.forEach(Runnable::run);
}
}

void commit() {
public void commit() {
uncheck(connection::commit);
}

void rollback() throws SQLException {
public void rollback() throws SQLException {
connection.rollback();
}

Expand Down
Loading

0 comments on commit 88d0493

Please sign in to comment.