/** * INTERNAL: * Append the branch with all subclasses expression to the statement. */ public void appendWithAllSubclassesExpression(SQLSelectStatement selectStatement) { if (getWithAllSubclassesExpression() != null) { // For Flashback: Must always rebuild with simple expression on right. if (selectStatement.getWhereClause() == null) { selectStatement.setWhereClause((Expression)getWithAllSubclassesExpression().clone()); } else { selectStatement.setWhereClause(selectStatement.getWhereClause().and(getWithAllSubclassesExpression())); } } }
/** * INTERNAL: * Append the branch with all subclasses expression to the statement. */ public void appendWithAllSubclassesExpression(SQLSelectStatement selectStatement) { if (getWithAllSubclassesExpression() != null) { // For Flashback: Must always rebuild with simple expression on right. if (selectStatement.getWhereClause() == null) { selectStatement.setWhereClause((Expression)getWithAllSubclassesExpression().clone()); } else { selectStatement.setWhereClause(selectStatement.getWhereClause().and(getWithAllSubclassesExpression())); } } }
/** * INTERNAL: * Append the branch with all subclasses expression to the statement. */ public void appendWithAllSubclassesExpression(SQLSelectStatement selectStatement) { if (getWithAllSubclassesExpression() != null) { // For Flashback: Must always rebuild with simple expression on right. if (selectStatement.getWhereClause() == null) { selectStatement.setWhereClause((Expression)getWithAllSubclassesExpression().clone()); } else { selectStatement.setWhereClause(selectStatement.getWhereClause().and(getWithAllSubclassesExpression())); } } }
/** * INTERNAL: * Initialize lockRelationTableQuery. */ protected void initializeLockRelationTableQuery(AbstractSession session, ForeignReferenceMapping mapping, Expression startCriteria) { lockRelationTableQuery = new DirectReadQuery(); Expression criteria = buildSelectionCriteriaAndAddFieldsToQueryInternal(mapping, startCriteria, false, false); SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(this.relationTable); statement.addField(this.sourceRelationKeyFields.get(0).clone()); statement.setWhereClause(criteria); statement.normalize(session, null); lockRelationTableQuery.setSQLStatement(statement); lockRelationTableQuery.setSessionName(session.getName()); }
/** * INTERNAL: * Initialize lockRelationTableQuery. */ protected void initializeLockRelationTableQuery(AbstractSession session, ForeignReferenceMapping mapping, Expression startCriteria) { lockRelationTableQuery = new DirectReadQuery(); Expression criteria = buildSelectionCriteriaAndAddFieldsToQueryInternal(mapping, startCriteria, false, false); SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(this.relationTable); statement.addField((DatabaseField)this.sourceRelationKeyFields.get(0).clone()); statement.setWhereClause(criteria); statement.normalize(session, null); lockRelationTableQuery.setSQLStatement(statement); lockRelationTableQuery.setSessionName(session.getName()); }
/** * INTERNAL: * Initialize lockRelationTableQuery. */ protected void initializeLockRelationTableQuery(AbstractSession session, ForeignReferenceMapping mapping, Expression startCriteria) { lockRelationTableQuery = new DirectReadQuery(); Expression criteria = buildSelectionCriteriaAndAddFieldsToQueryInternal(mapping, startCriteria, false, false); SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(this.relationTable); statement.addField(this.sourceRelationKeyFields.get(0).clone()); statement.setWhereClause(criteria); statement.normalize(session, null); lockRelationTableQuery.setSQLStatement(statement); lockRelationTableQuery.setSessionName(session.getName()); }
/** * INTERNAL: * Returns a query that */ ReadQuery getLockRelationTableQueryClone(AbstractSession session, short lockMode) { DirectReadQuery lockRelationTableQueryClone = (DirectReadQuery)lockRelationTableQuery.clone(); SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(this.relationTable); statement.addField(this.sourceRelationKeyFields.get(0).clone()); statement.setWhereClause((Expression)lockRelationTableQuery.getSelectionCriteria().clone()); statement.setLockingClause(new ForUpdateClause(lockMode)); statement.normalize(session, null); lockRelationTableQueryClone.setSQLStatement(statement); lockRelationTableQueryClone.setIsExecutionClone(true); return lockRelationTableQueryClone; }
/** * INTERNAL: * Returns a query that */ ReadQuery getLockRelationTableQueryClone(AbstractSession session, short lockMode) { DirectReadQuery lockRelationTableQueryClone = (DirectReadQuery)lockRelationTableQuery.clone(); SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(this.relationTable); statement.addField(this.sourceRelationKeyFields.get(0).clone()); statement.setWhereClause((Expression)lockRelationTableQuery.getSelectionCriteria().clone()); statement.setLockingClause(new ForUpdateClause(lockMode)); statement.normalize(session, null); lockRelationTableQueryClone.setSQLStatement(statement); lockRelationTableQueryClone.setIsExecutionClone(true); return lockRelationTableQueryClone; }
/** * INTERNAL: * Returns a query that */ ReadQuery getLockRelationTableQueryClone(AbstractSession session, short lockMode) { DirectReadQuery lockRelationTableQueryClone = (DirectReadQuery)lockRelationTableQuery.clone(); SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(this.relationTable); statement.addField((DatabaseField)this.sourceRelationKeyFields.get(0).clone()); statement.setWhereClause((Expression)lockRelationTableQuery.getSelectionCriteria().clone()); statement.setLockingClause(new ForUpdateClause(lockMode)); statement.normalize(session, null); lockRelationTableQueryClone.setSQLStatement(statement); lockRelationTableQueryClone.setIsExecutionClone(true); return lockRelationTableQueryClone; }
/** * INTERNAL: * Get the ref for the object. * This is required for use by Refs, there might be a better way to do it when objID are supported. * (i.e. getting it from the object or identity map). */ public Ref getRef(Object object, AbstractSession session) { SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(getTables().firstElement());// Assumed only one for obj-rel descriptors. statement.getFields().addElement(new org.eclipse.persistence.expressions.ExpressionBuilder().ref()); statement.setWhereClause(getObjectBuilder().buildPrimaryKeyExpressionFromObject(object, session)); statement.setRequiresAliases(true); statement.normalize(session, this); ValueReadQuery valueQuery = new ValueReadQuery(); valueQuery.setSQLStatement(statement); valueQuery.checkPrepare(session, new DatabaseRecord(), true); // Must return unwrapped Ref on WLS. valueQuery.getCall().setIsNativeConnectionRequired(true); Ref ref = (Ref)session.executeQuery(valueQuery); return ref; }
/** * INTERNAL: * Get the ref for the object. * This is required for use by Refs, there might be a better way to do it when objID are supported. * (i.e. getting it from the object or identity map). */ public Ref getRef(Object object, AbstractSession session) { SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(getTables().firstElement());// Assumed only one for obj-rel descriptors. statement.getFields().addElement(new org.eclipse.persistence.expressions.ExpressionBuilder().ref()); statement.setWhereClause(getObjectBuilder().buildPrimaryKeyExpressionFromObject(object, session)); statement.setRequiresAliases(true); statement.normalize(session, this); ValueReadQuery valueQuery = new ValueReadQuery(); valueQuery.setSQLStatement(statement); valueQuery.checkPrepare(session, new DatabaseRecord(), true); // Must return unwrapped Ref on WLS. valueQuery.getCall().setIsNativeConnectionRequired(true); Ref ref = (Ref)session.executeQuery(valueQuery); return ref; }
protected void initializeSelectionStatement(AbstractSession session) { SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(getReferenceTable()); statement.addField((DatabaseField)getDirectField().clone()); statement.setWhereClause(getSelectionCriteria()); if(listOrderField != null) { Expression expField = getListOrderFieldExpression(statement.getBuilder()); statement.addField(expField); } statement.normalize(session, null); getSelectionQuery().setSQLStatement(statement); }
/** * 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; }
protected void initializeSelectionStatement(AbstractSession session) { SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(getReferenceTable()); statement.addField(getDirectField().clone()); statement.setWhereClause(getSelectionCriteria()); statement.setOrderByExpressions(orderByExpressions); getSelectionQuery().setSQLStatement(statement); getContainerPolicy().addAdditionalFieldsToQuery(selectionQuery, getAdditionalFieldsBaseExpression(getSelectionQuery())); statement.normalize(session, null); }
protected void initializeSelectionStatement(AbstractSession session) { SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(getReferenceTable()); statement.addField(getDirectField().clone()); statement.setWhereClause(getSelectionCriteria()); statement.setOrderByExpressions(orderByExpressions); getSelectionQuery().setSQLStatement(statement); getContainerPolicy().addAdditionalFieldsToQuery(selectionQuery, getAdditionalFieldsBaseExpression(getSelectionQuery())); statement.normalize(session, null); }
/** * INTERNAL: * Return a select statement that will be used to query the class indicators required to query. * This is used in the abstract-multiple read. */ public SQLSelectStatement buildClassIndicatorSelectStatement(ObjectLevelReadQuery query) { SQLSelectStatement selectStatement; selectStatement = new SQLSelectStatement(); selectStatement.useDistinct(); selectStatement.addTable(classIndicatorField.getTable()); selectStatement.addField(getClassIndicatorField()); // 2612538 - the default size of Map (32) is appropriate Map clonedExpressions = new IdentityHashMap(); selectStatement.setWhereClause(((ExpressionQueryMechanism)query.getQueryMechanism()).buildBaseSelectionCriteria(false, clonedExpressions)); appendWithAllSubclassesExpression(selectStatement); selectStatement.setTranslationRow(query.getTranslationRow()); if (query.isReadAllQuery() && ((ReadAllQuery)query).hasHierarchicalExpressions()) { ReadAllQuery readAllQuery = (ReadAllQuery)query; selectStatement.setHierarchicalQueryExpressions(readAllQuery.getStartWithExpression(), readAllQuery.getConnectByExpression(), readAllQuery.getOrderSiblingsByExpressions()); } selectStatement.setHintString(query.getHintString()); selectStatement.normalize(query.getSession(), getDescriptor(), clonedExpressions); return selectStatement; }
/** * Return the appropriate select statement to perform a does exist check * @param field fields for does exist check. */ protected SQLSelectStatement buildSelectStatementForDoesExist(DatabaseField field) { // Build appropriate select statement SQLSelectStatement selectStatement; selectStatement = new SQLSelectStatement(); selectStatement.addField(field); selectStatement.setWhereClause(((Expression)getDescriptor().getObjectBuilder().getPrimaryKeyExpression().clone()).and(getDescriptor().getQueryManager().getAdditionalJoinExpression())); selectStatement.setTranslationRow(getTranslationRow()); selectStatement.normalize(getSession(), getQuery().getDescriptor()); selectStatement.setHintString(getQuery().getHintString()); return selectStatement; }
/** * INTERNAL: * Return a select statement that will be used to query the class indicators required to query. * This is used in the abstract-multiple read. */ public SQLSelectStatement buildClassIndicatorSelectStatement(ObjectLevelReadQuery query) { SQLSelectStatement selectStatement; selectStatement = new SQLSelectStatement(); selectStatement.useDistinct(); selectStatement.addTable(classIndicatorField.getTable()); selectStatement.addField(getClassIndicatorField()); // 2612538 - the default size of Map (32) is appropriate Map clonedExpressions = new IdentityHashMap(); selectStatement.setWhereClause(((ExpressionQueryMechanism)query.getQueryMechanism()).buildBaseSelectionCriteria(false, clonedExpressions)); appendWithAllSubclassesExpression(selectStatement); selectStatement.setTranslationRow(query.getTranslationRow()); if (query.isReadAllQuery() && ((ReadAllQuery)query).hasHierarchicalExpressions()) { ReadAllQuery readAllQuery = (ReadAllQuery)query; selectStatement.setHierarchicalQueryExpressions(readAllQuery.getStartWithExpression(), readAllQuery.getConnectByExpression(), readAllQuery.getOrderSiblingsByExpressions(), readAllQuery.getDirection()); } selectStatement.setHintString(query.getHintString()); selectStatement.normalize(query.getSession(), getDescriptor(), clonedExpressions); return selectStatement; }
/** * Return the appropriate select statement to perform a does exist check * @param field fields for does exist check. */ protected SQLSelectStatement buildSelectStatementForDoesExist(DatabaseField field) { // Build appropriate select statement SQLSelectStatement selectStatement; selectStatement = new SQLSelectStatement(); selectStatement.addField(field); selectStatement.setWhereClause(((Expression)getDescriptor().getObjectBuilder().getPrimaryKeyExpression().clone()).and(getDescriptor().getQueryManager().getAdditionalJoinExpression())); selectStatement.setTranslationRow(getTranslationRow()); selectStatement.normalize(getSession(), getQuery().getDescriptor()); selectStatement.setHintString(getQuery().getHintString()); return selectStatement; }
/** * Return the appropriate select statement to perform a does exist check * @param field fields for does exist check. */ protected SQLSelectStatement buildSelectStatementForDoesExist(DatabaseField field) { // Build appropriate select statement SQLSelectStatement selectStatement; selectStatement = new SQLSelectStatement(); selectStatement.addField(field); selectStatement.setWhereClause(((Expression)getDescriptor().getObjectBuilder().getPrimaryKeyExpression().clone()).and(getDescriptor().getQueryManager().getAdditionalJoinExpression())); selectStatement.setTranslationRow(getTranslationRow()); selectStatement.normalize(getSession(), getQuery().getDescriptor()); selectStatement.setHintString(getQuery().getHintString()); return selectStatement; }