Java Code Examples for org.hibernate.hql.internal.ast.HqlSqlWalker#getAST()
The following examples show how to use
org.hibernate.hql.internal.ast.HqlSqlWalker#getAST() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalTemporaryTableBulkIdStrategy.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public UpdateHandler buildUpdateHandler(SessionFactoryImplementor factory, HqlSqlWalker walker) { final UpdateStatement updateStatement = (UpdateStatement) walker.getAST(); final FromElement fromElement = updateStatement.getFromClause().getFromElement(); final Queryable targetedPersister = fromElement.getQueryable(); return new TableBasedUpdateHandlerImpl( factory, walker, getIdTableInfo( targetedPersister ) ) { @Override protected void releaseFromUse(Queryable persister, SharedSessionContractImplementor session) { if ( afterUseAction == AfterUseAction.NONE ) { return; } // clean up our id-table rows cleanUpRows( getIdTableInfo( persister ).getQualifiedIdTableName(), session ); } }; }
Example 2
Source File: GlobalTemporaryTableBulkIdStrategy.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public DeleteHandler buildDeleteHandler(SessionFactoryImplementor factory, HqlSqlWalker walker) { final DeleteStatement updateStatement = (DeleteStatement) walker.getAST(); final FromElement fromElement = updateStatement.getFromClause().getFromElement(); final Queryable targetedPersister = fromElement.getQueryable(); return new TableBasedDeleteHandlerImpl( factory, walker, getIdTableInfo( targetedPersister ) ) { @Override protected void releaseFromUse(Queryable persister, SharedSessionContractImplementor session) { if ( afterUseAction == AfterUseAction.NONE ) { return; } // clean up our id-table rows cleanUpRows( getIdTableInfo( persister ).getQualifiedIdTableName(), session ); } }; }
Example 3
Source File: PersistentTableBulkIdStrategy.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public UpdateHandler buildUpdateHandler(SessionFactoryImplementor factory, HqlSqlWalker walker) { final UpdateStatement updateStatement = (UpdateStatement) walker.getAST(); final FromElement fromElement = updateStatement.getFromClause().getFromElement(); final Queryable targetedPersister = fromElement.getQueryable(); return new UpdateHandlerImpl( factory, walker, getIdTableInfo( targetedPersister ) ); }
Example 4
Source File: PersistentTableBulkIdStrategy.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public DeleteHandler buildDeleteHandler(SessionFactoryImplementor factory, HqlSqlWalker walker) { final DeleteStatement updateStatement = (DeleteStatement) walker.getAST(); final FromElement fromElement = updateStatement.getFromClause().getFromElement(); final Queryable targetedPersister = fromElement.getQueryable(); return new DeleteHandlerImpl( factory, walker, getIdTableInfo( targetedPersister ) ); }
Example 5
Source File: TableBasedDeleteHandlerImpl.java From lams with GNU General Public License v2.0 | 4 votes |
public TableBasedDeleteHandlerImpl( SessionFactoryImplementor factory, HqlSqlWalker walker, IdTableInfo idTableInfo) { super( factory, walker ); DeleteStatement deleteStatement = ( DeleteStatement ) walker.getAST(); FromElement fromElement = deleteStatement.getFromClause().getFromElement(); this.targetedPersister = fromElement.getQueryable(); final String bulkTargetAlias = fromElement.getTableAlias(); final ProcessedWhereClause processedWhereClause = processWhereClause( deleteStatement.getWhereClause() ); this.idSelectParameterSpecifications = processedWhereClause.getIdSelectParameterSpecifications(); this.idInsertSelect = generateIdInsertSelect( bulkTargetAlias, idTableInfo, processedWhereClause ); log.tracev( "Generated ID-INSERT-SELECT SQL (multi-table delete) : {0}", idInsertSelect ); final String idSubselect = generateIdSubselect( targetedPersister, idTableInfo ); deletes = new ArrayList<>(); // If many-to-many, delete the FK row in the collection table. // This partially overlaps with DeleteExecutor, but it instead uses the temp table in the idSubselect. for ( Type type : targetedPersister.getPropertyTypes() ) { if ( type.isCollectionType() ) { CollectionType cType = (CollectionType) type; AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory.getMetamodel().collectionPersister( cType.getRole() ); if ( cPersister.isManyToMany() ) { deletes.add( generateDelete( cPersister.getTableName(), cPersister.getKeyColumnNames(), idSubselect, "bulk delete - m2m join table cleanup")); } } } String[] tableNames = targetedPersister.getConstraintOrderedTableNameClosure(); String[][] columnNames = targetedPersister.getContraintOrderedTableKeyColumnClosure(); for ( int i = 0; i < tableNames.length; i++ ) { // TODO : an optimization here would be to consider cascade deletes and not gen those delete statements; // the difficulty is the ordering of the tables here vs the cascade attributes on the persisters -> // the table info gotten here should really be self-contained (i.e., a class representation // defining all the needed attributes), then we could then get an array of those deletes.add( generateDelete( tableNames[i], columnNames[i], idSubselect, "bulk delete")); } }
Example 6
Source File: TableBasedUpdateHandlerImpl.java From lams with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("unchecked") public TableBasedUpdateHandlerImpl( SessionFactoryImplementor factory, HqlSqlWalker walker, IdTableInfo idTableInfo) { super( factory, walker ); final Dialect dialect = factory.getJdbcServices().getJdbcEnvironment().getDialect(); final UpdateStatement updateStatement = (UpdateStatement) walker.getAST(); final FromElement fromElement = updateStatement.getFromClause().getFromElement(); this.targetedPersister = fromElement.getQueryable(); final String bulkTargetAlias = fromElement.getTableAlias(); final ProcessedWhereClause processedWhereClause = processWhereClause( updateStatement.getWhereClause() ); this.idSelectParameterSpecifications = processedWhereClause.getIdSelectParameterSpecifications(); this.idInsertSelect = generateIdInsertSelect( bulkTargetAlias, idTableInfo, processedWhereClause ); log.tracev( "Generated ID-INSERT-SELECT SQL (multi-table update) : {0}", idInsertSelect ); String[] tableNames = targetedPersister.getConstraintOrderedTableNameClosure(); String[][] columnNames = targetedPersister.getContraintOrderedTableKeyColumnClosure(); String idSubselect = generateIdSubselect( targetedPersister, idTableInfo ); updates = new String[tableNames.length]; assignmentParameterSpecifications = new ParameterSpecification[tableNames.length][]; for ( int tableIndex = 0; tableIndex < tableNames.length; tableIndex++ ) { boolean affected = false; final List<ParameterSpecification> parameterList = new ArrayList<>(); final Update update = new Update( dialect ) .setTableName( tableNames[tableIndex] ) .setWhere( "(" + String.join( ", ", columnNames[tableIndex] ) + ") IN (" + idSubselect + ")" ); if ( factory().getSessionFactoryOptions().isCommentsEnabled() ) { update.setComment( "bulk update" ); } final List<AssignmentSpecification> assignmentSpecifications = walker.getAssignmentSpecifications(); for ( AssignmentSpecification assignmentSpecification : assignmentSpecifications ) { if ( assignmentSpecification.affectsTable( tableNames[tableIndex] ) ) { affected = true; update.appendAssignmentFragment( assignmentSpecification.getSqlAssignmentFragment() ); if ( assignmentSpecification.getParameters() != null ) { Collections.addAll( parameterList, assignmentSpecification.getParameters() ); } } } if ( affected ) { updates[tableIndex] = update.toStatementString(); assignmentParameterSpecifications[tableIndex] = parameterList.toArray( new ParameterSpecification[parameterList.size()] ); } } }
Example 7
Source File: AbstractIdsBulkIdHandler.java From lams with GNU General Public License v2.0 | 4 votes |
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(); }
Example 8
Source File: DeleteExecutor.java From lams with GNU General Public License v2.0 | 4 votes |
public DeleteExecutor(HqlSqlWalker walker, Queryable persister) { super( walker, persister ); final SessionFactoryImplementor factory = walker.getSessionFactoryHelper().getFactory(); final Dialect dialect = factory.getJdbcServices().getJdbcEnvironment().getDialect(); try { final DeleteStatement deleteStatement = (DeleteStatement) walker.getAST(); final String idSubselectWhere; if ( deleteStatement.hasWhereClause() ) { final AST whereClause = deleteStatement.getWhereClause(); final SqlGenerator gen = new SqlGenerator( factory ); gen.whereClause( whereClause ); parameterSpecifications = gen.getCollectedParameters(); idSubselectWhere = gen.getSQL().length() > 7 ? gen.getSQL() : ""; } else { parameterSpecifications = new ArrayList<>(); idSubselectWhere = ""; } // If many-to-many, delete the FK row in the collection table. for ( Type type : persister.getPropertyTypes() ) { if ( type.isCollectionType() ) { final CollectionType cType = (CollectionType) type; final AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory.getMetamodel().collectionPersister( cType.getRole() ); if ( cPersister.isManyToMany() ) { if ( persister.getIdentifierColumnNames().length > 1 && !dialect.supportsTuplesInSubqueries() ) { LOG.warn( "This dialect is unable to cascade the delete into the many-to-many join table" + " when the entity has multiple primary keys. Either properly setup cascading on" + " the constraints or manually clear the associations prior to deleting the entities." ); } else { final String idSubselect = "(select " + String.join( ", ", persister.getIdentifierColumnNames() ) + " from " + persister.getTableName() + idSubselectWhere + ")"; final String where = "(" + String.join( ", ", cPersister.getKeyColumnNames() ) + ") in " + idSubselect; final Delete delete = new Delete().setTableName( cPersister.getTableName() ).setWhere( where ); if ( factory.getSessionFactoryOptions().isCommentsEnabled() ) { delete.setComment( "delete FKs in join table" ); } deletes.add( delete.toStatementString() ); } } } } } catch (RecognitionException e) { throw new HibernateException( "Unable to delete the FKs in the join table!", e ); } }