selectStatement.setFields(fieldExpressions); if (reportQuery.hasNonFetchJoinedAttributeExpressions()) { selectStatement.setNonSelectFields(cloneExpressions(reportQuery.getNonFetchJoinAttributeExpressions(), clonedExpressions));
selectStatement.setFields(fieldExpressions); if (reportQuery.hasNonFetchJoinedAttributeExpressions()) { selectStatement.setNonSelectFields(cloneExpressions(reportQuery.getNonFetchJoinAttributeExpressions(), clonedExpressions));
/** * INTERNAL: * Build a select statement for all subclasses on the view using the same * selection criteria as the query. */ public SQLSelectStatement buildViewSelectStatement(ObjectLevelReadQuery query) { // 2612538 - the default size of Map (32) is appropriate Map clonedExpressions = new IdentityHashMap(); ExpressionQueryMechanism mechanism = (ExpressionQueryMechanism)query.getQueryMechanism(); // CR#3166555 - Have the mechanism build the statement to avoid duplicating code and ensure that lock-mode, hints, hierarchical, etc. are set. SQLSelectStatement selectStatement = mechanism.buildBaseSelectStatement(false, clonedExpressions); selectStatement.setTables(org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(1)); selectStatement.addTable(getReadAllSubclassesView()); // Case, normal read for branch inheritance class that reads subclasses all in its own table(s). if (getWithAllSubclassesExpression() != null) { Expression branchIndicator = (Expression)getWithAllSubclassesExpression().clone(); if (branchIndicator != null) { selectStatement.setWhereClause(branchIndicator.and(selectStatement.getWhereClause())); } } selectStatement.setFields(mechanism.getSelectionFields(selectStatement, true)); selectStatement.normalizeForView(query.getSession(), getDescriptor(), clonedExpressions); // Allow for joining indexes to be computed to ensure distinct rows if (query.hasJoining()) { query.getJoinedAttributeManager().computeJoiningMappingIndexes(false, query.getSession(), 0); } return selectStatement; }
/** * INTERNAL: * Build a select statement for all subclasses on the view using the same * selection criteria as the query. */ public SQLSelectStatement buildViewSelectStatement(ObjectLevelReadQuery query) { // 2612538 - the default size of Map (32) is appropriate Map clonedExpressions = new IdentityHashMap(); ExpressionQueryMechanism mechanism = (ExpressionQueryMechanism)query.getQueryMechanism(); // CR#3166555 - Have the mechanism build the statement to avoid duplicating code and ensure that lock-mode, hints, hierarchical, etc. are set. SQLSelectStatement selectStatement = mechanism.buildBaseSelectStatement(false, clonedExpressions); selectStatement.setTables(org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(1)); selectStatement.addTable(getReadAllSubclassesView()); // Case, normal read for branch inheritance class that reads subclasses all in its own table(s). if (getWithAllSubclassesExpression() != null) { Expression branchIndicator = (Expression)getWithAllSubclassesExpression().clone(); if (branchIndicator != null) { selectStatement.setWhereClause(branchIndicator.and(selectStatement.getWhereClause())); } } selectStatement.setFields(mechanism.getSelectionFields(selectStatement, true)); selectStatement.normalizeForView(query.getSession(), getDescriptor(), clonedExpressions); // Allow for joining indexes to be computed to ensure distinct rows if (query.hasJoining()) { query.getJoinedAttributeManager().computeJoiningMappingIndexes(false, query.getSession(), 0); } return selectStatement; }
/** * INTERNAL: * Build a select statement for all subclasses on the view using the same * selection criteria as the query. */ public SQLSelectStatement buildViewSelectStatement(ObjectLevelReadQuery query) { // 2612538 - the default size of Map (32) is appropriate Map clonedExpressions = new IdentityHashMap(); ExpressionQueryMechanism mechanism = (ExpressionQueryMechanism)query.getQueryMechanism(); // CR#3166555 - Have the mechanism build the statement to avoid duplicating code and ensure that lock-mode, hints, hierarchical, etc. are set. SQLSelectStatement selectStatement = mechanism.buildBaseSelectStatement(false, clonedExpressions); selectStatement.setTables(org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(1)); selectStatement.addTable(getReadAllSubclassesView()); // Case, normal read for branch inheritance class that reads subclasses all in its own table(s). if (getWithAllSubclassesExpression() != null) { Expression branchIndicator = (Expression)getWithAllSubclassesExpression().clone(); if (branchIndicator != null) { selectStatement.setWhereClause(branchIndicator.and(selectStatement.getWhereClause())); } } selectStatement.setFields(mechanism.getSelectionFields(selectStatement, true)); selectStatement.normalizeForView(query.getSession(), getDescriptor(), clonedExpressions); // Allow for joining indexes to be computed to ensure distinct rows if (query.hasJoining()) { query.getJoinedAttributeManager().computeJoiningMappingIndexes(false, query.getSession(), 0); } return selectStatement; }
/** * Build the select statement for selecting the locator */ private SQLSelectStatement buildSelectStatementForLocator(WriteObjectQuery writeQuery, DatabaseCall call, AbstractSession session) { SQLSelectStatement selectStatement = new SQLSelectStatement(); Vector tables = writeQuery.getDescriptor().getTables(); selectStatement.setTables(tables); //rather than get ALL fields from the descriptor, only use the LOB-related fields to build the minimal SELECT statement. selectStatement.setFields(call.getContexts().getFields()); //the where clause setting here is sufficient if the object does not map to multiple tables. selectStatement.setWhereClause(writeQuery.getDescriptor().getObjectBuilder().buildPrimaryKeyExpressionFromObject(writeQuery.getObject(), session)); //need pessimistic locking for the locator select selectStatement.setLockingClause(ForUpdateClause.newInstance(ObjectBuildingQuery.LOCK)); if (tables.size() > 1) { //the primary key expression from the primary table Expression expression = selectStatement.getWhereClause(); //additional join from the non-primary tables Expression additionalJoin = writeQuery.getDescriptor().getQueryManager().getAdditionalJoinExpression(); if (additionalJoin != null) { expression = expression.and(additionalJoin); } //where clause now contains extra joins across all tables selectStatement.setWhereClause(expression); } //normalize the statement at the end, such as assign alias to all tables, and build sorting statement selectStatement.normalize(session, writeQuery.getDescriptor()); return selectStatement; }
/** * Build the select statement for selecting the locator */ private SQLSelectStatement buildSelectStatementForLocator(WriteObjectQuery writeQuery, DatabaseCall call, AbstractSession session) { SQLSelectStatement selectStatement = new SQLSelectStatement(); Vector tables = writeQuery.getDescriptor().getTables(); selectStatement.setTables(tables); //rather than get ALL fields from the descriptor, only use the LOB-related fields to build the minimal SELECT statement. selectStatement.setFields(call.getContexts().getFields()); //the where clause setting here is sufficient if the object does not map to multiple tables. selectStatement.setWhereClause(writeQuery.getDescriptor().getObjectBuilder().buildPrimaryKeyExpressionFromObject(writeQuery.getObject(), session)); //need pessimistic locking for the locator select selectStatement.setLockingClause(ForUpdateClause.newInstance(ObjectBuildingQuery.LOCK)); if (tables.size() > 1) { //the primary key expression from the primary table Expression expression = selectStatement.getWhereClause(); //additional join from the non-primary tables Expression additionalJoin = writeQuery.getDescriptor().getQueryManager().getAdditionalJoinExpression(); if (additionalJoin != null) { expression = expression.and(additionalJoin); } //where clause now contains extra joins across all tables selectStatement.setWhereClause(expression); } //normalize the statement at the end, such as assign alias to all tables, and build sorting statement selectStatement.normalize(session, writeQuery.getDescriptor()); return selectStatement; }
/** * Build the select statement for selecting the locator */ private SQLSelectStatement buildSelectStatementForLocator(WriteObjectQuery writeQuery, DatabaseCall call, AbstractSession session) { SQLSelectStatement selectStatement = new SQLSelectStatement(); Vector tables = writeQuery.getDescriptor().getTables(); selectStatement.setTables(tables); //rather than get ALL fields from the descriptor, only use the LOB-related fields to build the minimal SELECT statement. selectStatement.setFields(call.getContexts().getFields()); //the where clause setting here is sufficient if the object does not map to multiple tables. selectStatement.setWhereClause(writeQuery.getDescriptor().getObjectBuilder().buildPrimaryKeyExpressionFromObject(writeQuery.getObject(), session)); //need pessimistic locking for the locator select selectStatement.setLockingClause(ForUpdateClause.newInstance(ObjectBuildingQuery.LOCK)); if (tables.size() > 1) { //the primary key expression from the primary table Expression expression = selectStatement.getWhereClause(); //additional join from the non-primary tables Expression additionalJoin = writeQuery.getDescriptor().getQueryManager().getAdditionalJoinExpression(); if (additionalJoin != null) { expression = expression.and(additionalJoin); } //where clause now contains extra joins across all tables selectStatement.setWhereClause(expression); } //normalize the statement at the end, such as assign alias to all tables, and build sorting statement selectStatement.normalize(session, writeQuery.getDescriptor()); return selectStatement; }
/** * Return the appropriate select statement containing the fields in the table. */ protected SQLSelectStatement buildNormalSelectStatement() { // From bug 2612185 Remember the identity hashtable used in cloning the selection criteria even in the normal case // for performance, in case subqueries need it, or for order by expressions. // 2612538 - the default size of Map (32) is appropriate Map clonedExpressions = new IdentityHashMap(); SQLSelectStatement selectStatement = buildBaseSelectStatement(false, clonedExpressions); ObjectLevelReadQuery query = ((ObjectLevelReadQuery)getQuery()); // Case, normal read for branch inheritance class that reads subclasses all in its own table(s). boolean includeAllSubclassesFields = true; if (getDescriptor().hasInheritance()) { getDescriptor().getInheritancePolicy().appendWithAllSubclassesExpression(selectStatement); if ((!query.isReportQuery()) && query.shouldOuterJoinSubclasses()) { selectStatement.getExpressionBuilder().setShouldUseOuterJoinForMultitableInheritance(true); } // Bug 380929 - Find whether to include all subclass fields or not. includeAllSubclassesFields = shouldIncludeAllSubclassFields(selectStatement); } selectStatement.setFields(getSelectionFields(selectStatement, includeAllSubclassesFields)); selectStatement.normalize(getSession(), getDescriptor(), clonedExpressions); // Allow for joining indexes to be computed to ensure distinct rows. if (((ObjectLevelReadQuery)getQuery()).hasJoining()) { ((ObjectLevelReadQuery)getQuery()).getJoinedAttributeManager().computeJoiningMappingIndexes(true, getSession(), 0); } return selectStatement; }
/** * Return the appropriate select statement containing the fields in the table. */ protected SQLSelectStatement buildNormalSelectStatement() { // From bug 2612185 Remember the identity hashtable used in cloning the selection criteria even in the normal case // for performance, in case subqueries need it, or for order by expressions. // 2612538 - the default size of Map (32) is appropriate Map clonedExpressions = new IdentityHashMap(); SQLSelectStatement selectStatement = buildBaseSelectStatement(false, clonedExpressions); ObjectLevelReadQuery query = ((ObjectLevelReadQuery)getQuery()); // Case, normal read for branch inheritance class that reads subclasses all in its own table(s). boolean includeAllSubclassesFields = true; if (getDescriptor().hasInheritance()) { getDescriptor().getInheritancePolicy().appendWithAllSubclassesExpression(selectStatement); if ((!query.isReportQuery()) && query.shouldOuterJoinSubclasses()) { selectStatement.getExpressionBuilder().setShouldUseOuterJoinForMultitableInheritance(true); } // Bug 380929 - Find whether to include all subclass fields or not. includeAllSubclassesFields = shouldIncludeAllSubclassFields(selectStatement); } selectStatement.setFields(getSelectionFields(selectStatement, includeAllSubclassesFields)); selectStatement.normalize(getSession(), getDescriptor(), clonedExpressions); // Allow for joining indexes to be computed to ensure distinct rows. if (((ObjectLevelReadQuery)getQuery()).hasJoining()) { ((ObjectLevelReadQuery)getQuery()).getJoinedAttributeManager().computeJoiningMappingIndexes(true, getSession(), 0); } return selectStatement; }
selectStatement.setFields(getSelectionFields(selectStatement, false)); selectStatement.normalize(getSession(), descriptor, clonedExpressions);
/** * Return the appropriate select statement containing the fields in the table. * This is used as a second read to a concrete class with subclasses in an abstract-multiple table read. */ protected SQLSelectStatement buildConcreteSelectStatement() { // 2612538 - the default size of Map (32) is appropriate Map clonedExpressions = new IdentityHashMap(); SQLSelectStatement selectStatement = buildBaseSelectStatement(false, clonedExpressions); // Case of class with subclasses that also has instances on abstract-multiple table read. if (getDescriptor().hasInheritance() && getDescriptor().getInheritancePolicy().shouldReadSubclasses()) { Expression concrete = getDescriptor().getInheritancePolicy().getOnlyInstancesExpression(); if ((concrete != null) && (selectStatement.getWhereClause() != null)) { selectStatement.setWhereClause(selectStatement.getWhereClause().and(concrete)); } else if (concrete != null) { selectStatement.setWhereClause((Expression)concrete.clone()); } } selectStatement.setFields(getSelectionFields(selectStatement, false)); selectStatement.normalize(getSession(), getDescriptor(), clonedExpressions); // Allow for joining indexes to be computed to ensure distinct rows. if (((ObjectLevelReadQuery)getQuery()).hasJoining()) { ((ObjectLevelReadQuery)getQuery()).getJoinedAttributeManager().computeJoiningMappingIndexes(false, getSession(), 0); } return selectStatement; }
selectStatement.setFields(getSelectionFields(selectStatement, false)); selectStatement.normalize(getSession(), descriptor, clonedExpressions);
/** * Return the appropriate select statement containing the fields in the table. */ protected SQLSelectStatement buildNormalSelectStatement() { // From bug 2612185 Remember the identity hashtable used in cloning the selection criteria even in the normal case // for performance, in case subqueries need it, or for order by expressions. // 2612538 - the default size of Map (32) is appropriate Map clonedExpressions = new IdentityHashMap(); SQLSelectStatement selectStatement = buildBaseSelectStatement(false, clonedExpressions); ObjectLevelReadQuery query = ((ObjectLevelReadQuery)getQuery()); // Case, normal read for branch inheritance class that reads subclasses all in its own table(s). if (getDescriptor().hasInheritance()) { getDescriptor().getInheritancePolicy().appendWithAllSubclassesExpression(selectStatement); if ((!query.isReportQuery()) && query.shouldOuterJoinSubclasses()) { selectStatement.getExpressionBuilder().setShouldUseOuterJoinForMultitableInheritance(true); } } selectStatement.setFields(getSelectionFields(selectStatement, true)); if (query.hasNonFetchJoinedAttributeExpressions()) { selectStatement.setNonSelectFields(cloneExpressions(query.getNonFetchJoinAttributeExpressions(), clonedExpressions)); } selectStatement.normalize(getSession(), getDescriptor(), clonedExpressions); // Allow for joining indexes to be computed to ensure distinct rows. if (((ObjectLevelReadQuery)getQuery()).hasJoining()) { ((ObjectLevelReadQuery)getQuery()).getJoinedAttributeManager().computeJoiningMappingIndexes(true, getSession(), 0); } return selectStatement; }
computeFieldExpressions(items, clonedExpressions, selectStatement, fieldExpressions); selectStatement.setFields(fieldExpressions); if (reportQuery.hasNonFetchJoinedAttributeExpressions()) { selectStatement.setNonSelectFields(cloneExpressions(reportQuery.getNonFetchJoinAttributeExpressions(), clonedExpressions));