Java Code Examples for org.eclipse.rdf4j.repository.sail.SailRepository#init()
The following examples show how to use
org.eclipse.rdf4j.repository.sail.SailRepository#init() .
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: NoReificationTest.java From inception with Apache License 2.0 | 6 votes |
@Before public void setUp() { kb = new KnowledgeBase(); kb.setDefaultLanguage("en"); kb.setType(RepositoryType.LOCAL); kb.setFullTextSearchIri(null); kb.setMaxResults(1000); initRdfsMapping(); // Local in-memory store - this should be used for most tests because we can // a) rely on its availability // b) import custom test data LuceneSail lucenesail = new LuceneSail(); lucenesail.setParameter(LuceneSail.LUCENE_RAMDIR_KEY, "true"); lucenesail.setBaseSail(new MemoryStore()); rdf4jLocalRepo = new SailRepository(lucenesail); rdf4jLocalRepo.init(); sut = new NoReification(); }
Example 2
Source File: NotClassBenchmarkEmpty.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void noShacl() { SailRepository repository = new SailRepository(new MemoryStore()); repository.init(); try (SailRepositoryConnection connection = repository.getConnection()) { connection.begin(); connection.commit(); } try (SailRepositoryConnection connection = repository.getConnection()) { for (List<Statement> statements : allStatements) { connection.begin(); connection.add(statements); connection.commit(); } } repository.shutDown(); }
Example 3
Source File: ClassBenchmarkEmpty.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void noShacl() { SailRepository repository = new SailRepository(new MemoryStore()); repository.init(); try (SailRepositoryConnection connection = repository.getConnection()) { connection.begin(); connection.commit(); } try (SailRepositoryConnection connection = repository.getConnection()) { for (List<Statement> statements : allStatements) { connection.begin(); connection.add(statements); connection.commit(); } } repository.shutDown(); }
Example 4
Source File: UniqueLangBenchmarkEmpty.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void noShacl() { SailRepository repository = new SailRepository(new MemoryStore()); repository.init(); try (SailRepositoryConnection connection = repository.getConnection()) { for (List<Statement> statements : allStatements) { connection.begin(IsolationLevels.SNAPSHOT); connection.add(statements); connection.commit(); } } repository.shutDown(); }
Example 5
Source File: BasicBenchmarks.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void addRemoveWithoutConstraintValidations() { SpinSail spinSail = new SpinSail(new MemoryStore()); spinSail.setValidateConstraints(false); SailRepository sail = new SailRepository(spinSail); sail.init(); try (SailRepositoryConnection connection = sail.getConnection()) { connection.begin(); connection.add(bob, name, nameBob); connection.add(alice, name, nameAlice); connection.commit(); connection.remove(bob, name, nameBob); connection.remove(alice, null, null); } sail.shutDown(); }
Example 6
Source File: BasicBenchmarks.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void addRemoveSingleTransaction() { SailRepository spinSail = new SailRepository(new SpinSail(new MemoryStore())); spinSail.init(); try (SailRepositoryConnection connection = spinSail.getConnection()) { connection.begin(); connection.add(bob, name, nameBob); connection.add(alice, name, nameAlice); connection.remove(bob, name, nameBob); connection.remove(alice, null, null); connection.commit(); } spinSail.shutDown(); }
Example 7
Source File: DatatypeBenchmarkLinear.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void noShacl() { SailRepository repository = new SailRepository(new MemoryStore()); repository.init(); try (SailRepositoryConnection connection = repository.getConnection()) { connection.begin(IsolationLevels.SNAPSHOT); connection.commit(); } try (SailRepositoryConnection connection = repository.getConnection()) { for (List<Statement> statements : allStatements) { connection.begin(IsolationLevels.SNAPSHOT); connection.add(statements); connection.commit(); } } repository.shutDown(); }
Example 8
Source File: TrackAddedStatementsTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testSingleRemove() throws Exception { SailRepository shaclRepository = Utils.getInitializedShaclRepository("empty.ttl", false); ((ShaclSail) shaclRepository.getSail()).setIgnoreNoShapesLoadedException(true); shaclRepository.init(); try (SailRepositoryConnection connection = shaclRepository.getConnection()) { connection.add(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); connection.begin(); connection.remove(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); ShaclSailConnection shaclSailConnection = (ShaclSailConnection) connection.getSailConnection(); shaclSailConnection.fillAddedAndRemovedStatementRepositories(); try (ConnectionsGroup connectionsGroup = shaclSailConnection.getConnectionsGroup()) { assertEquals(0, size(connectionsGroup.getAddedStatements())); assertEquals(1, size(connectionsGroup.getRemovedStatements())); } connection.commit(); } }
Example 9
Source File: DatatypeBenchmarkSerializableEmpty.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void noShacl() { SailRepository repository = new SailRepository(new MemoryStore()); repository.init(); try (SailRepositoryConnection connection = repository.getConnection()) { connection.begin(IsolationLevels.SERIALIZABLE); connection.commit(); } try (SailRepositoryConnection connection = repository.getConnection()) { for (List<Statement> statements : allStatements) { connection.begin(IsolationLevels.SERIALIZABLE); connection.add(statements); connection.commit(); } } repository.shutDown(); }
Example 10
Source File: ModifyShapesPostInitTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test() public void checkForNoExceptionWithEmptyTransaction() { SailRepository sailRepository = new SailRepository(new ShaclSail(new MemoryStore())); sailRepository.init(); try (SailRepositoryConnection connection = sailRepository.getConnection()) { connection.begin(); connection.commit(); } }
Example 11
Source File: NativeSailStoreTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Before public void before() throws Exception { File dataDir = tempFolder.newFolder("dbmodel"); repo = new SailRepository(new NativeStore(dataDir, "spoc,posc")); repo.init(); try (RepositoryConnection conn = repo.getConnection()) { conn.add(S0); conn.add(S1, CTX_1); conn.add(S2, CTX_2); } }
Example 12
Source File: DeadlockTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void test() throws IOException { for (int i = 0; i < 10; i++) { String shaclPath = "complexBenchmark/"; File dataDir = Files.newTemporaryFolder(); dataDir.deleteOnExit(); ShaclSail shaclSail = new ShaclSail(new NativeStore(dataDir)); SailRepository shaclRepository = new SailRepository(shaclSail); shaclRepository.init(); shaclSail.setParallelValidation(true); Utils.loadShapeData(shaclRepository, shaclPath + "shacl.ttl"); try (SailRepositoryConnection connection = shaclRepository.getConnection()) { connection.begin(IsolationLevels.SNAPSHOT); connection .prepareUpdate(IOUtil.readString( DeadlockTest.class.getClassLoader().getResourceAsStream(shaclPath + "transaction1.qr"))) .execute(); connection.commit(); connection.begin(IsolationLevels.SNAPSHOT); connection .prepareUpdate(IOUtil.readString( DeadlockTest.class.getClassLoader().getResourceAsStream(shaclPath + "transaction2.qr"))) .execute(); connection.commit(); } } }
Example 13
Source File: DatatypeBenchmarkSerializableEmpty.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Benchmark public void sparqlInsteadOfShacl() { SailRepository repository = new SailRepository(new MemoryStore()); repository.init(); try (SailRepositoryConnection connection = repository.getConnection()) { connection.begin(IsolationLevels.SERIALIZABLE); connection.commit(); } try (SailRepositoryConnection connection = repository.getConnection()) { for (List<Statement> statements : allStatements) { connection.begin(IsolationLevels.SERIALIZABLE); connection.add(statements); try (Stream<BindingSet> stream = connection .prepareTupleQuery("select * where {?a a <" + RDFS.RESOURCE + ">; <" + FOAF.AGE + "> ?age. FILTER(datatype(?age) != <http://www.w3.org/2001/XMLSchema#int>)}") .evaluate() .stream()) { stream.forEach(System.out::println); } connection.commit(); } } repository.shutDown(); }
Example 14
Source File: TrackAddedStatementsTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testAddRemove() throws Exception { SailRepository shaclRepository = Utils.getInitializedShaclRepository("empty.ttl", false); ((ShaclSail) shaclRepository.getSail()).setIgnoreNoShapesLoadedException(true); shaclRepository.init(); try (SailRepositoryConnection connection = shaclRepository.getConnection()) { connection.begin(); // System.out.println(size(connection)); connection.add(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); // System.out.println(size(connection)); connection.remove(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); // System.out.println(size(connection)); ShaclSailConnection shaclSailConnection = (ShaclSailConnection) connection.getSailConnection(); shaclSailConnection.fillAddedAndRemovedStatementRepositories(); try (ConnectionsGroup connectionsGroup = shaclSailConnection.getConnectionsGroup()) { assertEquals(0, size(connectionsGroup.getAddedStatements())); assertEquals(0, size(connectionsGroup.getRemovedStatements())); } connection.commit(); System.out.println(size(connection)); } }
Example 15
Source File: TrackAddedStatementsTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testTransactions() throws Exception { SailRepository shaclRepository = Utils.getInitializedShaclRepository("empty.ttl", false); ((ShaclSail) shaclRepository.getSail()).setIgnoreNoShapesLoadedException(true); shaclRepository.init(); try (SailRepositoryConnection connection = shaclRepository.getConnection()) { connection.begin(); connection.add(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); ShaclSailConnection shaclSailConnection = (ShaclSailConnection) connection.getSailConnection(); shaclSailConnection.fillAddedAndRemovedStatementRepositories(); assertNotNull(shaclSailConnection.addedStatements); assertNotNull(shaclSailConnection.removedStatements); connection.commit(); } }
Example 16
Source File: TrackAddedStatementsTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testCleanupOnClose() throws Exception { SailRepository shaclRepository = Utils.getInitializedShaclRepository("shacl.ttl", false); ((ShaclSail) shaclRepository.getSail()).setIgnoreNoShapesLoadedException(true); shaclRepository.init(); SailRepositoryConnection connection = shaclRepository.getConnection(); connection.begin(); connection.add(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); connection.close(); ShaclSailConnection shaclSailConnection = (ShaclSailConnection) connection.getSailConnection(); assertNull(shaclSailConnection.addedStatements); assertNull(shaclSailConnection.removedStatements); assertEquals(0, size(shaclRepository)); }
Example 17
Source File: ModifyShapesPostInitTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test(expected = ShaclSailValidationException.class) public void testUpdatingShapesViolation() throws Throwable { ShaclSail shaclSail = new ShaclSail(new MemoryStore()); SailRepository sailRepository = new SailRepository(shaclSail); sailRepository.init(); try (SailRepositoryConnection connection = sailRepository.getConnection()) { connection.begin(); StringReader shaclRules = new StringReader(String.join("\n", "", "@prefix ex: <http://example.com/ns#> .", "@prefix sh: <http://www.w3.org/ns/shacl#> .", "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .", "@prefix foaf: <http://xmlns.com/foaf/0.1/>.", "ex:PersonShape", " a sh:NodeShape ;", " sh:targetClass ex:Person ;", " sh:property [", " sh:path ex:age ;", " sh:datatype xsd:integer ;", " ] .")); connection.add(shaclRules, "", RDFFormat.TURTLE, RDF4J.SHACL_SHAPE_GRAPH); connection.commit(); add(connection, "ex:pete a ex:Person ."); StringReader extraShaclRules = new StringReader(String.join("\n", "", "@prefix ex: <http://example.com/ns#> .", "@prefix sh: <http://www.w3.org/ns/shacl#> .", "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .", "@prefix foaf: <http://xmlns.com/foaf/0.1/>.", "ex:PersonShape", " a sh:NodeShape ;", " sh:targetClass ex:Person ;", " sh:property [", " sh:path ex:age ;", " sh:minCount 1 ;", " ] .")); try { connection.add(extraShaclRules, "", RDFFormat.TURTLE, RDF4J.SHACL_SHAPE_GRAPH); } catch (RepositoryException e) { throw e.getCause(); } } }
Example 18
Source File: ModifyShapesPostInitTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testAddingShapesThatFails() throws Throwable { ShaclSail shaclSail = new ShaclSail(new MemoryStore()); SailRepository sailRepository = new SailRepository(shaclSail); sailRepository.init(); SailRepositoryConnection connection1 = sailRepository.getConnection(); SailRepositoryConnection connection2 = sailRepository.getConnection(); add(connection1, "ex:pete a ex:Person ."); connection2.begin(); StringReader shaclRules = new StringReader(String.join("\n", "", "@prefix ex: <http://example.com/ns#> .", "@prefix sh: <http://www.w3.org/ns/shacl#> .", "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .", "@prefix foaf: <http://xmlns.com/foaf/0.1/>.", "ex:PersonShape", " a sh:NodeShape ;", " sh:targetClass ex:Person ;", " sh:property [", " sh:path ex:age ;", " sh:minCount 1 ;", " ] .")); connection2.add(shaclRules, "", RDFFormat.TURTLE, RDF4J.SHACL_SHAPE_GRAPH); try { connection2.commit(); } catch (Throwable ignored) { } connection2.rollback(); add(connection1, "ex:steve a ex:Person ."); connection2.close(); connection1.close(); sailRepository.shutDown(); }
Example 19
Source File: TempTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 3 votes |
@Test(expected = RepositoryException.class) public void maxCount() throws Exception { SailRepository shaclRepository = Utils.getInitializedShaclRepository("shaclMax.ttl", false); shaclRepository.init(); try (SailRepositoryConnection connection = shaclRepository.getConnection()) { connection.begin(); // connection.add(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); connection.add(RDFS.CLASS, RDFS.LABEL, connection.getValueFactory().createLiteral("class1")); connection.add(RDFS.CLASS, RDFS.LABEL, connection.getValueFactory().createLiteral("class2")); connection.add(RDFS.CLASS, RDFS.LABEL, connection.getValueFactory().createLiteral("class3")); connection.commit(); System.out.println("\n\n\n\n\n\n\n\n\n\n"); connection.begin(); connection.add(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); connection.add(RDFS.RESOURCE, RDFS.LABEL, connection.getValueFactory().createLiteral("a")); connection.add(RDFS.RESOURCE, RDFS.LABEL, connection.getValueFactory().createLiteral("b")); connection.add(RDFS.RESOURCE, RDFS.LABEL, connection.getValueFactory().createLiteral("c")); connection.add(RDFS.RESOURCE, RDFS.LABEL, connection.getValueFactory().createLiteral("d")); connection.add(RDFS.CLASS, RDF.TYPE, RDFS.RESOURCE); connection.commit(); } }
Example 20
Source File: TrackAddedStatementsTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 3 votes |
@Test public void testTrandactionRollbackCleanup() throws Exception { SailRepository shaclRepository = Utils.getInitializedShaclRepository("shacl.ttl", false); ((ShaclSail) shaclRepository.getSail()).setIgnoreNoShapesLoadedException(true); shaclRepository.init(); try (SailRepositoryConnection connection = shaclRepository.getConnection()) { connection.begin(); connection.add(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); try { connection.commit(); } catch (Throwable e) { System.out.println(e.getMessage()); } connection.rollback(); ShaclSailConnection shaclSailConnection = (ShaclSailConnection) connection.getSailConnection(); assertNull(shaclSailConnection.addedStatements); assertNull(shaclSailConnection.removedStatements); } }