use of oracle.kv.Consistency 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;
}
Aggregations