/** * Initialize the RI at the given level and return it. If the RI is already * initialized, it will be closed and re-initialized at the given level. */ protected void initRI(int indexLevel) throws Exception { if (_ri != null) { try { _ri.close(); } catch (Exception e) { } } TriplestoreConnector connector = getConnector(); TripleGenerator generator = new ModelBasedTripleGenerator(); _ri = new ResourceIndexImpl(connector, generator, indexLevel, false); }
@SuppressWarnings("deprecation") private void tearDownTriplestore() throws Exception { // delete all triples from the RI initRI(1); try { TriplestoreWriter writer = getConnector().getWriter(); // write all to temp file TripleIterator triples = writer.findTriples(null, null, null, -1); HashSet<Triple> temp = new HashSet<Triple>(); while(triples.hasNext()) { temp.add(triples.next()); } triples.close(); triples = new SimpleTripleIterator(temp, triples.getAliasMap()); _ri.delete(triples, true); } finally { // nothing left to do } _ri.close(); }