use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class QueryExecUtils method getExactlyOne.
/**
* Execute, expecting the result to be one row, one column. Return that one
* RDFNode or throw an exception
*/
public static RDFNode getExactlyOne(QueryExecution qExec, String varname) {
try {
ResultSet rs = qExec.execSelect();
if (!rs.hasNext())
throw new ARQException("Not found: var ?" + varname);
QuerySolution qs = rs.nextSolution();
RDFNode r = qs.get(varname);
if (rs.hasNext())
throw new ARQException("More than one: var ?" + varname);
return r;
} finally {
qExec.close();
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class QueryExecUtils method getOne.
/**
* Execute, expecting the result to be one row, one column. Return that one
* RDFNode or null Throw excpetion if more than one.
*/
public static RDFNode getOne(QueryExecution qExec, String varname) {
try {
ResultSet rs = qExec.execSelect();
if (!rs.hasNext())
return null;
QuerySolution qs = rs.nextSolution();
RDFNode r = qs.get(varname);
if (rs.hasNext()) {
QuerySolution qs2 = rs.next();
RDFNode r2 = qs2.get(varname);
if (rs.hasNext())
throw new ARQException("More than one: var ?" + varname + " -> " + r + ", " + r2 + ", ...");
else
throw new ARQException("Found two matches: var ?" + varname + " -> " + r + ", " + r2);
}
return r;
} finally {
qExec.close();
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class SecuredRDFNodeImpl method as.
@SuppressWarnings("unchecked")
@Override
public <T extends RDFNode> T as(final Class<T> view) throws ReadDeniedException, AuthenticationRequiredException, SecuredUnsupportedPolymorphismException {
checkRead();
// see if the base Item can as
T baseAs = holder.getBaseItem().as(view);
if (view.equals(SecuredRDFNodeImpl.class) || view.equals(RDFNode.class)) {
return (T) this;
}
final Method m = getConstructor(view);
if (m == null) {
throw new SecuredUnsupportedPolymorphismException(this, view);
}
try {
return (T) m.invoke(null, securedModel, baseAs);
} catch (final UnsupportedPolymorphismException e) {
throw new SecuredUnsupportedPolymorphismException(this, view);
} catch (final IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (final IllegalAccessException e) {
throw new RuntimeException(e);
} catch (final InvocationTargetException e) {
throw new RuntimeException(e);
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class SpatialIndexLuceneAssembler method open.
/*
<#index> a :SpatialIndexLucene ;
#spatial:directory "mem" ;
spatial:directory <file:DIR> ;
spatial:definition <#definition> ;
.
*/
@SuppressWarnings("resource")
@Override
public SpatialIndex open(Assembler a, Resource root, Mode mode) {
try {
if (!GraphUtils.exactlyOneProperty(root, pDirectory))
throw new SpatialIndexException("No 'spatial:directory' property on " + root);
Directory directory;
RDFNode n = root.getProperty(pDirectory).getObject();
if (n.isLiteral()) {
if (!"mem".equals(n.asLiteral().getLexicalForm()))
throw new SpatialIndexException("No 'spatial:directory' property on " + root + " is a literal and not \"mem\"");
directory = new RAMDirectory();
} else {
Resource x = n.asResource();
String path = IRILib.IRIToFilename(x.getURI());
File dir = new File(path);
directory = FSDirectory.open(dir.toPath());
}
Resource r = GraphUtils.getResourceValue(root, pDefinition);
EntityDefinition docDef = (EntityDefinition) a.open(r);
return SpatialDatasetFactory.createLuceneIndex(directory, docDef);
} catch (IOException e) {
IO.exception(e);
return null;
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class AbstractTestModel method testCreateLiteralFromNode.
public void testCreateLiteralFromNode() {
RDFNode S = model.getRDFNode(NodeCreateUtils.create("42"));
assertInstanceOf(Literal.class, S);
assertEquals("42", ((Literal) S).getLexicalForm());
}
Aggregations