Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema export via reactive driver #112

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ subprojects {
// which can be useful to monitor compatibility for upcoming versions on CI:
// ./gradlew clean build -PhibernateOrmVersion=5.4.9-SNAPSHOT
ext {
hibernateOrmVersion = '5.4.14.Final'
hibernateOrmVersion = '5.5.0-SNAPSHOT'
}


Expand Down
2 changes: 0 additions & 2 deletions hibernate-rx-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ dependencies {

testImplementation 'org.assertj:assertj-core:3.13.2'
testImplementation 'io.vertx:vertx-unit:3.8.1'
testImplementation 'org.postgresql:postgresql:42.2.12'
testImplementation 'mysql:mysql-connector-java:8.0.19'
testImplementation 'org.testcontainers:postgresql:1.13.0'
testImplementation 'org.testcontainers:mysql:1.13.0'
testImplementation 'org.slf4j:slf4j-log4j12:1.7.30'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ else if (identifierGenerator instanceof SelectGenerator) {
throw new HibernateException("SelectGenerator is not yet supported");
}
else if (identifierGenerator instanceof IdentityGenerator) {
if (!creationContext.getSessionFactory().getSessionFactoryOptions()
.isGetGeneratedKeysEnabled()
&& !creationContext.getSessionFactory().getJdbcServices().getDialect()
.getIdentityColumnSupport().supportsInsertSelectIdentity() ) {
throw new HibernateException("getGeneratedKeys() is disabled");
}
// if (!creationContext.getSessionFactory().getSessionFactoryOptions()
// .isGetGeneratedKeysEnabled()
// && !creationContext.getSessionFactory().getJdbcServices().getDialect()
// .getIdentityColumnSupport().supportsInsertSelectIdentity() ) {
// throw new HibernateException("getGeneratedKeys() is disabled");
// }
return f -> RxUtil.nullFuture();
}
else if (identifierGenerator instanceof Assigned
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.hibernate.rx.service;

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;

import java.sql.Connection;
import java.sql.SQLException;

public class RxDummyConnectionProvider implements ConnectionProvider {
@Override
public Connection getConnection() throws SQLException {
throw new SQLException("Not using JDBC");
}

@Override
public void closeConnection(Connection conn) {}

@Override
public boolean supportsAggressiveRelease() {
return false;
}

@Override
public boolean isUnwrappableAs(Class unwrapType) {
return false;
}

@Override
public <T> T unwrap(Class<T> unwrapType) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.hibernate.rx.service;

import org.hibernate.rx.service.initiator.RxConnectionPoolProvider;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.schema.internal.exec.GenerationTarget;

/**
* Adaptor that redirects DDL generated by the schema export
* tool to the reactive connection.
*
* @author Gavin King
*/
public class RxGenerationTarget implements GenerationTarget {
RxConnection connection;
private ServiceRegistry registry;

public RxGenerationTarget(ServiceRegistry registry) {
this.registry = registry;
}

@Override
public void prepare() {
connection = registry.getService( RxConnectionPoolProvider.class ).getConnection();
}

@Override
public void accept(String command) {
try {
connection.preparedQuery(command).toCompletableFuture().join();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vietj @FroMage @Sanne @DavideD WDYT of this?

I want to run Schema Export against the Vert.x driver, but I don't need it to actually be reactive. Also, I don't want to rewrite all of Hibernate's schema export stuff to use CompletionStage or whatever.

This seems to work fine, except with the @RunWith(VertxUnitRunner.class) where sometimes I get a harmless stacktrace from Vert.x at the end of my test.

Is this for some reason a terrible thing to be doing? Is there some other way we should be doing it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gavinking What's the stack trace complaining about? Is it the Vertx blocked thread checker? If that's the case, I think we can safely ignore that because we are intending to be blocking here. To silence the blocked thread checker, we could use our own Vertx instance where we can set the blocked thread checker interval to a really high value like so:

    VertxOptions vertxOptions = new VertxOptions();
    vertxOptions.setBlockedThreadCheckInterval(600);
    vertxOptions.setBlockedThreadCheckIntervalUnit(TimeUnit.MINUTES);
    Vertx vertx = Vertx.vertx(vertxOptions);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it looks to me like Vert.x shuts down the thread because it thinks it's misbehaving.

Let's try your suggestion. Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aguibert so I looked for a place to set this up in VertxUnitRunner and didn't find anything obvious. @vietj any suggestion?

}
catch (Exception e) {
System.out.println( e.getMessage() );
}
}

@Override
public void release() {
connection.close();
connection = null;
}
}
10 changes: 10 additions & 0 deletions hibernate-rx-core/src/test/java/org/hibernate/rx/BaseRxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.rx.containers.PostgreSQLDatabase;
import org.hibernate.rx.service.RxConnection;
import org.hibernate.rx.service.RxGenerationTarget;
import org.hibernate.rx.service.initiator.RxConnectionPoolProvider;
import org.hibernate.rx.service.RxDummyConnectionProvider;
import org.hibernate.rx.util.impl.RxUtil;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -49,15 +54,20 @@ protected Configuration constructConfiguration() {
configuration.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
configuration.setProperty( AvailableSettings.URL, PostgreSQLDatabase.getJdbcUrl() );
configuration.setProperty( AvailableSettings.SHOW_SQL, "true" );
configuration.setProperty( AvailableSettings.DIALECT, PostgreSQL81Dialect.class.getName() );
return configuration;
}

@Before
public void before() {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.applySettings( constructConfiguration().getProperties() )
.addService( ConnectionProvider.class, new RxDummyConnectionProvider() )
.build();

registry.getService( SchemaManagementTool.class )
.setCustomDatabaseGenerationTarget( new RxGenerationTarget(registry) );

sessionFactory = constructConfiguration().buildSessionFactory( registry );
poolProvider = registry.getService( RxConnectionPoolProvider.class );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class MySQLAutoincrementTest extends BaseRxTest {
protected Configuration constructConfiguration() {
Configuration configuration = super.constructConfiguration();
configuration.setProperty( AvailableSettings.URL, MySQLDatabase.getJdbcUrl() );
configuration.setProperty( AvailableSettings.DIALECT, MySQL8Dialect.class.getName());
configuration.setProperty( AvailableSettings.DIALECT, MySQL8Dialect.class.getName() );
configuration.addAnnotatedClass( Basic.class );
return configuration;
}
Expand Down