Search in sources :

Example 11 with DOMTransaction

use of org.exist.storage.dom.DOMTransaction in project exist by eXist-db.

the class NativeBroker method updateNode.

@Override
public <T extends IStoredNode> void updateNode(final Txn transaction, final IStoredNode<T> node, final boolean reindex) {
    try {
        final DocumentImpl doc = node.getOwnerDocument();
        final long internalAddress = node.getInternalAddress();
        final byte[] data = node.serialize();
        new DOMTransaction(this, domDb, () -> lockManager.acquireBtreeWriteLock(domDb.getLockName())) {

            @Override
            public Object start() throws ReadOnlyException {
                if (StorageAddress.hasAddress(internalAddress)) {
                    domDb.update(transaction, internalAddress, data);
                } else {
                    domDb.update(transaction, new NodeRef(doc.getDocId(), node.getNodeId()), data);
                }
                return null;
            }
        }.run();
        ByteArrayPool.releaseByteArray(data);
    } catch (final Exception e) {
        final Value oldVal = new DOMTransaction<Value>(this, domDb, () -> lockManager.acquireBtreeReadLock(domDb.getLockName())) {

            @Override
            public Value start() {
                return domDb.get(node.getInternalAddress());
            }
        }.run();
        // TODO what can we do about abstracting this out?
        final IStoredNode old = StoredNode.deserialize(oldVal.data(), oldVal.start(), oldVal.getLength(), node.getOwnerDocument(), false);
        LOG.error("Exception while storing {}; gid = {}; old = {}", node.getNodeName(), node.getNodeId(), old.getNodeName(), e);
    }
}
Also used : PooledObject(org.apache.commons.pool2.PooledObject) DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) DOMTransaction(org.exist.storage.dom.DOMTransaction) TerminatedException(org.exist.xquery.TerminatedException) XMLStreamException(javax.xml.stream.XMLStreamException) SAXException(org.xml.sax.SAXException) EXistException(org.exist.EXistException) TransactionException(org.exist.storage.txn.TransactionException)

Aggregations

PooledObject (org.apache.commons.pool2.PooledObject)11 DefaultPooledObject (org.apache.commons.pool2.impl.DefaultPooledObject)11 DOMTransaction (org.exist.storage.dom.DOMTransaction)11 TerminatedException (org.exist.xquery.TerminatedException)5 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 EXistException (org.exist.EXistException)2 INodeIterator (org.exist.storage.dom.INodeIterator)2 TransactionException (org.exist.storage.txn.TransactionException)2 NodeList (org.w3c.dom.NodeList)2 SAXException (org.xml.sax.SAXException)2 NumberFormat (java.text.NumberFormat)1 QName (org.exist.dom.QName)1 StreamListener (org.exist.indexing.StreamListener)1