/** * Read all rows from the database. * @return Vector containing the database rows. * @exception DatabaseException - an error has occurred on the database. */ public Vector selectAllRows() throws DatabaseException { // Check for multiple table inheritance which may require multiple queries. if (!((ObjectLevelReadQuery)this.query).shouldOuterJoinSubclasses()) { ClassDescriptor descriptor = getDescriptor(); if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().requiresMultipleTableSubclassRead() && (!descriptor.getInheritancePolicy().hasView())) { return descriptor.getInheritancePolicy().selectAllRowUsingMultipleTableSubclassRead((ReadAllQuery)this.query); } } return selectAllRowsFromTable(); }
/** * Read all rows from the database. * @return Vector containing the database rows. * @exception DatabaseException - an error has occurred on the database. */ public Vector selectAllRows() throws DatabaseException { // Check for multiple table inheritance which may require multiple queries. if (!((ObjectLevelReadQuery)this.query).shouldOuterJoinSubclasses()) { ClassDescriptor descriptor = getDescriptor(); if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().requiresMultipleTableSubclassRead() && (!descriptor.getInheritancePolicy().hasView())) { return descriptor.getInheritancePolicy().selectAllRowUsingMultipleTableSubclassRead((ObjectLevelReadQuery)this.query); } } return selectAllRowsFromTable(); }
/** * Read all rows from the database. * @return Vector containing the database rows. * @exception DatabaseException - an error has occurred on the database. */ public Vector selectAllRows() throws DatabaseException { // Check for multiple table inheritance which may require multiple queries. if (!((ObjectLevelReadQuery)this.query).shouldOuterJoinSubclasses()) { ClassDescriptor descriptor = getDescriptor(); if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().requiresMultipleTableSubclassRead() && (!descriptor.getInheritancePolicy().hasView())) { return descriptor.getInheritancePolicy().selectAllRowUsingMultipleTableSubclassRead((ObjectLevelReadQuery)this.query); } } return selectAllRowsFromTable(); }
/** * INTERNAL: * Indicates whether the query can use ResultSet optimization. * The method is called when the query is prepared, * so it should refer only to the attributes that cannot be altered without re-preparing the query. * If the query is a clone and the original has been already prepared * this method will be called to set a (transient and therefore set to null) usesResultSetAccessOptimization attribute. */ public boolean supportsResultSetAccessOptimizationOnPrepare() { DatabaseCall call = getCall(); return ((call != null) && call.getReturnsResultSet()) && // must return ResultSet (!hasJoining() || !this.joinedAttributeManager.isToManyJoin()) && (!this.descriptor.hasInheritance() || !this.descriptor.getInheritancePolicy().hasClassExtractor() && // ClassExtractor requires the whole row (shouldOuterJoinSubclasses() || !this.descriptor.getInheritancePolicy().requiresMultipleTableSubclassRead() || this.descriptor.getInheritancePolicy().hasView())) && // don't know how to handle select class type call - ResultSet optimization breaks it. (this.batchFetchPolicy == null || !this.batchFetchPolicy.isIN()); // batchFetchPolicy.isIN() requires all rows up front - can't support it }
/** * INTERNAL: * Indicates whether the query can use ResultSet optimization. * The method is called when the query is prepared, * so it should refer only to the attributes that cannot be altered without re-preparing the query. * If the query is a clone and the original has been already prepared * this method will be called to set a (transient and therefore set to null) usesResultSetAccessOptimization attribute. */ public boolean supportsResultSetAccessOptimizationOnPrepare() { DatabaseCall call = getCall(); return ((call != null) && call.getReturnsResultSet()) && // must return ResultSet (!hasJoining() || !this.joinedAttributeManager.isToManyJoin()) && (!this.descriptor.hasInheritance() || !this.descriptor.getInheritancePolicy().hasClassExtractor() && // ClassExtractor requires the whole row (shouldOuterJoinSubclasses() || !this.descriptor.getInheritancePolicy().requiresMultipleTableSubclassRead() || this.descriptor.getInheritancePolicy().hasView())) && // don't know how to handle select class type call - ResultSet optimization breaks it. (this.batchFetchPolicy == null || !this.batchFetchPolicy.isIN()); // batchFetchPolicy.isIN() requires all rows up front - can't support it }
/** * 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; }
/** * 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; }
if (!shouldOuterJoinSubclasses()) { setShouldOuterJoinSubclasses(getMaxRows()>0 || getFirstResult()>0 || (this.descriptor != null && this.descriptor.hasInheritance() && (this.descriptor.getInheritancePolicy().shouldOuterJoinSubclasses()|| this.getExpressionBuilder().isTreatUsed()) )); if (!shouldOuterJoinSubclasses() && this.descriptor.hasInheritance() && this.descriptor.getInheritancePolicy().requiresMultipleTableSubclassRead()) { getConcreteSubclassCalls();
if (!shouldOuterJoinSubclasses()) { setShouldOuterJoinSubclasses(getMaxRows()>0 || getFirstResult()>0 || (this.descriptor != null && this.descriptor.hasInheritance() && (this.descriptor.getInheritancePolicy().shouldOuterJoinSubclasses()|| this.getExpressionBuilder().isTreatUsed()) )); if (!shouldOuterJoinSubclasses() && this.descriptor.hasInheritance() && this.descriptor.getInheritancePolicy().requiresMultipleTableSubclassRead()) { getConcreteSubclassCalls();
if (readQuery.shouldOuterJoinSubclasses()) { method.addLine(queryIdentifier + ".setShouldOuterJoinSubclasses(true);");
if (!shouldOuterJoinSubclasses()) { setShouldOuterJoinSubclasses(getMaxRows()>0 || getFirstResult()>0 || (this.descriptor != null && this.descriptor.hasInheritance() && this.descriptor.getInheritancePolicy().shouldOuterJoinSubclasses()) ); if ((!shouldOuterJoinSubclasses()) && this.descriptor.hasInheritance() && this.descriptor.getInheritancePolicy().requiresMultipleTableSubclassRead()) { getConcreteSubclassCalls();
/** * Pre-build the SQL statement from the expression. */ public void prepareSelectAllRows() { // Check for multiple table inheritance which may require multiple queries. if (!getDescriptor().hasInheritance() || !getDescriptor().getInheritancePolicy().requiresMultipleTableSubclassRead()){ setSQLStatement(buildNormalSelectStatement()); super.prepareSelectAllRows(); } else { InheritancePolicy policy = getDescriptor().getInheritancePolicy(); if (policy.hasView()){ // CR#3158703 if the descriptor has a view, then it requires a single select, // so can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildViewSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectAllRows(); } else if ( ((ObjectLevelReadQuery)getQuery()).shouldOuterJoinSubclasses() ){ //outer join into a single select that can be built normally setSQLStatement(buildNormalSelectStatement()); super.prepareSelectAllRows(); } else if (!getDescriptor().getInheritancePolicy().hasClassExtractor()) { // CR#3158703 otherwise if using a type indicator at least the type select can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildClassIndicatorSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectAllRows(); } } }
/** * Pre-build the SQL statement from the expression. */ public void prepareSelectOneRow() { // Check for multiple table inheritance which may require multiple queries. if (!getDescriptor().hasInheritance() || !getDescriptor().getInheritancePolicy().requiresMultipleTableSubclassRead()){ setSQLStatement(buildNormalSelectStatement()); super.prepareSelectOneRow(); } else { InheritancePolicy policy = getDescriptor().getInheritancePolicy(); if (policy.hasView()){ // CR#3158703 if the descriptor has a view, then it requires a single select, // so can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildViewSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectOneRow(); } else if ( ((ObjectLevelReadQuery)getQuery()).shouldOuterJoinSubclasses() ){ //outer join into a single select that can be built normally setSQLStatement(buildNormalSelectStatement()); super.prepareSelectOneRow(); } else if (!getDescriptor().getInheritancePolicy().hasClassExtractor()) { // CR#3158703 otherwise if using a type indicator at least the type select can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildClassIndicatorSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectOneRow(); } } }
/** * Pre-build the SQL statement from the expression. */ public void prepareSelectAllRows() { // Check for multiple table inheritance which may require multiple queries. if (!getDescriptor().hasInheritance() || !getDescriptor().getInheritancePolicy().requiresMultipleTableSubclassRead()){ setSQLStatement(buildNormalSelectStatement()); super.prepareSelectAllRows(); } else { InheritancePolicy policy = getDescriptor().getInheritancePolicy(); if (policy.hasView()){ // CR#3158703 if the descriptor has a view, then it requires a single select, // so can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildViewSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectAllRows(); } else if ( ((ObjectLevelReadQuery)getQuery()).shouldOuterJoinSubclasses() ){ //outer join into a single select that can be built normally setSQLStatement(buildNormalSelectStatement()); super.prepareSelectAllRows(); } else if (!getDescriptor().getInheritancePolicy().hasClassExtractor()) { // CR#3158703 otherwise if using a type indicator at least the type select can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildClassIndicatorSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectAllRows(); } } }
/** * Pre-build the SQL statement from the expression. */ public void prepareSelectOneRow() { // Check for multiple table inheritance which may require multiple queries. if (!getDescriptor().hasInheritance() || !getDescriptor().getInheritancePolicy().requiresMultipleTableSubclassRead()){ setSQLStatement(buildNormalSelectStatement()); super.prepareSelectOneRow(); } else { InheritancePolicy policy = getDescriptor().getInheritancePolicy(); if (policy.hasView()){ // CR#3158703 if the descriptor has a view, then it requires a single select, // so can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildViewSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectOneRow(); } else if ( ((ObjectLevelReadQuery)getQuery()).shouldOuterJoinSubclasses() ){ //outer join into a single select that can be built normally setSQLStatement(buildNormalSelectStatement()); super.prepareSelectOneRow(); } else if (!getDescriptor().getInheritancePolicy().hasClassExtractor()) { // CR#3158703 otherwise if using a type indicator at least the type select can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildClassIndicatorSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectOneRow(); } } }
/** * Pre-build the SQL statement from the expression. */ public void prepareSelectOneRow() { // Check for multiple table inheritance which may require multiple queries. if (!getDescriptor().hasInheritance() || !getDescriptor().getInheritancePolicy().requiresMultipleTableSubclassRead()){ setSQLStatement(buildNormalSelectStatement()); super.prepareSelectOneRow(); } else { InheritancePolicy policy = getDescriptor().getInheritancePolicy(); if (policy.hasView()){ // CR#3158703 if the descriptor has a view, then it requires a single select, // so can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildViewSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectOneRow(); } else if ( ((ObjectLevelReadQuery)getQuery()).shouldOuterJoinSubclasses() ){ //outer join into a single select that can be built normally setSQLStatement(buildNormalSelectStatement()); super.prepareSelectOneRow(); } else if (!getDescriptor().getInheritancePolicy().hasClassExtractor()) { // CR#3158703 otherwise if using a type indicator at least the type select can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildClassIndicatorSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectOneRow(); } } }
/** * Pre-build the SQL statement from the expression. */ public void prepareSelectAllRows() { // Check for multiple table inheritance which may require multiple queries. if (!getDescriptor().hasInheritance() || !getDescriptor().getInheritancePolicy().requiresMultipleTableSubclassRead()){ setSQLStatement(buildNormalSelectStatement()); super.prepareSelectAllRows(); } else { InheritancePolicy policy = getDescriptor().getInheritancePolicy(); if (policy.hasView()){ // CR#3158703 if the descriptor has a view, then it requires a single select, // so can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildViewSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectAllRows(); } else if ( ((ObjectLevelReadQuery)getQuery()).shouldOuterJoinSubclasses() ){ //outer join into a single select that can be built normally setSQLStatement(buildNormalSelectStatement()); super.prepareSelectAllRows(); } else if (!getDescriptor().getInheritancePolicy().hasClassExtractor()) { // CR#3158703 otherwise if using a type indicator at least the type select can be prepared. setSQLStatement(getDescriptor().getInheritancePolicy().buildClassIndicatorSelectStatement((ObjectLevelReadQuery)getQuery())); super.prepareSelectAllRows(); } } }
batchQuery.setShouldPrepare(query.shouldPrepare()); batchQuery.setShouldOuterJoinSubclasses(query.shouldOuterJoinSubclasses());
batchQuery.setShouldPrepare(query.shouldPrepare()); batchQuery.setShouldOuterJoinSubclasses(query.shouldOuterJoinSubclasses());