Search in sources :

Example 1 with EISDOMRecord

use of org.eclipse.persistence.eis.EISDOMRecord 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 EISDOMRecord

use of org.eclipse.persistence.eis.EISDOMRecord 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 3 with EISDOMRecord

use of org.eclipse.persistence.eis.EISDOMRecord in project eclipselink by eclipse-ee4j.

the class XMLFileInteraction method executeRead.

/**
 * Execute the read operation.
 */
public Record executeRead(XMLFileInteractionSpec spec, File file) throws Exception {
    // Parse file and return document, or xpath/xquery result from dom.
    if (!file.exists()) {
        return null;
    }
    EISDOMRecord fileRecord = connection.getXMLFileTransaction().retrieveDOMRecord(file);
    // Check for and process XPath or XQuery
    if (spec.getXPath() != null) {
        // Either a value/string or list of element records is returned
        Object result = fileRecord.getValues(buildField(spec));
        EISDOMRecord output = new EISDOMRecord();
        if (result instanceof List) {
            List<?> results = (List<?>) result;
            output.setDOM(output.createNewDocument("results"));
            for (int index = 0; index < results.size(); index++) {
                output.add(new DatabaseField("result"), results.get(index));
            }
        } else {
            output.setDOM(output.createNewDocument("results"));
            output.add(new DatabaseField("result"), result);
        }
        return output;
    } else {
        return fileRecord;
    }
}
Also used : DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) EISDOMRecord(org.eclipse.persistence.eis.EISDOMRecord) List(java.util.List)

Example 4 with EISDOMRecord

use of org.eclipse.persistence.eis.EISDOMRecord in project eclipselink by eclipse-ee4j.

the class XMLFileInteraction method executeDelete.

/**
 * Execute the delete operation.
 */
public Record executeDelete(XMLFileInteractionSpec spec, File file) throws Exception {
    // Delete file, or remove dom node.
    if (!file.exists()) {
        return null;
    }
    // If xpath, get tx dom, delete node, (tx commit will write back)
    if (spec.getXPath() != null) {
        EISDOMRecord outputToFile = connection.getXMLFileTransaction().retrieveDOMRecord(file);
        outputToFile.remove(buildField(spec));
    } else {
        boolean success = file.delete();
        if (!success) {
            throw EISException.couldNotDeleteFile(new Object[] { file });
        }
    }
    return null;
}
Also used : EISDOMRecord(org.eclipse.persistence.eis.EISDOMRecord)

Example 5 with EISDOMRecord

use of org.eclipse.persistence.eis.EISDOMRecord in project eclipselink by eclipse-ee4j.

the class XMLFileRecordFactory method createMappedRecord.

@Override
public MappedRecord createMappedRecord(String recordName) {
    EISDOMRecord record = new EISDOMRecord();
    record.setRecordName(recordName);
    return record;
}
Also used : EISDOMRecord(org.eclipse.persistence.eis.EISDOMRecord)

Aggregations

EISDOMRecord (org.eclipse.persistence.eis.EISDOMRecord)10 OracleNoSQLRecord (org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord)2 ResourceException (jakarta.resource.ResourceException)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Vector (java.util.Vector)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)1