Hi Niclas, Thanks for your detailed report. Indeed, this is a known limitation of the current implementation and API. A feature request to improve this is on the roadmap: https://github.com/jOOQ/jOOQ/issues/5388
Specifically, the TransactionProvider should expose a ConnectionProvider, which should be preferred by jOOQ's internals over the Configuration.connectionProvider(), if available. All this inconvenience should be rectified and re-specified with #5388. In your actual implementation (that is not the simplified version you posted here), what was your intent of wrapping the ThreadLocalTransactionProvider specifically? I cannot explain the difference between the dbcpDataSource and the rawDataSource. Hope this helps, Lukas 2017-10-16 3:37 GMT+02:00 Niclas Hedhman <[email protected]>: > > Version: 3.10.1 > Postgres 9.6 server > JDBC Driver: org.postgresql:postgresql:42.1.4 > > T > > The testcase found below will not work. It will say > > Caused by: org.postgresql.util.PSQLException: ERROR: schema > "POLYGENE" does not exist > > when trying to create the table. > > Further looking, when the commit() is issued inside the > dsl.createSchema( "POLYGENE" ).execute(); > > the transaction state is in "IDLE" mode, and the commit is not executed. > The reason for that is that some ROLLBACK has been executed as part of a > close() that I don't understand. The commit() not executing is silently > ignored in driver, and nothing happens. Hence the failure on the creation > of the table. > > Ok, so that might have been a bug. > > Swap the comments of > > DataSource dataSource = dbcpDataSource( host, port ); > // DataSource dataSource = rawDataSource(host,port); > > > and the test case works. Now, that could possibly be that there is an > autoCommit going on. I have not investigated that. > > Swap those comments back to original, and the test fails (after manually > cleaning up the database). > > Finally, swap the > > TransactionProvider transactionProvider = new > PolygeneTransactionProvider( new ThreadLocalTransactionProvider( > connectionProvider, false ) ); > // TransactionProvider transactionProvider = new > ThreadLocalTransactionProvider( connectionProvider, false ); > > > and the testcase also works. The wrapper couldn't be simpler, but why does > that cause a failure of this nature? Why is JOOQ checking the instance type > for behavior, instead of having proper methods for it? > > > > > package org.hedhman.niclas; > > import javax.sql.DataSource; > import org.apache.commons.dbcp2.BasicDataSource; > import org.jooq.Configuration; > import org.jooq.ConnectionProvider; > import org.jooq.DSLContext; > import org.jooq.Field; > import org.jooq.Name; > import org.jooq.SQLDialect; > import org.jooq.Schema; > import org.jooq.TransactionContext; > import org.jooq.TransactionProvider; > import org.jooq.conf.RenderNameStyle; > import org.jooq.conf.Settings; > import org.jooq.exception.DataAccessException; > import org.jooq.impl.DSL; > import org.jooq.impl.DataSourceConnectionProvider; > import org.jooq.impl.DefaultConfiguration; > import org.jooq.impl.ThreadLocalTransactionProvider; > import org.junit.Test; > import org.postgresql.ds.PGSimpleDataSource; > import org.postgresql.jdbc.AutoSave; > > > import static org.apache.polygene.entitystore.sql.TableFields.ta > bleNameColumn; > import static org.apache.polygene.entitystore.sql.TypesTable.makeField; > > public class Experiment > { > @Test > public void test1() > throws Exception > { > String host = "127.0.0.1"; > int port = 5432; > DataSource dataSource = dbcpDataSource( host, port ); > // DataSource dataSource = rawDataSource(host,port); > Settings settings = new Settings().withRenderNameStyle( RenderNameStyle.QUOTED > ); > SQLDialect dialect = SQLDialect.POSTGRES; > Schema schema = DSL.schema( DSL.name( "POLYGENE" ) ); > > ConnectionProvider connectionProvider = new DataSourceConnectionProvider( > dataSource ); > TransactionProvider transactionProvider = new PolygeneTransactionProvider( > new ThreadLocalTransactionProvider( connectionProvider, false ) ); > // TransactionProvider transactionProvider = new > ThreadLocalTransactionProvider( connectionProvider, false ); > Configuration configuration = new DefaultConfiguration() > .set( dialect ) > .set( connectionProvider ) > .set( transactionProvider ) > .set( settings ); > > DSLContext dsl = DSL.using( configuration ); > > Field<String> identityColumn = makeField( "_identity", String.class ); > Name tableName = DSL.name( schema.getName(), "TESTTABLE" ); > > dsl.transaction( t -> { > dsl.createSchema( "POLYGENE" ).execute(); > } ); > > dsl.transaction( t -> { > > dsl.createTableIfNotExists( tableName ) > .column( identityColumn ) > .execute(); > }); > } > private DataSource dbcpDataSource( String host, int port ) > throws Exception > { > BasicDataSource pool = new BasicDataSource(); > > String driverClass = "org.postgresql.Driver"; > Class.forName( driverClass ); > pool.setDriverClassName( driverClass ); > pool.setUrl( "jdbc:postgresql://" + host + ":" + port + "/jdbc_test_db" ); > pool.setUsername( System.getProperty( "user.name" ) ); > pool.setPassword( "ThisIsGreat!" ); > pool.setDefaultAutoCommit( false ); > return pool; > } > > private DataSource rawDataSource( String host, int port ) > throws Exception > { > PGSimpleDataSource datasource = new PGSimpleDataSource(); > datasource.setUser( System.getProperty( "user.name" ) ); > datasource.setPassword( "ThisIsGreat!" ); > datasource.setAutosave( AutoSave.NEVER ); > datasource.setUrl( "jdbc:postgresql://" + host + ":" + port + "/jdbc_test_db" > ); > return datasource; > } > > static class PolygeneTransactionProvider > implements TransactionProvider > { > > private TransactionProvider delegate; > > private PolygeneTransactionProvider( TransactionProvider delegate ) > { > this.delegate = delegate; > } > > @Override > public void begin( TransactionContext ctx ) > throws DataAccessException > { > System.out.println( "\"------------------------------> begin( " + ctx + " > )" ); > delegate.begin( ctx ); > } > > @Override > public void commit( TransactionContext ctx ) > throws DataAccessException > { > System.out.println( "------------------------------> commit( " + ctx + " > )" ); > delegate.commit( ctx ); > } > > @Override > public void rollback( TransactionContext ctx ) > throws DataAccessException > { > System.out.println( "\"------------------------------> rollback( " + ctx > + " )" ); > delegate.rollback( ctx ); > } > } > } > > > > > -- > You received this message because you are subscribed to the Google Groups > "jOOQ User Group" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "jOOQ User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
