use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class SDBConnectionDesc method worker.
private static SDBConnectionDesc worker(Model m) {
Resource r = GraphUtils.getResourceByType(m, AssemblerVocab.SDBConnectionAssemblerType);
if (r == null)
throw new SDBException("Can't find connection description");
SDBConnectionDesc desc = (SDBConnectionDesc) AssemblerBase.general.open(r);
desc.initJDBC();
return desc;
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class CmdDescAssembler method open.
/* This SPARQL query will process arguments
PREFIX acmd: <http://jena.hpl.hp.com/2007/sdb#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX list: <http://jena.apache.org/ARQ/list#>
SELECT ?name ?value
{ ?x rdf:type acmd:Cmd ;
acmd:args ?args .
{ ?args list:member [ acmd:name ?name ; acmd:value ?value ] }
UNION
{ ?args list:member ?e .
OPTIONAL { ?e acmd:name ?name }
FILTER (!bound(?name)) .
?e acmd:value ?value .
}
UNION
{ ?args list:member ?value . FILTER isLiteral(?value) }
}
*/
@Override
public Object open(Assembler a, Resource root, Mode mode) {
CmdDesc cd = new CmdDesc();
String main = GraphUtils.getStringValue(root, AssemblerVocab.pMain);
if (main == null)
main = GraphUtils.getStringValue(root, AssemblerVocab.pClassname);
cd.setCmd(main);
Resource x = GraphUtils.getResourceValue(root, AssemblerVocab.pArgs);
if (x != null) {
for (; !x.equals(RDF.nil); ) {
RDFNode e = x.getRequiredProperty(RDF.first).getObject();
// Move to next list item
x = x.getRequiredProperty(RDF.rest).getResource();
// Either : a literal or a named pair.
if (e.isLiteral()) {
cd.addPosn(((Literal) e).getString());
continue;
}
Resource entry = (Resource) e;
String name = GraphUtils.getStringValue(entry, AssemblerVocab.pArgName);
String value = GraphUtils.getStringValue(entry, AssemblerVocab.pArgValue);
if (value == null)
throw new CommandAssemblerException(entry, "Strange entry: " + entry);
if (name != null)
cd.addNamedArg(name, value);
else
cd.addPosn(value);
}
}
return cd;
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class QueryCommandAssembler method open.
@Override
public Object open(Assembler a, Resource root, Mode mode) {
// Query
Resource queryDesc = getUniqueResource(root, AssemblerVocab.pQuery);
Query query = (Query) a.open(a, queryDesc, mode);
// Dataset
Resource datasetDesc = getUniqueResource(root, AssemblerVocab.pDataset);
Dataset dataset = (Dataset) a.open(a, datasetDesc, mode);
// Output format
String s = GraphUtils.getStringValue(root, AssemblerVocab.pOutputFormat);
if (s == null)
s = "text";
ResultsFormat format = ResultsFormat.lookup(s);
QueryExecution qExec = QueryExecutionFactory.create(query, dataset);
return new QExec(query, qExec, format);
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class ScriptAssembler method open.
// A script is a number of command descriptions (CmdDesc)
@Override
public Object open(Assembler a, Resource root, Mode mode) {
ScriptDesc sd = new ScriptDesc();
Resource x = GraphUtils.getResourceValue(root, AssemblerVocab.pSteps);
if (x != null) {
for (; !x.equals(RDF.nil); ) {
Resource e = x.getRequiredProperty(RDF.first).getResource();
// Move to next list item
x = x.getRequiredProperty(RDF.rest).getResource();
// Process this item.
try {
CmdDesc cd = (CmdDesc) a.open(e);
sd.add(cd);
} catch (ClassCastException ex) {
System.err.println("Not a command description : " + ex.getMessage());
}
}
}
return sd;
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class T_TDBWriteTransaction method run.
public static void run(String location) {
if (false) {
Journal journal = Journal.create(Location.create(location));
JournalControl.print(journal);
journal.close();
}
//String location = args[0]; // + "/" + UUID.randomUUID().toString();
//String baseGraphName = "com.ibm.test.graphNamePrefix.";
long totalExecTime = 0L;
long size = 0;
Dataset dataset = TDBFactory.createDataset(location);
Dataset dataset1 = TDBFactory.createDataset(location);
if (bracketWithReader)
dataset1.begin(ReadWrite.READ);
for (int i = 0; i < TOTAL; i++) {
List<String> lastProcessedUris = new ArrayList<>();
for (int j = 0; j < 10 * i; j++) {
String lastProcessedUri = "http://test.net/xmlns/test/1.0/someUri" + j;
lastProcessedUris.add(lastProcessedUri);
}
//Dataset dataset = TDBFactory.createDataset(location);
//String graphName = baseGraphName + i;
long t = System.currentTimeMillis();
try {
dataset.begin(ReadWrite.WRITE);
Model m = dataset.getDefaultModel();
m.removeAll();
Resource subject = m.createResource(INDEX_INFO_SUBJECT);
Property predicate = m.createProperty(TIMESTAMP_PREDICATE);
m.addLiteral(subject, predicate, System.currentTimeMillis());
predicate = m.createProperty(URI_PREDICATE);
for (String uri : lastProcessedUris) {
m.add(subject, predicate, m.createResource(uri));
}
predicate = m.createProperty(VERSION_PREDICATE);
m.addLiteral(subject, predicate, 1.0);
size += m.size() + 1;
predicate = m.createProperty(INDEX_SIZE_PREDICATE);
m.addLiteral(subject, predicate, size);
dataset.commit();
} catch (Throwable e) {
dataset.abort();
throw new RuntimeException(e);
} finally {
dataset.end();
long writeOperationDuration = System.currentTimeMillis() - t;
totalExecTime += writeOperationDuration;
System.out.println("Write operation " + i + " took " + writeOperationDuration + "ms");
}
}
if (bracketWithReader)
dataset1.end();
System.out.println("All " + TOTAL + " write operations wrote " + size + " triples and took " + totalExecTime + "ms");
}
Aggregations