Search in sources :

Example 21 with SirixUsageException

use of org.sirix.exception.SirixUsageException in project sirix by sirixdb.

the class XdmResourceManager method beginNodeReadTrx.

@Override
public synchronized XdmNodeReadTrx beginNodeReadTrx(@Nonnegative final int revisionKey) {
    assertAccess(revisionKey);
    // Make sure not to exceed available number of read transactions.
    try {
        if (!mReadSemaphore.tryAcquire(20, TimeUnit.SECONDS)) {
            throw new SirixUsageException("No read transactions available, please close at least one read transaction at first!");
        }
    } catch (final InterruptedException e) {
        throw new SirixThreadedException(e);
    }
    final PageReadTrx pageReadTrx = beginPageReadTrx(revisionKey);
    final Node documentNode = getDocumentNode(pageReadTrx);
    // Create new reader.
    final XdmNodeReadTrx reader = new XdmNodeReadTrxImpl(this, mNodeTrxIDCounter.incrementAndGet(), pageReadTrx, documentNode);
    // Remember reader for debugging and safe close.
    if (mNodeReaderMap.put(reader.getId(), reader) != null) {
        throw new SirixUsageException("ID generation is bogus because of duplicate ID.");
    }
    return reader;
}
Also used : SirixThreadedException(org.sirix.exception.SirixThreadedException) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Node(org.sirix.node.interfaces.Node) SirixUsageException(org.sirix.exception.SirixUsageException) PageReadTrx(org.sirix.api.PageReadTrx)

Example 22 with SirixUsageException

use of org.sirix.exception.SirixUsageException in project sirix by sirixdb.

the class XdmResourceManager method beginNodeWriteTrx.

@Override
public synchronized XdmNodeWriteTrx beginNodeWriteTrx(@Nonnegative final int maxNodeCount, @Nonnull final TimeUnit timeUnit, @Nonnegative final int maxTime) {
    // Checks.
    assertAccess(mLastCommittedUberPage.get().getRevision());
    if (maxNodeCount < 0 || maxTime < 0) {
        throw new SirixUsageException("maxNodeCount may not be < 0!");
    }
    checkNotNull(timeUnit);
    // Make sure not to exceed available number of write transactions.
    try {
        if (!mWriteSemaphore.tryAcquire(20, TimeUnit.SECONDS)) {
            throw new SirixUsageException("No write transaction available, please close the write transaction first.");
        }
    } catch (final InterruptedException e) {
        throw new SirixThreadedException(e);
    }
    // Create new page write transaction (shares the same ID with the node write trx).
    final long currentTrxID = mNodeTrxIDCounter.incrementAndGet();
    final int lastRev = mLastCommittedUberPage.get().getRevisionNumber();
    final PageWriteTrx<Long, Record, UnorderedKeyValuePage> pageWtx = createPageWriteTransaction(currentTrxID, lastRev, lastRev, Abort.NO);
    final Node documentNode = getDocumentNode(pageWtx);
    // Create new node write transaction.
    final XdmNodeWriteTrx wtx = new XdmNodeWriterTrxImpl(currentTrxID, this, pageWtx, maxNodeCount, timeUnit, maxTime, documentNode);
    // Remember node transaction for debugging and safe close.
    if (mNodeReaderMap.put(currentTrxID, wtx) != null || mNodePageTrxMap.put(currentTrxID, pageWtx) != null) {
        throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
    }
    return wtx;
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) SirixThreadedException(org.sirix.exception.SirixThreadedException) Node(org.sirix.node.interfaces.Node) AtomicLong(java.util.concurrent.atomic.AtomicLong) Record(org.sirix.node.interfaces.Record) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) SirixUsageException(org.sirix.exception.SirixUsageException)

Aggregations

SirixUsageException (org.sirix.exception.SirixUsageException)22 StructNode (org.sirix.node.interfaces.StructNode)13 SirixDeweyID (org.sirix.node.SirixDeweyID)10 ElementNode (org.sirix.node.ElementNode)8 TextNode (org.sirix.node.TextNode)7 Node (org.sirix.node.interfaces.Node)6 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)6 CommentNode (org.sirix.node.CommentNode)5 PINode (org.sirix.node.PINode)5 NameNode (org.sirix.node.interfaces.NameNode)5 ValueNode (org.sirix.node.interfaces.ValueNode)5 ImmutableNode (org.sirix.node.interfaces.immutable.ImmutableNode)5 QNm (org.brackit.xquery.atomic.QNm)4 SirixThreadedException (org.sirix.exception.SirixThreadedException)4 AttributeNode (org.sirix.node.AttributeNode)4 NamespaceNode (org.sirix.node.NamespaceNode)4 Optional (java.util.Optional)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Axis (org.sirix.api.Axis)2 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)2