Digest for jooq-user@googlegroups.com - 1 update in 1 topic

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Digest for jooq-user@googlegroups.com - 1 update in 1 topic

http://groups.google.com/group/jooq-user/topics mailing list
Niclas Hedhman <[hidden email]>: Oct 23 11:49AM +0800

Thanks a lot for looking into this. It has been driving my nuts... Also
want to express my gratitude for JOOQ, as I am really really sick and tired
of JPA/Hibernate and variants.
 
 
The real reason behind the wrapper was to try to locate why my code (Apache
Polygene[1] extension in the works) doesn't work.
 
The actual code segment not working is;
 
dsl.transaction( t -> {
if( dsl.isSchemaCapable()
&& dsl.meta().getSchemas().stream().noneMatch( s ->
schema.getName().equalsIgnoreCase( s.getName() ) ) )
{
dsl.createSchema( schemaName ).execute();
}
 
} );
 
 
NOTE; the dsl is an 'enhanced' type on my side. Apache Polygene is capable
of adding mixins/aspects/traits, so we have an extended interface, but
backed by your implementation (See at bottom, can be confusing)
 
This is for a "SQL Entity Store extension"[2] to bring "proper" SQL to our
capabilities (we have 12 other Entity Store impls as well).
 
The problem in the code above is that the schema is not created. The
commit() at Postgres driver level happens, but before that call, there has
been a "close()", seemingly do to some "keep" variable stating "false"
(don't recall the exact details here). And the driver rollbacks the
transaction during the close, and doesn't warn or anything about the
commit() that is just 'lost'. AT first I tried to extract sequencing and
specifics with the wrapper, but that ended up influencing the behavior.
 
I have still not solved the actual problem, and next time I dig in it
(different pool implementations, different JDBC drivers), I will try to
provide more feedback of my findings, because it just doesn't seem right.
 
Oh yeah, if I turn on auto-commit, my entire implementation "works", but
with it disabled there are several different problems in my stuff, and I
don't think all of that is on my side of the equation, and think that there
might be some JOOQ issues as well. But JOOQ is helping so much that instead
of giving up, I want to assist in fixing these, rather than going
JDBC-native. Unfortunately, only work on this on spare time.
 
[1] https://github.com/apache/polygene-java
[2]
https://github.com/apache/polygene-java/tree/es-sql/extensions/entitystore-sql
 
 
 
Cheers
Niclas
 
P.S. If you are interested in what we are doing, perhaps first read
https://hedhman.wordpress.com/2017/05/10/introducing-apache-polygene/
 
P.P.S If you want to debug, I think checking out the entire repository and
the "es-sql" branch, then go to extensions/entitystore-sql and run
"../../gradlew build check" should work without additional setup. I have
focused on the problems in the Postgres test variant.
 
@Mixins( JooqDslContext.Mixin.class )
public interface JooqDslContext extends DSLContext
{
boolean isSchemaCapable();
 
Name tableNameOf( String tableName );
 
Table<Record> tableOf( String tableName );
 
class Mixin
implements InvocationHandler
{
private final Schema schema;
private final DSLContext dsl;
 
public Mixin( @Service DataSource dataSource, @Uses Settings
settings, @Uses SQLDialect dialect, @Uses Schema schema )
{
this.schema = schema;
ConnectionProvider connectionProvider = new
DataSourceConnectionProvider( dataSource );
TransactionProvider transactionProvider = new
ThreadLocalTransactionProvider( connectionProvider, false );
Configuration configuration = new DefaultConfiguration()
.set( dialect )
.set( connectionProvider )
.set( transactionProvider )
.set( settings );
dsl = DSL.using( configuration );
}
 
@Override
public Object invoke( Object o, Method method, Object[] args )
throws Throwable
{
if( method.getName().equals( "tableOf" ) )
{
return DSL.table( tableNameOf( (String) args[ 0 ] ) );
}
if( method.getName().equals( "tableNameOf" ) )
{
return tableNameOf( (String) args[ 0 ] );
}
 
if( method.getName().equals( "isSchemaCapable" ) )
{
return isSchemaCapable();
}
return method.invoke( dsl, args ); // delegate all
}
 
private Name tableNameOf( String name )
{
return this.isSchemaCapable() ? DSL.name(
schema.getName(), name ) : DSL.name( name );
}
 
private boolean isSchemaCapable()
{
return !dsl.dialect().equals( SQLDialect.SQLITE ) &&
!dsl.dialect().equals( SQLDialect.MYSQL );
}
}
}
 
 
// instantiation of the above;
 
SqlEntityStoreConfiguration config = this.configuration.get(); // our
configuration
SQLDialect dialect = getSqlDialect( config ); // just convert String
and deals with null value.
Settings settings = serviceDescriptor
.metaInfo( Settings.class ); // metaInfo is set
'onto' services during bootstrap (see below).
// set to new
Settings().withRenderNameStyle( RenderNameStyle.QUOTED )
 
String schemaName = config.schemaName().get();
String typesTableName = config.typesTableName().get();
String entitiesTableName = config.entitiesTableName().get();
Schema schema = DSL.schema( DSL.name( schemaName ) );
 
// tbf is a factory for instantiation of transient
(mutable/non-persistable) composites (objects)
// the additional args are mapped to '@Uses" parameter in constructor
dsl = tbf.newTransient( JooqDslContext.class, settings, dialect, schema );
 
 
 
 
 
 
--
Niclas Hedhman, Software Developer
http://polygene.apache.org - New Energy for Java
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to [hidden email].