/** * Synchronize the Jena Model with the field system by calling * {@link TDB#sync(Model)} */ public void sync(){ TDB.sync(model); } /**
public QualityReport(){ TDB.sync(dataset); dataset.begin(ReadWrite.WRITE); // System.out.println("Dataset :" + EnvironmentProperties.getInstance().getBaseURI() + " TDB File :" + TDB_DIRECTORY); //dataset.getDefaultModel().removeAll(); // since this TDB is meant to be temporary, then we will remove all statements } //
public void syncWithFileSystem() { synchronized (dir2Dataset) { for (Map.Entry<File, Dataset> entry : dir2Dataset.entrySet()) { Lock l = dir2Lock.get(entry.getKey()); if (l == null) { return; } l.lock(); try { TDB.sync(entry.getValue()); } finally { l.unlock(); } } } } }
@Override public ImmutableGraph createImmutableGraph(IRI name, Graph triples) throws UnsupportedOperationException, EntityAlreadyExistsException { File tcDir = getImmutableGraphDir(name); if (tcDir.exists()) { throw new EntityAlreadyExistsException(name); } if (triples == null) { triples = new SimpleGraph(); } tcDir.mkdirs(); File otimizationIndicator = new File(tcDir, "fixed.opt"); try { otimizationIndicator.createNewFile(); } catch (IOException ex) { throw new RuntimeException(ex); } Graph mGraph = getGraph(tcDir); mGraph.addAll(triples); ImmutableGraph result = mGraph.getImmutableGraph(); TDB.sync(dir2Dataset.get(tcDir)); graphMap.put(name, result); return result; }
/** * Deactivates this component. Called by the OSGI environment if this * component gets deactivated. * @param ctx the ComponentContext. May be <code>null</code> */ @Deactivate 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(); } } }
public void addModel(Model m, String name) { if (name == null) { logger.info("cannot add the model because the given name is null."); return; } Model namedModel = this.dataset.getNamedModel(name); namedModel.removeAll(); namedModel.add(m.listStatements()); namedModel.setNsPrefixes(m.getNsPrefixMap()); namedModel.commit(); TDB.sync(this.dataset); }
@Test public void special4() { Dataset ds = create() ; load1(ds.getDefaultModel()) ; load2(ds.getNamedModel("http://example/graph1")) ; load3(ds.getNamedModel("http://example/graph2")) ; Model m = ModelFactory.createDefaultModel() ; load2(m) ; load3(m) ; TDB.sync(ds) ; String qs = "PREFIX : <"+baseNS+"> SELECT (COUNT(?x) as ?c) WHERE { ?x (:p1|:p2) 'x1' }" ; Query q = QueryFactory.create(qs, Syntax.syntaxARQ) ; QueryExecution qExec = QueryExecutionFactory.create(q, ds) ; qExec.getContext().set(TDB.symUnionDefaultGraph, true) ; long c1 = qExec.execSelect().next().getLiteral("c").getLong() ; qExec.close() ; qExec = QueryExecutionFactory.create(q, m) ; long c2 = qExec.execSelect().next().getLiteral("c").getLong() ; assertEquals(c1, c2) ; qExec.close() ; }