org.openrdf.sail.SailException Java Examples

The following examples show how to use org.openrdf.sail.SailException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SailBase.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public SailConnection getConnection()
	throws SailException
{
	initializationLock.readLock().lock();
	try {
		if (!isInitialized()) {
			throw new IllegalStateException("Sail is not initialized or has been shut down");
		}

		final SailConnection connection = getConnectionInternal();

		synchronized (activeConnections) {
			if (!activeConnections.containsKey(connection)) {
				throw new IllegalStateException("Connection is not managed");
			}
		}

		return connection;
	}
	finally {
		initializationLock.readLock().unlock();
	}
}
 
Example #2
Source File: AST2BOpUpdate.java    From database with GNU General Public License v2.0 6 votes vote down vote up
private static PipelineOp convertCreateEntailments(PipelineOp left,
		AST2BOpUpdateContext context) throws SailException {
	
	long stmtCount = 0;
	if (log.isDebugEnabled()) {
		stmtCount = context.conn.getSailConnection().getTripleStore().getStatementCount(true);
		log.info("begin compute closure");
	}
	
	context.conn.getSailConnection().computeClosure();
	
	if (log.isDebugEnabled()) {
		long inferredCount = context.conn.getSailConnection().getTripleStore().getStatementCount(true) - stmtCount;
           log.debug("Inferred statements = " + inferredCount);
           
	}
	
	return left;
}
 
Example #3
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int applyRuleRdf1()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> iter = this.newThisIteration.match(null, null, null);

	while (iter.hasNext()) {
		Statement st = iter.next();

		boolean added = addInferredStatement(st.getPredicate(), RDF.TYPE, RDF.PROPERTY);

		if (added) {
			nofInferred++;
		}
	}

	return nofInferred;
}
 
Example #4
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int applyRuleRdfs12()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> iter = this.newThisIteration.match(null, RDF.TYPE, RDFS.CONTAINERMEMBERSHIPPROPERTY);

	while (iter.hasNext()) {
		Statement st = iter.next();

		Resource xxx = st.getSubject();

		boolean added = addInferredStatement(xxx, RDFS.SUBPROPERTYOF, RDFS.MEMBER);
		if (added) {
			nofInferred++;
		}
	}

	return nofInferred;
}
 
Example #5
Source File: AST2BOpUpdate.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Note: Bigdata does not support empty graphs, so {@link UpdateType#Clear}
 * and {@link UpdateType#Drop} have the same semantics.
 * 
 * <pre>
 * DROP ( SILENT )? (GRAPH IRIref | DEFAULT | NAMED | ALL )
 * </pre>
 * 
 * @param left
 * @param op
 * @param context
 * @return
 * @throws RepositoryException
 * @throws SailException 
 */
private static PipelineOp convertClearOrDropGraph(PipelineOp left,
        final DropGraph op, final AST2BOpUpdateContext context)
        throws RepositoryException, SailException {

    if (runOnQueryEngine)
        throw new UnsupportedOperationException();

    final TermNode targetGraphNode = op.getTargetGraph();

    final BigdataURI targetGraph = targetGraphNode == null ? null
            : (BigdataURI) targetGraphNode.getValue();

    clearGraph(op.isSilent(), op.getTargetSolutionSet(), targetGraph,
            op.getScope(), op.isAllGraphs(), op.isAllSolutionSets(),
            context);

    return left;
    
}
 
Example #6
Source File: CumulusRDFSailConnection.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
@Override
protected CloseableIteration<? extends Statement, SailException> getStatementsInternal(
		final Resource subj,
		final URI pred,
		final Value obj,
		final boolean includeInferred,
		final Resource... contexts) throws SailException {

	if (_quad && (contexts == null || contexts.length == 0)) {
		throw new IllegalArgumentException("A quadstore always needs a context.");
	}

	if (contexts != null && contexts.length > 0) {
		@SuppressWarnings("unchecked")
		CloseableIteration<Statement, SailException>[] iterations = new CloseableIteration[contexts.length];

		for (int i = 0; i < contexts.length; i++) {
			iterations[i] = newStatementIterator(subj, pred, obj, contexts[i]);
		}

		return new CloseableMultiIterator<Statement, SailException>(iterations);
	} else {
		return newStatementIterator(subj, pred, obj, contexts);
	}
}
 
Example #7
Source File: TestConcurrentKBCreate.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Verify that the named kb exists.
  * 
  * @throws SailException
  */
private void assertKBExists(final Journal jnl, final String namespace)
      throws RepositoryException, SailException {
   // Attempt to discover the KB instance.
   BigdataSailRepositoryConnection conn = null;
   try {
      // Request query connection.
      conn = getQueryConnection(jnl, namespace, ITx.READ_COMMITTED);
      // Verify KB exists.
      assertNotNull(namespace, conn);
   } finally {
      // Ensure connection is closed.
      if (conn != null)
         conn.close();
   }
}
 
Example #8
Source File: ForwardChainingRDFSPlusInverseInferencer.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Adds axiom statements to the underlying Sail.
 */
@Override
public void initialize()
	throws SailException
{
	super.initialize();

	ForwardChainingRDFSPlusInverseInferencerConnection con = getConnection();
	try {
		con.addAxiomStatements();
		con.commit();
	}
	finally {
		con.close();
	}
}
 
Example #9
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int applyRuleRdfs10()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> iter = this.newThisIteration.match(null, RDF.TYPE, RDFS.CLASS);

	while (iter.hasNext()) {
		Statement st = iter.next();

		Resource xxx = st.getSubject();

		boolean added = addInferredStatement(xxx, RDFS.SUBCLASSOF, xxx);
		if (added) {
			nofInferred++;
		}
	}

	return nofInferred;
}
 
Example #10
Source File: CumulusRDFSailConnection.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
@Override
protected void addStatementInternal(
		final Resource subj,
		final URI pred,
		final Value obj,
		final Resource... contexts) throws SailException {

	try {
		if (_quad) {
			if (contexts == null || contexts.length == 0) {
				throw new IllegalArgumentException("A quadstore always needs a context.");
			}

			for (int i = 0; i < contexts.length; i++) {
				_crdf.addData(_factory.createStatement(subj, pred, obj, contexts[i]));
			}
		} else {
			_crdf.addData(_factory.createStatement(subj, pred, obj));
		}
	} catch (CumulusStoreException e) {
		e.printStackTrace();
		throw new SailException(e);
	}
}
 
Example #11
Source File: CumulusRDFSailConnection.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
@Override
public CloseableIteration<? extends Statement, QueryEvaluationException> getStatements(
		final Resource subj,
		final URI pred,
		final Value obj,
		final Resource... contexts) throws QueryEvaluationException {
	try {
		if (contexts != null && contexts.length > 0) {
			@SuppressWarnings("unchecked")
			final CloseableIteration<Statement, QueryEvaluationException>[] iterations = new CloseableIteration[contexts.length];
			
			for (int i = 0; i < contexts.length; i++) {
				iterations[i] = newStatementIterator(subj, pred, obj, contexts[i]);
			}

			return new CloseableMultiIterator<Statement, QueryEvaluationException>(iterations);
		} else {
			return newStatementIterator(subj, pred, obj, contexts);
		}
	} catch (final SailException exception) {
		LOGGER.error(MessageCatalog._00025_CUMULUS_SYSTEM_INTERNAL_FAILURE, exception);
		throw new QueryEvaluationException(exception);
	}
}
 
Example #12
Source File: BigdataSailRepositoryConnection.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Commit, returning the timestamp associated with the new commit point.
     * <p>
     * Note: auto-commit is an EXTREMELY bad idea. Performance will be terrible.
     * The database will swell to an outrageous size. TURN OFF AUTO COMMIT.
     * 
     * @return The timestamp associated with the new commit point. This will be
     *         <code>0L</code> if the write set was empty such that nothing was
     *         committed.
     * 
     * @see BigdataSail.Options#ALLOW_AUTO_COMMIT
     */
    public long commit2() throws RepositoryException {
        
        // auto-commit is heinously inefficient
        if (isAutoCommit() && 
            !((BigdataSailConnection) getSailConnection()).getAllowAutoCommit()) {
            
            throw new RepositoryException("please set autoCommit to false");

        }
        
        // Note: Just invokes sailConnection.commit()
//        super.commit();
        try {
//            sailConnection.commit();
            return getSailConnection().commit2();
        }
        catch (SailException e) {
            throw new RepositoryException(e);
        }
        
    }
 
Example #13
Source File: CumulusRDFSailConnection.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
public CloseableIteration<? extends Statement, QueryEvaluationException> getRangeStatements(
		final Resource subj, 
		final URI pred, 
		final Literal lowerBound,
		final boolean lower_equals, 
		final Literal upperBound, 
		final boolean upper_equals, 
		final Literal equals, 
		final boolean reverse) throws QueryEvaluationException {
	try {
		return createRangeStatementIterator(subj, pred, lowerBound, lower_equals, upperBound, upper_equals, equals, reverse);
	} catch (SailException e) {
		e.printStackTrace();
		throw new QueryEvaluationException(e);
	}
}
 
Example #14
Source File: CumulusRDFSailConnection.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
@Override
protected void removeStatementsInternal(
		final Resource subj,
		final URI pred,
		final Value obj,
		final Resource... contexts) throws SailException {

	try {
		if (_quad) {
			if (contexts == null || contexts.length == 0) {
				throw new IllegalArgumentException("A quadstore always needs a context.");
			}

			for (int i = 0; i < contexts.length; i++) {
				_crdf.removeData(_factory.createNodes(subj, pred, obj, contexts[0]));
			}
		} else {
			_crdf.removeData(_factory.createNodes(subj, pred, obj));
		}
	} catch (CumulusStoreException e) {
		e.printStackTrace();
		throw new SailException(e);
	}
}
 
Example #15
Source File: DeleteServlet.java    From database with GNU General Public License v2.0 6 votes vote down vote up
private void doRemoveStatement(final Statement stmt) throws SailException {

         final Resource[] c = (Resource[]) (stmt.getContext() == null ? defaultContext
               : new Resource[] { stmt.getContext() });

         conn.removeStatements(//
               stmt.getSubject(), //
               stmt.getPredicate(), //
               stmt.getObject(), //
               c);

         if (c.length >= 2) {
            // removed from more than one context
            nmodified.addAndGet(c.length);
         } else {
            nmodified.incrementAndGet();
         }

      }
 
Example #16
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int applyRuleRdfs3_2()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.RANGE, null);

	while (ntIter.hasNext()) {
		Statement nt = ntIter.next();

		Resource aaa = nt.getSubject();
		Value zzz = nt.getObject();

		if (aaa instanceof URI && zzz instanceof Resource) {
			CloseableIteration<? extends Statement, SailException> t1Iter;
			t1Iter = getWrappedConnection().getStatements(null, (URI)aaa, null, true);

			while (t1Iter.hasNext()) {
				Statement t1 = t1Iter.next();

				Value uuu = t1.getObject();
				if (uuu instanceof Resource) {
					boolean added = addInferredStatement((Resource)uuu, RDF.TYPE, zzz);
					if (added) {
						nofInferred++;
					}
				}
			}
			t1Iter.close();
		}
	}

	return nofInferred;

}
 
Example #17
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int applyRuleRdfs5_2()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.SUBPROPERTYOF, null);

	while (ntIter.hasNext()) {
		Statement nt = ntIter.next();

		Resource bbb = nt.getSubject();
		Value ccc = nt.getObject();

		if (ccc instanceof Resource) {
			CloseableIteration<? extends Statement, SailException> t1Iter;
			t1Iter = getWrappedConnection().getStatements(null, RDFS.SUBPROPERTYOF, bbb, true);

			while (t1Iter.hasNext()) {
				Statement t1 = t1Iter.next();

				Resource aaa = t1.getSubject();
				boolean added = addInferredStatement(aaa, RDFS.SUBPROPERTYOF, ccc);
				if (added) {
					nofInferred++;
				}
			}
			t1Iter.close();
		}
	}

	return nofInferred;
}
 
Example #18
Source File: CumulusRDFSailConnection.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
protected void setNamespaceInternal(final String prefix, final String name) throws SailException {
	try {
		_crdf.getPrefix2Namespaces().put(prefix, name);
	} catch (DataAccessLayerException exception) {
		throw new SailException(exception);
	}
}
 
Example #19
Source File: ForwardChainingRDFSPlusInverseInferencer.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public ForwardChainingRDFSPlusInverseInferencerConnection getConnection()
	throws SailException
{
	try {
		InferencerConnection con = (InferencerConnection)super.getConnection();
		return new ForwardChainingRDFSPlusInverseInferencerConnection(con);
	}
	catch (ClassCastException e) {
		throw new SailException(e.getMessage(), e);
	}
}
 
Example #20
Source File: BigdataSail.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unsupported API.
 */
@Override
public void endUpdate(UpdateContext op)
    throws SailException
{
    
    throw new SailException(ERR_OPENRDF_QUERY_MODEL);
    
}
 
Example #21
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int applyRuleRdfs11_1()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.SUBCLASSOF, null);

	while (ntIter.hasNext()) {
		Statement nt = ntIter.next();

		Resource xxx = nt.getSubject();
		Value yyy = nt.getObject();

		if (yyy instanceof Resource) {
			CloseableIteration<? extends Statement, SailException> t1Iter;
			t1Iter = getWrappedConnection().getStatements((Resource)yyy, RDFS.SUBCLASSOF, null, true);

			while (t1Iter.hasNext()) {
				Statement t1 = t1Iter.next();

				Value zzz = t1.getObject();

				if (zzz instanceof Resource) {
					boolean added = addInferredStatement(xxx, RDFS.SUBCLASSOF, zzz);
					if (added) {
						nofInferred++;
					}
				}
			}
			t1Iter.close();
		}
	}

	return nofInferred;
}
 
Example #22
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void rollback()
	throws SailException
{
	this.statementsRemoved = false;
	this.newStatements = null;

	super.rollback();
}
 
Example #23
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int applyRuleRdfs9_1()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.SUBCLASSOF, null);

	while (ntIter.hasNext()) {
		Statement nt = ntIter.next();

		Resource xxx = nt.getSubject();
		Value yyy = nt.getObject();

		if (yyy instanceof Resource) {
			CloseableIteration<? extends Statement, SailException> t1Iter;
			t1Iter = getWrappedConnection().getStatements(null, RDF.TYPE, xxx, true);

			while (t1Iter.hasNext()) {
				Statement t1 = t1Iter.next();

				Resource aaa = t1.getSubject();

				boolean added = addInferredStatement(aaa, RDF.TYPE, yyy);
				if (added) {
					nofInferred++;
				}
			}
			t1Iter.close();
		}
	}

	return nofInferred;
}
 
Example #24
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int applyRuleRdfs3_1()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> ntIter = this.newThisIteration.match(null, null, null);

	while (ntIter.hasNext()) {
		Statement nt = ntIter.next();

		URI aaa = nt.getPredicate();
		Value uuu = nt.getObject();

		if (uuu instanceof Resource) {
			CloseableIteration<? extends Statement, SailException> t1Iter;
			t1Iter = getWrappedConnection().getStatements(aaa, RDFS.RANGE, null, true);

			while (t1Iter.hasNext()) {
				Statement t1 = t1Iter.next();

				Value zzz = t1.getObject();
				if (zzz instanceof Resource) {
					boolean added = addInferredStatement((Resource)uuu, RDF.TYPE, zzz);
					if (added) {
						nofInferred++;
					}
				}
			}
			t1Iter.close();
		}
	}
	return nofInferred;
}
 
Example #25
Source File: InsertServlet.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleStatement(final Statement stmt)
        throws RDFHandlerException {

	final Resource[] c = (Resource[]) 
			(stmt.getContext() == null 
			?  defaultContext
            : new Resource[] { stmt.getContext() }); 
	
    try {

        conn.addStatement(//
                stmt.getSubject(), //
                stmt.getPredicate(), //
                stmt.getObject(), //
                c
                );

    } catch (SailException e) {

        throw new RDFHandlerException(e);

    }

    if (c.length >= 2) {
        // added to more than one context
        nmodified.addAndGet(c.length);
    } else {
        nmodified.incrementAndGet();
    }

}
 
Example #26
Source File: CumulusRDFSailConnection.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
protected void clearInternal(final Resource... contexts) throws SailException {

	if (contexts == null || contexts.length == 0) {
		_crdf.clear();
	} else {
		Arrays.stream(contexts).parallel().forEach(context -> {
			try {
				((QuadStore) _crdf).removeData(new Value[] { null, null, null, context});
			} catch (final Exception exception) {
				LOGGER.error(MessageCatalog._00025_CUMULUS_SYSTEM_INTERNAL_FAILURE, exception);
			}
		});
	}
}
 
Example #27
Source File: DeleteServlet.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleStatement(final Statement stmt)
        throws RDFHandlerException {

	final Resource[] c = (Resource[]) 
			(stmt.getContext() == null 
			?  defaultContext
            : new Resource[] { stmt.getContext() }); 
	
    try {

        conn.removeStatements(//
                stmt.getSubject(), //
                stmt.getPredicate(), //
                stmt.getObject(), //
                c
                );

    } catch (SailException e) {

        throw new RDFHandlerException(e);

    }

    if (c.length >= 2) {
        // removed from more than one context
        nmodified.addAndGet(c.length);
    } else {
        nmodified.incrementAndGet();
    }

}
 
Example #28
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
	 * xxx nrl:inverseProperty yyy
	 * aaa xxx bbb 
	 * -->
	 * bbb yyy aaa
	 * @return
	 * @throws SailException
	 */
	private int applyRuleN1a()
	throws SailException
{
	int nofInferred = 0;
	
	Iterator<Statement> ntIter = this.newThisIteration.match(null, NRL_InverseProperty, null);

	while (ntIter.hasNext()) {
		Statement nt = ntIter.next();

		Resource xxx = nt.getSubject();
		Value yyy = nt.getObject();

		if (xxx instanceof URI && yyy instanceof URI) {
			// apply to triples using the property
			CloseableIteration<? extends Statement, SailException> t1Iter;
			t1Iter = getWrappedConnection().getStatements(null, (URI)xxx, null, true);

			while (t1Iter.hasNext()) {
				Statement t1 = t1Iter.next();

				Value aaa = t1.getSubject();
				Value bbb = t1.getObject();
				if (bbb instanceof Resource) {
					boolean added = addInferredStatement((Resource)bbb, (URI) yyy, aaa);
					if (added) {
						nofInferred++;
					}
				}
			}
			t1Iter.close();
		}
	}

	return nofInferred;
}
 
Example #29
Source File: CumulusRDFSailConnection.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
protected void clearNamespacesInternal() throws SailException {
	try {
		PersistentMap<String, String> prefix2ns = _crdf.getPrefix2Namespaces();

		for (String prefix : prefix2ns.keySet()) {
			prefix2ns.remove(prefix);
		}
	} catch (DataAccessLayerException exception) {
		throw new SailException(exception);
	}
}
 
Example #30
Source File: BigdataSail.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unsupported API.
 */
@Override
public void addStatement(UpdateContext op, Resource subj, URI pred, Value obj, Resource... contexts)
    throws SailException
{
    
    throw new SailException(ERR_OPENRDF_QUERY_MODEL);

}