use of org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy in project eclipselink by eclipse-ee4j.
the class RepeatableWriteUnitOfWork method cloneAndRegisterNewObject.
/**
* INTERNAL:
* To avoid putting the original object into the shared cache, and
* therefore, impede the 'detaching' of the original after commit, a clone
* of the original should be registered not the actual original object.
* This is a JPA override to traditional EclipseLink behavior.
*/
@Override
protected Object cloneAndRegisterNewObject(Object original, boolean isShallowClone) {
ClassDescriptor descriptor = getDescriptor(original);
// Nested unit of work is not supported for attribute change tracking
if (isNestedUnitOfWork() && (descriptor.getObjectChangePolicy() instanceof AttributeChangeTrackingPolicy)) {
throw ValidationException.nestedUOWNotSupportedForAttributeTracking();
}
ObjectBuilder builder = descriptor.getObjectBuilder();
// bug 2612602 create the working copy object.
Object clone = builder.instantiateWorkingCopyClone(original, this);
Object newOriginal = original;
// Must put in the detached original to clone to resolve circular refs.
getNewObjectsOriginalToClone().put(original, clone);
getNewObjectsCloneToOriginal().put(clone, original);
getNewObjectsCloneToMergeOriginal().put(clone, original);
// Must put in clone mapping.
getCloneMapping().put(clone, clone);
if (isShallowClone) {
builder.copyInto(original, clone, true);
} else {
builder.populateAttributesForClone(original, null, clone, null, this);
}
if (!this.discoverUnregisteredNewObjectsWithoutPersist) {
assignSequenceNumber(clone);
// JPA by default does not use the merge() object as the original, it creates a new instance to avoid
// putting the merge object into the cache.
// The native API does use the original, so this flag determine which policy to use.
newOriginal = builder.buildNewInstance();
}
// Must reregister in both new objects.
registerNewObjectClone(clone, newOriginal, descriptor);
// Build backup clone for DeferredChangeDetectionPolicy or ObjectChangeTrackingPolicy,
// but not for AttributeChangeTrackingPolicy
Object backupClone = descriptor.getObjectChangePolicy().buildBackupClone(clone, builder, this);
// The backup clone must be updated.
getCloneMapping().put(clone, backupClone);
// this is the second difference. Assign a sequence just like JPA unless this RWUOW is set to old behaviour
return clone;
}
use of org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy in project eclipselink by eclipse-ee4j.
the class OrderedListMergeTest method getNewProject.
@Override
protected Project getNewProject() {
Project empProject = new EmployeeProject();
empProject.getDescriptor(Employee.class).setObjectChangePolicy(new AttributeChangeTrackingPolicy());
return empProject;
}
use of org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy in project eclipselink by eclipse-ee4j.
the class TransparentIndirectionChangeFlagBasicTestModel method setup.
@Override
public void setup() {
// Save change policies for the all employee demo class in order to restore them at reset time.
fieldOfficeChangePolicy = getSession().getDescriptor(FieldOffice.class).getObjectChangePolicy();
getSession().getDescriptor(FieldOffice.class).setObjectChangePolicy(new AttributeChangeTrackingPolicy());
}
use of org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy in project eclipselink by eclipse-ee4j.
the class ALCTEmployeeProject method buildEmploymentPeriodDescriptor.
public ClassDescriptor buildEmploymentPeriodDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.descriptorIsAggregate();
descriptor.setJavaClass(ALCTEmploymentPeriod.class);
// Descriptor Properties.
descriptor.setAlias("EmploymentPeriod");
// Change Tracking
descriptor.setObjectChangePolicy(new AttributeChangeTrackingPolicy());
// Cache Invalidation Policy
// Query Manager.
// Named Queries.
// Event Manager.
// Mappings.
DirectToFieldMapping endDateMapping = new DirectToFieldMapping();
endDateMapping.setAttributeName("endDate");
endDateMapping.setFieldName("endDate->DIRECT");
descriptor.addMapping(endDateMapping);
DirectToFieldMapping startDateMapping = new DirectToFieldMapping();
startDateMapping.setAttributeName("startDate");
startDateMapping.setFieldName("startDate->DIRECT");
descriptor.addMapping(startDateMapping);
return descriptor;
}
use of org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy in project eclipselink by eclipse-ee4j.
the class ALCTEmployeeProject method buildEmployeeDescriptor.
public ClassDescriptor buildEmployeeDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClass(ALCTEmployee.class);
descriptor.addTableName("ALCTEMPLOYEE");
descriptor.addPrimaryKeyFieldName("ALCTEMPLOYEE.EMP_ID");
// Descriptor Properties.
descriptor.useSoftCacheWeakIdentityMap();
descriptor.setIdentityMapSize(100);
descriptor.useRemoteSoftCacheWeakIdentityMap();
descriptor.setRemoteIdentityMapSize(100);
descriptor.setSequenceNumberFieldName("ALCTEMPLOYEE.EMP_ID");
descriptor.setSequenceNumberName("EMP_SEQ");
VersionLockingPolicy lockingPolicy = new VersionLockingPolicy();
lockingPolicy.setWriteLockFieldName("ALCTEMPLOYEE.VERSION");
descriptor.setOptimisticLockingPolicy(lockingPolicy);
descriptor.setAlias("ALCTEmployee");
// Change Tracking
descriptor.setObjectChangePolicy(new AttributeChangeTrackingPolicy());
// Cache Invalidation Policy
// Query Manager.
descriptor.getQueryManager().checkCacheForDoesExist();
descriptor.getQueryManager().setQueryTimeout(0);
// Named Queries.
// Event Manager.
// Mappings.
DirectToFieldMapping firstNameMapping = new DirectToFieldMapping();
firstNameMapping.setAttributeName("firstName");
firstNameMapping.setFieldName("ALCTEMPLOYEE.F_NAME");
firstNameMapping.setNullValue("");
descriptor.addMapping(firstNameMapping);
DirectToFieldMapping idMapping = new DirectToFieldMapping();
idMapping.setAttributeName("id");
idMapping.setFieldName("ALCTEMPLOYEE.EMP_ID");
descriptor.addMapping(idMapping);
DirectToFieldMapping lastNameMapping = new DirectToFieldMapping();
lastNameMapping.setAttributeName("lastName");
lastNameMapping.setFieldName("ALCTEMPLOYEE.L_NAME");
lastNameMapping.setNullValue("");
descriptor.addMapping(lastNameMapping);
DirectToFieldMapping genderMapping = new DirectToFieldMapping();
genderMapping.setAttributeName("gender");
genderMapping.setFieldName("ALCTEMPLOYEE.GENDER");
ObjectTypeConverter genderMappingConverter = new ObjectTypeConverter();
genderMappingConverter.addConversionValue("F", "Female");
genderMappingConverter.addConversionValue("M", "Male");
genderMapping.setConverter(genderMappingConverter);
descriptor.addMapping(genderMapping);
AggregateObjectMapping periodMapping = new AggregateObjectMapping();
periodMapping.setAttributeName("period");
periodMapping.setReferenceClass(ALCTEmploymentPeriod.class);
periodMapping.setIsNullAllowed(true);
periodMapping.addFieldNameTranslation("ALCTEMPLOYEE.END_DATE", "endDate->DIRECT");
periodMapping.addFieldNameTranslation("ALCTEMPLOYEE.START_DATE", "startDate->DIRECT");
descriptor.addMapping(periodMapping);
return descriptor;
}
Aggregations