Search in sources :

Example 6 with EISDOMRecord

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;
}
Also used : EISDOMRecord(org.eclipse.persistence.eis.EISDOMRecord)

Example 7 with EISDOMRecord

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;
}
Also used : EISDOMRecord(org.eclipse.persistence.eis.EISDOMRecord) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader)

Example 8 with EISDOMRecord

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;
}
Also used : FileWriter(java.io.FileWriter) EISDOMRecord(org.eclipse.persistence.eis.EISDOMRecord) ResourceException(jakarta.resource.ResourceException) Map(java.util.Map) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) Writer(java.io.Writer) ResourceException(jakarta.resource.ResourceException)

Example 9 with EISDOMRecord

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;
}
Also used : EISDOMRecord(org.eclipse.persistence.eis.EISDOMRecord)

Example 10 with EISDOMRecord

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