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