/** Create a dataset with the given model as the default graph * @param model * @return Dataset */ public static Dataset create(Model model) { return new DatasetImpl(model) ; }
@Override public Model getNamedModel(String uri) { checkGraphName(uri) ; Node n = NodeFactory.createURI(uri) ; synchronized(internalLock) { Graph g = dsg.getGraph(n) ; if ( g == null ) return null ; return graph2model(g) ; } }
/** Wrap a datasetgraph to make a mutable dataset * @param dataset DatasetGraph * @return Dataset */ public static Dataset create(DatasetGraph dataset) { return DatasetImpl.wrap(dataset) ; }
@Override public void replaceNamedModel(String uri, Model model) { // Assumes single writer. checkGraphName(uri) ; Node n = NodeFactory.createURI(uri) ; removeFromCache(dsg.getGraph(n)) ; dsg.removeGraph(n) ; addToCache(model) ; dsg.addGraph(n, model.getGraph() ) ; }
@Override public void addNamedModel(String uri, Model model) throws LabelExistsException { checkGraphName(uri) ; // Assumes single writer. addToCache(model) ; Node n = NodeFactory.createURI(uri) ; dsg.addGraph(n, model.getGraph()) ; }
@Override public void removeNamedModel(String uri) { checkGraphName(uri) ; Node n = NodeFactory.createURI(uri) ; // Assumes single writer. removeFromCache(dsg.getGraph(n)) ; dsg.removeGraph(n) ; }
public boolean containsNamedModel(String uri) { checkGraphName(uri) ; // Don't look in the cache - just ask the DSG which either caches graphs // or asks the storage as needed. The significant case is whether an // empty graph is contained in a dataset. If it's pure quad storage, // the answer is usually better as "no"; if it's an in-memory // dataset the answer is "yes". return dsg.containsGraph(Node.createURI(uri)) ; }
@Override public Model getDefaultModel() { synchronized(internalLock) { return graph2model(dsg.getDefaultGraph()) ; } }
@Override public void setDefaultModel(Model model) { if ( model == null ) model = ModelFactory.createDefaultModel() ; // Assumes single writer. removeFromCache(dsg.getDefaultGraph()) ; addToCache(model) ; dsg.setDefaultGraph(model.getGraph()) ; }
/** Create a Dataset with the model as default model. * Named models must be explicitly added to identify the storage to be used. */ public DatasetImpl(Model model) { addToCache(model) ; this.dsg = DatasetGraphFactory.create(model.getGraph()) ; }
@Override public boolean containsNamedModel(String uri) { // Does not touch the cache. checkGraphName(uri) ; Node n = NodeFactory.createURI(uri) ; return dsg.containsGraph(n) ; }
/** Return the default model */ public Model getDefaultModel() { synchronized(this) { if ( defaultModel == null ) defaultModel = graph2model(dsg.getDefaultGraph()) ; return defaultModel ; } }
/** Create a dataset * @param dataset * @return Dataset */ public static Dataset create(Dataset dataset) { return new DatasetImpl(dataset) ; }
/** Return a model for the named graph - repeated calls so not guarantee to return the same Java object */ public Model getNamedModel(String uri) { checkGraphName(uri) ; // synchronized because we need to read and possible update the cache atomically synchronized(this) { Model m = cache.get(uri) ; if ( m == null ) { m = graph2model(dsg.getGraph(Node.createURI(uri))) ; cache.put(uri, m) ; } return m ; } }
/** Wrap an existing DatasetGraph */ public static Dataset wrap(DatasetGraph datasetGraph) { DatasetImpl ds = new DatasetImpl(datasetGraph) ; return ds ; }
public static Dataset make(Dataset ds, Model defaultModel) { Dataset ds2 = new DatasetImpl(ds) ; ds2.setDefaultModel(defaultModel) ; return ds2 ; }
public Dataset getDataset() { if ( dsg == null ) return null ; return new DatasetImpl(dsg) ; }
public Dataset toDataset() { return new DatasetImpl(getWrapped()) ; }
/** Create an in-memory, modifable Dataset * @deprecated Use createMem */ @Deprecated public static Dataset create() { // This may not be a defaultJena model - during testing, // we use a graph that is not value-aware for xsd:String vs plain literals. return new DatasetImpl(ModelFactory.createModelForGraph(GraphFactory.createDefaultGraph())) ; }
/** Clone the structure of a DatasetGraph. * The current graph themselves are shared but new naming and new graphs are * only in the cloned */ public static Dataset cloneStructure(DatasetGraph datasetGraph) { return new DatasetImpl(new DatasetGraphMap(datasetGraph)) ; }