use of org.openrdf.model.URI in project backstage by zepheira.
the class Database method createTypeRecord.
private TypeRecord createTypeRecord(URI type, SailConnection sc) {
String id = getTypeId(type, sc);
String label = SailUtilities.getStringObject(sc, type, RDFS.LABEL, id);
Properties properties = new Properties();
CloseableIteration<? extends Statement, SailException> i = null;
try {
i = sc.getStatements(type, null, null, true);
} catch (SailException e) {
_logger.error("Failed to get all statements in order to get type record", e);
return null;
}
if (i != null) {
try {
while (i.hasNext()) {
Statement s = i.next();
URI p = s.getPredicate();
Value o = s.getObject();
if (!p.equals(RDFS.LABEL) && !p.equals(ExhibitOntology.ID)) {
properties.put(p.getLocalName(), SailUtilities.valueToString(o));
}
}
} catch (SailException e) {
_logger.warn("Failed to iterate through statements", e);
} finally {
try {
i.close();
} catch (SailException e) {
_logger.warn("Failed to close statement iterator", e);
}
}
}
return new TypeRecord(type, id, label, properties);
}
use of org.openrdf.model.URI in project backstage by zepheira.
the class Database method abbreviateItems.
protected synchronized void abbreviateItems() {
if (_abbreviatedItems) {
return;
}
_abbreviatedItems = true;
getRepository();
SailConnection sc = null;
try {
sc = _sail.getConnection();
} catch (SailException e) {
_logger.error("Failed to open sail connection in order to compute cached information", e);
}
if (sc != null) {
try {
CloseableIteration<? extends Statement, SailException> i;
try {
i = sc.getStatements(null, RDF.TYPE, null, true);
} catch (SailException e) {
_logger.error("Failed to get all statements in order to abbreviate items", e);
return;
}
try {
while (i.hasNext()) {
Statement s = i.next();
Resource r = s.getSubject();
if (r instanceof URI) {
getItemId((URI) r, sc);
}
}
} catch (SailException e) {
_logger.warn("Failed to iterate through statements", e);
} finally {
try {
i.close();
} catch (SailException e) {
_logger.warn("Failed to close statement iterator", e);
}
}
} finally {
try {
sc.close();
} catch (SailException e) {
_logger.warn("Failed to close sail connection", e);
}
}
}
}
use of org.openrdf.model.URI in project backstage by zepheira.
the class Database method internalBuildTypeRecords.
private void internalBuildTypeRecords(SailConnection sc) {
_typeRecords = new LinkedList<TypeRecord>();
_typeIDToRecord = new HashMap<String, TypeRecord>();
getRepository();
CloseableIteration<? extends Statement, SailException> i;
try {
i = sc.getStatements(null, RDF.TYPE, null, true);
} catch (SailException e) {
_logger.error("Failed to get all statements in order to get type records", e);
return;
}
Set<URI> types = new HashSet<URI>();
try {
while (i.hasNext()) {
Statement s = i.next();
types.add((URI) s.getObject());
}
} catch (SailException e) {
_logger.warn("Failed to iterate through statements", e);
} finally {
try {
i.close();
} catch (SailException e) {
_logger.warn("Failed to close statement iterator", e);
}
}
for (URI type : types) {
TypeRecord r = createTypeRecord(type, sc);
if (r != null) {
_typeRecords.add(r);
_typeIDToRecord.put(r.id, r);
}
}
}
use of org.openrdf.model.URI in project qi4j-sdk by Qi4j.
the class EntityStateSerializer method serialize.
public void serialize(final EntityState entityState, final boolean includeNonQueryable, final Graph graph) {
ValueFactory values = graph.getValueFactory();
EntityReference identity = entityState.identity();
URI entityUri = createEntityURI(values, identity);
graph.add(entityUri, Rdfs.TYPE, values.createURI(Classes.toURI(first(entityState.entityDescriptor().types()))));
serializeProperties(entityState, graph, entityUri, entityState.entityDescriptor(), includeNonQueryable);
serializeAssociations(entityState, graph, entityUri, entityState.entityDescriptor().state().associations(), includeNonQueryable);
serializeManyAssociations(entityState, graph, entityUri, entityState.entityDescriptor().state().manyAssociations(), includeNonQueryable);
}
use of org.openrdf.model.URI in project qi4j-sdk by Qi4j.
the class EntityStateSerializer method serializeAssociations.
private void serializeAssociations(final EntityState entityState, final Graph graph, URI entityUri, final Iterable<? extends AssociationDescriptor> associations, final boolean includeNonQueryable) {
ValueFactory values = graph.getValueFactory();
// Associations
for (AssociationDescriptor associationType : associations) {
if (!(includeNonQueryable || associationType.queryable())) {
// Skip non-queryable
continue;
}
EntityReference associatedId = entityState.associationValueOf(associationType.qualifiedName());
if (associatedId != null) {
URI assocURI = values.createURI(associationType.qualifiedName().toURI());
URI assocEntityURI = values.createURI(associatedId.toURI());
graph.add(entityUri, assocURI, assocEntityURI);
}
}
}
Aggregations