Search in sources :

Example 6 with Resource

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;
}
Also used : SDBException(org.apache.jena.sdb.SDBException) Resource(org.apache.jena.rdf.model.Resource)

Example 7 with Resource

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;
}
Also used : Resource(org.apache.jena.rdf.model.Resource) CommandAssemblerException(org.apache.jena.sdb.assembler.CommandAssemblerException) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 8 with Resource

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);
}
Also used : Query(org.apache.jena.query.Query) Dataset(org.apache.jena.query.Dataset) Resource(org.apache.jena.rdf.model.Resource) ResultsFormat(org.apache.jena.sparql.resultset.ResultsFormat) QueryExecution(org.apache.jena.query.QueryExecution)

Example 9 with Resource

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;
}
Also used : Resource(org.apache.jena.rdf.model.Resource)

Example 10 with Resource

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");
}
Also used : Dataset(org.apache.jena.query.Dataset) ArrayList(java.util.ArrayList) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Journal(org.apache.jena.tdb.transaction.Journal) Property(org.apache.jena.rdf.model.Property)

Aggregations

Resource (org.apache.jena.rdf.model.Resource)178 Model (org.apache.jena.rdf.model.Model)86 Test (org.junit.Test)55 Property (org.apache.jena.rdf.model.Property)34 RDFNode (org.apache.jena.rdf.model.RDFNode)24 Dataset (org.apache.jena.query.Dataset)20 Literal (org.apache.jena.rdf.model.Literal)17 BaseTest (org.apache.jena.atlas.junit.BaseTest)16 Node (org.apache.jena.graph.Node)16 Statement (org.apache.jena.rdf.model.Statement)14 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)13 StringReader (java.io.StringReader)9 InfModel (org.apache.jena.rdf.model.InfModel)9 Reader (java.io.Reader)8 ArrayList (java.util.ArrayList)8 JsonString (org.apache.jena.atlas.json.JsonString)8 Triple (org.apache.jena.graph.Triple)8 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)6 PrefixMapping (org.apache.jena.shared.PrefixMapping)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5