Package uk.ac.open.kmi.smartproducts.sesame.sail

Source Code of uk.ac.open.kmi.smartproducts.sesame.sail.NativeTripleSource

/*
* Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
*
* Licensed under the Aduna BSD-style license.
*/
package uk.ac.open.kmi.smartproducts.sesame.sail;

import java.io.IOException;
import java.nio.channels.ClosedByInterruptException;

import info.aduna.iteration.CloseableIteration;
import info.aduna.iteration.ExceptionConvertingIteration;

import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
import org.openrdf.model.ValueFactory;
import org.openrdf.query.QueryEvaluationException;
import org.openrdf.query.QueryInterruptedException;
import org.openrdf.query.algebra.evaluation.TripleSource;

public class NativeTripleSource implements TripleSource {

  /*-----------*
   * Constants *
   *-----------*/

  protected final AndroidNativeStore nativeStore;

  protected final boolean includeInferred;

  protected final boolean readTransaction;

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

  protected NativeTripleSource(AndroidNativeStore store, boolean includeInferred, boolean readTransaction) {
    this.nativeStore = store;
    this.includeInferred = includeInferred;
    this.readTransaction = readTransaction;
  }

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

  public CloseableIteration<? extends Statement, QueryEvaluationException> getStatements(Resource subj,
      URI pred, Value obj, Resource... contexts)
    throws QueryEvaluationException
  {
    try {
      return new ExceptionConvertingIteration<Statement, QueryEvaluationException>(
          nativeStore.createStatementIterator(subj, pred, obj, includeInferred, readTransaction,
              contexts))
      {

        @Override
        protected QueryEvaluationException convert(Exception e) {
          if (e instanceof ClosedByInterruptException) {
            return new QueryInterruptedException(e);
          }
          else if (e instanceof IOException) {
            return new QueryEvaluationException(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) {
      throw new QueryEvaluationException("Unable to get statements", e);
    }
  }

  public ValueFactory getValueFactory() {
    return nativeStore.getValueFactory();
  }
}
TOP

Related Classes of uk.ac.open.kmi.smartproducts.sesame.sail.NativeTripleSource

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.