use of org.eclipse.persistence.eis.EISDOMRecord in project eclipselink by eclipse-ee4j.
the class XMLFileInteraction method executeInsert.
/**
* Execute the insert operation.
*/
public Record executeInsert(XMLFileInteractionSpec spec, File file, EISDOMRecord input) throws Exception {
// Write input record dom to file, or insert dom node.
EISDOMRecord outputToFile = input;
// If xpath, parse, insert node, then write back
if (spec.getXPath() != null) {
// If the file exists get tx dom.
outputToFile = connection.getXMLFileTransaction().retrieveDOMRecord(file);
outputToFile.add(buildField(spec), input);
}
return null;
}
use of org.eclipse.persistence.eis.EISDOMRecord in project eclipselink by eclipse-ee4j.
the class XMLFileTransaction method retrieveDOMRecord.
/**
* Return the transactional copy of the file's DOM record.
* This will be written on commit.
*/
public EISDOMRecord retrieveDOMRecord(File file) throws Exception {
// Check for transactional copy.
EISDOMRecord fileRecord = this.domFiles.get(file.getPath());
if (fileRecord == null) {
// If the file exists parse it, otherwise create a new record.
if (file.exists()) {
Reader fileReader = new FileReader(file);
fileRecord = new EISDOMRecord();
// Parse file.
fileRecord.transformFromXML(fileReader);
fileReader.close();
} else {
fileRecord = new EISDOMRecord();
fileRecord.setDOM(fileRecord.createNewDocument("root"));
}
this.domFiles.put(file.getPath(), fileRecord);
}
return fileRecord;
}
use of org.eclipse.persistence.eis.EISDOMRecord in project eclipselink by eclipse-ee4j.
the class XMLFileTransaction method commit.
/**
* Write each of the transactional DOM records back to their files.
*/
@Override
public void commit() throws ResourceException {
try {
// store any dom to their files
for (Iterator<Map.Entry<String, EISDOMRecord>> doms = domFiles.entrySet().iterator(); doms.hasNext(); ) {
Map.Entry<String, EISDOMRecord> entry = doms.next();
String fileName = entry.getKey();
EISDOMRecord record = entry.getValue();
try (Writer fileWriter = new FileWriter(fileName)) {
record.transformToWriter(fileWriter);
fileWriter.flush();
}
}
} catch (Exception exception) {
throw new ResourceException(exception.toString());
}
this.domFiles = new HashMap<>(10);
this.isInTransaction = false;
}
use of org.eclipse.persistence.eis.EISDOMRecord in project eclipselink by eclipse-ee4j.
the class XMLFileInteraction method execute.
/**
* Execute the interaction and set the output into the output record.
* Return true or false if the execute returned data (similar to row-count).
*/
@Override
public boolean execute(InteractionSpec spec, Record input, Record output) throws ResourceException {
EISDOMRecord result = (EISDOMRecord) execute(spec, input);
if (result == null) {
return false;
}
((EISDOMRecord) output).setDOM(result.getDOM());
return true;
}
use of org.eclipse.persistence.eis.EISDOMRecord in project eclipselink by eclipse-ee4j.
the class XMLFileInteraction method executeUpdate.
/**
* Execute the update operation.
*/
public Record executeUpdate(XMLFileInteractionSpec spec, File file, EISDOMRecord input) throws Exception {
// If the file does not exist must first create the file.
if (!file.exists()) {
return null;
}
// Write input record dom to file, or insert dom node.
EISDOMRecord outputToFile = input;
// If xpath, get tx dom, find and update node, (tx commit will write back)
if (spec.getXPath() != null) {
outputToFile = connection.getXMLFileTransaction().retrieveDOMRecord(file);
outputToFile.put(buildField(spec), input);
}
return null;
}
Aggregations