Skip to content

Fix for creation and dropping options of ids temporary tables #2109

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

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

public interface ReactiveGlobalTemporaryTableStrategy {

Log LOG = make( Log.class, lookup() );

static String sessionIdentifier(SharedSessionContractImplementor session) {
return session.getSessionIdentifier().toString();
}
Expand Down Expand Up @@ -65,22 +63,23 @@ default void prepare(MappingModelCreationProcess mappingModelCreationProcess, Jd
if ( !createIdTables ) {
tableCreatedStage.complete( null );
}

LOG.debugf( "Creating global-temp ID table : %s", getTemporaryTable().getTableExpression() );

connectionStage()
.thenCompose( this::createTable )
.whenComplete( (connection, throwable) -> releaseConnection( connection )
.thenAccept( v -> {
if ( throwable == null ) {
setDropIdTables( configService );
tableCreatedStage.complete( null );
}
else {
tableCreatedStage.completeExceptionally( throwable );
}
} )
);
else {
make( Log.class, lookup() ).debugf( "Creating global-temp ID table : %s", getTemporaryTable().getTableExpression() );

connectionStage()
.thenCompose( this::createTable )
.whenComplete( (connection, throwable) -> releaseConnection( connection )
.thenAccept( v -> {
if ( throwable == null ) {
setDropIdTables( configService );
tableCreatedStage.complete( null );
}
else {
tableCreatedStage.completeExceptionally( throwable );
}
} )
);
}
}

private CompletionStage<Void> releaseConnection(ReactiveConnection connection) {
Expand All @@ -103,7 +102,7 @@ private CompletionStage<Void> releaseConnection(ReactiveConnection connection) {

private static void logConnectionClosedError(Throwable t) {
if ( t != null ) {
LOG.debugf( "Ignoring error closing the connection: %s", t.getMessage() );
make( Log.class, lookup() ).debugf( "Ignoring error closing the connection: %s", t.getMessage() );
}
}

Expand Down Expand Up @@ -147,24 +146,25 @@ default void release(
if ( !isDropIdTables() ) {
tableDroppedStage.complete( null );
}

setDropIdTables( false );

final TemporaryTable temporaryTable = getTemporaryTable();
LOG.debugf( "Dropping global-tempk ID table : %s", temporaryTable.getTableExpression() );

connectionStage()
.thenCompose( this::dropTable )
.whenComplete( (connection, throwable) -> releaseConnection( connection )
.thenAccept( v -> {
if ( throwable == null ) {
tableDroppedStage.complete( null );
}
else {
tableDroppedStage.completeExceptionally( throwable );
}
} )
);
else {
setDropIdTables( false );

final TemporaryTable temporaryTable = getTemporaryTable();
make( Log.class, lookup() ).debugf( "Dropping global-tempk ID table : %s", temporaryTable.getTableExpression() );

connectionStage()
.thenCompose( this::dropTable )
.whenComplete( (connection, throwable) -> releaseConnection( connection )
.thenAccept( v -> {
if ( throwable == null ) {
tableDroppedStage.complete( null );
}
else {
tableDroppedStage.completeExceptionally( throwable );
}
} )
);
}
}

private CompletionStage<ReactiveConnection> dropTable(ReactiveConnection connection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,23 @@ default void prepare(MappingModelCreationProcess mappingModelCreationProcess, Jd
if ( !createIdTables ) {
tableCreatedStage.complete( null );
}

LOG.debugf( "Creating persistent ID table : %s", getTemporaryTable().getTableExpression() );

connectionStage()
.thenCompose( this::createTable )
.whenComplete( (connection, throwable) -> releaseConnection( connection )
.thenAccept( v -> {
if ( throwable == null ) {
setDropIdTables( configService );
tableCreatedStage.complete( null );
}
else {
tableCreatedStage.completeExceptionally( throwable );
}
} )
);
else {
LOG.debugf( "Creating persistent ID table : %s", getTemporaryTable().getTableExpression() );

connectionStage()
.thenCompose( this::createTable )
.whenComplete( (connection, throwable) -> releaseConnection( connection )
.thenAccept( v -> {
if ( throwable == null ) {
setDropIdTables( configService );
tableCreatedStage.complete( null );
}
else {
tableCreatedStage.completeExceptionally( throwable );
}
} )
);
}
}

private CompletionStage<Void> releaseConnection(ReactiveConnection connection) {
Expand Down Expand Up @@ -150,24 +151,25 @@ default void release(
if ( !isDropIdTables() ) {
tableDroppedStage.complete( null );
}

setDropIdTables( false );

final TemporaryTable temporaryTable = getTemporaryTable();
LOG.debugf( "Dropping persistent ID table : %s", temporaryTable.getTableExpression() );

connectionStage()
.thenCompose( this::dropTable )
.whenComplete( (connection, throwable) -> releaseConnection( connection )
.thenAccept( v -> {
if ( throwable == null ) {
tableDroppedStage.complete( null );
}
else {
tableDroppedStage.completeExceptionally( throwable );
}
} )
);
else {
setDropIdTables( false );

final TemporaryTable temporaryTable = getTemporaryTable();
LOG.debugf( "Dropping persistent ID table : %s", temporaryTable.getTableExpression() );

connectionStage()
.thenCompose( this::dropTable )
.whenComplete( (connection, throwable) -> releaseConnection( connection )
.thenAccept( v -> {
if ( throwable == null ) {
tableDroppedStage.complete( null );
}
else {
tableDroppedStage.completeExceptionally( throwable );
}
} )
);
}
}

private CompletionStage<ReactiveConnection> dropTable(ReactiveConnection connection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,8 @@ public TemporaryTableCreationWork(

@Override
public CompletionStage<Void> reactiveExecute(ReactiveConnection connection) {
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();

try {
final String creationCommand = exporter.getSqlCreateCommand( temporaryTable );
logStatement( creationCommand, jdbcServices );

return connection.executeUnprepared( creationCommand )
.handle( (integer, throwable) -> {
Expand Down Expand Up @@ -115,11 +112,8 @@ public TemporaryTableDropWork(

@Override
public CompletionStage<Void> reactiveExecute(ReactiveConnection connection) {
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();

try {
final String dropCommand = exporter.getSqlDropCommand( temporaryTable );
logStatement( dropCommand, jdbcServices );

return connection.update( dropCommand )
.handle( (integer, throwable) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableStrategy;
import org.hibernate.query.sqm.mutation.internal.temptable.PersistentTableStrategy;
import org.hibernate.reactive.containers.DatabaseConfiguration;
import org.hibernate.reactive.containers.DatabaseConfiguration.DBType;
import org.hibernate.reactive.mutiny.Mutiny;
Expand Down Expand Up @@ -105,6 +107,8 @@ public static void setDefaultProperties(Configuration configuration) {
configuration.setProperty( Settings.SHOW_SQL, System.getProperty( Settings.SHOW_SQL, "false" ) );
configuration.setProperty( Settings.FORMAT_SQL, System.getProperty( Settings.FORMAT_SQL, "false" ) );
configuration.setProperty( Settings.HIGHLIGHT_SQL, System.getProperty( Settings.HIGHLIGHT_SQL, "true" ) );
configuration.setProperty( PersistentTableStrategy.DROP_ID_TABLES, "true" );
configuration.setProperty( GlobalTemporaryTableStrategy.DROP_ID_TABLES, "true" );
}

public static final SessionFactoryManager factoryManager = new SessionFactoryManager();
Expand Down
Loading
Loading