/** * PUBLIC: * Set the locking policy a selected fields locking policy. * A field locking policy is base on locking on the specified fields by comparing with their previous values to detect field-level collisions. * Note: the unit of work must be used for all updates when using field locking. * @see SelectedFieldsLockingPolicy */ public void useSelectedFieldsLocking(Vector fieldNames) { SelectedFieldsLockingPolicy policy = new SelectedFieldsLockingPolicy(); policy.setLockFieldNames(fieldNames); setOptimisticLockingPolicy(policy); }
/** * PUBLIC: Set the field names to lock on. All fields in this list will be * compared when Updating. If the value of any of the fields does not match * the value in memory, an OptimisticLockException will be thrown. * * Note: An Automatic update will not be done on this field, only a * comparison occurs. */ public void setLockFieldNames(List<String> lockFieldNames) { for (String name : lockFieldNames) { addLockFieldName(name); } }
/** * INTERNAL: * returns the lock fields to compare based on the passed in table. */ protected Vector getFieldsToCompare(org.eclipse.persistence.internal.helper.DatabaseTable table, AbstractRecord transRow, AbstractRecord modifyRow) { return getLockFields(table); }
/** * INTERNAL: It is responsible for initializing the policy; */ @Override public void initialize(AbstractSession session) { super.initialize(session); List<DatabaseField> lockFields = getLockFields(); int size = lockFields.size(); for (int index = 0; index < size; index++) { DatabaseField field = lockFields.get(index); field = descriptor.buildField(field); lockFields.set(index, field); List<DatabaseField> fieldsForTable = getLockFieldsByTable().get(field.getTable()); if (fieldsForTable == null) { fieldsForTable = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(); getLockFieldsByTable().put(field.getTable(), fieldsForTable); } fieldsForTable.add(field); } }
/** * INTERNAL: * Values to be included in the locking mechanism are added to the translation row. * For changed fields the normal build row is ok as only changed fields matter. */ public void addLockValuesToTranslationRow(ObjectLevelModifyQuery query) throws DatabaseException{ Object object; verifyUsage(query.getSession()); if (query.isDeleteObjectQuery()) { object = query.getObject(); } else { object = query.getBackupClone(); } for (Iterator vectors = getLockFieldsByTable().values().iterator(); vectors.hasNext();) { for (Enumeration fields = ((Vector)vectors.next()).elements(); fields.hasMoreElements();) { DatabaseField field = (DatabaseField)fields.nextElement(); DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForField(field); //Bug5892889, Exception will be thrown if no matched database field found if(mapping == null ){ throw DatabaseException.specifiedLockingFieldsNotFoundInDatabase(field.getQualifiedName()); }else{ mapping.writeFromObjectIntoRow(object, query.getTranslationRow(), query.getSession()); } } } }
throw ValidationException.optimisticLockingSelectedColumnNamesNotSpecified(descriptor.getJavaClass()); } else { SelectedFieldsLockingPolicy policy = new SelectedFieldsLockingPolicy(); throw ValidationException.optimisticLockingSelectedColumnNamesNotSpecified(descriptor.getJavaClass()); } else { policy.addLockFieldName(selectedColumn.getName());
/** * INTERNAL: It is responsible for initializing the policy; */ @Override public void initialize(AbstractSession session) { super.initialize(session); List<DatabaseField> lockFields = getLockFields(); int size = lockFields.size(); for (int index = 0; index < size; index++) { DatabaseField field = lockFields.get(index); field = descriptor.buildField(field); lockFields.set(index, field); List<DatabaseField> fieldsForTable = getLockFieldsByTable().get(field.getTable()); if (fieldsForTable == null) { fieldsForTable = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(); getLockFieldsByTable().put(field.getTable(), fieldsForTable); } fieldsForTable.add(field); } }
public void addLockValuesToTranslationRow(ObjectLevelModifyQuery query) throws DatabaseException { Object object; verifyUsage(query.getSession()); if (query.isDeleteObjectQuery()) { object = query.getObject(); for (Iterator<List<DatabaseField>> fields = getLockFieldsByTable().values().iterator(); fields.hasNext();) { for (DatabaseField field : fields.next()) { DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForField(field);
/** * PUBLIC: * Set the locking policy a selected fields locking policy. * A field locking policy is base on locking on the specified fields by comparing with their previous values to detect field-level collisions. * Note: the unit of work must be used for all updates when using field locking. * @see SelectedFieldsLockingPolicy */ public void useSelectedFieldsLocking(Vector fieldNames) { SelectedFieldsLockingPolicy policy = new SelectedFieldsLockingPolicy(); policy.setLockFieldNames(fieldNames); setOptimisticLockingPolicy(policy); }
/** * INTERNAL: * It is responsible for initializing the policy; */ public void initialize(AbstractSession session) { super.initialize(session); List lockFields = getLockFields(); int size = lockFields.size(); for (int index = 0; index < size; index++) { DatabaseField field = (DatabaseField)lockFields.get(index); field = descriptor.buildField(field); lockFields.set(index, field); Vector fieldsForTable = (Vector)getLockFieldsByTable().get(field.getTable()); if (fieldsForTable == null) { fieldsForTable = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(); getLockFieldsByTable().put(field.getTable(), fieldsForTable); } fieldsForTable.addElement(field); } }
public void addLockValuesToTranslationRow(ObjectLevelModifyQuery query) throws DatabaseException { Object object; verifyUsage(query.getSession()); if (query.isDeleteObjectQuery()) { object = query.getObject(); for (Iterator<List<DatabaseField>> fields = getLockFieldsByTable().values().iterator(); fields.hasNext();) { for (DatabaseField field : fields.next()) { DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForField(field);
/** * INTERNAL: returns the lock fields to compare based on the passed in * table. */ @Override protected List<DatabaseField> getFieldsToCompare(org.eclipse.persistence.internal.helper.DatabaseTable table, AbstractRecord transRow, AbstractRecord modifyRow) { return getLockFields(table); }
/** * PUBLIC: Set the field names to lock on. All fields in this list will be * compared when Updating. If the value of any of the fields does not match * the value in memory, an OptimisticLockException will be thrown. * * Note: An Automatic update will not be done on this field, only a * comparison occurs. */ public void setLockFieldNames(List<String> lockFieldNames) { for (String name : lockFieldNames) { addLockFieldName(name); } }
/** * PUBLIC: * Set the locking policy a selected fields locking policy. * A field locking policy is base on locking on the specified fields by comparing with their previous values to detect field-level collisions. * Note: the unit of work must be used for all updates when using field locking. * @see SelectedFieldsLockingPolicy */ public void useSelectedFieldsLocking(Vector fieldNames) { SelectedFieldsLockingPolicy policy = new SelectedFieldsLockingPolicy(); policy.setLockFieldNames(fieldNames); setOptimisticLockingPolicy(policy); }
/** * INTERNAL: returns the lock fields to compare based on the passed in * table. */ @Override protected List<DatabaseField> getFieldsToCompare(org.eclipse.persistence.internal.helper.DatabaseTable table, AbstractRecord transRow, AbstractRecord modifyRow) { return getLockFields(table); }
/** * PUBLIC: * Set the field names to lock on. All fields in this list will be compared when Updating. * If the value of any of the fields does not match the value in memory, an * OptimisticLockException will be thrown. * * Note: An Automatic update will not be done on this field, only a comparison occurs. */ public void setLockFieldNames(Vector lockFieldNames) { for (Enumeration enumtr = lockFieldNames.elements(); enumtr.hasMoreElements();) { addLockFieldName((String)enumtr.nextElement()); } }
/** * PUBLIC: Add a field name to lock on. All fields in this list will be * compared when updating if the value of any of the fields does not match * the value in memory, an OptimisticLockException will be thrown. * * Note: An Automatic update will not be done on this field, only a * comparison occurs. */ public void addLockFieldName(String fieldName) { getLockFields().add(new DatabaseField(fieldName)); }
/** * PUBLIC: Add a field name to lock on. All fields in this list will be * compared when updating if the value of any of the fields does not match * the value in memory, an OptimisticLockException will be thrown. * * Note: An Automatic update will not be done on this field, only a * comparison occurs. */ public void addLockFieldName(String fieldName) { getLockFields().add(new DatabaseField(fieldName)); }
/** * PUBLIC: * Add a fieldname to lock on. All fields in this list will be compared when Updating * if the value of any of the fields does not match the value in memory, an * OptimisticLockException will be thrown. * * Note: An Automatic update will not be done on this field, only a comparison occurs. */ public void addLockFieldName(String fieldName) { getLockFields().addElement(new DatabaseField(fieldName)); }
protected void addOptimisticLockingLines(NonreflectiveMethodDefinition method, OptimisticLockingPolicy policy) { String policyClassName = policy.getClass().getName(); String packageName = policyClassName.substring(0, policyClassName.lastIndexOf('.')); if (packageName.equals("org.eclipse.persistence.descriptors")) { policyClassName = Helper.getShortClassName(policy); } method.addLine(policyClassName + " lockingPolicy = new " + policyClassName + "();"); if (policy instanceof SelectedFieldsLockingPolicy) { SelectedFieldsLockingPolicy fieldPolicy = (SelectedFieldsLockingPolicy)policy; for (Enumeration fieldsEnum = fieldPolicy.getLockFields().elements(); fieldsEnum.hasMoreElements();) { DatabaseField field = (DatabaseField)fieldsEnum.nextElement(); method.addLine("lockingPolicy.addLockFieldName(\"" + field.getQualifiedName() + "\");"); } } else if (policy instanceof VersionLockingPolicy) { VersionLockingPolicy versionPolicy = (VersionLockingPolicy)policy; method.addLine("lockingPolicy.setWriteLockFieldName(\"" + versionPolicy.getWriteLockField().getQualifiedName() + "\");"); if (versionPolicy.isStoredInObject()) { method.addLine("lockingPolicy.storeInObject();"); } if (policy instanceof TimestampLockingPolicy) { TimestampLockingPolicy timestampPolicy = (TimestampLockingPolicy)policy; if (timestampPolicy.usesLocalTime()) { method.addLine("lockingPolicy.useLocalTime();"); } } } method.addLine("descriptor.setOptimisticLockingPolicy(lockingPolicy);"); }