/** * PUBLIC: * Return true if this descriptor should using an additional join expresison. */ public boolean shouldUseAdditionalJoinExpression() { // Return true, if the query manager has an additional join expression // and this descriptor is not part of an inheritance hierarchy using a // view (CR#3701077) return ((getQueryManager().getAdditionalJoinExpression() != null) && ! (hasInheritance() && getInheritancePolicy().hasView())); }
/** * PUBLIC: * Return true if this descriptor should using an additional join expresison. */ public boolean shouldUseAdditionalJoinExpression() { // Return true, if the query manager has an additional join expression // and this descriptor is not part of an inheritance hierarchy using a // view (CR#3701077) return ((getQueryManager().getAdditionalJoinExpression() != null) && ! (hasInheritance() && getInheritancePolicy().hasView())); }
/** * 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(); }
/** * Read a single row from the database. Create an SQL statement object, * use it to create an SQL command string, and delegate row building * responsibility to the accessor. */ public AbstractRecord selectOneRow() throws DatabaseException { // Check for multiple table inheritance which may require multiple queries. if (!getReadObjectQuery().shouldOuterJoinSubclasses()) { ClassDescriptor descriptor = getDescriptor(); if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().requiresMultipleTableSubclassRead() && (!descriptor.getInheritancePolicy().hasView())) { return descriptor.getInheritancePolicy().selectOneRowUsingMultipleTableSubclassRead((ReadObjectQuery)this.query); } } return selectOneRowFromTable(); }
/** * Read a single row from the database. Create an SQL statement object, * use it to create an SQL command string, and delegate row building * responsibility to the accessor. */ public AbstractRecord selectOneRow() throws DatabaseException { // Check for multiple table inheritance which may require multiple queries. if (!getReadObjectQuery().shouldOuterJoinSubclasses()) { ClassDescriptor descriptor = getDescriptor(); if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().requiresMultipleTableSubclassRead() && (!descriptor.getInheritancePolicy().hasView())) { return descriptor.getInheritancePolicy().selectOneRowUsingMultipleTableSubclassRead((ReadObjectQuery)this.query); } } return selectOneRowFromTable(); }
/** * Read a single row from the database. Create an SQL statement object, * use it to create an SQL command string, and delegate row building * responsibility to the accessor. */ public AbstractRecord selectOneRow() throws DatabaseException { // Check for multiple table inheritance which may require multiple queries. if (!getReadObjectQuery().shouldOuterJoinSubclasses()) { ClassDescriptor descriptor = getDescriptor(); if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().requiresMultipleTableSubclassRead() && (!descriptor.getInheritancePolicy().hasView())) { return descriptor.getInheritancePolicy().selectOneRowUsingMultipleTableSubclassRead((ReadObjectQuery)this.query); } } return selectOneRowFromTable(); }
/** * 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 }
/** * INTERNAL: * Post initializations after mappings are initialized. */ public void postInitialize(AbstractSession session) throws DescriptorException { // If the additional criteria is specified, append it to the additional // join expression. We do this in postInitialize after all the mappings // have been fully initialized. if (additionalCriteria != null) { if (getDescriptor().hasInheritance() && getDescriptor().getInheritancePolicy().hasView()) { throw DescriptorException.additionalCriteriaNotSupportedWithInheritanceViews(getDescriptor()); } JPAQueryBuilder queryBuilder = session.getQueryBuilder(); Expression selectionCriteria = queryBuilder.buildSelectionCriteria( getDescriptor().getAlias(), additionalCriteria, session ); updatePropertyParameterExpression(selectionCriteria); additionalJoinExpression = selectionCriteria.and(additionalJoinExpression); } if (additionalJoinExpression != null) { // The make sure the additional join expression has the correct // context, rebuild the additional join expression on a new // expression builder. additionalJoinExpression = additionalJoinExpression.rebuildOn(new ExpressionBuilder()); } }
/** * Pre-build the SQL statement from the expression. */ public void prepareCursorSelectAllRows() { if (getQuery().isReportQuery()) { SQLSelectStatement statement = buildReportQuerySelectStatement(false); setSQLStatement(statement); // For bug 2718118 inheritance with cursors is supported provided there is a read all subclasses view. } else if (getDescriptor().hasInheritance() && getDescriptor().getInheritancePolicy().requiresMultipleTableSubclassRead() && getDescriptor().getInheritancePolicy().hasView()) { InheritancePolicy inheritancePolicy = getDescriptor().getInheritancePolicy(); SQLSelectStatement statement = inheritancePolicy.buildViewSelectStatement((ObjectLevelReadQuery)getQuery()); setSQLStatement(statement); } else { setSQLStatement(buildNormalSelectStatement()); } super.prepareCursorSelectAllRows(); }
/** * Pre-build the SQL statement from the expression. */ public void prepareCursorSelectAllRows() { if (getQuery().isReportQuery()) { SQLSelectStatement statement = buildReportQuerySelectStatement(false); setSQLStatement(statement); // For bug 2718118 inheritance with cursors is supported provided there is a read all subclasses view. } else if (getDescriptor().hasInheritance() && getDescriptor().getInheritancePolicy().requiresMultipleTableSubclassRead() && getDescriptor().getInheritancePolicy().hasView()) { InheritancePolicy inheritancePolicy = getDescriptor().getInheritancePolicy(); SQLSelectStatement statement = inheritancePolicy.buildViewSelectStatement((ObjectLevelReadQuery)getQuery()); setSQLStatement(statement); } else { setSQLStatement(buildNormalSelectStatement()); } super.prepareCursorSelectAllRows(); }
/** * Pre-build the SQL statement from the expression. */ public void prepareCursorSelectAllRows() { if (getQuery().isReportQuery()) { SQLSelectStatement statement = buildReportQuerySelectStatement(false); setSQLStatement(statement); // For bug 2718118 inheritance with cursors is supported provided there is a read all subclasses view. } else if (getDescriptor().hasInheritance() && getDescriptor().getInheritancePolicy().requiresMultipleTableSubclassRead() && getDescriptor().getInheritancePolicy().hasView()) { InheritancePolicy inheritancePolicy = getDescriptor().getInheritancePolicy(); SQLSelectStatement statement = inheritancePolicy.buildViewSelectStatement((ObjectLevelReadQuery)getQuery()); setSQLStatement(statement); } else { setSQLStatement(buildNormalSelectStatement()); } super.prepareCursorSelectAllRows(); }
/** * 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(); } } }
/** * 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(); } } }