Search in sources :

Example 1 with OracleNoSQLRecord

use of org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord in project eclipselink by eclipse-ee4j.

the class OracleNoSQLPlatform method createDatabaseRowFromDOMRecord.

/**
 * Allow the platform to handle the creation of the Record for the DOM record.
 * Creates a DOM record from the XML data stored as a value in the OracleNoSQLRecord.
 */
@Override
public AbstractRecord createDatabaseRowFromDOMRecord(jakarta.resource.cci.Record record, EISInteraction call, EISAccessor accessor) {
    if (record == null) {
        return null;
    }
    EISDOMRecord domRecord = null;
    OracleNoSQLRecord noSqlRecord = (OracleNoSQLRecord) record;
    if (noSqlRecord.size() == 0) {
        return null;
    } else if (noSqlRecord.size() == 1) {
        domRecord = new EISDOMRecord();
        Object value = noSqlRecord.values().iterator().next();
        String xml = null;
        if (value instanceof byte[]) {
            xml = new String((byte[]) value);
        } else {
            xml = (String) value;
        }
        if (xml != null) {
            domRecord.transformFromXML(xml);
        }
    } else {
        domRecord = new EISDOMRecord();
        for (Map.Entry<?, ?> entry : (Set<Map.Entry<?, ?>>) noSqlRecord.entrySet()) {
            Object value = entry.getValue();
            String xml = null;
            if (value instanceof byte[]) {
                xml = new String((byte[]) value);
            } else {
                xml = (String) value;
            }
            if (xml != null) {
                EISDOMRecord dom = new EISDOMRecord();
                dom.transformFromXML(xml);
                domRecord.put(entry.getKey(), dom);
            }
        }
    }
    return domRecord;
}
Also used : OracleNoSQLRecord(org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord) EISDOMRecord(org.eclipse.persistence.eis.EISDOMRecord)

Example 2 with OracleNoSQLRecord

use of org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord in project eclipselink by eclipse-ee4j.

the class OracleNoSQLPlatform method setDOMInRecord.

/**
 * Stores the XML DOM value into the record.
 * XML is stored in Oracle NoSQL but storing the XML text, keyed on the object's {@literal "&lt;dataTypeName&gt;/&lt;id&gt;"}.
 */
@Override
public void setDOMInRecord(Element dom, jakarta.resource.cci.Record record, EISInteraction interaction, EISAccessor accessor) {
    OracleNoSQLRecord noSqlRecord = (OracleNoSQLRecord) record;
    org.eclipse.persistence.oxm.record.DOMRecord domRecord = new org.eclipse.persistence.oxm.record.DOMRecord(dom);
    domRecord.setSession(interaction.getQuery().getSession());
    // Create the key from the objects id.
    ClassDescriptor descriptor = interaction.getQuery().getDescriptor();
    if (descriptor == null) {
        throw new EISException("XMLInteraction is only valid for object queries, use MappedIneraction for native queries: " + interaction);
    }
    Object key = createMajorKey(descriptor, domRecord, interaction, accessor);
    noSqlRecord.put(key, domRecord.transformToXML().getBytes());
}
Also used : OracleNoSQLRecord(org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) EISDOMRecord(org.eclipse.persistence.eis.EISDOMRecord) EISException(org.eclipse.persistence.eis.EISException)

Example 3 with OracleNoSQLRecord

use of org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord in project eclipselink by eclipse-ee4j.

the class OracleNoSQLPlatform method buildRows.

/**
 * Allow the platform to handle record to row conversion.
 */
@Override
public Vector<AbstractRecord> buildRows(jakarta.resource.cci.Record record, EISInteraction interaction, EISAccessor accessor) {
    if (record == null) {
        return new Vector<>(0);
    }
    OracleNoSQLRecord output = (OracleNoSQLRecord) record;
    if ((output.size() == 1) && (interaction.getQuery().getDescriptor() != null)) {
        // Check for a nested mapped record.
        Object value = output.values().iterator().next();
        if (value instanceof OracleNoSQLRecord) {
            Vector<AbstractRecord> rows = new Vector<>(1);
            convertRecordBytesToString((OracleNoSQLRecord) value);
            rows.add(interaction.buildRow((OracleNoSQLRecord) value, accessor));
            return rows;
        } else if (value instanceof Collection) {
            Vector<AbstractRecord> rows = new Vector<>(((Collection<?>) value).size());
            for (Object nestedValue : (Collection<?>) value) {
                if (nestedValue instanceof OracleNoSQLRecord) {
                    rows.add(interaction.buildRow((OracleNoSQLRecord) nestedValue, accessor));
                }
            }
            return rows;
        }
    }
    if (interaction.getQuery().getDescriptor() != null) {
        // Check for a map of values.
        Vector<AbstractRecord> rows = new Vector<>();
        for (Object value : output.values()) {
            if (value instanceof OracleNoSQLRecord) {
                convertRecordBytesToString((OracleNoSQLRecord) value);
                rows.add(interaction.buildRow((OracleNoSQLRecord) value, accessor));
            } else if (value instanceof byte[]) {
                EISDOMRecord domRecord = new EISDOMRecord();
                domRecord.transformFromXML(new String((byte[]) value));
                rows.add(domRecord);
            }
        }
        return rows;
    }
    return interaction.buildRows(record, accessor);
}
Also used : OracleNoSQLRecord(org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) Collection(java.util.Collection) EISDOMRecord(org.eclipse.persistence.eis.EISDOMRecord) Vector(java.util.Vector)

Example 4 with OracleNoSQLRecord

use of org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord in project eclipselink by eclipse-ee4j.

the class OracleNoSQLPlatform method buildRow.

/**
 * INTERNAL:
 * Allow the platform to handle record to row conversion.
 */
@Override
public AbstractRecord buildRow(jakarta.resource.cci.Record record, EISInteraction interaction, EISAccessor accessor) {
    if (record == null) {
        return null;
    }
    OracleNoSQLRecord output = (OracleNoSQLRecord) record;
    if ((output.size() == 1) && (interaction.getQuery().getDescriptor() != null)) {
        // Check for a nested mapped record.
        Object value = output.values().iterator().next();
        if (value instanceof OracleNoSQLRecord) {
            convertRecordBytesToString((OracleNoSQLRecord) value);
            output = (OracleNoSQLRecord) value;
        }
    }
    jakarta.resource.cci.Record result = output;
    if (getRecordConverter() != null) {
        result = getRecordConverter().converterFromAdapterRecord(output);
    }
    return interaction.buildRow(result, accessor);
}
Also used : OracleNoSQLRecord(org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord)

Example 5 with OracleNoSQLRecord

use of org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord in project eclipselink by eclipse-ee4j.

the class OracleNoSQLPlatform method createInputRecord.

/**
 * Allow the platform to create the appropriate type of record for the interaction.
 * Convert the nested local mapped record to a flat global keyed record.
 */
@Override
public jakarta.resource.cci.Record createInputRecord(EISInteraction interaction, EISAccessor accessor) {
    if (interaction instanceof XMLInteraction) {
        return super.createInputRecord(interaction, accessor);
    }
    if (interaction instanceof MappedInteraction) {
        MappedRecord input = (MappedRecord) interaction.createInputRecord(accessor);
        // Create the key from the objects id.
        ClassDescriptor descriptor = interaction.getQuery().getDescriptor();
        if (descriptor == null) {
            if (getRecordConverter() != null) {
                return getRecordConverter().converterToAdapterRecord(input);
            }
            return input;
        }
        Object key = createMajorKey(descriptor, new EISMappedRecord(input, accessor), interaction, accessor);
        OracleNoSQLRecord record = new OracleNoSQLRecord();
        record.put(key, input);
        if (getRecordConverter() != null) {
            return getRecordConverter().converterToAdapterRecord(record);
        }
        return record;
    } else {
        return super.createInputRecord(interaction, accessor);
    }
}
Also used : OracleNoSQLRecord(org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord) MappedInteraction(org.eclipse.persistence.eis.interactions.MappedInteraction) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) EISMappedRecord(org.eclipse.persistence.eis.EISMappedRecord) XMLInteraction(org.eclipse.persistence.eis.interactions.XMLInteraction) EISMappedRecord(org.eclipse.persistence.eis.EISMappedRecord) MappedRecord(jakarta.resource.cci.MappedRecord)

Aggregations

OracleNoSQLRecord (org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord)5 EISDOMRecord (org.eclipse.persistence.eis.EISDOMRecord)3 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 MappedRecord (jakarta.resource.cci.MappedRecord)1 Collection (java.util.Collection)1 Vector (java.util.Vector)1 EISException (org.eclipse.persistence.eis.EISException)1 EISMappedRecord (org.eclipse.persistence.eis.EISMappedRecord)1 MappedInteraction (org.eclipse.persistence.eis.interactions.MappedInteraction)1 XMLInteraction (org.eclipse.persistence.eis.interactions.XMLInteraction)1 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)1