/** * INTERNAL: Answers if this valueholder is a pessimistic locking one. Such * valueholders are special in that they can be triggered multiple times by * different UnitsOfWork. Each time a lock query will be issued. Hence even * if instantiated it may have to be instantiated again, and once * instantiated all fields can not be reset. * <p> * Since locks will be issued each time this valueholder is triggered, * triggering this directly on the session in auto commit mode will generate * an exception. This only UnitOfWorkValueHolder's wrapping this can trigger * it. Note: This method is not thread-safe. It must be used in a * synchronized manner */ public boolean isPessimisticLockingValueHolder() { // Get the easy checks out of the way first. if ((this.query == null) || !this.query.isObjectLevelReadQuery()) { return false; } ObjectLevelReadQuery query = (ObjectLevelReadQuery) this.query; // Note even if the reference class is not locked, but the valueholder // query // has joined attributes, then this may count as a lock query. // This means it is possible to trigger a valueholder to get an object // which // is not to be pess. locked and get an exception for triggering it on // the // session outside a transaction. return query.isLockQuery(this.session); }
/** * PUBLIC: * Release all objects read in so far. * This should be performed when reading in a large collection of * objects in order to preserve memory. */ public void clear() { // If using 1-m joining need to release 1-m rows as well. if ((this.query != null) && this.query.isObjectLevelReadQuery() && ((ObjectLevelReadQuery)this.query).hasJoining()) { ((ObjectLevelReadQuery)this.query).getJoinedAttributeManager().clearDataResults(); } } }
/** * Sets the query */ protected void setSelectionQuery(ReadQuery aQuery) { selectionQuery = aQuery; // Make sure the reference class of the selectionQuery is set. if ((selectionQuery != null) && selectionQuery.isObjectLevelReadQuery() && (selectionQuery.getReferenceClassName() == null)) { ((ObjectLevelReadQuery)selectionQuery).setReferenceClass(getReferenceClass()); } }
/** * Sets the query */ protected void setSelectionQuery(ReadQuery aQuery) { selectionQuery = aQuery; // Make sure the reference class of the selectionQuery is set. if ((selectionQuery != null) && selectionQuery.isObjectLevelReadQuery() && (selectionQuery.getReferenceClassName() == null)) { ((ObjectLevelReadQuery)selectionQuery).setReferenceClass(getReferenceClass()); } }
/** * PUBLIC: * Release all objects read in so far. * This should be performed when reading in a large collection of * objects in order to preserve memory. */ public void clear() { // If using 1-m joining need to release 1-m rows as well. if ((this.query != null) && this.query.isObjectLevelReadQuery() && ((ObjectLevelReadQuery)this.query).hasJoining()) { ((ObjectLevelReadQuery)this.query).getJoinedAttributeManager().clearDataResults(); } } }
/** * Sets the query */ protected void setSelectionQuery(ReadQuery aQuery) { selectionQuery = aQuery; // Make sure the reference class of the selectionQuery is set. if ((selectionQuery != null) && selectionQuery.isObjectLevelReadQuery() && (selectionQuery.getReferenceClassName() == null)) { ((ObjectLevelReadQuery)selectionQuery).setReferenceClass(getReferenceClass()); } }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map * Called when the selection query is being initialized to add the fields for the map key to the query */ public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression){ Iterator i = getForeignKeyFields().iterator(); while (i.hasNext()){ DatabaseField field = (DatabaseField)i.next(); if (selectionQuery.isObjectLevelReadQuery()){ if (baseExpression != null){ ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(field)); } else { ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(field); } } else if (selectionQuery.isDataReadQuery()){ ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(field); } } }
/** * INTERNAL: * Add the index field to the query. */ @Override public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression) { if (this.listOrderField != null) { if (selectionQuery.isObjectLevelReadQuery()) { ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(this.listOrderField)); } else { ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(baseExpression.getField(this.listOrderField)); } } } }
/** * INTERNAL: * Add the index field to the query. */ @Override public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression) { if (this.listOrderField != null) { if (selectionQuery.isObjectLevelReadQuery()) { ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(this.listOrderField)); } else { ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(baseExpression.getField(this.listOrderField)); } } } }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map. * Called when the selection query is being initialized to add the fields for the map key to the query. */ public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression){ for (DatabaseField field : getForeignKeyFields()) { if (selectionQuery.isObjectLevelReadQuery()){ ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(field)); } else if (selectionQuery.isDataReadQuery()){ ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(field); } } }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map. * Called when the selection query is being initialized to add the fields for the map key to the query. */ public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression){ for (DatabaseField field : getForeignKeyFields()) { if (selectionQuery.isObjectLevelReadQuery()){ ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(field)); } else if (selectionQuery.isDataReadQuery()){ ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(field); } } }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map. * Called when the selection query is being initialized to add the fields for the map key to the query. */ public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression){ if (selectionQuery.isObjectLevelReadQuery()){ ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(getField())); } else if (selectionQuery.isDataReadQuery()){ ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(baseExpression.getField(getField())); } }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map. * Called when the selection query is being initialized to add the fields for the map key to the query. */ public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression){ if (selectionQuery.isObjectLevelReadQuery()){ ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(getField())); } else if (selectionQuery.isDataReadQuery()){ ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(baseExpression.getField(getField())); } }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map * Called when the selection query is being initialized to add the fields for the map key to the query */ @Override public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression){ for (DatabaseField field : getReferenceDescriptor().getAllFields()) { if (selectionQuery.isObjectLevelReadQuery()) { ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(field)); } else if (selectionQuery.isDataReadQuery()) { ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(baseExpression.getField(field)); } } }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map * Called when the selection query is being initialized to add the fields for the map key to the query */ @Override public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression){ for (DatabaseField field : getReferenceDescriptor().getAllFields()) { if (selectionQuery.isObjectLevelReadQuery()) { ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(field)); } else if (selectionQuery.isDataReadQuery()) { ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(baseExpression.getField(field)); } } }
/** * INTERNAL: */ public Cursor(DatabaseCall call, CursorPolicy policy) { ReadQuery query = policy.getQuery(); this.query = query; this.session = query.getSession(); this.executionSession = session.getExecutionSession(query); this.statement = call.getStatement(); this.fields = call.getFields(); this.resultSet = call.getResult(); this.policy = policy; this.objectCollection = new Vector(); if (query.getSession().isUnitOfWork() && query.isObjectLevelReadQuery()) { // Call register on the cursor itself. This will set up // incremental conforming by setting the // selection criteria clone and arguments, and building the // intially conforming index (scans the UOW cache). // The incremental registration/conforming is done // in retrieveNext/PreviousObject -> buildAndRegisterObject ((ObjectLevelReadQuery)query).registerResultInUnitOfWork(this, (UnitOfWorkImpl)this.session, query.getTranslationRow(), false);// object collection is empty, so setting irrelevant. } }
/** * INTERNAL: */ public Cursor(DatabaseCall call, CursorPolicy policy) { ReadQuery query = policy.getQuery(); this.query = query; this.session = query.getSession(); this.executionSession = session.getExecutionSession(query); this.statement = call.getStatement(); this.fields = call.getFields(); this.resultSet = call.getResult(); this.policy = policy; this.objectCollection = new Vector(); if (query.getSession().isUnitOfWork() && query.isObjectLevelReadQuery()) { // Call register on the cursor itself. This will set up // incremental conforming by setting the // selection criteria clone and arguments, and building the // intially conforming index (scans the UOW cache). // The incremental registration/conforming is done // in retrieveNext/PreviousObject -> buildAndRegisterObject ((ObjectLevelReadQuery)query).registerResultInUnitOfWork(this, (UnitOfWorkImpl)this.session, query.getTranslationRow(), false);// object collection is empty, so setting irrelevant. } }
/** * INTERNAL: */ public Cursor(DatabaseCall call, CursorPolicy policy) { this.session = policy.getQuery().getSession(); this.executionSession = session.getExecutionSession(policy.getQuery()); this.statement = call.getStatement(); this.fields = call.getFields(); this.resultSet = call.getResult(); this.policy = policy; setObjectCollection(new Vector()); if (getQuery().getSession().isUnitOfWork() && getQuery().isObjectLevelReadQuery()) { // Call register on the cursor itself. This will set up // incremental conforming by setting the // selection criteria clone and arguments, and building the // intially conforming index (scans the UOW cache). // The incremental registration/conforming is done // in retrieveNext/PreviousObject -> buildAndRegisterObject ObjectLevelReadQuery query = (ObjectLevelReadQuery)getQuery(); query.registerResultInUnitOfWork(this, (UnitOfWorkImpl)this.session, getQuery().getTranslationRow(), false);// object collection is empty, so setting irrelevant. } }
/** * INTERNAL: * builds and registers an object from a row for cursors. * Behavior is different from the query version in that refreshing is not * supported. */ protected Object buildAndRegisterObject(AbstractRecord row) { ReadQuery query = this.query; if (query.isObjectLevelReadQuery()) { ObjectLevelReadQuery objectQuery = (ObjectLevelReadQuery)query; if (objectQuery.hasBatchReadAttributes() && objectQuery.getBatchFetchPolicy().isIN()) { objectQuery.getBatchFetchPolicy().addDataResults(row); } if (this.session.isUnitOfWork() && (!query.isReportQuery()) && query.shouldMaintainCache() && (objectQuery.shouldConformResultsInUnitOfWork() || objectQuery.getDescriptor().shouldAlwaysConformResultsInUnitOfWork())) { Object object = objectQuery.conformIndividualResult( objectQuery.buildObject(row), (UnitOfWorkImpl)this.session, this.translationRow, this.selectionCriteriaClone, this.initiallyConformingIndex); // Notifies caller to continue until conforming instance found if (object == null) { return InvalidObject.instance; } return object; } } return query.buildObject(row); }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map * Called when the selection query is being initialized to add the fields for the map key to the query */ public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression){ if (selectionQuery.isObjectLevelReadQuery()){ if (baseExpression == null){ ((ObjectLevelReadQuery)selectionQuery).addAdditionalField((DatabaseField)getField().clone()); } else { ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(getField())); } } else if (selectionQuery.isDataReadQuery()){ if (baseExpression == null){ ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField((DatabaseField)getField().clone()); ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addTable((DatabaseTable)getField().getTable().clone()); } else { ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(baseExpression.getTable(getField().getTable()).getField(getField())); } } }