/** * 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; }
/** * 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; }
selectStatement.setTables((Vector)descriptor.getTables().clone());
selectStatement.setTables((Vector)descriptor.getTables().clone());
selectStatement.setLockingClause(query.getLockingClause()); selectStatement.setDistinctState(query.getDistinctState()); selectStatement.setTables((Vector)getDescriptor().getTables().clone()); selectStatement.setWhereClause(buildBaseSelectionCriteria(isSubSelect, clonedExpressions));
selectStatement.setTables((Vector)getQuery().getDescriptor().getTables().clone());
selectStatement.setLockingClause(query.getLockingClause()); selectStatement.setDistinctState(query.getDistinctState()); selectStatement.setTables((Vector)getDescriptor().getTables().clone()); selectStatement.setWhereClause(buildBaseSelectionCriteria(isSubSelect, clonedExpressions, shouldUseAdditionalJoinExpression));
selectStatement.setLockingClause(query.getLockingClause()); selectStatement.setDistinctState(query.getDistinctState()); selectStatement.setTables((Vector)getDescriptor().getTables().clone()); selectStatement.setWhereClause(buildBaseSelectionCriteria(isSubSelect, clonedExpressions, shouldUseAdditionalJoinExpression));