// Path: dalesbred/src/main/java/org/dalesbred/connection/ConnectionProvider.java
// public interface ConnectionProvider {
// 
//     @NotNull
//     Connection getConnection() throws SQLException;
// 
//     void releaseConnection(@NotNull Connection connection) throws SQLException;
// }
// 
// Path: dalesbred/src/main/java/org/dalesbred/dialect/Dialect.java
// public abstract class Dialect {
// 
//     private static final String SERIALIZATION_FAILURE = "40001";
// 
//     private static final Logger log = LoggerFactory.getLogger(Dialect.class);
// 
//     public @NotNull Object valueToDatabase(@NotNull Object value) {
//         return value;
//     }
// 
//     public @NotNull <T extends Enum<T>, K> TypeConversionPair<Object,T> createNativeEnumConversions(@NotNull Class<T> enumType, @NotNull String typeName, @NotNull Function<T,K> keyFunction) {
//         throw new UnsupportedOperationException("native enums are not supported by " + getClass().getName());
//     }
// 
//     @Override
//     public @NotNull String toString() {
//         return getClass().getName();
//     }
// 
//     public static @NotNull Dialect detect(@NotNull DataSource dataSource) {
//         return detect(new DataSourceConnectionProvider(dataSource));
//     }
// 
//     public static @NotNull Dialect detect(@NotNull TransactionManager transactionManager) {
//         return transactionManager.withTransaction(new TransactionSettings(),
//                 tx -> detect(tx.getConnection()), new DefaultDialect());
//     }
// 
//     public static @NotNull Dialect detect(@NotNull ConnectionProvider connectionProvider) {
//         try {
//             Connection connection = connectionProvider.getConnection();
//             try {
//                 return detect(connection);
//             } finally {
//                 connectionProvider.releaseConnection(connection);
//             }
//         } catch (SQLException e) {
//             throw new DatabaseSQLException("Failed to auto-detect database dialect: " + e, e);
//         }
//     }
// 
//     public static @NotNull Dialect detect(@NotNull Connection connection) {
//         try {
//             String productName = connection.getMetaData().getDatabaseProductName();
// 
//             switch (productName) {
//                 case "PostgreSQL":
//                     log.debug("Automatically detected dialect PostgreSQL.");
//                     return new PostgreSQLDialect();
// 
//                 case "HSQL Database Engine":
//                     log.debug("Automatically detected dialect HSQLDB.");
//                     return new HsqldbDialect();
// 
//                 case "H2":
//                     log.debug("Automatically detected dialect H2.");
//                     return new H2Dialect();
// 
//                 case "MySQL":
//                     log.debug("Automatically detected dialect MySQL.");
//                     return new MySQLDialect();
// 
//                 case "Oracle":
//                     log.debug("Automatically detected dialect Oracle.");
//                     return new OracleDialect();
// 
//                 case "Microsoft SQL Server":
//                     log.debug("Automatically detected dialect SQLServer.");
//                     return new SQLServerDialect();
// 
//                 default:
//                     log.info("Could not detect dialect for product name '{}', falling back to default.", productName);
//                     return new DefaultDialect();
//             }
//         } catch (SQLException e) {
//             throw new DatabaseSQLException("Failed to auto-detect database dialect: " + e, e);
//         }
//     }
// 
//     public @NotNull DatabaseException convertException(@NotNull SQLException e) {
//         String sqlState = e.getSQLState();
//         if (sqlState == null)
//             return new DatabaseSQLException(e);
// 
//         if (sqlState.equals(SERIALIZATION_FAILURE))
//             return new TransactionSerializationException(e);
//         else if (sqlState.startsWith("40"))
//             return new TransactionRollbackException(e);
//         else
//             return new DatabaseSQLException(e);
//     }
// 
//     public void registerTypeConversions(@NotNull TypeConversionRegistry typeConversionRegistry) {
// 
//     }
// 
//     /**
//      * Bind object to {@link PreparedStatement}. Can be overridden by subclasses to
//      * implement custom argument binding.
//      *
//      * @param ps    statement to bind object to
//      * @param index index of the parameter
//      * @param value to bind
//      * @throws SQLException if something fails
//      */
//     public void bindArgument(@NotNull PreparedStatement ps, int index, @Nullable Object value) throws SQLException {
//         ArgumentBinder.bindArgument(ps, index, value);
//     }
// }


import static java.util.Objects.requireNonNull;
import org.dalesbred.connection.ConnectionProvider;
import org.dalesbred.dialect.Dialect;
import org.jetbrains.annotations.NotNull;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Optional;
            activeTransaction.set(newTransaction);
            return newTransaction.execute(callback, dialect);
        } finally {
            activeTransaction.set(null);
            releaseConnection(connection, dialect);
        }
    }

    @Override
    protected <T> T withSuspendedTransaction(@NotNull TransactionCallback<T> callback,
                                             @NotNull Isolation isolation,
                                             @NotNull Dialect dialect) {
        DefaultTransaction suspended = getActiveTransaction().orElse(null);
        try {
            activeTransaction.set(null);

            TransactionSettings settings = new TransactionSettings();
            settings.setPropagation(Propagation.REQUIRED);
            settings.setIsolation(isolation);
            return withTransaction(settings, callback, dialect);
        } finally {
            activeTransaction.set(suspended);
        }
    }

    @Override
    protected @NotNull Optional<DefaultTransaction> getActiveTransaction() {
        return Optional.ofNullable(activeTransaction.get());
    }

// Path: dalesbred/src/main/java/org/dalesbred/connection/ConnectionProvider.java
// public interface ConnectionProvider {
// 
//     @NotNull
//     Connection getConnection() throws SQLException;
// 
//     void releaseConnection(@NotNull Connection connection) throws SQLException;
// }
// 
// Path: dalesbred/src/main/java/org/dalesbred/dialect/Dialect.java
// public abstract class Dialect {
// 
//     private static final String SERIALIZATION_FAILURE = "40001";
// 
//     private static final Logger log = LoggerFactory.getLogger(Dialect.class);
// 
//     public @NotNull Object valueToDatabase(@NotNull Object value) {
//         return value;
//     }
// 
//     public @NotNull <T extends Enum<T>, K> TypeConversionPair<Object,T> createNativeEnumConversions(@NotNull Class<T> enumType, @NotNull String typeName, @NotNull Function<T,K> keyFunction) {
//         throw new UnsupportedOperationException("native enums are not supported by " + getClass().getName());
//     }
// 
//     @Override
//     public @NotNull String toString() {
//         return getClass().getName();
//     }
// 
//     public static @NotNull Dialect detect(@NotNull DataSource dataSource) {
//         return detect(new DataSourceConnectionProvider(dataSource));
//     }
// 
//     public static @NotNull Dialect detect(@NotNull TransactionManager transactionManager) {
//         return transactionManager.withTransaction(new TransactionSettings(),
//                 tx -> detect(tx.getConnection()), new DefaultDialect());
//     }
// 
//     public static @NotNull Dialect detect(@NotNull ConnectionProvider connectionProvider) {
//         try {
//             Connection connection = connectionProvider.getConnection();
//             try {
//                 return detect(connection);
//             } finally {
//                 connectionProvider.releaseConnection(connection);
//             }
//         } catch (SQLException e) {
//             throw new DatabaseSQLException("Failed to auto-detect database dialect: " + e, e);
//         }
//     }
// 
//     public static @NotNull Dialect detect(@NotNull Connection connection) {
//         try {
//             String productName = connection.getMetaData().getDatabaseProductName();
// 
//             switch (productName) {
//                 case "PostgreSQL":
//                     log.debug("Automatically detected dialect PostgreSQL.");
//                     return new PostgreSQLDialect();
// 
//                 case "HSQL Database Engine":
//                     log.debug("Automatically detected dialect HSQLDB.");
//                     return new HsqldbDialect();
// 
//                 case "H2":
//                     log.debug("Automatically detected dialect H2.");
//                     return new H2Dialect();
// 
//                 case "MySQL":
//                     log.debug("Automatically detected dialect MySQL.");
//                     return new MySQLDialect();
// 
//                 case "Oracle":
//                     log.debug("Automatically detected dialect Oracle.");
//                     return new OracleDialect();
// 
//                 case "Microsoft SQL Server":
//                     log.debug("Automatically detected dialect SQLServer.");
//                     return new SQLServerDialect();
// 
//                 default:
//                     log.info("Could not detect dialect for product name '{}', falling back to default.", productName);
//                     return new DefaultDialect();
//             }
//         } catch (SQLException e) {
//             throw new DatabaseSQLException("Failed to auto-detect database dialect: " + e, e);
//         }
//     }
// 
//     public @NotNull DatabaseException convertException(@NotNull SQLException e) {
//         String sqlState = e.getSQLState();
//         if (sqlState == null)
//             return new DatabaseSQLException(e);
// 
//         if (sqlState.equals(SERIALIZATION_FAILURE))
//             return new TransactionSerializationException(e);
//         else if (sqlState.startsWith("40"))
//             return new TransactionRollbackException(e);
//         else
//             return new DatabaseSQLException(e);
//     }
// 
//     public void registerTypeConversions(@NotNull TypeConversionRegistry typeConversionRegistry) {
// 
//     }
// 
//     /**
//      * Bind object to {@link PreparedStatement}. Can be overridden by subclasses to
//      * implement custom argument binding.
//      *
//      * @param ps    statement to bind object to
//      * @param index index of the parameter
//      * @param value to bind
//      * @throws SQLException if something fails
//      */
//     public void bindArgument(@NotNull PreparedStatement ps, int index, @Nullable Object value) throws SQLException {
//         ArgumentBinder.bindArgument(ps, index, value);
//     }
// }


// Path: dalesbred/src/main/java/org/dalesbred/transaction/DefaultTransactionManager.java
import static java.util.Objects.requireNonNull;
import org.dalesbred.connection.ConnectionProvider;
import org.dalesbred.dialect.Dialect;
import org.jetbrains.annotations.NotNull;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Optional;

            activeTransaction.set(newTransaction);
            return newTransaction.execute(callback, dialect);
        } finally {
            activeTransaction.set(null);
            releaseConnection(connection, dialect);
        }
    }

    @Override
    protected <T> T withSuspendedTransaction(@NotNull TransactionCallback<T> callback,
                                             @NotNull Isolation isolation,
                                             @NotNull Dialect dialect) {
        DefaultTransaction suspended = getActiveTransaction().orElse(null);
        try {
            activeTransaction.set(null);

            TransactionSettings settings = new TransactionSettings();
            settings.setPropagation(Propagation.REQUIRED);
            settings.setIsolation(isolation);
            return withTransaction(settings, callback, dialect);
        } finally {
            activeTransaction.set(suspended);
        }
    }

    @Override
    protected @NotNull Optional<DefaultTransaction> getActiveTransaction() {
        return Optional.ofNullable(activeTransaction.get());
    }

    private @NotNull Connection openConnection(@NotNull Isolation isolation, @NotNull Dialect dialect) {