public static ForUpdateClause newInstance(short lockMode) { if (lockMode == ObjectBuildingQuery.NO_LOCK) { return NO_LOCK_CLAUSE; } else { return new ForUpdateClause(lockMode); } }
/** * INTERNAL: * The locking clause contains a list of expressions representing which * objects are to be locked by the query. * <p> * Use for even finer grained control over what is and is not locked by * a particular query. */ public void setLockingClause(ForUpdateClause clause) { if (clause.isForUpdateOfClause()) { this.lockingClause = clause; setIsPrePrepared(false); } else { setLockMode(clause.getLockMode()); } setWasDefaultLockMode(false); }
/** * INTERNAL: * Cache the locking policy isReferenceClassLocked check. */ protected boolean isReferenceClassLocked() { if (isReferenceClassLocked == null) { isReferenceClassLocked = Boolean.valueOf(isLockQuery() && lockingClause.isReferenceClassLocked()); } return isReferenceClassLocked.booleanValue(); }
/** * Print the FOR UPDATE clause after each join if required. */ protected void printForUpdateClauseOnJoin(DatabaseTable alias, ExpressionSQLPrinter printer, boolean shouldPrintUpdateClauseForAllTables, Collection aliasesOfTablesToBeLocked, DatabasePlatform platform) { if (shouldPrintUpdateClauseForAllTables || (aliasesOfTablesToBeLocked != null && aliasesOfTablesToBeLocked.remove(alias))) { getForUpdateClause().printSQL(printer, this); } }
/** * PUBLIC: * Sets whether this is a pessimistically locking query. * <ul> * <li>ObjectBuildingQuery.LOCK: SELECT .... FOR UPDATE issued. * <li>ObjectBuildingQuery.LOCK_NOWAIT: SELECT .... FOR UPDATE NO WAIT issued. * <li>ObjectBuildingQuery.NO_LOCK: no pessimistic locking. * <li>ObjectBuildingQuery.DEFAULT_LOCK_MODE (default) and you have a CMP descriptor: * fine grained locking will occur. * </ul> * <p>Fine Grained Locking: On execution the reference class * and those of all joined attributes will be checked. If any of these have a * PessimisticLockingPolicy set on their descriptor, they will be locked in a * SELECT ... FOR UPDATE OF ... {NO WAIT}. Issues fewer locks * and avoids setting the lock mode on each query. * <p>Example:<code>readAllQuery.setSelectionCriteria(employee.get("address").equal("Ottawa"));</code> * <ul><li>LOCK: all employees in Ottawa and all referenced Ottawa addresses will be locked. * <li>DEFAULT_LOCK_MODE: if address is a joined attribute, and only address has a pessimistic * locking policy, only referenced Ottawa addresses will be locked. * </ul> * @see org.eclipse.persistence.descriptors.PessimisticLockingPolicy */ public void setLockMode(short lockMode) { lockingClause = ForUpdateClause.newInstance(lockMode); }
if (((ObjectLevelReadQuery)baseQuery).getLockingClause().isForUpdateOfClause()) { ForUpdateOfClause clause = (ForUpdateOfClause)((ObjectLevelReadQuery)baseQuery).getLockingClause().clone(); clause.setLockedExpressions(extractNestedExpressions(clause.getLockedExpressions(), nestedQuery.getExpressionBuilder(), true)); nestedQuery.setLockingClause(clause);
boolean shouldPrintUpdateClauseForAllTables = false; if(shouldPrintUpdateClause) { aliasesOfTablesToBeLocked = getForUpdateClause().getAliasesOfTablesToBeLocked(this); shouldPrintUpdateClauseForAllTables = aliasesOfTablesToBeLocked.size() == getTableAliases().size(); getForUpdateClause().printSQL(printer, this);
/** * PUBLIC: * Return the current locking mode. */ public short getLockMode() { if (lockingClause == null) { return DEFAULT_LOCK_MODE; } else { return lockingClause.getLockMode(); } }
/** * INTERNAL: * There is a very special case where a query may be a bean-level * pessimistic locking query. * <p> * If that is so, only queries executed inside of a UnitOfWork should * have a locking clause. In the extremely rare case that we execute * a locking query outside of a UnitOfWork, must disable locking so that * we do not get a fetch out of sequence error. */ public DatabaseQuery prepareOutsideUnitOfWork(AbstractSession session) { // Implementation is complicated because: if locking refresh will be // auto set to true preventing cache hit. // Must prepare this query from scratch if outside uow but locking // Must not reprepare this query as a NO_LOCK, but create a clone first // Must not cloneAndUnPrepare unless really have to if (isLockQuery(session) && getLockingClause().isForUpdateOfClause()) { ObjectLevelReadQuery clone = (ObjectLevelReadQuery)clone(); clone.setIsExecutionClone(true); clone.dontAcquireLocks(); clone.setIsPrepared(false); clone.checkPrePrepare(session); return clone; } return this; }
/** * Print the FOR UPDATE clause after each join if required. */ protected void printForUpdateClauseOnJoin(DatabaseTable alias, ExpressionSQLPrinter printer, boolean shouldPrintUpdateClauseForAllTables, Collection aliasesOfTablesToBeLocked, DatabasePlatform platform) { if (shouldPrintUpdateClauseForAllTables || (aliasesOfTablesToBeLocked != null && aliasesOfTablesToBeLocked.remove(alias))) { getForUpdateClause().printSQL(printer, this); } }
/** * PUBLIC: * Sets whether this is a pessimistically locking query. * <ul> * <li>ObjectBuildingQuery.LOCK: SELECT .... FOR UPDATE issued. * <li>ObjectBuildingQuery.LOCK_NOWAIT: SELECT .... FOR UPDATE NO WAIT issued. * <li>ObjectBuildingQuery.NO_LOCK: no pessimistic locking. * <li>ObjectBuildingQuery.DEFAULT_LOCK_MODE (default) and you have a CMP descriptor: * fine grained locking will occur. * </ul> * <p>Fine Grained Locking: On execution the reference class * and those of all joined attributes will be checked. If any of these have a * PessimisticLockingPolicy set on their descriptor, they will be locked in a * SELECT ... FOR UPDATE OF ... {NO WAIT}. Issues fewer locks * and avoids setting the lock mode on each query. * <p>Example:<code>readAllQuery.setSelectionCriteria(employee.get("address").equal("Ottawa"));</code> * <ul><li>LOCK: all employees in Ottawa and all referenced Ottawa addresses will be locked. * <li>DEFAULT_LOCK_MODE: if address is a joined attribute, and only address has a pessimistic * locking policy, only referenced Ottawa addresses will be locked. * </ul> * @see org.eclipse.persistence.descriptors.PessimisticLockingPolicy */ public void setLockMode(short lockMode) { lockingClause = ForUpdateClause.newInstance(lockMode); }
if (((ObjectLevelReadQuery)baseQuery).getLockingClause().isForUpdateOfClause()) { ForUpdateOfClause clause = (ForUpdateOfClause)((ObjectLevelReadQuery)baseQuery).getLockingClause().clone(); clause.setLockedExpressions(extractNestedNonAggregateExpressions(clause.getLockedExpressions(), nestedQuery.getExpressionBuilder(), true)); nestedQuery.setLockingClause(clause);
boolean shouldPrintUpdateClauseForAllTables = false; if (shouldPrintUpdateClause) { aliasesOfTablesToBeLocked = getForUpdateClause().getAliasesOfTablesToBeLocked(this); shouldPrintUpdateClauseForAllTables = aliasesOfTablesToBeLocked.size() == getTableAliases().size(); getForUpdateClause().printSQL(printer, this);
/** * PUBLIC: * Return the current locking mode. */ public short getLockMode() { if (lockingClause == null) { return DEFAULT_LOCK_MODE; } else { return lockingClause.getLockMode(); } }
/** * INTERNAL: * There is a very special case where a query may be a bean-level * pessimistic locking query. * <p> * If that is so, only queries executed inside of a UnitOfWork should * have a locking clause. In the extremely rare case that we execute * a locking query outside of a UnitOfWork, must disable locking so that * we do not get a fetch out of sequence error. */ public DatabaseQuery prepareOutsideUnitOfWork(AbstractSession session) { // Implementation is complicated because: if locking refresh will be // auto set to true preventing cache hit. // Must prepare this query from scratch if outside uow but locking // Must not reprepare this query as a NO_LOCK, but create a clone first // Must not cloneAndUnPrepare unless really have to if (isLockQuery(session) && getLockingClause().isForUpdateOfClause()) { ObjectLevelReadQuery clone = (ObjectLevelReadQuery)clone(); clone.setIsExecutionClone(true); clone.dontAcquireLocks(); clone.setIsPrepared(false); clone.checkPrePrepare(session); return clone; } return this; }
/** * Print the FOR UPDATE clause after each join if required. */ protected void printForUpdateClauseOnJoin(DatabaseTable alias, ExpressionSQLPrinter printer, boolean shouldPrintUpdateClauseForAllTables, Collection aliasesOfTablesToBeLocked, DatabasePlatform platform) { if (shouldPrintUpdateClauseForAllTables || (aliasesOfTablesToBeLocked != null && aliasesOfTablesToBeLocked.remove(alias))) { getForUpdateClause().printSQL(printer, this); } }
public static ForUpdateClause newInstance(short lockMode) { if (lockMode == ObjectBuildingQuery.NO_LOCK) { return NO_LOCK_CLAUSE; } else { return new ForUpdateClause(lockMode); } }
/** * INTERNAL: * The locking clause contains a list of expressions representing which * objects are to be locked by the query. * <p> * Use for even finer grained control over what is and is not locked by * a particular query. */ public void setLockingClause(ForUpdateClause clause) { if (clause.isForUpdateOfClause()) { this.lockingClause = clause; setIsPrePrepared(false); } else { setLockMode(clause.getLockMode()); } setWasDefaultLockMode(false); }
/** * PUBLIC: * Sets whether this is a pessimistically locking query. * <ul> * <li>ObjectBuildingQuery.LOCK: SELECT .... FOR UPDATE issued. * <li>ObjectBuildingQuery.LOCK_NOWAIT: SELECT .... FOR UPDATE NO WAIT issued. * <li>ObjectBuildingQuery.NO_LOCK: no pessimistic locking. * <li>ObjectBuildingQuery.DEFAULT_LOCK_MODE (default) and you have a CMP descriptor: * fine grained locking will occur. * </ul> * <p>Fine Grained Locking: On execution the reference class * and those of all joined attributes will be checked. If any of these have a * PessimisticLockingPolicy set on their descriptor, they will be locked in a * SELECT ... FOR UPDATE OF ... {NO WAIT}. Issues fewer locks * and avoids setting the lock mode on each query. * <p>Example:<code>readAllQuery.setSelectionCriteria(employee.get("address").equal("Ottawa"));</code> * <ul><li>LOCK: all employees in Ottawa and all referenced Ottawa addresses will be locked. * <li>DEFAULT_LOCK_MODE: if address is a joined attribute, and only address has a pessimistic * locking policy, only referenced Ottawa addresses will be locked. * </ul> * @see org.eclipse.persistence.descriptors.PessimisticLockingPolicy */ public void setLockMode(short lockMode) { lockingClause = ForUpdateClause.newInstance(lockMode); }
if (((ObjectLevelReadQuery)baseQuery).getLockingClause().isForUpdateOfClause()) { ForUpdateOfClause clause = (ForUpdateOfClause)((ObjectLevelReadQuery)baseQuery).getLockingClause().clone(); clause.setLockedExpressions(extractNestedNonAggregateExpressions(clause.getLockedExpressions(), nestedQuery.getExpressionBuilder(), true)); nestedQuery.setLockingClause(clause);