Skip to content

Commit

Permalink
schema export via reactive driver
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed May 13, 2020
1 parent 69f2b66 commit c3176ab
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 10 deletions.
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();
}
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

0 comments on commit c3176ab

Please sign in to comment.