use of org.eclipse.persistence.descriptors.SelectedFieldsLockingPolicy in project eclipselink by eclipse-ee4j.
the class OptimisticLockingLinesSelectedFieldsLockingPolicyTest method setup.
@Override
protected void setup() {
getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
descriptorToModify = project.getDescriptors().get(Employee.class);
SelectedFieldsLockingPolicy lockingTestPolicy = new SelectedFieldsLockingPolicy();
lockingTestPolicy.addLockFieldName("testField1");
lockingTestPolicy.addLockFieldName("testField2");
descriptorToModify.setOptimisticLockingPolicy(lockingTestPolicy);
generator = new ProjectClassGenerator(project);
}
use of org.eclipse.persistence.descriptors.SelectedFieldsLockingPolicy in project eclipselink by eclipse-ee4j.
the class OracleNoSQLPlatform method buildInteractionSpec.
/**
* Allow the platform to build the interaction spec based on properties defined in the interaction.
*/
@Override
public InteractionSpec buildInteractionSpec(EISInteraction interaction) {
InteractionSpec spec = interaction.getInteractionSpec();
if (spec == null) {
OracleNoSQLInteractionSpec noSqlSpec = new OracleNoSQLInteractionSpec();
Object operation = interaction.getProperty(OPERATION);
if (operation == null) {
throw new EISException("'" + OPERATION + "' property must be set on the query's interation.");
}
if (operation instanceof String) {
operation = OracleNoSQLOperation.valueOf((String) operation);
}
noSqlSpec.setOperation((OracleNoSQLOperation) operation);
// Allows setting of consistency as a property.
Object consistency = interaction.getProperty(CONSISTENCY);
if (consistency == null) {
// Default to session property.
consistency = interaction.getQuery().getSession().getProperty(CONSISTENCY);
}
if (consistency instanceof Consistency) {
noSqlSpec.setConsistency((Consistency) consistency);
} else if (consistency instanceof String) {
String constant = (String) consistency;
if (constant.equals("ABSOLUTE")) {
noSqlSpec.setConsistency(Consistency.ABSOLUTE);
} else if (constant.equals("NONE_REQUIRED")) {
noSqlSpec.setConsistency(Consistency.NONE_REQUIRED);
} else {
throw new EISException("Invalid consistency property value: " + constant);
}
}
// Allows setting of durability as a property.
Object durability = interaction.getProperty(DURABILITY);
if (durability == null) {
// Default to session property.
durability = interaction.getQuery().getSession().getProperty(DURABILITY);
}
if (durability instanceof Durability) {
noSqlSpec.setDurability((Durability) durability);
} else if (durability instanceof String) {
String constant = (String) durability;
if (constant.equals("COMMIT_NO_SYNC")) {
noSqlSpec.setDurability(Durability.COMMIT_NO_SYNC);
} else if (constant.equals("COMMIT_SYNC")) {
noSqlSpec.setDurability(Durability.COMMIT_SYNC);
} else if (constant.equals("COMMIT_WRITE_NO_SYNC")) {
noSqlSpec.setDurability(Durability.COMMIT_WRITE_NO_SYNC);
} else {
throw new EISException("Invalid durability property value: " + constant);
}
}
// Allows setting of timeout as a property.
Object timeout = interaction.getProperty(TIMEOUT);
if (timeout == null) {
// Default to session property.
timeout = interaction.getQuery().getSession().getProperty(TIMEOUT);
}
if (timeout instanceof Number) {
noSqlSpec.setTimeout(((Number) timeout).longValue());
} else if (timeout instanceof String) {
noSqlSpec.setTimeout(Long.parseLong(((String) timeout)));
} else if (interaction.getQuery().getQueryTimeout() > 0) {
noSqlSpec.setTimeout(interaction.getQuery().getQueryTimeout());
}
// Allows setting of version as a property.
Object version = interaction.getProperty(VERSION);
if (version == null) {
// Default to session property.
version = interaction.getQuery().getSession().getProperty(VERSION);
}
if (version == null) {
if (interaction.getQuery().getDescriptor() != null) {
ClassDescriptor descriptor = interaction.getQuery().getDescriptor();
if (descriptor.usesOptimisticLocking() && descriptor.getOptimisticLockingPolicy() instanceof SelectedFieldsLockingPolicy) {
DatabaseField field = ((SelectedFieldsLockingPolicy) descriptor.getOptimisticLockingPolicy()).getLockFields().get(0);
if (interaction.getInputRow() != null) {
version = interaction.getInputRow().get(field);
}
}
}
}
if (version instanceof Version) {
noSqlSpec.setVersion((Version) version);
} else if (version instanceof byte[]) {
noSqlSpec.setVersion(Version.fromByteArray((byte[]) version));
}
spec = noSqlSpec;
}
return spec;
}
use of org.eclipse.persistence.descriptors.SelectedFieldsLockingPolicy in project eclipselink by eclipse-ee4j.
the class EntityMappingsAdvancedJUnitTestCase method testProjectOptimisticLockingSettings.
/**
* Verifies that the optimistic-locking settings were read correctly from XML.
*/
public void testProjectOptimisticLockingSettings() {
ServerSession session = JUnitTestCase.getServerSession(m_persistenceUnit);
ClassDescriptor descriptor = session.getDescriptor(Project.class);
if (descriptor == null) {
fail("Project descriptor was not found in the PU [" + m_persistenceUnit + "]");
} else {
OptimisticLockingPolicy policy = descriptor.getOptimisticLockingPolicy();
if (policy instanceof SelectedFieldsLockingPolicy) {
List<DatabaseField> lockFields = ((SelectedFieldsLockingPolicy) policy).getLockFields();
if (lockFields.isEmpty() || lockFields.size() > 1) {
fail("Invalid amount of lock fields were set on Project's selected fields locking policy.");
} else {
DatabaseField lockField = lockFields.get(0);
assertTrue("Incorrect lock field was set on Project's selected fields locking policy.", lockField.getName().equals("VERSION"));
}
} else {
fail("A SelectedFieldsLockingPolicy was not set on the Project descriptor.");
}
}
}
use of org.eclipse.persistence.descriptors.SelectedFieldsLockingPolicy in project eclipselink by eclipse-ee4j.
the class EntityMappingsAdvancedJUnitTestCase method testProjectOptimisticLockingSettings.
/**
* Verifies that the optimistic-locking settings were read correctly from XML.
*/
public void testProjectOptimisticLockingSettings() {
DatabaseSessionImpl session = getDatabaseSession();
ClassDescriptor descriptor = session.getDescriptor(Project.class);
if (descriptor == null) {
fail("Project descriptor was not found in the PU [" + m_persistenceUnit + "]");
} else {
OptimisticLockingPolicy policy = descriptor.getOptimisticLockingPolicy();
if (policy instanceof SelectedFieldsLockingPolicy) {
List<DatabaseField> lockFields = ((SelectedFieldsLockingPolicy) policy).getLockFields();
if (lockFields.isEmpty() || lockFields.size() > 1) {
fail("Invalid amount of lock fields were set on Project's selected fields locking policy.");
} else {
DatabaseField lockField = lockFields.get(0);
assertTrue("Incorrect lock field was set on Project's selected fields locking policy.", lockField.getName().equals("VERSION"));
}
} else {
fail("A SelectedFieldsLockingPolicy was not set on the Project descriptor.");
}
}
}
use of org.eclipse.persistence.descriptors.SelectedFieldsLockingPolicy in project eclipselink by eclipse-ee4j.
the class ProjectClassGenerator method addOptimisticLockingLines.
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 (DatabaseField field : fieldPolicy.getLockFields()) {
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);");
}
Aggregations