Java Code Examples for org.eclipse.rdf4j.repository.Repository#initialize()
The following examples show how to use
org.eclipse.rdf4j.repository.Repository#initialize() .
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: ConnectionManager.java From semagrow with Apache License 2.0 | 6 votes |
public RepositoryConnection getConnection(URL endpoint) throws RepositoryException { Repository repo = null; if (!repoMap.containsKey(endpoint)) { repo = new SPARQLRepository(endpoint.toString()); repoMap.put(endpoint,repo); } else { repo = repoMap.get(endpoint); } if (!repo.isInitialized()) repo.initialize(); RepositoryConnection conn = repo.getConnection(); logger.info("Open [{}] (currently open={})", conn, countconn); synchronized(this) { countconn++; } return conn; }
Example 2
Source File: RyaAccumuloSailFactoryTest.java From rya with Apache License 2.0 | 6 votes |
@Ignore @Test public void testAddStatement() throws Exception { SailRepositoryFactory f = new SailRepositoryFactory(); Repository r = f.getRepository(getConfig()); r.initialize(); RepositoryConnection rc = r.getConnection(); ValueFactory vf = rc.getValueFactory(); Statement s = vf.createStatement(vf.createIRI("u:a"), vf.createIRI("u:b"), vf.createIRI("u:c")); assertFalse(rc.hasStatement(s, false)); rc.add(s); Assert.assertTrue(rc.hasStatement(s, false)); rc.close(); }
Example 3
Source File: SeRQLQueryTestCase.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected Repository createRepository(String entailment) throws Exception { Repository dataRep; if ("RDF".equals(entailment)) { dataRep = newRepository(); } else { dataRep = newRepository(entailment); } dataRep.initialize(); RepositoryConnection con = dataRep.getConnection(); try { con.clear(); con.clearNamespaces(); } finally { con.close(); } return dataRep; }
Example 4
Source File: TurtleParserTestCase.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public TestSuite createTestSuite() throws Exception { // Create test suite TestSuite suite = new TestSuite(TurtleParserTestCase.class.getName()); // Add the manifest for W3C test cases to a repository and query it Repository w3cRepository = new SailRepository(new MemoryStore()); w3cRepository.initialize(); RepositoryConnection w3cCon = w3cRepository.getConnection(); InputStream inputStream = this.getClass().getResourceAsStream(TEST_W3C_MANIFEST_URL); w3cCon.add(inputStream, TEST_W3C_MANIFEST_URI_BASE, RDFFormat.TURTLE); parsePositiveTurtleSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); parseNegativeTurtleSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); parsePositiveTurtleEvalTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); parseNegativeTurtleEvalTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); w3cCon.close(); w3cRepository.shutDown(); return suite; }
Example 5
Source File: AbstractNQuadsParserTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public TestSuite createTestSuite() throws Exception { // Create test suite TestSuite suite = new TestSuite(this.getClass().getName()); // Add the manifest for W3C test cases to a repository and query it Repository w3cRepository = new SailRepository(new MemoryStore()); w3cRepository.initialize(); RepositoryConnection w3cCon = w3cRepository.getConnection(); InputStream inputStream = this.getClass().getResourceAsStream(TEST_W3C_MANIFEST_URL); w3cCon.add(inputStream, TEST_W3C_MANIFEST_URI_BASE, RDFFormat.TURTLE); parsePositiveNQuadsSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TEST_W3C_TEST_URI_BASE, w3cCon); parseNegativeNQuadsSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TEST_W3C_TEST_URI_BASE, w3cCon); w3cCon.close(); w3cRepository.shutDown(); return suite; }
Example 6
Source File: TriGParserTestCase.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public TestSuite createTestSuite() throws Exception { // Create test suite TestSuite suite = new TestSuite(TriGParserTestCase.class.getName()); // Add the manifest for W3C test cases to a repository and query it Repository w3cRepository = new SailRepository(new MemoryStore()); w3cRepository.initialize(); RepositoryConnection w3cCon = w3cRepository.getConnection(); InputStream inputStream = this.getClass().getResourceAsStream(TEST_W3C_MANIFEST_URL); w3cCon.add(inputStream, TEST_W3C_MANIFEST_URI_BASE, RDFFormat.TURTLE); parsePositiveTriGSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); parseNegativeTriGSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); parsePositiveTriGEvalTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); parseNegativeTriGEvalTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); w3cCon.close(); w3cRepository.shutDown(); return suite; }
Example 7
Source File: AbstractNTriplesParserTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public TestSuite createTestSuite() throws Exception { // Create test suite TestSuite suite = new TestSuite(this.getClass().getName()); // Add the manifest for W3C test cases to a repository and query it Repository w3cRepository = new SailRepository(new MemoryStore()); w3cRepository.initialize(); RepositoryConnection w3cCon = w3cRepository.getConnection(); InputStream inputStream = this.getClass().getResourceAsStream(TEST_W3C_MANIFEST_URL); w3cCon.add(inputStream, TEST_W3C_MANIFEST_URI_BASE, RDFFormat.TURTLE); parsePositiveNTriplesSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TEST_W3C_TEST_URI_BASE, w3cCon); parseNegativeNTriplesSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TEST_W3C_TEST_URI_BASE, w3cCon); w3cCon.close(); w3cRepository.shutDown(); return suite; }
Example 8
Source File: SemagrowRepositoryResolver.java From semagrow with Apache License 2.0 | 6 votes |
@Override public Repository getRepository(String s) throws RepositoryException, RepositoryConfigException { RepositoryImplConfig repoConfig = getConfig(); RepositoryFactory repoFactory = RepositoryRegistry.getInstance().get(repoConfig.getType()).get(); Repository repository = repoFactory.getRepository(repoConfig); repository.initialize(); // remove CSV and TSV format due to bug: literals are recognized as URIs if they contain a substring parsable as URI. TupleQueryResultParserRegistry registry = TupleQueryResultParserRegistry.getInstance(); registry.get(TupleQueryResultFormat.CSV).ifPresent(f -> registry.remove(f)); registry.get(TupleQueryResultFormat.TSV).ifPresent(f -> registry.remove(f)); registry.get(TupleQueryResultFormat.JSON).ifPresent(f -> registry.remove(f)); BooleanQueryResultParserRegistry booleanRegistry = BooleanQueryResultParserRegistry.getInstance(); booleanRegistry.get(BooleanQueryResultFormat.JSON).ifPresent(f -> booleanRegistry.remove(f)); return repository; }
Example 9
Source File: TestExploreServlet.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @throws RepositoryException if an issue occurs making the connection * @throws MalformedQueryException if an issue occurs inserting data * @throws UpdateExecutionException if an issue occurs inserting data */ @Before public void setUp() throws RepositoryException, MalformedQueryException, UpdateExecutionException { Repository repo = new SailRepository(new MemoryStore()); repo.initialize(); connection = repo.getConnection(); servlet = new ExploreServlet(); ValueFactory factory = connection.getValueFactory(); foo = factory.createIRI("http://www.test.com/foo"); bar = factory.createIRI("http://www.test.com/bar"); bang = factory.createIRI("http://www.test.com/bang"); foos = new IRI[128]; for (int i = 0; i < foos.length; i++) { foos[i] = factory.createIRI("http://www.test.com/foo/" + i); } builder = mock(TupleResultBuilder.class); }
Example 10
Source File: LockRemover.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Try to remove lock from repository * * @param repo * @param consoleIO * @return true if lock was removed * @throws IOException * @throws RepositoryException */ public static boolean tryToRemoveLock(Repository repo, ConsoleIO consoleIO) throws IOException, RepositoryException { boolean lockRemoved = false; LockManager lockManager = new DirectoryLockManager(repo.getDataDir()); if (lockManager.isLocked() && consoleIO .askProceed("WARNING: The lock from another process on this repository needs to be removed", true)) { repo.shutDown(); lockRemoved = lockManager.revokeLock(); repo.initialize(); } return lockRemoved; }
Example 11
Source File: RyaAccumuloSailFactoryTest.java From rya with Apache License 2.0 | 5 votes |
@Test public void testCreateFromTemplateName() throws Exception { LocalRepositoryManager repoman = new LocalRepositoryManager(Files.createTempDir()); repoman.initialize(); try(InputStream templateStream = RepositoryConfig.class.getResourceAsStream("RyaAccumuloSail.ttl")) { String template = IOUtils.toString(templateStream); final ConfigTemplate configTemplate = new ConfigTemplate(template); final Map<String, String> valueMap = ImmutableMap.<String, String> builder() .put("Repository ID", "RyaAccumuloSail") .put("Repository title", "RyaAccumuloSail Store") .put("Rya Accumulo user", "root") .put("Rya Accumulo password", "") .put("Rya Accumulo instance", "dev") .put("Rya Accumulo zookeepers", "zoo1,zoo2,zoo3") .put("Rya Accumulo is mock", "true") .build(); final String configString = configTemplate.render(valueMap); // final Repository systemRepo = this.state.getManager().getSystemRepository(); final Model model = new LinkedHashModel(); final RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE); rdfParser.setRDFHandler(new StatementCollector(model)); rdfParser.parse(new StringReader(configString), RepositoryConfigSchema.NAMESPACE); final Resource repositoryNode = Models.subject(model.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY)).get(); final RepositoryConfig repConfig = RepositoryConfig.create(model, repositoryNode); repConfig.validate(); repoman.addRepositoryConfig(repConfig); Repository r = repoman.getRepository("RyaAccumuloSail"); r.initialize(); } }
Example 12
Source File: RyaAccumuloSailFactoryTest.java From rya with Apache License 2.0 | 5 votes |
@Ignore @Test public void testCreateAccumuloSail() throws Exception { SailRepositoryFactory f = new SailRepositoryFactory(); Repository r = f.getRepository(getConfig()); r.initialize(); RepositoryConnection rc = r.getConnection(); rc.close(); }
Example 13
Source File: Federation.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void init() throws SailException { for (Repository member : members) { try { member.initialize(); } catch (RepositoryException e) { throw new SailException(e); } } }
Example 14
Source File: GenerateFullAxioms.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] args) throws Exception { MemoryStore baseSail = new MemoryStore(); DedupingInferencer deduper = new DedupingInferencer(baseSail); SchemaCachingRDFSInferencer rdfsInferencer = new SchemaCachingRDFSInferencer(deduper); SpinSail spinSail = new SpinSail(rdfsInferencer); Repository repo = new SailRepository(spinSail); repo.initialize(); try (FileWriter writer = new FileWriter("spin-full.ttl")) { try (RepositoryConnection conn = repo.getConnection()) { conn.exportStatements(null, null, null, true, Rio.createWriter(RDFFormat.TURTLE, writer)); } } repo.shutDown(); }
Example 15
Source File: RepositoryModelTest.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override @Test public void testRemoveAll() throws Exception { Repository repo = new SailRepository(new MemoryStore()); repo.initialize(); RepositoryModelSet modelSet = new RepositoryModelSet(repo); modelSet.open(); URI context1 = new URIImpl("uri:context1"); URI context2 = new URIImpl("uri:context2"); modelSet.addStatement(context1, new URIImpl("uri:r1"), new URIImpl( "uri:p1"), new URIImpl("uri:r2")); modelSet.addStatement(context1, new URIImpl("uri:r1"), new URIImpl( "uri:p1"), new URIImpl("uri:r3")); modelSet.addStatement(context2, new URIImpl("uri:r4"), new URIImpl( "uri:p2"), new URIImpl("uri:r5")); modelSet.addStatement(context2, new URIImpl("uri:r4"), new URIImpl( "uri:p2"), new URIImpl("uri:r6")); Model model1 = modelSet.getModel(context1); model1.open(); Model model2 = modelSet.getModel(context2); model2.open(); assertEquals(4, modelSet.size()); assertEquals(2, model1.size()); assertEquals(2, model2.size()); model2.removeAll(); assertEquals(2, modelSet.size()); assertEquals(2, model1.size()); assertEquals(0, model2.size()); model1.close(); model2.close(); }
Example 16
Source File: AbstractSHACLTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected Repository createRepository(Model shapesGraph) throws Exception { Repository repo = new SailRepository(newSail()); repo.initialize(); try (RepositoryConnection conn = repo.getConnection()) { conn.clear(); conn.clearNamespaces(); conn.add(shapesGraph, RDF4J.SHACL_SHAPE_GRAPH); } return repo; }
Example 17
Source File: SPARQLUpdateTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates, initializes and clears a repository. * * @return an initialized empty repository. * @throws Exception */ protected Repository createRepository() throws Exception { Repository repository = newRepository(); repository.initialize(); RepositoryConnection con = repository.getConnection(); con.clear(); con.clearNamespaces(); con.close(); return repository; }
Example 18
Source File: SPARQLUpdateConformanceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected Repository createRepository() throws Exception { Repository repo = newRepository(); repo.initialize(); Repositories.consume(repo, con -> { con.clear(); con.clearNamespaces(); }); return repo; }
Example 19
Source File: SPARQLQueryTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected final Repository createRepository() throws Exception { Repository repo = newRepository(); repo.initialize(); RepositoryConnection con = repo.getConnection(); try { con.clear(); con.clearNamespaces(); } finally { con.close(); } return repo; }
Example 20
Source File: CustomGraphQueryInferencerTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected void runTest(final CustomGraphQueryInferencer inferencer) throws RepositoryException, RDFParseException, IOException, MalformedQueryException, UpdateExecutionException { // Initialize Repository sail = new SailRepository(inferencer); sail.initialize(); RepositoryConnection connection = sail.getConnection(); try { connection.begin(); connection.clear(); connection.add(new StringReader(initial), BASE, RDFFormat.TURTLE); // Test initial inferencer state Collection<Value> watchPredicates = inferencer.getWatchPredicates(); assertThat(watchPredicates).hasSize(testData.predCount); Collection<Value> watchObjects = inferencer.getWatchObjects(); assertThat(watchObjects).hasSize(testData.objCount); Collection<Value> watchSubjects = inferencer.getWatchSubjects(); assertThat(watchSubjects).hasSize(testData.subjCount); ValueFactory factory = connection.getValueFactory(); if (resourceFolder.startsWith(PREDICATE)) { assertThat(watchPredicates.contains(factory.createIRI(BASE, "brotherOf"))).isTrue(); assertThat(watchPredicates.contains(factory.createIRI(BASE, "parentOf"))).isTrue(); } else { IRI bob = factory.createIRI(BASE, "Bob"); IRI alice = factory.createIRI(BASE, "Alice"); assertThat(watchSubjects).contains(bob, alice); assertThat(watchObjects).contains(bob, alice); } // Test initial inferencing results assertThat(Iterations.asSet(connection.getStatements(null, null, null, true))) .hasSize(testData.initialCount); // Test results after removing some statements connection.prepareUpdate(QueryLanguage.SPARQL, delete).execute(); assertThat(Iterations.asSet(connection.getStatements(null, null, null, true))) .hasSize(testData.countAfterRemove); // Tidy up. Storage gets re-used for subsequent tests, so must clear here, // in order to properly clear out any inferred statements. connection.clear(); connection.commit(); } finally { connection.close(); } sail.shutDown(); }