Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-11262 - Bulk Operations attempt to create temporary tables, but u…
…ser does not have permission to create table
- Loading branch information
1 parent
8f6e4d5
commit d48f393
Showing
43 changed files
with
2,348 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
hibernate-core/src/main/java/org/hibernate/hql/spi/id/AbstractIdsBulkIdHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.hql.spi.id; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.hibernate.JDBCException; | ||
import org.hibernate.dialect.Dialect; | ||
import org.hibernate.engine.jdbc.spi.JdbcServices; | ||
import org.hibernate.engine.spi.QueryParameters; | ||
import org.hibernate.engine.spi.SessionFactoryImplementor; | ||
import org.hibernate.engine.spi.SharedSessionContractImplementor; | ||
import org.hibernate.hql.internal.ast.HqlSqlWalker; | ||
import org.hibernate.hql.internal.ast.tree.AbstractRestrictableStatement; | ||
import org.hibernate.hql.internal.ast.tree.FromElement; | ||
import org.hibernate.param.ParameterSpecification; | ||
import org.hibernate.persister.entity.Queryable; | ||
|
||
/** | ||
* Base class for all strategies that select the ids to be updated/deleted prior to executing the update/delete operation. | ||
* | ||
* @author Vlad Mihalcea | ||
*/ | ||
public abstract class AbstractIdsBulkIdHandler | ||
extends AbstractTableBasedBulkIdHandler { | ||
|
||
private final Queryable targetedPersister; | ||
|
||
private final String idSelect; | ||
private final List<ParameterSpecification> idSelectParameterSpecifications; | ||
|
||
public AbstractIdsBulkIdHandler( | ||
SessionFactoryImplementor sessionFactory, HqlSqlWalker walker) { | ||
super(sessionFactory, walker); | ||
|
||
final AbstractRestrictableStatement statement = (AbstractRestrictableStatement) walker.getAST(); | ||
final FromElement fromElement = statement.getFromClause().getFromElement(); | ||
|
||
this.targetedPersister = fromElement.getQueryable(); | ||
|
||
final ProcessedWhereClause processedWhereClause = processWhereClause( statement.getWhereClause() ); | ||
this.idSelectParameterSpecifications = processedWhereClause.getIdSelectParameterSpecifications(); | ||
|
||
final String bulkTargetAlias = fromElement.getTableAlias(); | ||
|
||
this.idSelect = generateIdSelect( bulkTargetAlias, processedWhereClause ).toStatementString(); | ||
} | ||
|
||
@Override | ||
public Queryable getTargetedQueryable() { | ||
return targetedPersister; | ||
} | ||
|
||
protected Dialect dialect() { | ||
return factory().getServiceRegistry().getService( JdbcServices.class ).getDialect(); | ||
} | ||
|
||
protected JDBCException convert( | ||
SQLException e, | ||
String message, | ||
String sql) { | ||
throw factory().getServiceRegistry().getService( JdbcServices.class ).getSqlExceptionHelper().convert( e, message, sql ); | ||
} | ||
|
||
protected List<Object[]> selectIds( | ||
SharedSessionContractImplementor session, | ||
QueryParameters queryParameters) { | ||
List<Object[]> ids = new ArrayList<>(); | ||
try { | ||
try (PreparedStatement ps = session.getJdbcCoordinator() | ||
.getStatementPreparer() | ||
.prepareStatement( idSelect, false )) { | ||
int position = 1; | ||
for ( ParameterSpecification parameterSpecification : idSelectParameterSpecifications ) { | ||
position += parameterSpecification.bind( ps, queryParameters, session, position ); | ||
} | ||
|
||
ResultSet rs = session | ||
.getJdbcCoordinator() | ||
.getResultSetReturn() | ||
.extract( ps ); | ||
while ( rs.next() ) { | ||
Object[] result = new Object[targetedPersister.getIdentifierColumnNames().length]; | ||
for ( String columnName : targetedPersister.getIdentifierColumnNames() ) { | ||
Object column = rs.getObject( columnName ); | ||
result[rs.findColumn( columnName ) - 1] = column; | ||
} | ||
ids.add( result ); | ||
} | ||
} | ||
} | ||
catch ( SQLException e ) { | ||
throw convert( e, "could not select ids for bulk operation", idSelect ); | ||
} | ||
|
||
return ids; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...e-core/src/main/java/org/hibernate/hql/spi/id/cte/AbstractCteValuesListBulkIdHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.hql.spi.id.cte; | ||
|
||
import org.hibernate.boot.model.naming.Identifier; | ||
import org.hibernate.boot.model.relational.QualifiedTableName; | ||
import org.hibernate.dialect.Dialect; | ||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; | ||
import org.hibernate.engine.jdbc.spi.JdbcServices; | ||
import org.hibernate.engine.spi.QueryParameters; | ||
import org.hibernate.engine.spi.SessionFactoryImplementor; | ||
import org.hibernate.engine.spi.SharedSessionContractImplementor; | ||
import org.hibernate.hql.internal.ast.HqlSqlWalker; | ||
import org.hibernate.hql.spi.id.AbstractIdsBulkIdHandler; | ||
import org.hibernate.persister.entity.Queryable; | ||
|
||
/** | ||
* Defines how identifier values are selected from the updatable/deletable tables. | ||
* | ||
* @author Evandro Pires da Silva | ||
* @author Vlad Mihalcea | ||
*/ | ||
public abstract class AbstractCteValuesListBulkIdHandler extends | ||
AbstractIdsBulkIdHandler { | ||
|
||
private final String catalog; | ||
private final String schema; | ||
|
||
private final JdbcEnvironment jdbcEnvironment; | ||
|
||
public AbstractCteValuesListBulkIdHandler( | ||
SessionFactoryImplementor sessionFactory, HqlSqlWalker walker, | ||
String catalog, String schema) { | ||
super( sessionFactory, walker ); | ||
Dialect dialect = sessionFactory.getServiceRegistry().getService( JdbcServices.class ).getDialect(); | ||
if ( !dialect.supportsNonQueryWithCTE() ) { | ||
throw new UnsupportedOperationException( | ||
"The " + getClass().getSimpleName() + | ||
" can only be used with Dialects that support CTE that can take UPDATE or DELETE statements as well!" | ||
); | ||
} | ||
if ( !dialect.supportsValuesList() ) { | ||
throw new UnsupportedOperationException( | ||
"The " + getClass().getSimpleName() + | ||
" can only be used with Dialects that support VALUES lists!" | ||
); | ||
} | ||
if ( !dialect.supportsRowValueConstructorSyntaxInInList() ) { | ||
throw new UnsupportedOperationException( | ||
"The " + getClass().getSimpleName() + | ||
" can only be used with Dialects that support IN clause row-value expressions (for composite identifiers)!" | ||
); | ||
} | ||
|
||
this.jdbcEnvironment = sessionFactory.getServiceRegistry().getService( | ||
JdbcServices.class ).getJdbcEnvironment(); | ||
this.catalog = catalog; | ||
this.schema = schema; | ||
} | ||
|
||
protected String determineIdTableName(Queryable persister) { | ||
return jdbcEnvironment.getQualifiedObjectNameFormatter().format( | ||
new QualifiedTableName( | ||
Identifier.toIdentifier( catalog ), | ||
Identifier.toIdentifier( schema ), | ||
Identifier.toIdentifier( "HT_" + persister.getTableName() ) | ||
), | ||
jdbcEnvironment.getDialect() | ||
); | ||
} | ||
|
||
protected String generateIdSubselect(Queryable persister) { | ||
return new StringBuilder() | ||
.append( "select " ) | ||
.append( String.join( | ||
", ", | ||
(CharSequence[]) persister.getIdentifierColumnNames() | ||
) ) | ||
.append( " from " ) | ||
.append( determineIdTableName( persister ) ) | ||
.toString(); | ||
} | ||
|
||
protected CteValuesListBuilder prepareCteStatement( | ||
SharedSessionContractImplementor session, | ||
QueryParameters queryParameters) { | ||
|
||
return new CteValuesListBuilder( | ||
determineIdTableName( getTargetedQueryable() ), | ||
getTargetedQueryable().getIdentifierColumnNames(), | ||
selectIds( session, queryParameters ) | ||
); | ||
} | ||
} |
Oops, something went wrong.