use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class RepositoryConfig method export.
/**
* Exports the configuration into RDF using the given repositoryNode
*
* @param model
* target RDF collection
* @param repositoryNode
* @since 2.3
*/
public void export(Model model, Resource repositoryNode) {
ValueFactory vf = SimpleValueFactory.getInstance();
model.setNamespace(RDFS.NS);
model.setNamespace(XMLSchema.NS);
model.setNamespace("rep", NAMESPACE);
model.add(repositoryNode, RDF.TYPE, REPOSITORY);
if (id != null) {
model.add(repositoryNode, REPOSITORYID, vf.createLiteral(id));
}
if (title != null) {
model.add(repositoryNode, RDFS.LABEL, vf.createLiteral(title));
}
if (implConfig != null) {
Resource implNode = implConfig.export(model);
model.add(repositoryNode, REPOSITORYIMPL, implNode);
}
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class RepositoryConfigUtil method removeRepositoryConfigs.
/**
* Removes one or more Repository configurations from a Repository. Nothing happens when this Repository
* does not contain configurations for these Repository IDs.
*
* @param repository
* The Repository to remove the configurations from.
* @param repositoryIDs
* The IDs of the Repositories whose configurations need to be removed.
* @throws RepositoryException
* Whenever access to the Repository's RepositoryConnection causes a RepositoryException.
* @throws RepositoryConfigException
*/
@Deprecated
public static boolean removeRepositoryConfigs(Repository repository, String... repositoryIDs) throws RepositoryException, RepositoryConfigException {
boolean changed = false;
RepositoryConnection con = repository.getConnection();
try {
con.begin();
for (String id : repositoryIDs) {
Resource context = getContext(con, id);
if (context != null) {
con.clear(context);
con.remove(context, RDF.TYPE, REPOSITORY_CONTEXT);
changed = true;
}
}
con.commit();
} finally {
con.close();
}
return changed;
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class RepositoryConfigUtil method getRepositoryConfig.
@Deprecated
public static RepositoryConfig getRepositoryConfig(Repository repository, String repositoryID) throws RepositoryConfigException, RepositoryException {
RepositoryConnection con = repository.getConnection();
try {
Statement idStatement = getIDStatement(con, repositoryID);
if (idStatement == null) {
// No such config
return null;
}
Resource repositoryNode = idStatement.getSubject();
Resource context = idStatement.getContext();
if (context == null) {
throw new RepositoryException("No configuration context for repository " + repositoryID);
}
Model contextGraph = QueryResults.asModel(con.getStatements(null, null, null, true, context));
return RepositoryConfig.create(contextGraph, repositoryNode);
} finally {
con.close();
}
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class Connections method consumeRDFCollection.
/**
* Retrieve all {@link Statement}s that together form the RDF Collection starting with the supplied start
* resource and send them to the supplied {@link Consumer}.
*
* @param conn
* the {@link RepositoryConnection} to use for statement retrieval.
* @param head
* the start resource of the RDF Collection. May not be {@code null}.
* @param collectionConsumer
* a {@link Consumer} function to which all retrieved statements will be reported. May not be
* {@code null}.
* @param contexts
* the context(s) from which to read the RDF Collection. This argument is an optional vararg and
* can be left out.
* @throws RepositoryException
* if an error occurred while reading the collection statements, for example if a cycle is
* detected in the RDF collection, or some other anomaly which makes it non-wellformed.
* @see RDFCollections
* @see <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Schema 1.1 section on Collection
* vocabulary</a>.
*/
public static void consumeRDFCollection(RepositoryConnection conn, Resource head, Consumer<Statement> collectionConsumer, Resource... contexts) throws RepositoryException {
GetStatementOptional statementSupplier = (s, p, o, c) -> getStatement(conn, s, p, o, c);
Function<String, Supplier<RepositoryException>> exceptionSupplier = Repositories::repositoryException;
RDFCollections.extract(statementSupplier, head, collectionConsumer, exceptionSupplier, contexts);
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class RDFCollectionsTest method testNonWellformedCollection.
@Test
public void testNonWellformedCollection() {
Resource head = vf.createBNode();
Model m = RDFCollections.asRDF(values, head, new TreeModel());
m.remove(null, RDF.REST, RDF.NIL);
try {
RDFCollections.asValues(m, head, new ArrayList<Value>());
fail("collection missing terminator should result in error");
} catch (ModelException e) {
// fall through, expected
}
m = RDFCollections.asRDF(values, head, new TreeModel());
m.add(head, RDF.REST, head);
try {
RDFCollections.asValues(m, head, new ArrayList<Value>());
fail("collection with cycle should result in error");
} catch (ModelException e) {
// fall through, expected
}
// supply incorrect head node
try {
RDFCollections.asValues(m, vf.createBNode(), new ArrayList<Value>());
fail("resource that is not a collection should result in error");
} catch (ModelException e) {
// fall through, expected
}
}
Aggregations