use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class InstallFunction method getBinaryDoc.
private LockedDocument getBinaryDoc(final String path) throws XPathException {
try {
final XmldbURI uri = XmldbURI.createInternal(path);
final LockedDocument lockedDoc = context.getBroker().getXMLResource(uri, LockMode.READ_LOCK);
if (lockedDoc == null) {
throw new XPathException(this, EXPathErrorCode.EXPDY001, path + " is not .xar resource", new StringValue(path));
} else if (lockedDoc.getDocument().getResourceType() != DocumentImpl.BINARY_FILE) {
lockedDoc.close();
throw new XPathException(this, EXPathErrorCode.EXPDY001, path + " is not a valid .xar, it's not a binary resource", new StringValue(path));
}
return lockedDoc;
} catch (PermissionDeniedException e) {
throw new XPathException(this, EXPathErrorCode.EXPDY003, e.getMessage(), new StringValue(path), e);
}
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class MoveCollectionRecoveryTest method read.
private void read() throws EXistException, PermissionDeniedException, SAXException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Serializer serializer = broker.borrowSerializer();
try (final LockedDocument lockedDoc = broker.getXMLResource(TestConstants.DESTINATION_COLLECTION_URI.append("test3").append(TestConstants.TEST_XML_URI), LockMode.READ_LOCK)) {
assertNotNull("Document should not be null", lockedDoc);
String data = serializer.serialize(lockedDoc.getDocument());
assertNotNull(data);
} finally {
broker.returnSerializer(serializer);
}
}
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class CopyCollectionRecoveryTest method read.
private void read() throws EXistException, PermissionDeniedException, SAXException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Serializer serializer = broker.borrowSerializer();
try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("destination/test3/test.xml"), LockMode.READ_LOCK)) {
assertNotNull("Document should not be null", lockedDoc);
serializer.serialize(lockedDoc.getDocument());
} finally {
broker.returnSerializer(serializer);
}
}
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class CopyResourceRecoveryTest method read.
private void read(final String testCollectionName) throws EXistException, PermissionDeniedException, SAXException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Serializer serializer = broker.borrowSerializer();
try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName).append("new_test.xml"), LockMode.READ_LOCK)) {
assertNotNull("Document should not be null", lockedDoc);
final String data = serializer.serialize(lockedDoc.getDocument());
assertNotNull(data);
} finally {
broker.returnSerializer(serializer);
}
}
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class CopyResourceRecoveryTest method readAborted.
private void readAborted(final String testCollectionName, final String subCollection) throws EXistException, PermissionDeniedException, SAXException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Serializer serializer = broker.borrowSerializer();
try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName).append(subCollection).append("test2.xml"), LockMode.READ_LOCK)) {
assertNotNull("Document should not be null", lockedDoc);
final String data = serializer.serialize(lockedDoc.getDocument());
assertNotNull(data);
} finally {
broker.returnSerializer(serializer);
}
try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName).append("new_test2.xml"), LockMode.READ_LOCK)) {
assertNull("Document should not exist as copy was not committed", lockedDoc);
}
}
}
Aggregations