Java Code Examples for org.openrdf.repository.Repository#shutDown()
The following examples show how to use
org.openrdf.repository.Repository#shutDown() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SampleBlazegraphSesameEmbedded.java From blazegraph-samples with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws IOException, OpenRDFException { // load journal properties from resources final Properties props = loadProperties("/blazegraph.properties"); // instantiate a sail final BigdataSail sail = new BigdataSail(props); final Repository repo = new BigdataSailRepository(sail); try{ repo.initialize(); /* * Load data from resources * src/main/resources/data.n3 */ loadDataFromResources(repo, "/data.n3", ""); final String query = "select * {<http://blazegraph.com/blazegraph> ?p ?o}"; final TupleQueryResult result = executeSelectQuery(repo, query, QueryLanguage.SPARQL); try { while(result.hasNext()){ final BindingSet bs = result.next(); log.info(bs); } } finally { result.close(); } } finally { repo.shutDown(); } }
Example 2
Source File: SampleBlazegraphCustomFunctionEmbedded.java From blazegraph-samples with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws OpenRDFException, IOException { final Repository repo = createRepository(); registerCustomFunction(repo); try{ repo.initialize(); /* * Load data from resources * src/main/resources/data.n3 */ Utils.loadDataFromResources(repo, "data.n3", ""); final TupleQueryResult result = Utils.executeSelectQuery(repo, QUERY, QueryLanguage.SPARQL); try { while(result.hasNext()){ BindingSet bs = result.next(); log.info(bs); } } finally { result.close(); } } finally { repo.shutDown(); } }
Example 3
Source File: Listener.java From cumulusrdf with Apache License 2.0 | 5 votes |
/** * Shutdown a repository. * Tries to shutdown the underlying store too. * * @param repository the repository. * @param store the store. */ void shutdown(final Repository repository) { if (repository != null) { _log.info(MessageCatalog._00012_REPOSITORY_SHUTDOWN_START); try { repository.shutDown(); _log.info(MessageCatalog._00014_REPOSITORY_SHUTDOWN); } catch (final RepositoryException repositoryException) { _log.error(MessageCatalog._00013_REPOSITORY_SHUTDOWN_FAILURE, repositoryException); } } }
Example 4
Source File: RepositoryManager.java From cumulusrdf with Apache License 2.0 | 5 votes |
/** * Shuts down a repository. * Tries to shutdown the underlying store too. * * @param repository the repository. */ void shutdown(final Repository repository) { if (repository != null) { _log.info(MessageCatalog._00012_REPOSITORY_SHUTDOWN_START); try { repository.shutDown(); _log.info(MessageCatalog._00014_REPOSITORY_SHUTDOWN); } catch (final RepositoryException repositoryException) { _log.error(MessageCatalog._00013_REPOSITORY_SHUTDOWN_FAILURE, repositoryException); } } }
Example 5
Source File: RDFModelParser.java From ldp4j with Apache License 2.0 | 5 votes |
private void shutDownQuietly(Repository repository) { if(repository!=null) { try { repository.shutDown(); } catch (OpenRDFException e) { if(LOGGER.isWarnEnabled()) { LOGGER.warn("Could not shutdown internal repository",e); } } } }
Example 6
Source File: HelloBlazegraph.java From blazegraph-samples with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws OpenRDFException { final Properties props = new Properties(); /* * For more configuration parameters see * http://www.blazegraph.com/docs/api/index.html?com/bigdata/journal/BufferMode.html */ props.put(Options.BUFFER_MODE, BufferMode.DiskRW); // persistent file system located journal props.put(Options.FILE, "/tmp/blazegraph/test.jnl"); // journal file location final BigdataSail sail = new BigdataSail(props); // instantiate a sail final Repository repo = new BigdataSailRepository(sail); // create a Sesame repository repo.initialize(); try { // prepare a statement final URIImpl subject = new URIImpl("http://blazegraph.com/Blazegraph"); final URIImpl predicate = new URIImpl("http://blazegraph.com/says"); final Literal object = new LiteralImpl("hello"); final Statement stmt = new StatementImpl(subject, predicate, object); // open repository connection RepositoryConnection cxn = repo.getConnection(); // upload data to repository try { cxn.begin(); cxn.add(stmt); cxn.commit(); } catch (OpenRDFException ex) { cxn.rollback(); throw ex; } finally { // close the repository connection cxn.close(); } // open connection if (repo instanceof BigdataSailRepository) { cxn = ((BigdataSailRepository) repo).getReadOnlyConnection(); } else { cxn = repo.getConnection(); } // evaluate sparql query try { final TupleQuery tupleQuery = cxn .prepareTupleQuery(QueryLanguage.SPARQL, "select ?p ?o where { <http://blazegraph.com/Blazegraph> ?p ?o . }"); final TupleQueryResult result = tupleQuery.evaluate(); try { while (result.hasNext()) { final BindingSet bindingSet = result.next(); System.err.println(bindingSet); } } finally { result.close(); } } finally { // close the repository connection cxn.close(); } } finally { repo.shutDown(); } }
Example 7
Source File: ScaleOut.java From database with GNU General Public License v2.0 | 4 votes |
/** * Issue the query. * * @throws Exception */ private void doQuery() throws Exception { // this is how you get a read-only transaction. MUST be // committed or aborted later, see below. long transactionId = fed.getTransactionService().newTx(ITx.READ_COMMITTED); try { // open the read-only triple store final AbstractTripleStore tripleStore = openTripleStore(fed, transactionId); // wrap it in a Sesame SAIL final BigdataSail sail = new BigdataSail(tripleStore); final Repository repo = new BigdataSailRepository(sail); repo.initialize(); RepositoryConnection cxn = repo.getConnection(); try { final TupleQuery tupleQuery = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); tupleQuery.setIncludeInferred(true /* includeInferred */); TupleQueryResult result = tupleQuery.evaluate(); // do something with the results int resultCount = 0; while (result.hasNext()) { BindingSet bindingSet = result.next(); // log.info(bindingSet); resultCount++; } log.info(resultCount + " results"); } finally { // close the repository connection cxn.close(); } repo.shutDown(); } finally { // MUST close the transaction, abort is sufficient fed.getTransactionService().abort(transactionId); } }
Example 8
Source File: TestBOpUtility.java From database with GNU General Public License v2.0 | 4 votes |
public void testOpenWorldEq() throws Exception { final Sail sail = new MemoryStore(); final Repository repo = new SailRepository(sail); repo.initialize(); final RepositoryConnection cxn = repo.getConnection(); try { final ValueFactory vf = sail.getValueFactory(); final URI mike = vf.createURI(BD.NAMESPACE + "mike"); final URI age = vf.createURI(BD.NAMESPACE + "age"); final Literal mikeAge = vf.createLiteral(34); cxn.add(vf.createStatement(mike, RDF.TYPE, RDFS.RESOURCE)); cxn.add(vf.createStatement(mike, age, mikeAge)); final String query = "select * " + "where { " + " ?s ?p ?o . " + " filter (?o < 40) " + "}"; final TupleQuery tupleQuery = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); final TupleQueryResult result = tupleQuery.evaluate(); while (result.hasNext()) { final BindingSet tmp = result.next(); if(log.isInfoEnabled()) log.info(tmp.toString()); } } finally { cxn.close(); repo.shutDown(); } }
Example 9
Source File: SampleBlazegraphCustomFunctionEmbeddedTest.java From blazegraph-samples with GNU General Public License v2.0 | 3 votes |
@Test public void testCustomFunctionEmbedded() throws OpenRDFException, IOException{ final Repository repo = SampleBlazegraphCustomFunctionEmbedded.createRepository(); SampleBlazegraphCustomFunctionEmbedded.registerCustomFunction(repo); try { repo.initialize(); Utils.loadDataFromResources(repo, "data.n3", ""); final TupleQueryResult result = Utils.executeSelectQuery(repo, SampleBlazegraphCustomFunctionEmbedded.QUERY, QueryLanguage.SPARQL); int countResults = 0; String expected = "http://www.example.com/document1"; String actual = null; while(result.hasNext()){ BindingSet bs = result.next(); actual = bs.getBinding("doc").getValue().stringValue(); countResults++; } result.close(); Assert.assertEquals(1, countResults); Assert.assertEquals(expected, actual); }finally { repo.shutDown(); } }
Example 10
Source File: ScaleOut.java From database with GNU General Public License v2.0 | 3 votes |
/** * Opens the triple store and writes the LUBM ontology and U10 data * files. Does a commit after every file, which is not the most * efficient way to bulk load, but simulates incremental updates. */ public void run() { try { // get the unisolated triple store for writing final AbstractTripleStore tripleStore = openTripleStore(fed, ITx.UNISOLATED); // wrap the triple store in a Sesame SAIL final BigdataSail sail = new BigdataSail(tripleStore); final Repository repo = new BigdataSailRepository(sail); repo.initialize(); // load the data loadU10(repo); // shut it down repo.shutDown(); } catch (Exception ex) { ex.printStackTrace(); } }