use of org.exist.util.LockException in project exist by eXist-db.
the class ExtCollection method eval.
@Override
public Sequence eval(final Sequence contextSequence, final Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
final List<String> args = getParameterValues(contextSequence, contextItem);
final Sequence result;
try {
if (args.isEmpty()) {
final Sequence docs = toSequence(context.getStaticallyKnownDocuments());
final Sequence dynamicCollection = context.getDynamicallyAvailableCollection("");
if (dynamicCollection != null) {
result = new ValueSequence();
result.addAll(docs);
result.addAll(dynamicCollection);
} else {
result = docs;
}
} else {
final Sequence dynamicCollection = context.getDynamicallyAvailableCollection(asUri(args.get(0)).toString());
if (dynamicCollection != null) {
result = dynamicCollection;
} else {
final MutableDocumentSet ndocs = new DefaultDocumentSet();
for (final String next : args) {
final XmldbURI uri = new AnyURIValue(next).toXmldbURI();
try (final Collection coll = context.getBroker().openCollection(uri, Lock.LockMode.READ_LOCK)) {
if (coll == null) {
if (context.isRaiseErrorOnFailedRetrieval()) {
throw new XPathException(this, ErrorCodes.FODC0002, "Can not access collection '" + uri + "'");
}
} else {
if (context.inProtectedMode()) {
context.getProtectedDocs().getDocsByCollection(coll, ndocs);
} else {
coll.allDocs(context.getBroker(), ndocs, includeSubCollections, context.getProtectedDocs());
}
}
}
}
result = toSequence(ndocs);
}
}
} catch (final XPathException e) {
// From AnyURIValue constructor
e.setLocation(line, column);
Sequence flattenedArgs = Sequence.EMPTY_SEQUENCE;
try {
flattenedArgs = argsToSeq(contextSequence, contextItem);
} catch (final XPathException xe) {
LOG.warn(e.getMessage(), xe);
}
throw new XPathException(this, ErrorCodes.FODC0002, e.getMessage(), flattenedArgs, e);
} catch (final PermissionDeniedException e) {
Sequence flattenedArgs = Sequence.EMPTY_SEQUENCE;
try {
flattenedArgs = argsToSeq(contextSequence, contextItem);
} catch (final XPathException xe) {
LOG.warn(e.getMessage(), xe);
}
throw new XPathException(this, ErrorCodes.FODC0002, "Can not access collection '" + e.getMessage() + "'", flattenedArgs, e);
} catch (final LockException e) {
Sequence flattenedArgs = Sequence.EMPTY_SEQUENCE;
try {
flattenedArgs = argsToSeq(contextSequence, contextItem);
} catch (final XPathException xe) {
LOG.warn(e.getMessage(), xe);
}
throw new XPathException(this, ErrorCodes.FODC0002, e.getMessage(), flattenedArgs, e);
}
// iterate through all docs and create the node set
registerUpdateListener();
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.util.LockException in project exist by eXist-db.
the class FluentBrokerAPITest method collectionThenCollectionAndDoc.
@Test
public void collectionThenCollectionAndDoc() throws PermissionDeniedException, EXistException, LockException {
final XmldbURI docUri = uri("all-test.xml");
final long collectionCreated = 1234;
final IMocksControl ctrl = createStrictControl();
ctrl.checkOrder(true);
final BrokerPool mockBrokerPool = ctrl.createMock(BrokerPool.class);
final DBBroker mockBroker = ctrl.createMock(DBBroker.class);
final Collection mockCollection = ctrl.createMock(Collection.class);
final LockedDocument mockLockedDocument = ctrl.createMock(LockedDocument.class);
final DocumentImpl mockDocument = ctrl.createMock(DocumentImpl.class);
expect(mockBrokerPool.getBroker()).andReturn(mockBroker);
expect(mockBroker.openCollection(TEST_COLLECTION_URI, READ_LOCK)).andReturn(mockCollection);
expect(mockCollection.getCreated()).andReturn(collectionCreated);
expect(mockCollection.getDocumentWithLock(mockBroker, docUri, READ_LOCK)).andReturn(mockLockedDocument);
expect(mockLockedDocument.getDocument()).andReturn(mockDocument);
expect(mockCollection.getURI()).andReturn(TEST_COLLECTION_URI);
expect(mockDocument.getFileURI()).andReturn(docUri);
// NOTE: checks that Collection lock is release before Document lock
mockCollection.close();
mockLockedDocument.close();
mockBroker.close();
ctrl.replay();
final Function<Collection, Long> collectionOp = collection -> collection.getCreated();
final BiFunction<Collection, DocumentImpl, String> collectionDocOp = (collection, doc) -> collection.getURI().append(doc.getFileURI()).toString();
final Tuple2<Long, String> result = FluentBrokerAPI.builder(mockBrokerPool).withCollection(TEST_COLLECTION_URI, READ_LOCK).execute(collectionOp).withDocument(collection -> new Tuple2<>(docUri, READ_LOCK)).execute(collectionDocOp).doAll();
assertEquals(collectionCreated, result._1.longValue());
assertEquals(TEST_COLLECTION_URI.append(docUri), result._2);
ctrl.verify();
}
use of org.exist.util.LockException in project exist by eXist-db.
the class FluentBrokerAPITest method collectionOnly.
@Test
public void collectionOnly() throws PermissionDeniedException, EXistException, LockException {
final long collectionCreated = 1234;
final IMocksControl ctrl = createStrictControl();
ctrl.checkOrder(true);
final BrokerPool mockBrokerPool = ctrl.createMock(BrokerPool.class);
final DBBroker mockBroker = ctrl.createMock(DBBroker.class);
final Collection mockCollection = ctrl.createMock(Collection.class);
expect(mockBrokerPool.getBroker()).andReturn(mockBroker);
expect(mockBroker.openCollection(TEST_COLLECTION_URI, READ_LOCK)).andReturn(mockCollection);
expect(mockCollection.getCreated()).andReturn(collectionCreated);
mockCollection.close();
mockBroker.close();
ctrl.replay();
final Function<Collection, Long> collectionOp = collection -> collection.getCreated();
final long result = FluentBrokerAPI.builder(mockBrokerPool).withCollection(TEST_COLLECTION_URI, READ_LOCK).execute(collectionOp).doAll();
assertEquals(collectionCreated, result);
ctrl.verify();
}
use of org.exist.util.LockException in project exist by eXist-db.
the class RemoveIndex method eval.
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
final SortIndexWorker index = (SortIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(SortIndex.ID);
final String id = args[0].getStringValue();
try {
if (getArgumentCount() == 2) {
final NodeValue nv = (NodeValue) args[1].itemAt(0);
if (nv.getImplementationType() == NodeValue.IN_MEMORY_NODE)
throw new XPathException(this, "Second argument to remove should be a persistent node, not " + "an in-memory node.");
final NodeProxy proxy = (NodeProxy) nv;
index.remove(id, proxy.getOwnerDocument());
} else {
index.remove(id);
}
} catch (final EXistException e) {
throw new XPathException(this, e.getMessage(), e);
} catch (final LockException e) {
throw new XPathException(this, "Caught lock error while removing index. Giving up.", e);
}
return Sequence.EMPTY_SEQUENCE;
}
use of org.exist.util.LockException in project exist by eXist-db.
the class RangeIndexWorker method removeCollection.
@Override
public void removeCollection(Collection collection, DBBroker broker, boolean reindex) throws PermissionDeniedException {
if (LOG.isDebugEnabled())
LOG.debug("Removing collection {}", collection.getURI());
IndexWriter writer = null;
try {
writer = index.getWriter();
for (Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
DocumentImpl doc = i.next();
final BytesRefBuilder bytes = new BytesRefBuilder();
NumericUtils.intToPrefixCoded(doc.getDocId(), 0, bytes);
Term dt = new Term(FIELD_DOC_ID, bytes.toBytesRef());
writer.deleteDocuments(dt);
}
} catch (IOException | PermissionDeniedException | LockException e) {
LOG.error("Error while removing lucene index: {}", e.getMessage(), e);
} finally {
index.releaseWriter(writer);
if (reindex) {
try {
index.sync();
} catch (DBException e) {
LOG.warn("Exception during reindex: {}", e.getMessage(), e);
}
}
mode = ReindexMode.STORE;
}
if (LOG.isDebugEnabled())
LOG.debug("Collection removed.");
}
Aggregations