Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Dec 10, 2024
1 parent 029a48c commit aa35975
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ protected <T> T processSchemaResultSet(
final List<Object> parameters = new ArrayList<>();
appendClauseAndParameterIfNotNullOrEmpty( " and catalog_name = ", catalog, sb, parameters );
appendClauseAndParameterIfNotNullOrEmpty( " and schema_name like ", schemaPattern, sb, parameters );
return getExtractionContext().getQueryResults( sb.toString(), parameters.toArray(), processor );
return getExtractionContext().getQueryResults(
sb.toString(),
parameters.toArray(),
processor
);
}

protected boolean appendClauseAndParameterIfNotNullOrEmpty(
Expand All @@ -195,12 +199,16 @@ protected boolean appendClauseAndParameterIfNotNullOrEmpty(
if ( parameter != null && ( ! String.class.isInstance( parameter ) || ! ( (String) parameter ).isEmpty() ) ) {
parameters.add( parameter );
sb.append( clause );
sb.append( "?");
sb.append( parameterMarker( parameters.size() ) );
return true;
}
return false;
}

protected String parameterMarker(int pos) {
return "?";
}

@Override
protected <T> T processTableResultSet(
String catalog,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ protected <T> T processIndexInfoResultSet(
appendClauseAndParameterIfNotNullOrEmpty( " and ui.table_owner = ", schema, sb, parameters );
appendClauseAndParameterIfNotNullOrEmpty( " and ui.table_name = ", table, sb, parameters );


return getExtractionContext().getQueryResults( sb.toString(), parameters.toArray(), processor );
}

@Override
protected String parameterMarker(int pos) {
return ":" + pos;
}


@Override
protected <T> T processImportedKeysResultSet(
String catalog,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ protected <T> T processIndexInfoResultSet(
);
}

@Override
protected String parameterMarker(int pos) {
return "$" + pos;
}

@Override
protected <T> T processImportedKeysResultSet(
String catalog,
Expand Down Expand Up @@ -135,7 +140,6 @@ protected <T> T processImportedKeysResultSet(

// No need to order by catalog since it is always null.
sb.append( " order by pkn.nspname, pkc.relname, con.conname, pos.n" );

return getExtractionContext().getQueryResults( sb.toString(), parameterValues.toArray(), processor );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ protected <T> T processTableResultSet(
return getExtractionContext().getQueryResults( sb.toString(), parameterValues.toArray(), processor );
}


@Override
protected String parameterMarker(int pos) {
return "@P" + pos;
}

@Override
protected <T> T processColumnsResultSet(
String catalog,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hibernate.query.sql.spi.ParameterOccurrence;
import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter;
import org.hibernate.reactive.engine.spi.ReactiveSharedSessionContractImplementor;
import org.hibernate.reactive.pool.impl.Parameters;
import org.hibernate.reactive.query.sql.spi.ReactiveNonSelectQueryPlan;
import org.hibernate.reactive.sql.exec.internal.StandardReactiveJdbcMutationExecutor;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
Expand Down Expand Up @@ -71,8 +72,9 @@ public CompletionStage<Integer> executeReactiveUpdate(DomainQueryExecutionContex

final SQLQueryParser parser = new SQLQueryParser( sql, null, session.getFactory() );

Parameters parameters = Parameters.instance( session.getDialect() );
final JdbcOperationQueryMutation jdbcMutation = new JdbcOperationQueryMutationNative(
parser.process(),
parameters.process( parser.process() ),
jdbcParameterBinders,
affectedTableNames
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Set;
import java.util.concurrent.CompletionStage;

import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.results.ResultSetMapping;
import org.hibernate.query.spi.DomainQueryExecutionContext;
Expand All @@ -22,6 +23,7 @@
import org.hibernate.query.sql.spi.ParameterOccurrence;
import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter;
import org.hibernate.reactive.engine.spi.ReactiveSharedSessionContractImplementor;
import org.hibernate.reactive.pool.impl.Parameters;
import org.hibernate.reactive.query.internal.ReactiveResultSetMappingProcessor;
import org.hibernate.reactive.query.spi.ReactiveNativeSelectQueryPlan;
import org.hibernate.reactive.sql.exec.internal.StandardReactiveSelectExecutor;
Expand Down Expand Up @@ -59,7 +61,8 @@ public ReactiveNativeSelectQueryPlanImpl(
resultSetMapping.addAffectedTableNames( affectedTableNames, sessionFactory );
}
this.affectedTableNames = affectedTableNames;
this.sql = parser.process();
Dialect dialect = sessionFactory.getJdbcServices().getDialect();
this.sql = Parameters.instance( dialect ).process( parser.process() );
this.parameterList = parameterList;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ private CompletionStage<ResultSet> executeQuery() {
LOG.tracef( "Executing query to retrieve ResultSet : %s", getFinalSql() );

Dialect dialect = executionContext.getSession().getJdbcServices().getDialect();
// I'm not sure calling Parameters here is necessary, the query should already have the right parameters
final String sql = getFinalSql();
Object[] parameters = PreparedStatementAdaptor.bind( super::bindParameters );

Expand Down

0 comments on commit aa35975

Please sign in to comment.