@Override public BlankNode addReificationOf(Statement statement) { BlankNode bnode = createBlankNode(); return (BlankNode)addReificationOf(statement, bnode); }
/** * Implementations with support for transactions should use them instead of * this implementation. */ @Override public synchronized void update(DiffReader diff) throws ModelRuntimeException { assertModel(); for(Statement r : diff.getRemoved()) { removeStatement(r); } for(Statement a : diff.getAdded()) { addStatement(a); } }
/** * Convenience method. */ public boolean contains(ResourceOrVariable subject, UriOrVariable predicate, String plainLiteral) throws ModelRuntimeException { assertModel(); return contains(subject, predicate, new PlainLiteralImpl(plainLiteral)); }
/** * Throws an exception if the syntax is not known */ public void writeTo(OutputStream out, Syntax syntax) throws IOException, ModelRuntimeException { assertModel(); if (syntax == Syntax.RdfXml) { writeTo(out); } else { throw new ModelRuntimeException("Unsupported syntax: " + syntax); } }
@Override public void addStatement(Resource subject, URI predicate, String literal) throws ModelRuntimeException { assertModel(); super.addStatement(subject, predicate, literal); }
/** * Convenience method. Might have faster implementations. Overwrite me! */ @Override public boolean contains(ResourceOrVariable subject, UriOrVariable predicate, NodeOrVariable object) throws ModelRuntimeException { assertModel(); ClosableIterator<? extends Statement> cit = findStatements(subject, predicate, object); boolean result = cit.hasNext(); cit.close(); return result; }
/** * Throws an exception if the syntax is not RDF/XML. Set baseURI to the * empty string. Subclasses are encouraged to overwrite this. */ public void readFrom(InputStream in, Syntax syntax, String baseURI) throws IOException, ModelRuntimeException { assertModel(); if (syntax == Syntax.RdfXml) { readFrom(in); } else { throw new ModelRuntimeException("Unsupported syntax: " + syntax); } }
assertModel(); log.trace("this has " + size() + " triples, other has " + otherSet.size() + " triples"); if(!this.contains(s)) added.add(s);
/** * This method checks if the model is properly initialized and i.e. not * closed. */ protected void assertModel() { if (this.getUnderlyingModelImplementation() == null) { throw new ModelRuntimeException("Underlying model is null."); } if (!isOpen()) throw new ModelRuntimeException("Model is not open"); }
/** * Throws an exception if the syntax is not SPARQL */ @Override public QueryResultTable querySelect(String query, String querylanguage) throws QueryLanguageNotSupportedException, ModelRuntimeException { assertModel(); if(querylanguage.equalsIgnoreCase("SPARQL")) return sparqlSelect(query); // else throw new QueryLanguageNotSupportedException("Unsupported query language: " + querylanguage); }
/** * Throws an exception if the syntax is not SPARQL */ @Override public ClosableIterable<Statement> queryConstruct(String query, String querylanguage) throws QueryLanguageNotSupportedException, ModelRuntimeException { assertModel(); if(querylanguage.equalsIgnoreCase("SPARQL")) return sparqlConstruct(query); // else throw new QueryLanguageNotSupportedException("Unsupported query language: " + querylanguage); }
/** * This is a really slow implementation, please override. */ public long size() throws ModelRuntimeException { assertModel(); ClosableIterator<Statement> it = iterator(); int count = 0; while (it.hasNext()) { count++; it.next(); } it.close(); return count; }
public void deleteReification(Resource reificationResource) { Diff diff = new DiffImpl(); diff.removeStatement(reificationResource, RDF.type, RDF.Statement); ClosableIterator<Statement> it = findStatements(reificationResource, RDF.subject, Variable.ANY); while (it.hasNext()) { diff.removeStatement(it.next()); } it.close(); it = findStatements(reificationResource, RDF.predicate, Variable.ANY); while (it.hasNext()) { diff.removeStatement(it.next()); } it.close(); it = findStatements(reificationResource, RDF.object, Variable.ANY); while (it.hasNext()) { diff.removeStatement(it.next()); } it.close(); update( (DiffReader) diff); } }
/** * Close connection to defined, underlying implementation */ @Override public void close() { if(isOpen()) { this.open = false; } else { log.trace("Model was closed already, ignored."); } }
/** subclasses should overwrite this for performance reasons */ public void addModel(Model model) { ClosableIterator<Statement> it = model.iterator(); Set<Statement> statements = new HashSet<Statement>(); while (it.hasNext()) { Statement stmt = it.next(); statements.add(stmt); } it.close(); for( Statement stmt : statements) { this.addStatement( stmt.getSubject(), stmt.getPredicate(), stmt.getObject()); } }
@Override public Statement createStatement(Resource subject, URI predicate, Node object) { return new StatementImpl(getContextURI(), subject, predicate, object); }
@Override public void addStatement(Resource subject, URI predicate, String literal, URI datatypeURI) throws ModelRuntimeException { assertModel(); super.addStatement(subject, predicate, literal, datatypeURI); }
/** * Convenience method. Might have faster implementations. Overwrite me! */ public boolean contains(ResourceOrVariable subject, UriOrVariable predicate, NodeOrVariable object) throws ModelRuntimeException { assertModel(); ClosableIterator<? extends Statement> cit = findStatements(subject, predicate, object); boolean result = cit.hasNext(); cit.close(); return result; }
/** * Throws an exception if the syntax is not RDF/XML. Subclasses are * encouraged to overwrite this. */ @Override public void readFrom(InputStream in, Syntax syntax) throws IOException, ModelRuntimeException { assertModel(); if(syntax == Syntax.RdfXml) { readFrom(in); } else { throw new ModelRuntimeException("Unsupported syntax: " + syntax); } }