/** * INTERNAL: * Return true if the receiver uses either all or changed fields for optimistic locking. */ public boolean usesFieldLocking() { return (usesOptimisticLocking() && (getOptimisticLockingPolicy() instanceof FieldsLockingPolicy)); }
/** * PUBLIC: * Return true if the receiver uses version optimistic locking. */ public boolean usesVersionLocking() { return (usesOptimisticLocking() && (getOptimisticLockingPolicy() instanceof VersionLockingPolicy)); }
/** * INTERNAL: * Return true if the receiver uses either all or changed fields for optimistic locking. */ public boolean usesFieldLocking() { return (usesOptimisticLocking() && (getOptimisticLockingPolicy() instanceof FieldsLockingPolicy)); }
/** * PUBLIC: * Return true if the receiver uses version optimistic locking. */ public boolean usesVersionLocking() { return (usesOptimisticLocking() && (getOptimisticLockingPolicy() instanceof VersionLockingPolicy)); }
/** * PUBLIC: * Return true if the receiver uses version optimistic locking. */ public boolean usesVersionLocking() { return (usesOptimisticLocking() && (getOptimisticLockingPolicy() instanceof VersionLockingPolicy)); }
/** * INTERNAL: * Return true if the receiver uses either all or changed fields for optimistic locking. */ public boolean usesFieldLocking() { return (usesOptimisticLocking() && (getOptimisticLockingPolicy() instanceof FieldsLockingPolicy)); }
/** * Build and return the expression to use as the where clause to delete an object. * The row is passed to allow the version number to be extracted from it. * If called with usesOptimisticLocking==true the caller should make sure that descriptor uses optimistic locking policy. */ public Expression buildDeleteExpression(DatabaseTable table, AbstractRecord row, boolean usesOptimisticLocking) { if (usesOptimisticLocking && (this.descriptor.getTables().firstElement().equals(table))) { return this.descriptor.getOptimisticLockingPolicy().buildDeleteExpression(table, primaryKeyExpression, row); } else { return buildPrimaryKeyExpression(table); } }
/** * Build and return the expression to use as the where clause to delete an object. * The row is passed to allow the version number to be extracted from it. * If called with usesOptimisticLocking==true the caller should make sure that descriptor uses optimistic locking policy. */ public Expression buildDeleteExpression(DatabaseTable table, AbstractRecord row, boolean usesOptimisticLocking) { if (usesOptimisticLocking && (this.descriptor.getTables().firstElement().equals(table))) { return this.descriptor.getOptimisticLockingPolicy().buildDeleteExpression(table, primaryKeyExpression, row); } else { return buildPrimaryKeyExpression(table); } }
/** * Build and return the expression to use as the where clause to an update object. * The row is passed to allow the version number to be extracted from it. */ public Expression buildUpdateExpression(DatabaseTable table, AbstractRecord transactionRow, AbstractRecord modifyRow) { // Only the first table must use the lock check. Expression primaryKeyExpression = buildPrimaryKeyExpression(table); if (this.descriptor.usesOptimisticLocking()) { return this.descriptor.getOptimisticLockingPolicy().buildUpdateExpression(table, primaryKeyExpression, transactionRow, modifyRow); } else { return primaryKeyExpression; } }
/** * Build and return the expression to use as the where clause to delete an object. * The row is passed to allow the version number to be extracted from it. */ public Expression buildDeleteExpression(DatabaseTable table, AbstractRecord row) { if (this.descriptor.usesOptimisticLocking() && (this.descriptor.getTables().firstElement().equals(table))) { return this.descriptor.getOptimisticLockingPolicy().buildDeleteExpression(table, primaryKeyExpression, row); } else { return buildPrimaryKeyExpression(table); } }
/** * Add the initial write lock value to the row for insert. */ protected void addWriteLockFieldForInsert() { if (getDescriptor().usesOptimisticLocking()) { getDescriptor().getOptimisticLockingPolicy().setupWriteFieldsForInsert(getWriteObjectQuery()); } }
/** * Add the initial write lock value to the row for insert. */ protected void addWriteLockFieldForInsert() { if (getDescriptor().usesOptimisticLocking()) { getDescriptor().getOptimisticLockingPolicy().setupWriteFieldsForInsert(getWriteObjectQuery()); } }
/** * Add the initial write lock value to the row for insert. */ protected void addWriteLockFieldForInsert() { if (getDescriptor().usesOptimisticLocking()) { getDescriptor().getOptimisticLockingPolicy().setupWriteFieldsForInsert(getWriteObjectQuery()); } }
/** * INTERNAL: * Potentially override the optimistic locking behavior */ protected void initializeOptimisticLocking(){ // CR#3214106, do not override if specified in subclass. if (!getDescriptor().usesOptimisticLocking() && getParentDescriptor().usesOptimisticLocking()) { getDescriptor().setOptimisticLockingPolicy((OptimisticLockingPolicy)getParentDescriptor().getOptimisticLockingPolicy().clone()); getDescriptor().getOptimisticLockingPolicy().setDescriptor(getDescriptor()); } }
/** * INTERNAL: * Potentially override the optimistic locking behavior */ protected void initializeOptimisticLocking(){ // CR#3214106, do not override if specified in subclass. if (!getDescriptor().usesOptimisticLocking() && getParentDescriptor().usesOptimisticLocking()) { getDescriptor().setOptimisticLockingPolicy((OptimisticLockingPolicy)getParentDescriptor().getOptimisticLockingPolicy().clone()); getDescriptor().getOptimisticLockingPolicy().setDescriptor(getDescriptor()); } }
/** * INTERNAL: * Potentially override the optimistic locking behavior */ protected void initializeOptimisticLocking(){ // CR#3214106, do not override if specified in subclass. if (!getDescriptor().usesOptimisticLocking() && getParentDescriptor().usesOptimisticLocking()) { getDescriptor().setOptimisticLockingPolicy((OptimisticLockingPolicy)getParentDescriptor().getOptimisticLockingPolicy().clone()); getDescriptor().getOptimisticLockingPolicy().setDescriptor(getDescriptor()); } }
/** * Rebuild writeLockValue to the expected type from user format i.e XML change set has all values as String. */ protected void rebuildWriteLockValueFromUserFormat(ClassDescriptor descriptor, AbstractSession session) { if (descriptor.getOptimisticLockingPolicy() instanceof TimestampLockingPolicy) { this.writeLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.writeLockValue, ClassConstants.JavaSqlTimestamp_Class); this.initialWriteLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.initialWriteLockValue, ClassConstants.JavaSqlTimestamp_Class); } else if (descriptor.getOptimisticLockingPolicy() instanceof VersionLockingPolicy) { this.writeLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.writeLockValue, ClassConstants.BIGDECIMAL); this.initialWriteLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.initialWriteLockValue, ClassConstants.BIGDECIMAL); } }
/** * Rebuild writeLockValue to the expected type from user format i.e XML change set has all values as String. */ protected void rebuildWriteLockValueFromUserFormat(ClassDescriptor descriptor, AbstractSession session) { if (descriptor.getOptimisticLockingPolicy() instanceof TimestampLockingPolicy) { this.writeLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.writeLockValue, ClassConstants.JavaSqlTimestamp_Class); this.initialWriteLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.initialWriteLockValue, ClassConstants.JavaSqlTimestamp_Class); } else if (descriptor.getOptimisticLockingPolicy() instanceof VersionLockingPolicy) { this.writeLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.writeLockValue, ClassConstants.BIGDECIMAL); this.initialWriteLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.initialWriteLockValue, ClassConstants.BIGDECIMAL); } }
/** * Rebuild writeLockValue to the expected type from user format i.e XML change set has all values as String. */ protected void rebuildWriteLockValueFromUserFormat(ClassDescriptor descriptor, AbstractSession session) { if (descriptor.getOptimisticLockingPolicy() instanceof TimestampLockingPolicy) { this.writeLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.writeLockValue, ClassConstants.JavaSqlTimestamp_Class); this.initialWriteLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.initialWriteLockValue, ClassConstants.JavaSqlTimestamp_Class); } else if (descriptor.getOptimisticLockingPolicy() instanceof VersionLockingPolicy) { this.writeLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.writeLockValue, ClassConstants.BIGDECIMAL); this.initialWriteLockValue = session.getPlatform(descriptor.getJavaClass()).getConversionManager().convertObject(this.initialWriteLockValue, ClassConstants.BIGDECIMAL); } }
/** * Is the attribute a version attribute. * @return boolean indicating whether or not attribute is * a version attribute */ public boolean isVersion() { if (getDescriptor().usesOptimisticLocking() && getMapping().isDirectToFieldMapping()) { OptimisticLockingPolicy policy = getDescriptor().getOptimisticLockingPolicy(); return policy.getWriteLockField().equals(((AbstractDirectMapping) getMapping()).getField()); } return false; }