Search in sources :

Example 1 with AttributeChangeTrackingPolicy

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;
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ObjectBuilder(org.eclipse.persistence.internal.descriptors.ObjectBuilder) AttributeChangeTrackingPolicy(org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy)

Example 2 with AttributeChangeTrackingPolicy

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;
}
Also used : Project(org.eclipse.persistence.sessions.Project) EmployeeProject(org.eclipse.persistence.testing.models.employee.relational.EmployeeProject) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) AttributeChangeTrackingPolicy(org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy) EmployeeProject(org.eclipse.persistence.testing.models.employee.relational.EmployeeProject)

Example 3 with AttributeChangeTrackingPolicy

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());
}
Also used : FieldOffice(org.eclipse.persistence.testing.models.relationshipmaintenance.FieldOffice) AttributeChangeTrackingPolicy(org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy)

Example 4 with 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;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) AttributeChangeTrackingPolicy(org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy)

Example 5 with AttributeChangeTrackingPolicy

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;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) VersionLockingPolicy(org.eclipse.persistence.descriptors.VersionLockingPolicy) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter) AttributeChangeTrackingPolicy(org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy)

Aggregations

AttributeChangeTrackingPolicy (org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy)12 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)3 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)3 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)2 DeferredChangeDetectionPolicy (org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy)2 ObjectChangePolicy (org.eclipse.persistence.descriptors.changetracking.ObjectChangePolicy)2 ObjectChangeTrackingPolicy (org.eclipse.persistence.descriptors.changetracking.ObjectChangeTrackingPolicy)2 ObjectBuilder (org.eclipse.persistence.internal.descriptors.ObjectBuilder)2 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)2 Address (org.eclipse.persistence.testing.models.employee.domain.Address)2 EmploymentPeriod (org.eclipse.persistence.testing.models.employee.domain.EmploymentPeriod)2 LargeProject (org.eclipse.persistence.testing.models.employee.domain.LargeProject)2 PhoneNumber (org.eclipse.persistence.testing.models.employee.domain.PhoneNumber)2 Project (org.eclipse.persistence.testing.models.employee.domain.Project)2 SmallProject (org.eclipse.persistence.testing.models.employee.domain.SmallProject)2 HashMap (java.util.HashMap)1 TestSetup (junit.extensions.TestSetup)1 VersionLockingPolicy (org.eclipse.persistence.descriptors.VersionLockingPolicy)1 PartitioningPolicy (org.eclipse.persistence.descriptors.partitioning.PartitioningPolicy)1 HistoryPolicy (org.eclipse.persistence.history.HistoryPolicy)1