Package org.openrdf.sail.inferencer.helpers

Source Code of org.openrdf.sail.inferencer.helpers.SynchronizedInferencerConnection

/*
* Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2008.
*
* Licensed under the Aduna BSD-style license.
*/
package org.openrdf.sail.inferencer.helpers;

import info.aduna.concurrent.locks.Lock;

import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
import org.openrdf.sail.SailConnectionListener;
import org.openrdf.sail.helpers.SynchronizedSailConnection;
import org.openrdf.sail.inferencer.InferencerConnection;
import org.openrdf.store.StoreException;

/**
* Wrapper class offering synchronization functionality for InferencerConnection
* implementations. See {@link SynchronizedSailConnection} for more details.
*
* @author Arjohn Kampman
* @author jeen
* @author James Leigh
*/
public class SynchronizedInferencerConnection extends SynchronizedSailConnection implements
    InferencerConnection
{

  /*--------------*
   * Constructors *
   *--------------*/

  public SynchronizedInferencerConnection(InferencerConnection wrappedCon) {
    super(wrappedCon);
  }

  /*---------*
   * Methods *
   *---------*/

  @Override
  protected InferencerConnection getDelegate() {
    return (InferencerConnection)super.getDelegate();
  }

  public boolean addInferredStatement(Resource subj, URI pred, Value obj, Resource... contexts)
    throws StoreException
  {
    Lock conLock = getSharedConnectionLock();
    try {
      Lock txnLock = getTransactionLock();
      try {
        return getDelegate().addInferredStatement(subj, pred, obj, contexts);
      }
      finally {
        txnLock.release();
      }
    }
    finally {
      conLock.release();
    }
  }

  public boolean removeInferredStatements(Resource subj, URI pred, Value obj, Resource... contexts)
    throws StoreException
  {
    Lock conLock = getSharedConnectionLock();
    try {
      Lock txnLock = getTransactionLock();
      try {
        return getDelegate().removeInferredStatements(subj, pred, obj, contexts);
      }
      finally {
        txnLock.release();
      }
    }
    finally {
      conLock.release();
    }
  }

  public void flushUpdates()
    throws StoreException
  {
    Lock conLock = getSharedConnectionLock();
    try {
      Lock txnLock = getTransactionLock();
      try {
        getDelegate().flushUpdates();
      }
      finally {
        txnLock.release();
      }
    }
    finally {
      conLock.release();
    }
  }

  public void addConnectionListener(SailConnectionListener listener) {
    getDelegate().addConnectionListener(listener);
  }

  public void removeConnectionListener(SailConnectionListener listener) {
    getDelegate().removeConnectionListener(listener);
  }
}
TOP

Related Classes of org.openrdf.sail.inferencer.helpers.SynchronizedInferencerConnection

TOP
Copyright © 2018 www.massapi.com. 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.