Search in sources :

Example 86 with EXistException

use of org.exist.EXistException 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();
}
Also used : Tuple3(com.evolvedbinary.j8fu.tuple.Tuple3) Tuple2(com.evolvedbinary.j8fu.tuple.Tuple2) IMocksControl(org.easymock.IMocksControl) LockMode(org.exist.storage.lock.Lock.LockMode) LockedDocument(org.exist.dom.persistent.LockedDocument) EasyMock.createStrictControl(org.easymock.EasyMock.createStrictControl) BiFunction(java.util.function.BiFunction) Test(org.junit.Test) PermissionDeniedException(org.exist.security.PermissionDeniedException) EasyMock.expect(org.easymock.EasyMock.expect) Function(java.util.function.Function) FluentBrokerAPI.uri(org.exist.storage.FluentBrokerAPI.uri) LockException(org.exist.util.LockException) Collection(org.exist.collections.Collection) XmldbURI(org.exist.xmldb.XmldbURI) DocumentImpl(org.exist.dom.persistent.DocumentImpl) EXistException(org.exist.EXistException) Lock(org.exist.storage.lock.Lock) Assert.assertEquals(org.junit.Assert.assertEquals) DocumentImpl(org.exist.dom.persistent.DocumentImpl) IMocksControl(org.easymock.IMocksControl) LockedDocument(org.exist.dom.persistent.LockedDocument) Collection(org.exist.collections.Collection) XmldbURI(org.exist.xmldb.XmldbURI) Test(org.junit.Test)

Example 87 with EXistException

use of org.exist.EXistException 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();
}
Also used : IMocksControl(org.easymock.IMocksControl) Tuple3(com.evolvedbinary.j8fu.tuple.Tuple3) Tuple2(com.evolvedbinary.j8fu.tuple.Tuple2) IMocksControl(org.easymock.IMocksControl) LockMode(org.exist.storage.lock.Lock.LockMode) LockedDocument(org.exist.dom.persistent.LockedDocument) EasyMock.createStrictControl(org.easymock.EasyMock.createStrictControl) BiFunction(java.util.function.BiFunction) Test(org.junit.Test) PermissionDeniedException(org.exist.security.PermissionDeniedException) EasyMock.expect(org.easymock.EasyMock.expect) Function(java.util.function.Function) FluentBrokerAPI.uri(org.exist.storage.FluentBrokerAPI.uri) LockException(org.exist.util.LockException) Collection(org.exist.collections.Collection) XmldbURI(org.exist.xmldb.XmldbURI) DocumentImpl(org.exist.dom.persistent.DocumentImpl) EXistException(org.exist.EXistException) Lock(org.exist.storage.lock.Lock) Assert.assertEquals(org.junit.Assert.assertEquals) Collection(org.exist.collections.Collection) Test(org.junit.Test)

Example 88 with EXistException

use of org.exist.EXistException in project exist by eXist-db.

the class SortIndexWorker method registerId.

private void registerId(final short id, final String name) throws EXistException {
    final byte[] key = new byte[1 + UTF8.encoded(name)];
    key[0] = 1;
    UTF8.encode(name, key, 1);
    try (final ManagedLock<ReentrantLock> btreeLock = lockManager.acquireBtreeWriteLock(index.btree.getLockName())) {
        index.btree.addValue(new Value(key), id);
    } catch (final LockException | IOException | BTreeException e) {
        throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) BTreeException(org.exist.storage.btree.BTreeException) Value(org.exist.storage.btree.Value) IOException(java.io.IOException) EXistException(org.exist.EXistException)

Example 89 with EXistException

use of org.exist.EXistException in project exist by eXist-db.

the class SortIndexWorker method removeId.

private void removeId(final String name) throws EXistException {
    final byte[] key = new byte[1 + UTF8.encoded(name)];
    key[0] = 1;
    UTF8.encode(name, key, 1);
    try (final ManagedLock<ReentrantLock> btreeLock = lockManager.acquireBtreeWriteLock(index.btree.getLockName())) {
        index.btree.removeValue(new Value(key));
    } catch (final LockException | IOException | BTreeException e) {
        throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) BTreeException(org.exist.storage.btree.BTreeException) Value(org.exist.storage.btree.Value) IOException(java.io.IOException) EXistException(org.exist.EXistException)

Example 90 with EXistException

use of org.exist.EXistException in project exist by eXist-db.

the class SortIndexWorker method remove.

private void remove(final DocumentImpl doc, final short id) throws LockException, EXistException {
    try (final ManagedLock<ReentrantLock> btreeLock = lockManager.acquireBtreeWriteLock(index.btree.getLockName())) {
        final byte[] fromKey = computeKey(id, doc.getDocId());
        final byte[] toKey = computeKey(id, doc.getDocId() + 1);
        final IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(toKey));
        index.btree.remove(query, null);
    } catch (final BTreeException | TerminatedException | IOException e) {
        throw new EXistException("Exception caught while deleting sort index: " + e.getMessage(), e);
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) BTreeException(org.exist.storage.btree.BTreeException) IndexQuery(org.exist.storage.btree.IndexQuery) Value(org.exist.storage.btree.Value) IOException(java.io.IOException) EXistException(org.exist.EXistException) TerminatedException(org.exist.xquery.TerminatedException)

Aggregations

EXistException (org.exist.EXistException)218 PermissionDeniedException (org.exist.security.PermissionDeniedException)80 IOException (java.io.IOException)63 DBBroker (org.exist.storage.DBBroker)58 Txn (org.exist.storage.txn.Txn)46 XmldbURI (org.exist.xmldb.XmldbURI)42 Collection (org.exist.collections.Collection)41 SAXException (org.xml.sax.SAXException)32 LockException (org.exist.util.LockException)31 DocumentImpl (org.exist.dom.persistent.DocumentImpl)28 Subject (org.exist.security.Subject)23 XPathException (org.exist.xquery.XPathException)22 LockedDocument (org.exist.dom.persistent.LockedDocument)21 TriggerException (org.exist.collections.triggers.TriggerException)20 Path (java.nio.file.Path)19 URISyntaxException (java.net.URISyntaxException)18 BrokerPool (org.exist.storage.BrokerPool)18 TransactionManager (org.exist.storage.txn.TransactionManager)18 InputSource (org.xml.sax.InputSource)18 Sequence (org.exist.xquery.value.Sequence)17