/** * Build the row representation of the object for update. The row built does not * contain entries for uninstantiated attributes. */ public AbstractRecord buildTemplateUpdateRow(AbstractSession session) { AbstractRecord databaseRow = createRecord(session); for (Iterator mappings = getNonPrimaryKeyMappings().iterator(); mappings.hasNext();) { DatabaseMapping mapping = (DatabaseMapping)mappings.next(); mapping.writeUpdateFieldsIntoRow(databaseRow, session); } if (this.descriptor.usesOptimisticLocking()) { this.descriptor.getOptimisticLockingPolicy().addLockFieldsToUpdateRow(databaseRow, session); } return databaseRow; }
/** * 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; } }
Object originalWriteLockValue = optimisticLockingPolicy.getWriteLockValue(original, getId(), session); if (originalWriteLockValue != null && optimisticLockingPolicy.compareWriteLockValues(initialWriteLockValue, originalWriteLockValue) != 0) { return true; } else {
/** * 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()); } }
lockingPolicy.addLockValuesToTranslationRow(writeQuery); lockingPolicy.updateRowAndObjectForUpdate(writeQuery, object); } else if (!shouldModifyVersionField.booleanValue() && (lockingPolicy instanceof VersionLockingPolicy)) { lockingPolicy.validateUpdate(rowCount, object, writeQuery);
if (concreteDescriptor.usesOptimisticLocking()) { OptimisticLockingPolicy policy = concreteDescriptor.getOptimisticLockingPolicy(); Object cacheValue = policy.getValueToPutInCache(databaseRow, session); if (concreteDescriptor.getCachePolicy().shouldOnlyRefreshCacheIfNewerVersion()) { if (cacheValue == null) { refreshRequired = policy.isNewerVersion(databaseRow, domainObject, cacheKey.getKey(), session); } else { refreshRequired = policy.isNewerVersion(cacheValue, domainObject, cacheKey.getKey(), session);
int difference = descriptor.getOptimisticLockingPolicy().getVersionDifference(changeSet.getInitialWriteLockValue(), original, changeSet.getPrimaryKeys(), session); if (descriptor.usesOptimisticLocking() && descriptor.getOptimisticLockingPolicy().isStoredInCache()) { cacheKey.setWriteLockValue(changeSet.getWriteLockValue());
if(policy.getWriteLockField() != null) { Expression writeLock = builder.getField(policy.getWriteLockField()); Expression writeLockUpdateExpression = policy.getWriteLockUpdateExpression(builder, getQuery().getSession()); if (writeLockUpdateExpression != null) {
DatabaseField lockField = getDescriptor().getOptimisticLockingPolicy().getWriteLockField(); if (lockField != null) { fetchedFields.add(lockField);
/** * Store the query object in the identity map. */ protected void registerObjectInIdentityMap(Object object, ClassDescriptor descriptor, AbstractSession session) { WriteObjectQuery query = getWriteObjectQuery(); if (query.shouldMaintainCache()) { if (descriptor.usesOptimisticLocking()) { Object optimisticLockValue = descriptor.getOptimisticLockingPolicy().getValueToPutInCache(query.getModifyRow(), session); session.getIdentityMapAccessorInstance().putInIdentityMap(object, query.getPrimaryKey(), optimisticLockValue, System.currentTimeMillis(), descriptor); } else { session.getIdentityMapAccessorInstance().putInIdentityMap(object, query.getPrimaryKey(), null, System.currentTimeMillis(), descriptor); } } }
objectDescriptor.setWriteLockValue(null); }else{ objectDescriptor.setWriteLockValue(policy.getBaseValue()); objectDescriptor.setWriteLockValue(null); }else{ objectDescriptor.setWriteLockValue(policy.getBaseValue());
/** * INTERNAL: * Prepare the receiver for execution in a session. In particular, * verify that the object is not null and contains a valid primary key. */ public void prepareForExecution() throws QueryException { super.prepareForExecution(); // Set the translation row if ((this.translationRow == null) || this.translationRow.isEmpty()) { if (this.isFullRowRequired) { this.translationRow = this.descriptor.getObjectBuilder().buildRow(this.object, this.session, WriteType.UNDEFINED); } else { this.translationRow = this.descriptor.getObjectBuilder().buildRowForTranslation(this.object, this.session); } } // Add the write lock field if required if (this.usesOptimisticLocking) { this.descriptor.getOptimisticLockingPolicy().addLockValuesToTranslationRow(this); } } }
if(this.optimisticLockingPolicy.compareWriteLockValues(writeLockValueToCompare, changeSetToMergeFrom.initialWriteLockValue) != 0) { this.isInvalid = true; return;
clonedDescriptor.setOptimisticLockingPolicy((OptimisticLockingPolicy)getOptimisticLockingPolicy().clone());
policy.addLockValuesToTranslationRow(writeQuery); policy.updateRowAndObjectForUpdate(writeQuery, object); } else if (!shouldModifyVersionField.booleanValue() && (policy instanceof VersionLockingPolicy)) { descriptor.getOptimisticLockingPolicy().validateUpdate(rowCount, object, writeQuery);
/** * 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()); } }
Object originalWriteLockValue = optimisticLockingPolicy.getWriteLockValue(original, getId(), session); if (originalWriteLockValue != null && optimisticLockingPolicy.compareWriteLockValues(initialWriteLockValue, originalWriteLockValue) != 0) { return true; } else {
if (concreteDescriptor.usesOptimisticLocking()) { OptimisticLockingPolicy policy = concreteDescriptor.getOptimisticLockingPolicy(); Object cacheValue = policy.getValueToPutInCache(databaseRow, session); if (concreteDescriptor.getCachePolicy().shouldOnlyRefreshCacheIfNewerVersion()) { if (cacheValue == null) { refreshRequired = policy.isNewerVersion(databaseRow, domainObject, cacheKey.getKey(), session); } else { refreshRequired = policy.isNewerVersion(cacheValue, domainObject, cacheKey.getKey(), session);
int difference = descriptor.getOptimisticLockingPolicy().getVersionDifference(changeSet.getInitialWriteLockValue(), original, changeSet.getId(), session); if (descriptor.usesOptimisticLocking() && descriptor.getOptimisticLockingPolicy().isStoredInCache()) { cacheKey.setWriteLockValue(changeSet.getWriteLockValue());