Package info.aduna.concurrent.locks

Examples of info.aduna.concurrent.locks.Lock


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

    Lock readLock = nativeStore.getReadLock();

    try {
      replaceValues(tupleExpr);

      TripleSource tripleSource = new NativeTripleSource(nativeStore, includeInferred, transactionActive());
      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());
      optimizerList.add(new FilterOptimizer());

      optimizerList.optimize(tupleExpr, dataset, bindings);

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


  protected CloseableIteration<? extends Resource, SailException> getContextIDsInternal()
    throws SailException
  {
    // Which resources are used as context identifiers is not stored
    // separately. Iterate over all statements and extract their context.
    Lock readLock = nativeStore.getReadLock();
    try {
      // Iterator over all statements
      CloseableIteration<? extends Statement, IOException> stIter;
      stIter = nativeStore.createStatementIterator(null, null, null, true, transactionActive());

      // Filter statements without context resource
      stIter = new FilterIteration<Statement, IOException>(stIter) {

        @Override
        protected boolean accept(Statement st) {
          return st.getContext() != null;
        }
      };

      // Return the contexts of the statements, filtering any duplicates,
      // releasing the read lock when the iterator is closed
      CloseableIteration<? extends Resource, IOException> contextIter;
      contextIter = new DistinctIteration<Resource, IOException>(
          new ConvertingIteration<Statement, Resource, IOException>(stIter) {

            @Override
            protected Resource convert(Statement st) {
              return st.getContext();
            }
          });

      contextIter = new LockingIteration<Resource, IOException>(readLock, contextIter);

      return new ExceptionConvertingIteration<Resource, SailException>(contextIter) {

        @Override
        protected SailException convert(Exception e) {
          if (e instanceof IOException) {
            return new SailException(e);
          }
          else if (e instanceof RuntimeException) {
            throw (RuntimeException)e;
          }
          else if (e == null) {
            throw new IllegalArgumentException("e must not be null");
          }
          else {
            throw new IllegalArgumentException("Unexpected exception type: " + e.getClass());
          }
        }
      };
    }
    catch (IOException e) {
      readLock.release();
      throw new SailException(e);
    }
    catch (RuntimeException e) {
      readLock.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 readLock = nativeStore.getReadLock();
    try {
      CloseableIteration<? extends Statement, IOException> iter;
      iter = nativeStore.createStatementIterator(subj, pred, obj, includeInferred, transactionActive(),
          contexts);
      iter = new LockingIteration<Statement, IOException>(readLock, iter);

      return new ExceptionConvertingIteration<Statement, SailException>(iter) {

        @Override
        protected SailException convert(Exception e) {
          if (e instanceof IOException) {
            return new SailException(e);
          }
          else if (e instanceof RuntimeException) {
            throw (RuntimeException)e;
          }
          else if (e == null) {
            throw new IllegalArgumentException("e must not be null");
          }
          else {
            throw new IllegalArgumentException("Unexpected exception type: " + e.getClass());
          }
        }
      };
    }
    catch (IOException e) {
      readLock.release();
      throw new SailException("Unable to get statements", e);
    }
    catch (RuntimeException e) {
      readLock.release();
      throw e;
    }
  }
View Full Code Here

  protected long sizeInternal(Resource... contexts)
    throws SailException
  {
    OpenRDFUtil.verifyContextNotNull(contexts);

    Lock readLock = nativeStore.getReadLock();

    try {
      List<Integer> contextIDs;
      if (contexts.length == 0) {
        contextIDs = Arrays.asList(NativeValue.UNKNOWN_ID);
      }
      else {
        contextIDs = nativeStore.getContextIDs(contexts);
      }

      long size = 0L;

      for (int contextID : contextIDs) {
        // Iterate over all explicit statements
        RecordIterator iter = nativeStore.getTripleStore().getTriples(-1, -1, -1, contextID, true,
            transactionActive());
        try {
          while (iter.next() != null) {
            size++;
          }
        }
        finally {
          iter.close();
        }
      }

      return size;
    }
    catch (IOException e) {
      throw new SailException(e);
    }
    finally {
      readLock.release();
    }
  }
View Full Code Here

  @Override
  protected CloseableIteration<? extends Namespace, SailException> getNamespacesInternal()
    throws SailException
  {
    Lock readLock = nativeStore.getReadLock();
    try {
      return new LockingIteration<NamespaceImpl, SailException>(
          readLock,
          new IteratorIteration<NamespaceImpl, SailException>(nativeStore.getNamespaceStore().iterator()));
    }
    catch (RuntimeException e) {
      readLock.release();
      throw e;
    }
  }
View Full Code Here

  @Override
  protected String getNamespaceInternal(String prefix)
    throws SailException
  {
    Lock readLock = nativeStore.getReadLock();
    try {
      return nativeStore.getNamespaceStore().getNamespace(prefix);
    }
    finally {
      readLock.release();
    }
  }
View Full Code Here

  @Override
  protected void commitInternal()
    throws SailException
  {
    Lock storeReadLock = nativeStore.getReadLock();

    try {
      nativeStore.getValueStore().sync();
      nativeStore.getTripleStore().commit();
      nativeStore.getNamespaceStore().sync();

      txnLock.release();
    }
    catch (IOException e) {
      throw new SailException(e);
    }
    finally {
      storeReadLock.release();
    }

    nativeStore.notifySailChanged(sailChangedEvent);

    // create a fresh event object.
View Full Code Here

  @Override
  protected void rollbackInternal()
    throws SailException
  {
    Lock storeReadLock = nativeStore.getReadLock();

    try {
      nativeStore.getValueStore().sync();
      nativeStore.getTripleStore().rollback();
    }
    catch (IOException e) {
      throw new SailException(e);
    }
    finally {
      txnLock.release();
      storeReadLock.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 addStatement(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();
        int removeCount = removeStatements(subj, pred, obj, false, contexts);
        return removeCount > 0;
      }
      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.