Package com.hp.hpl.jena.query

Examples of com.hp.hpl.jena.query.Dataset


    public Dataset createDataset(Assembler a, Resource root, Mode mode) {
        // Expanding version.
        DatasetGraph dsg = DatasetGraphFactory.createMem() ;
        AssemblerUtils.setContext(root, dsg.getContext()) ;

        Dataset ds = DatasetFactory.create(dsg) ;

        // -------- Default graph
        // Can use ja:graph or ja:defaultGraph
        Resource dftGraph = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pDefaultGraph) ;
        if ( dftGraph == null )
            dftGraph = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pGraph) ;

        Model dftModel = null ;
        if ( dftGraph != null )
            dftModel = a.openModel(dftGraph) ;
        else
            // Assembler description did not define one - make a dummy.
            dftModel = GraphFactory.makePlainModel() ;

        ds.setDefaultModel(dftModel) ;

        // -------- Named graphs
        List<RDFNode> nodes = GraphUtils.multiValue(root, DatasetAssemblerVocab.pNamedGraph) ;

        for (Iterator<RDFNode> iter = nodes.iterator(); iter.hasNext();) {
            RDFNode n = iter.next() ;
            if ( !(n instanceof Resource) )
                throw new DatasetAssemblerException(root, "Not a resource: " + FmtUtils.stringForRDFNode(n)) ;
            Resource r = (Resource)n ;

            String gName = GraphUtils.getAsStringValue(r, DatasetAssemblerVocab.pGraphName) ;
            Resource g = GraphUtils.getResourceValue(r, DatasetAssemblerVocab.pGraph) ;
            if ( g == null ) {
                g = GraphUtils.getResourceValue(r, DatasetAssemblerVocab.pGraphAlt) ;
                if ( g != null )
                    Log.warn(this, "Use of old vocabulary: use :graph not :graphData") ;
                else
                    throw new DatasetAssemblerException(root, "no graph for: " + gName) ;
            }

            Model m = a.openModel(g) ;
            ds.addNamedModel(gName, m) ;
        }

        AssemblerUtils.setContext(root, ds.getContext()) ;
        return ds ;
    }
View Full Code Here


     * component gets deactivated.
     * @param ctx the ComponentContext. May be <code>null</code>
     */
    @Deactivate
    protected void deactivate(ComponentContext ctx) {
      Dataset dataset = getDataset();
        if(dataset != null){ //avoid NPE on multiple calls
            datasetLock.writeLock().lock();
            try {
                for(ModelGraph mg : initModels.values()){
                    mg.close(); //close also syncs!
                }
                TDB.sync(dataset);
                dataset.close();
                setDataset(null);
            } finally {
                datasetLock.writeLock().unlock();
            }
        }
View Full Code Here

    protected void deactivate(ComponentContext ctx) {
        if(syncThread != null){
            syncThread.requestStop();
            syncThread = null;
        }
      Dataset dataset = getDataset();
        if(dataset != null){ //avoid NPE on multiple calls
            datasetLock.writeLock().lock();
            try {
                for(ModelGraph mg : syncModels.values()){
                    mg.close(); //close also syncs!
                }
                syncModels.clear();

                graphNameIndex.close();
                graphNameIndex = null;

                TDB.sync(dataset);
                dataset.close();
                setDataset(null);
            } finally {
                datasetLock.writeLock().unlock();
            }
        }
View Full Code Here

        File base = new File(dataPathString);
        return getTcDir(new File(base, "graph"), name);
    }

    private MGraph getMGraph(File tcDir) {
        Dataset dataset = TDBFactory.createDataset(tcDir.getAbsolutePath());
        Model model = dataset.getDefaultModel();
        //Model model = TDBFactory.createModel(tcDir.getAbsolutePath());
        final com.hp.hpl.jena.graph.Graph jenaGraph = model.getGraph();
        dir2JenaGraphMap.put(tcDir, jenaGraph);
        synchronized(dir2Dataset) {
            dir2Dataset.put(tcDir, dataset);
View Full Code Here

        System.out.println() ;
        // This wil be the default graph of the dataset written.
        RDFDataMgr.write(System.out, model, Lang.TRIG) ;
       
        // Loading Turtle as Trig reads into the default graph.
        Dataset dataset = RDFDataMgr.loadDataset("D.ttl") ;
        System.out.println() ;
        System.out.println("#### ---- Write as NQuads") ;
        System.out.println() ;
        RDFDataMgr.write(System.out, dataset, Lang.NQUADS) ;
    }
View Full Code Here

/** Example of using RIOT : reading data into datasets. */
public class ExRIOT_3
{
    public static void main(String...argv)
    {
        Dataset ds = null ;
       
        // Read a TriG file into quad storage in-memory.
        ds = RDFDataMgr.loadDataset("data.trig") ;
       
        // read some (more) data into a dataset graph.
        RDFDataMgr.read(ds, "data2.trig") ;
       
        // Create a dataset,
        Dataset ds2 = DatasetFactory.createMem() ;
        // read in data, indicating the syntax in case the remote end does not
        // correctly provide the HTTP content type.
        RDFDataMgr.read(ds2, "http://host/data2.unknown", TRIG) ;
    }
View Full Code Here

public class ExTDB_Txn2
{
    public static void main(String... argv)
    {
        String directory = "MyDatabases/DB1" ;
        Dataset dataset = TDBFactory.createDataset(directory) ;

        // Start WRITE transaction.
        //   It's possible to read from the datet inside the write transaction.

        //   An application can have other Datasets, in the same JVM,
        //   tied to the same TDB database performing read
        //   transactions concurrently. If another write transaction
        //   starts, the call of dataset.begin(WRITE) blocks until
        //   existing writer finishes.
       
        dataset.begin(ReadWrite.WRITE) ;
        try
        {
            GraphStore graphStore = GraphStoreFactory.create(dataset) ;
            // Do a SPARQL Update.
            String sparqlUpdateString = StrUtils.strjoinNL(
                 "PREFIX . <http://example/>",
                 "INSERT { :s :p ?now } WHERE { BIND(now() AS ?now) }"
                 ) ;

            execUpdate(sparqlUpdateString, graphStore) ;
            dataset.commit() ;
            // Or call .abort()
           
        } finally
        {
            // Notify the end of the transaction.
            // The transaction was finished at the point .commit or .abort was called.
            // .end will force an abort() if no previous call to .commit() or .abort()
            // has occurred, so .end() help manage track the state of the transaction.
            // .end() can be called multiple times for the same .begin(WRITE)
            dataset.end() ;
        }
    }
View Full Code Here

{
    public static void main(String... argv)
    {
        // Direct way: Make a TDB-back Jena model in the named directory.
        String directory = "MyDatabases/DB1" ;
        Dataset dataset = TDBFactory.createDataset(directory) ;
       
        // Potentially expensive query.
        String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }" ;
        // See http://incubator.apache.org/jena/documentation/query/app_api.html
       
        Query query = QueryFactory.create(sparqlQueryString) ;
        QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ;
        try {
          ResultSet results = qexec.execSelect() ;
          for ( ; results.hasNext() ; )
          {
              QuerySolution soln = results.nextSolution() ;
              int count = soln.getLiteral("count").getInt() ;
              System.out.println("count = "+count) ;
          }
        } finally { qexec.close() ; }

        // Close the dataset.
        dataset.close();
       
    }
View Full Code Here

                    throw new JenaException("Failed to find a suitable root") ;
            } catch (TypeNotUniqueException ex)
            { throw new JenaException("Multiple types for: "+DatasetAssemblerVocab.tDataset) ; }
        }

        Dataset ds = (Dataset)Assembler.general.open(root) ;
    }
View Full Code Here

    public static Resource getType() { return DatasetAssemblerVocab.tDataset ; }
   
    @Override
    public Object open(Assembler a, Resource root, Mode mode)
    {
        Dataset ds = createDataset(a, root, mode) ;
        createTextIndex(ds, root) ;

        return ds ;
    }
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.query.Dataset

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.