use of org.exist.xmldb.XmldbURI in project exist by eXist-db.
the class AbstractRecoverTest method read.
/**
* Read a document from the database.
*
* @param shouldExist true if the document should exist in the database, false if the document should not exist
* @param data The data that was previously stored
* @param dbFilename The name of the file to read from the database
*/
protected void read(final boolean shouldExist, final InputSource data, final String dbFilename) throws EXistException, PermissionDeniedException, IOException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XmldbURI uri = TestConstants.TEST_COLLECTION_URI.append(dbFilename);
try (final LockedDocument doc = broker.getXMLResource(uri, LockMode.READ_LOCK)) {
if (!shouldExist) {
assertNull("Document should not exist in the database: " + uri, doc);
} else {
assertNotNull("Document does not exist in the database: " + uri, doc);
readAndVerify(broker, doc.getDocument(), data, dbFilename);
}
}
}
}
use of org.exist.xmldb.XmldbURI in project exist by eXist-db.
the class IndexIntegrationTest method removeAttribute.
@Test
public void removeAttribute() throws Exception {
final String docName = "pathNs2.xml";
final XmldbURI docUri = XmldbURI.create("/db/test/" + docName);
run(docUri, "<test><t xml:id=\"id2\"/></test>", (worker, stream) -> {
// get top reindex node
expect(worker.getReindexRoot(anyObject(), anyObject(), anyBoolean(), anyBoolean())).andStubReturn(null);
// REMOVE STAGE
// set document
worker.setDocument(eqDocument(docUri));
expectLastCall();
// set mode
worker.setMode(StreamListener.ReindexMode.REMOVE_SOME_NODES);
expectLastCall();
// get stream listener
worker.setDocument(eqDocument(docUri));
expectLastCall();
worker.setMode(StreamListener.ReindexMode.REMOVE_SOME_NODES);
expectLastCall();
// setup chain
// stream
stream.startIndexDocument(anyObject());
expectLastCall();
stream.attribute(anyObject(), eqAttr("xml:id", "id2"), anyObject());
expectLastCall();
stream.endIndexDocument(anyObject());
expectLastCall();
worker.flush();
expectLastCall();
// flush
worker.flush();
expectLastCall();
}, service -> queryResource(service, docName, "update delete //t/@xml:id", 0));
}
use of org.exist.xmldb.XmldbURI in project exist by eXist-db.
the class IndexIntegrationTest method insertElement.
@Test
public void insertElement() throws Exception {
final String docName = "pathNs2.xml";
final XmldbURI docUri = XmldbURI.create("/db/test/" + docName);
run(docUri, "<test/>", (worker, stream) -> {
// set document
worker.setDocument(eqDocument(docUri));
expectLastCall();
// get top reindex node
expect(worker.getReindexRoot(anyObject(), anyObject(), anyBoolean(), anyBoolean())).andStubReturn(null);
// set mode
worker.setMode(StreamListener.ReindexMode.STORE);
expectLastCall();
// get stream listener
// setup chain
// stream
stream.startIndexDocument(anyObject());
expectLastCall();
stream.startElement(anyObject(), anyObject(), anyObject());
expectLastCall();
stream.attribute(anyObject(), anyObject(), anyObject());
expectLastCall();
stream.endElement(anyObject(), anyObject(), anyObject());
expectLastCall();
stream.endIndexDocument(anyObject());
expectLastCall();
// flush
worker.flush();
expectLastCall();
}, service -> queryResource(service, docName, "update insert <t xml:id=\"id1\"/> into /test", 0));
}
use of org.exist.xmldb.XmldbURI in project exist by eXist-db.
the class ExistXqueryRegistry method deregisterServices.
public void deregisterServices(final DBBroker broker, final XmldbURI xqueryLocation) {
getRegistry(broker).deregister(xqueryLocation.getURI());
// find and remove services from modules that depend on this one
for (final String dependant : getDependants(xqueryLocation)) {
try {
// on the maps.
if (dependant != null) {
getRegistry(broker).deregister(new URI(dependant));
// record the now missing dependency
recordMissingDependency(xqueryLocation.toString(), XmldbURI.create(dependant));
}
} catch (final URISyntaxException e) {
LOG.error(e.getMessage(), e);
}
}
/*
* update the missingDependencies??
* Probably not needed as this will be done in find services
*/
}
use of org.exist.xmldb.XmldbURI in project exist by eXist-db.
the class MetadataFunctions method extractMetadataFromLocalResource.
private Sequence extractMetadataFromLocalResource(final XmldbURI docUri) throws XPathException {
try (final LockedDocument lockedDoc = context.getBroker().getXMLResource(docUri, LockMode.READ_LOCK)) {
if (lockedDoc != null && lockedDoc.getDocument() instanceof BinaryDocument) {
final BinaryDocument binDoc = (BinaryDocument) lockedDoc.getDocument();
final BrokerPool pool = context.getBroker().getBrokerPool();
final BlobStore blobStore = pool.getBlobStore();
try (final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final Sequence result = blobStore.with(transaction, binDoc.getBlobId(), blobFile -> TaggedTryUnchecked(XPathException.class, () -> exifToolExtract(blobFile))).get();
transaction.commit();
return result;
}
} else {
throw new XPathException(this, "The binary document at " + docUri.toString() + " cannot be found.");
}
} catch (PermissionDeniedException | IOException | TransactionException e) {
throw new XPathException(this, "Could not access binary document: " + e.getMessage(), e);
}
}
Aggregations