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 boolean containsNamedModel(String uri) { // Does not touch the cache. checkGraphName(uri) ; Node n = NodeFactory.createURI(uri) ; return dsg.containsGraph(n) ; }
@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) ; } }
@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) ; }
/** 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 ; } }
@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() ) ; }