Search in sources :

Example 1 with OracleNoSQLInteractionSpec

use of org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLInteractionSpec 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;
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) OracleNoSQLInteractionSpec(org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLInteractionSpec) InteractionSpec(jakarta.resource.cci.InteractionSpec) Consistency(oracle.kv.Consistency) Durability(oracle.kv.Durability) EISException(org.eclipse.persistence.eis.EISException) OracleNoSQLInteractionSpec(org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLInteractionSpec) SelectedFieldsLockingPolicy(org.eclipse.persistence.descriptors.SelectedFieldsLockingPolicy) Version(oracle.kv.Version) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField)

Aggregations

InteractionSpec (jakarta.resource.cci.InteractionSpec)1 Consistency (oracle.kv.Consistency)1 Durability (oracle.kv.Durability)1 Version (oracle.kv.Version)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 SelectedFieldsLockingPolicy (org.eclipse.persistence.descriptors.SelectedFieldsLockingPolicy)1 EISException (org.eclipse.persistence.eis.EISException)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 OracleNoSQLInteractionSpec (org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLInteractionSpec)1