Search in sources :

Example 1 with PessimisticLockingPolicy

use of org.eclipse.persistence.descriptors.PessimisticLockingPolicy in project eclipselink by eclipse-ee4j.

the class CMPDescriptorPessimisticLockingTest method setup.

@Override
protected void setup() {
    // Modify the employee project to use custom SQL queries
    EmployeeProject project = new EmployeeProject();
    ClassDescriptor employeeDescriptor = project.getDescriptors().get(Employee.class);
    ClassDescriptor addressDescriptor = project.getDescriptors().get(Address.class);
    employeeDescriptor.setCMPPolicy(new CMPPolicy());
    addressDescriptor.setCMPPolicy(new CMPPolicy());
    employeeDescriptor.getCMPPolicy().setPessimisticLockingPolicy(new PessimisticLockingPolicy());
    addressDescriptor.getCMPPolicy().setPessimisticLockingPolicy(new PessimisticLockingPolicy());
    employeeDescriptor.getCMPPolicy().getPessimisticLockingPolicy().setLockingMode(ObjectLevelReadQuery.LOCK);
    addressDescriptor.getCMPPolicy().getPessimisticLockingPolicy().setLockingMode(ObjectLevelReadQuery.LOCK_NOWAIT);
    // write project to an XML project file
    XMLProjectWriter.write(PROJECT_FILE, project);
}
Also used : CMPPolicy(org.eclipse.persistence.descriptors.CMPPolicy) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) PessimisticLockingPolicy(org.eclipse.persistence.descriptors.PessimisticLockingPolicy) EmployeeProject(org.eclipse.persistence.testing.models.employee.relational.EmployeeProject)

Example 2 with PessimisticLockingPolicy

use of org.eclipse.persistence.descriptors.PessimisticLockingPolicy in project eclipselink by eclipse-ee4j.

the class WriteNewPessimisticLockedObjectTest method setup.

@Override
protected void setup() {
    PessimisticLockingPolicy policy = new PessimisticLockingPolicy();
    policy.setLockingMode(ObjectLevelReadQuery.LOCK_NOWAIT);
    CMPPolicy cmpPolicy = new CMPPolicy();
    cmpPolicy.setPessimisticLockingPolicy(policy);
    ClassDescriptor empDescriptor = getSession().getDescriptor(Employee.class);
    oldCMPPolicy = empDescriptor.getCMPPolicy();
    empDescriptor.setCMPPolicy(cmpPolicy);
    empDescriptor.getQueryManager().getReadObjectQuery().setLockMode(ObjectLevelReadQuery.DEFAULT_LOCK_MODE);
    this.oldLevel = empDescriptor.getUnitOfWorkCacheIsolationLevel();
    empDescriptor.setUnitOfWorkCacheIsolationLevel(ClassDescriptor.ISOLATE_CACHE_ALWAYS);
    // Flush the cache
    getSession().getIdentityMapAccessor().initializeIdentityMaps();
    getAbstractSession().beginTransaction();
}
Also used : CMPPolicy(org.eclipse.persistence.descriptors.CMPPolicy) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) PessimisticLockingPolicy(org.eclipse.persistence.descriptors.PessimisticLockingPolicy)

Example 3 with PessimisticLockingPolicy

use of org.eclipse.persistence.descriptors.PessimisticLockingPolicy in project eclipselink by eclipse-ee4j.

the class ProjectClassGeneratorWithCMPDescriptorTest method setup.

@Override
protected void setup() {
    project = new org.eclipse.persistence.testing.models.employee.relational.EmployeeProject();
    // initialize new CMP descriptor with non-default settings
    CMPPolicy cmpPolicy = new CMPPolicy();
    cmpPolicy.setPessimisticLockingPolicy(new PessimisticLockingPolicy());
    cmpPolicy.setDeferModificationsUntilCommit(5);
    cmpPolicy.setForceUpdate(true);
    cmpPolicy.setNonDeferredCreateTime(1000);
    cmpPolicy.setUpdateAllFields(true);
    cmpPolicy.setPessimisticLockingPolicy(new PessimisticLockingPolicy());
    cmpPolicy.getPessimisticLockingPolicy().setLockingMode(ObjectLevelReadQuery.LOCK_NOWAIT);
    // set CMP descriptor to Address descriptor
    project.getDescriptor(org.eclipse.persistence.testing.models.employee.domain.Address.class).setCMPPolicy(cmpPolicy);
}
Also used : CMPPolicy(org.eclipse.persistence.descriptors.CMPPolicy) PessimisticLockingPolicy(org.eclipse.persistence.descriptors.PessimisticLockingPolicy)

Aggregations

CMPPolicy (org.eclipse.persistence.descriptors.CMPPolicy)3 PessimisticLockingPolicy (org.eclipse.persistence.descriptors.PessimisticLockingPolicy)3 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 EmployeeProject (org.eclipse.persistence.testing.models.employee.relational.EmployeeProject)1