Package info.aduna.concurrent.locks

Examples of info.aduna.concurrent.locks.Lock


  }

  public final void setNamespace(String prefix, String name)
    throws SailException
  {
    Lock conLock = getSharedConnectionLock();
    try {
      verifyIsOpen();

      Lock txnLock = getTransactionLock();
      try {
        autoStartTransaction();
        setNamespaceInternal(prefix, name);
      }
      finally {
        txnLock.release();
      }
    }
    finally {
      conLock.release();
    }
View Full Code Here


  }

  public final void removeNamespace(String prefix)
    throws SailException
  {
    Lock conLock = getSharedConnectionLock();
    try {
      verifyIsOpen();

      Lock txnLock = getTransactionLock();
      try {
        autoStartTransaction();
        removeNamespaceInternal(prefix);
      }
      finally {
        txnLock.release();
      }
    }
    finally {
      conLock.release();
    }
View Full Code Here

  }

  public final void clearNamespaces()
    throws SailException
  {
    Lock conLock = getSharedConnectionLock();
    try {
      verifyIsOpen();

      Lock txnLock = getTransactionLock();
      try {
        autoStartTransaction();
        clearNamespacesInternal();
      }
      finally {
        txnLock.release();
      }
    }
    finally {
      conLock.release();
    }
View Full Code Here

      // Add a dummy root node to the tuple expressions to allow the
      // optimizers to modify the actual root node
      tupleExpr = new QueryRoot(tupleExpr);
    }

    Lock stLock = store.getStatementsReadLock();

    try {
      int snapshot = store.getCurrentSnapshot();
      ReadMode readMode = ReadMode.COMMITTED;

      if (transactionActive()) {
        snapshot++;
        readMode = ReadMode.TRANSACTION;
      }

      TripleSource tripleSource = new MemTripleSource(includeInferred, snapshot, readMode);
      EvaluationStrategyImpl strategy = new EvaluationStrategyImpl(tripleSource, dataset);

      QueryOptimizerList optimizerList = new QueryOptimizerList();
      optimizerList.add(new BindingAssigner());
      optimizerList.add(new ConstantOptimizer(strategy));
      optimizerList.add(new CompareOptimizer());
      optimizerList.add(new ConjunctiveConstraintSplitter());
      optimizerList.add(new SameTermFilterOptimizer());
      optimizerList.add(new QueryModelPruner());
      optimizerList.add(new QueryJoinOptimizer(new MemEvaluationStatistics()));
      optimizerList.add(new FilterOptimizer());

      optimizerList.optimize(tupleExpr, dataset, bindings);

      CloseableIteration<BindingSet, QueryEvaluationException> iter;
      iter = strategy.evaluate(tupleExpr, bindings);
      return new LockingIteration<BindingSet, QueryEvaluationException>(stLock, iter);
    }
    catch (QueryEvaluationException e) {
      stLock.release();
      throw new SailException(e);
    }
    catch (RuntimeException e) {
      stLock.release();
      throw e;
    }
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  protected CloseableIteration<? extends Resource, SailException> getContextIDsInternal()
    throws SailException
  {
    Lock stLock = store.getStatementsReadLock();

    try {
      // Iterate over all MemURIs and MemBNodes
      CloseableIteration<MemResource, SailException> iter;

      iter = new UnionIteration<MemResource, SailException>(
          new IteratorIteration<MemResource, SailException>(
              store.getValueFactory().getMemURIs().iterator()),
          new IteratorIteration<MemResource, SailException>(
              store.getValueFactory().getMemBNodes().iterator()));

      final int snapshot = transactionActive() ? store.getCurrentSnapshot() + 1
          : store.getCurrentSnapshot();
      final ReadMode readMode = transactionActive() ? ReadMode.TRANSACTION : ReadMode.COMMITTED;

      iter = new FilterIteration<MemResource, SailException>(iter) {

        @Override
        protected boolean accept(MemResource memResource)
          throws SailException
        {
          MemStatementList contextStatements = memResource.getContextStatementList();

          // Filter resources that are not used as context identifier
          if (contextStatements.size() == 0) {
            return false;
          }

          // Filter more thoroughly by considering snapshot and read-mode
          // parameters
          MemStatementIterator<SailException> iter = new MemStatementIterator<SailException>(
              contextStatements, null, null, null, false, snapshot, readMode);
          try {
            return iter.hasNext();
          }
          finally {
            iter.close();
          }
        }
      };

      // Release query lock when iterator is closed
      iter = new LockingIteration<MemResource, SailException>(stLock, iter);

      return iter;
    }
    catch (RuntimeException e) {
      stLock.release();
      throw e;
    }
  }
View Full Code Here

  @Override
  protected CloseableIteration<? extends Statement, SailException> getStatementsInternal(Resource subj,
      URI pred, Value obj, boolean includeInferred, Resource... contexts)
    throws SailException
  {
    Lock stLock = store.getStatementsReadLock();

    try {
      int snapshot = store.getCurrentSnapshot();
      ReadMode readMode = ReadMode.COMMITTED;

      if (transactionActive()) {
        snapshot++;
        readMode = ReadMode.TRANSACTION;
      }

      return new LockingIteration<MemStatement, SailException>(stLock, store.createStatementIterator(
          SailException.class, subj, pred, obj, !includeInferred, snapshot, readMode, contexts));
    }
    catch (RuntimeException e) {
      stLock.release();
      throw e;
    }
  }
View Full Code Here

  @Override
  protected long sizeInternal(Resource... contexts)
    throws SailException
  {
    Lock stLock = store.getStatementsReadLock();

    try {
      CloseableIteration<? extends Statement, SailException> iter = getStatementsInternal(null, null,
          null, false, contexts);

      try {
        long size = 0L;

        while (iter.hasNext()) {
          iter.next();
          size++;
        }

        return size;
      }
      finally {
        iter.close();
      }
    }
    finally {
      stLock.release();
    }
  }
View Full Code Here

  }

  public boolean addInferredStatement(Resource subj, URI pred, Value obj, Resource... contexts)
    throws SailException
  {
    Lock conLock = getSharedConnectionLock();
    try {
      verifyIsOpen();

      Lock txnLock = getTransactionLock();
      try {
        autoStartTransaction();
        return addStatementInternal(subj, pred, obj, false, contexts);
      }
      finally {
        txnLock.release();
      }
    }
    finally {
      conLock.release();
    }
View Full Code Here

  }

  public boolean removeInferredStatement(Resource subj, URI pred, Value obj, Resource... contexts)
    throws SailException
  {
    Lock conLock = getSharedConnectionLock();
    try {
      verifyIsOpen();

      Lock txnLock = getTransactionLock();
      try {
        autoStartTransaction();
        return removeStatementsInternal(subj, pred, obj, false, contexts);
      }
      finally {
        txnLock.release();
      }
    }
    finally {
      conLock.release();
    }
View Full Code Here

  }

  public void clearInferred(Resource... contexts)
    throws SailException
  {
    Lock conLock = getSharedConnectionLock();
    try {
      verifyIsOpen();

      Lock txnLock = getTransactionLock();
      try {
        autoStartTransaction();
        removeStatementsInternal(null, null, null, false, contexts);
      }
      finally {
        txnLock.release();
      }
    }
    finally {
      conLock.release();
    }
View Full Code Here

TOP

Related Classes of info.aduna.concurrent.locks.Lock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.