public List<FromElement> toFromElements(FromClause fromClause, HqlSqlWalker walker) { // If a role already has an explicit fetch in the query, skip it in the graph. Map<String, FromElement> explicitFetches = new HashMap<String, FromElement>(); for ( Object o : fromClause.getFromElements() ) { final FromElement fromElement = (FromElement) o; if ( fromElement.getRole() != null ) { explicitFetches.put( fromElement.getRole(), fromElement ); } } return getFromElements( originEntityGraph.getAttributeNodes(), fromClause.getFromElement(), fromClause, walker, explicitFetches ); }
public AbstractTableBasedBulkIdHandler( SessionFactoryImplementor sessionFactory, HqlSqlWalker walker, String catalog, String schema) { this.sessionFactory = sessionFactory; this.walker = walker; this.catalog = catalog; this.schema = schema; }
public BasicExecutor(HqlSqlWalker walker, Queryable persister) { this.factory = walker.getSessionFactoryHelper().getFactory(); this.persister = persister; try { SqlGenerator gen = new SqlGenerator( factory ); gen.statement( walker.getAST() ); sql = gen.getSQL(); gen.getParseErrorHandler().throwQueryException(); parameterSpecifications = gen.getCollectedParameters(); } catch ( RecognitionException e ) { throw QuerySyntaxException.convert( e ); } }
public MultiTableUpdateExecutor(HqlSqlWalker walker) { MultiTableBulkIdStrategy strategy = walker.getSessionFactoryHelper() .getFactory() .getSettings() .getMultiTableBulkIdStrategy(); this.updateHandler = strategy.buildUpdateHandler( walker.getSessionFactoryHelper().getFactory(), walker ); }
public AbstractCTEBasedBulkIdHandler( SessionFactoryImplementor sessionFactory, HqlSqlWalker walker, String catalog, String schema) { this.sessionFactory = sessionFactory; this.walker = walker; this.catalog = catalog; this.schema = schema; }
public TableBasedDeleteHandlerImpl(SessionFactoryImplementor factory, HqlSqlWalker walker) { this( factory, walker, null, null ); }
public TableBasedDeleteHandlerImpl( SessionFactoryImplementor factory, HqlSqlWalker walker, String catalog, String schema) { super( factory, walker, catalog, schema ); 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( targetedPersister, bulkTargetAlias, processedWhereClause ); log.tracev( "Generated ID-INSERT-SELECT SQL (multi-table delete) : {0}", idInsertSelect ); final String idSubselect = generateIdSubselect( targetedPersister ); deletes = new ArrayList<String>(); // 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.getCollectionPersister( 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")); } }
@SuppressWarnings("unchecked") public TableBasedUpdateHandlerImpl(SessionFactoryImplementor factory, HqlSqlWalker walker) { this( factory, walker, null, null ); }
public TableBasedUpdateHandlerImpl( SessionFactoryImplementor factory, HqlSqlWalker walker, String catalog, String schema) { super( factory, walker, catalog, schema ); UpdateStatement updateStatement = ( UpdateStatement ) walker.getAST(); 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( targetedPersister, bulkTargetAlias, 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 ); 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<ParameterSpecification>(); final Update update = new Update( factory().getDialect() ) .setTableName( tableNames[tableIndex] ) .setWhere( "(" + StringHelper.join( ", ", columnNames[tableIndex] ) + ") IN (" + idSubselect + ")" ); if ( factory().getSettings().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 ) { for ( int paramIndex = 0; paramIndex < assignmentSpecification.getParameters().length; paramIndex++ ) { parameterList.add( assignmentSpecification.getParameters()[paramIndex] ); } } } } if ( affected ) { updates[tableIndex] = update.toStatementString(); assignmentParameterSpecifications[tableIndex] = parameterList.toArray( new ParameterSpecification[parameterList.size()] ); } } }
protected HqlSqlWalker walker() { return walker; }
public void initialize(Object param) { walker = (HqlSqlWalker) param; }
public HqlSqlWalker getWalker() { return walker; }
public DeleteExecutor(HqlSqlWalker walker, Queryable persister) { super( walker, persister ); final SessionFactoryImplementor factory = walker.getSessionFactoryHelper().getFactory(); final Dialect dialect = factory.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<ParameterSpecification>(); 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 .getCollectionPersister( 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 " + StringHelper.join( ", ", persister.getIdentifierColumnNames() ) + " from " + persister.getTableName() + idSubselectWhere + ")"; final String where = "(" + StringHelper.join( ", ", cPersister.getKeyColumnNames() ) + ") in " + idSubselect; final Delete delete = new Delete().setTableName( cPersister.getTableName() ).setWhere( where ); if ( factory.getSettings().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 ); } }
public MultiTableDeleteExecutor(HqlSqlWalker walker) { final MultiTableBulkIdStrategy strategy = walker.getSessionFactoryHelper().getFactory().getSettings() .getMultiTableBulkIdStrategy(); this.deleteHandler = strategy.buildDeleteHandler( walker.getSessionFactoryHelper().getFactory(), walker ); }
public LiteralProcessor(HqlSqlWalker hqlSqlWalker) { this.walker = hqlSqlWalker; }
public SyntheticAndFactory(HqlSqlWalker hqlSqlWalker) { this.hqlSqlWalker = hqlSqlWalker; }
public static void processDynamicFilterParameters( final String sqlFragment, final ParameterContainer container, final HqlSqlWalker walker) { if ( walker.getEnabledFilters().isEmpty() && ( !hasDynamicFilterParam( sqlFragment ) ) && ( !( hasCollectionFilterParam( sqlFragment ) ) ) ) { return; } Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect(); String symbols = ParserHelper.HQL_SEPARATORS + dialect.openQuote() + dialect.closeQuote(); StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true ); StringBuilder result = new StringBuilder(); while ( tokens.hasMoreTokens() ) { final String token = tokens.nextToken(); if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) { final String filterParameterName = token.substring( 1 ); final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName ); final FilterImpl filter = (FilterImpl) walker.getEnabledFilters().get( parts[0] ); final Object value = filter.getParameter( parts[1] ); final Type type = filter.getFilterDefinition().getParameterType( parts[1] ); final String typeBindFragment = StringHelper.join( ",", ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) ) ); final String bindFragment; if ( value != null && Collection.class.isInstance( value ) ) { bindFragment = StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( (Collection) value ).size() ) ); } else { bindFragment = typeBindFragment; } result.append( bindFragment ); container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) ); } else { result.append( token ); } } container.setText( result.toString() ); }
public CTEBasedUpdateHandlerImpl(SessionFactoryImplementor factory, HqlSqlWalker walker) { this(factory, walker, null, null); }
public CTEBasedUpdateHandlerImpl(SessionFactoryImplementor factory, HqlSqlWalker walker, String catalog, String schema) { super(factory, walker, catalog, schema); UpdateStatement updateStatement = (UpdateStatement) walker.getAST(); FromElement fromElement = updateStatement.getFromClause() .getFromElement(); this.targetedPersister = fromElement.getQueryable(); final ProcessedWhereClause processedWhereClause = processWhereClause(updateStatement .getWhereClause()); this.idSelectParameterSpecifications = processedWhereClause .getIdSelectParameterSpecifications(); final String bulkTargetAlias = fromElement.getTableAlias(); this.idSelect = generateIdSelect(targetedPersister, bulkTargetAlias, processedWhereClause); String[] tableNames = targetedPersister .getConstraintOrderedTableNameClosure(); String[][] columnNames = targetedPersister .getContraintOrderedTableKeyColumnClosure(); String idSubselect = generateIdSubselect( targetedPersister); 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<ParameterSpecification>(); final Update update = new Update( factory().getDialect()) .setTableName(tableNames[tableIndex]).setWhere( "(" + StringHelper.join( ", ", columnNames[tableIndex]) + ") IN (" + idSubselect + ")"); if (factory().getSettings().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) { for (int paramIndex = 0; paramIndex < assignmentSpecification .getParameters().length; paramIndex++) { parameterList.add(assignmentSpecification .getParameters()[paramIndex]); } } } } if (affected) { updates[tableIndex] = update.toStatementString(); assignmentParameterSpecifications[tableIndex] = parameterList .toArray(new ParameterSpecification[parameterList .size()]); } } }
public CTEBasedDeleteHandlerImpl(SessionFactoryImplementor factory, HqlSqlWalker walker) { this(factory, walker, null, null); }
public CTEBasedDeleteHandlerImpl(SessionFactoryImplementor factory, HqlSqlWalker walker, String catalog, String schema) { super(factory, walker, catalog, schema); DeleteStatement deleteStatement = (DeleteStatement) walker.getAST(); FromElement fromElement = deleteStatement.getFromClause() .getFromElement(); this.targetedPersister = fromElement.getQueryable(); final ProcessedWhereClause processedWhereClause = processWhereClause(deleteStatement .getWhereClause()); this.idSelectParameterSpecifications = processedWhereClause .getIdSelectParameterSpecifications(); final String bulkTargetAlias = fromElement.getTableAlias(); this.idSelect = generateIdSelect(targetedPersister, bulkTargetAlias, processedWhereClause); final String idSubselect = generateIdSubselect( targetedPersister); deletes = new ArrayList<String>(); // 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 .getCollectionPersister(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")); } }
public CTEBasedUpdateHandlerImpl(SessionFactoryImplementor factory, HqlSqlWalker walker, String catalog, String schema) { super(factory, walker, catalog, schema); UpdateStatement updateStatement = (UpdateStatement) walker.getAST(); FromElement fromElement = updateStatement.getFromClause() .getFromElement(); this.targetedPersister = fromElement.getQueryable(); final ProcessedWhereClause processedWhereClause = processWhereClause(updateStatement .getWhereClause()); this.idSelectParameterSpecifications = processedWhereClause .getIdSelectParameterSpecifications(); final String bulkTargetAlias = fromElement.getTableAlias(); this.idSelect = generateIdSelect(targetedPersister, bulkTargetAlias, processedWhereClause); String[] tableNames = targetedPersister .getConstraintOrderedTableNameClosure(); String[][] columnNames = targetedPersister .getContraintOrderedTableKeyColumnClosure(); String idSubselect = generateIdSubselect(targetedPersister); 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<ParameterSpecification>(); final Update update = new Update(factory().getDialect()) .setTableName(tableNames[tableIndex]).setWhere( "(" + StringHelper.join(", ", columnNames[tableIndex]) + ") IN (" + idSubselect + ")"); if (factory().getSettings().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) { for (int paramIndex = 0; paramIndex < assignmentSpecification .getParameters().length; paramIndex++) { parameterList.add(assignmentSpecification .getParameters()[paramIndex]); } } } } if (affected) { updates[tableIndex] = update.toStatementString(); assignmentParameterSpecifications[tableIndex] = parameterList .toArray(new ParameterSpecification[parameterList .size()]); } } }
public CTEBasedDeleteHandlerImpl(SessionFactoryImplementor factory, HqlSqlWalker walker, String catalog, String schema) { super(factory, walker, catalog, schema); DeleteStatement deleteStatement = (DeleteStatement) walker.getAST(); FromElement fromElement = deleteStatement.getFromClause() .getFromElement(); this.targetedPersister = fromElement.getQueryable(); final ProcessedWhereClause processedWhereClause = processWhereClause(deleteStatement .getWhereClause()); this.idSelectParameterSpecifications = processedWhereClause .getIdSelectParameterSpecifications(); final String bulkTargetAlias = fromElement.getTableAlias(); this.idSelect = generateIdSelect(targetedPersister, bulkTargetAlias, processedWhereClause); final String idSubselect = generateIdSubselect(targetedPersister); deletes = new ArrayList<String>(); // 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 .getCollectionPersister(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")); } }
/** * Build a handler capable of handling the bulk update indicated by the given walker. * * @param factory The SessionFactory * @param walker The AST walker, representing the update query * * @return The handler */ public UpdateHandler buildUpdateHandler(SessionFactoryImplementor factory, HqlSqlWalker walker);
/** * Build a handler capable of handling the bulk delete indicated by the given walker. * * @param factory The SessionFactory * @param walker The AST walker, representing the delete query * * @return The handler */ public DeleteHandler buildDeleteHandler(SessionFactoryImplementor factory, HqlSqlWalker walker);
/** * Retreive the "phase 2" walker which generated this statement tree. * * @return The HqlSqlWalker instance which generated this statement tree. */ public HqlSqlWalker getWalker();
/** * Constructs a new JoinProcessor. * * @param walker The walker to which we are bound, giving us access to needed resources. */ public JoinProcessor(HqlSqlWalker walker) { this.walker = walker; this.syntheticAndFactory = new SyntheticAndFactory( walker ); }