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;
}
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);
}
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;
}
}
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;
}
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;
}
Aggregations