Java Code Examples for org.eclipse.rdf4j.sail.memory.MemoryStore#getConnection()
The following examples show how to use
org.eclipse.rdf4j.sail.memory.MemoryStore#getConnection() .
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: MemoryBenchmark.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public long size() { MemoryStore memoryStore = new MemoryStore(); memoryStore.initialize(); try (NotifyingSailConnection connection = memoryStore.getConnection()) { connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); connection.commit(); return connection.size(); } }
Example 2
Source File: MemoryBenchmark.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public long singleTransactionGetFirstStatement() { MemoryStore memoryStore = new MemoryStore(); memoryStore.initialize(); try (NotifyingSailConnection connection = memoryStore.getConnection()) { connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); long count = 0; for (int i = 0; i < 10; i++) { try (CloseableIteration<? extends Statement, SailException> statements = connection.getStatements(null, null, null, false)) { count += statements.next().toString().length(); } } connection.commit(); return count; } }
Example 3
Source File: OrderingTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testSelect() { MemoryStore repository = new MemoryStore(); repository.init(); try (SailConnection connection = repository.getConnection()) { connection.begin(IsolationLevels.NONE); connection.addStatement(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); connection.addStatement(RDFS.CLASS, RDF.TYPE, RDFS.RESOURCE); connection.addStatement(RDFS.SUBCLASSOF, RDF.TYPE, RDFS.RESOURCE); connection.commit(); Select select = new Select(connection, "?a <" + RDF.TYPE + "> []", "*"); List<Tuple> tuples = new MockConsumePlanNode(select).asList(); String actual = Arrays.toString(tuples.toArray()); Collections.sort(tuples); String expected = Arrays.toString(tuples.toArray()); assertEquals(expected, actual); } }
Example 4
Source File: MemoryBenchmark.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Benchmark public void load() { MemoryStore memoryStore = new MemoryStore(); memoryStore.initialize(); try (NotifyingSailConnection connection = memoryStore.getConnection()) { connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); connection.commit(); } }
Example 5
Source File: MemoryBenchmark.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Benchmark public long duplicatesAndNewStatementsGetFirst() { MemoryStore memoryStore = new MemoryStore(); memoryStore.initialize(); try (NotifyingSailConnection connection = memoryStore.getConnection()) { connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); connection.commit(); connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); ValueFactory vf = memoryStore.getValueFactory(); connection.addStatement(vf.createBNode(), RDFS.LABEL, vf.createLiteral("label")); long counter = 0; for (int i = 0; i < 10; i++) { try (CloseableIteration<? extends Statement, SailException> statements = connection.getStatements(null, null, null, false)) { counter += statements.next().toString().length(); } } connection.commit(); return counter; } }
Example 6
Source File: MemoryBenchmark.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Benchmark public long duplicatesAndNewStatementsIteratorMatchesNothing() { MemoryStore memoryStore = new MemoryStore(); memoryStore.initialize(); try (NotifyingSailConnection connection = memoryStore.getConnection()) { connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); connection.commit(); connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); ValueFactory vf = memoryStore.getValueFactory(); connection.addStatement(vf.createBNode(), RDFS.LABEL, vf.createLiteral("label")); long count = 0; for (int i = 0; i < 10; i++) { try (Stream<? extends Statement> stream = connection.getStatements(vf.createBNode(), null, null, false) .stream()) { count += stream.count(); } } connection.commit(); return count; } }
Example 7
Source File: SailModelNamespacesTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected Model getModelImplementation() { sail = new MemoryStore(); try { sail.initialize(); conn = sail.getConnection(); conn.begin(); return new SailModel(conn, false); } catch (SailException e) { throw new ModelException(e); } }
Example 8
Source File: BulkedExternalInnerJoinTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void gapInResultsFromQueryTest() { SimpleValueFactory vf = SimpleValueFactory.getInstance(); IRI a = vf.createIRI("http://a"); IRI b = vf.createIRI("http://b"); IRI c = vf.createIRI("http://c"); IRI d = vf.createIRI("http://d"); PlanNode left = new MockInputPlanNode( Arrays.asList(new Tuple(Collections.singletonList(a)), new Tuple(Collections.singletonList(b)), new Tuple(Collections.singletonList(c)), new Tuple(Collections.singletonList(d)))); MemoryStore sailRepository = new MemoryStore(); sailRepository.init(); try (SailConnection connection = sailRepository.getConnection()) { connection.begin(); connection.addStatement(b, DCAT.ACCESS_URL, RDFS.RESOURCE); connection.addStatement(d, DCAT.ACCESS_URL, RDFS.SUBPROPERTYOF); connection.commit(); } try (SailConnection connection = sailRepository.getConnection()) { BulkedExternalInnerJoin bulkedExternalInnerJoin = new BulkedExternalInnerJoin(left, connection, "?a <http://www.w3.org/ns/dcat#accessURL> ?c. ", false, null, "?a", "?c"); List<Tuple> tuples = new MockConsumePlanNode(bulkedExternalInnerJoin).asList(); tuples.forEach(System.out::println); assertEquals("[http://b, http://www.w3.org/2000/01/rdf-schema#Resource]", Arrays.toString(tuples.get(0).line.toArray())); assertEquals("[http://d, http://www.w3.org/2000/01/rdf-schema#subPropertyOf]", Arrays.toString(tuples.get(1).line.toArray())); } }
Example 9
Source File: OrderingTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testSortPlanNode() { MemoryStore sailRepository = new MemoryStore(); sailRepository.init(); try (SailConnection connection = sailRepository.getConnection()) { connection.begin(); connection.addStatement(vf.createBNode("1"), RDF.TYPE, RDFS.RESOURCE); connection.addStatement(vf.createBNode("2"), RDF.TYPE, RDFS.RESOURCE); connection.addStatement(vf.createBNode("4"), RDF.TYPE, RDFS.RESOURCE); connection.addStatement(vf.createBNode("3"), RDF.TYPE, RDFS.RESOURCE); connection.addStatement(vf.createBNode("2"), RDF.TYPE, RDFS.RESOURCE); connection.addStatement(vf.createBNode("2"), RDF.TYPE, RDFS.RESOURCE); connection.addStatement(vf.createBNode("100"), RDF.TYPE, RDFS.RESOURCE); connection.addStatement(vf.createBNode("99"), RDF.TYPE, RDFS.RESOURCE); connection.addStatement(vf.createBNode("101"), RDF.TYPE, RDFS.RESOURCE); connection.addStatement(vf.createBNode("98"), RDF.TYPE, RDFS.RESOURCE); connection.addStatement(vf.createBNode("102"), RDF.TYPE, RDFS.RESOURCE); connection.commit(); } try (SailConnection connection = sailRepository.getConnection()) { Select select = new Select(connection, "?a a rdfs:Resource", "?a"); List<Tuple> sortedBySelect = new MockConsumePlanNode(select).asList(); Sort sort = new Sort(new Select(connection, "?a a rdfs:Resource", "?a")); List<Tuple> sortedBySort = new MockConsumePlanNode(sort).asList(); Assert.assertEquals(sortedBySelect, sortedBySort); } }
Example 10
Source File: OrderingTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testTargetNode() { MemoryStore memoryStore = new MemoryStore(); IRI target1 = vf.createIRI("http://example.com/target1"); IRI target2 = vf.createIRI("http://example.com/target2"); IRI target3 = vf.createIRI("http://example.com/target3"); IRI target4 = vf.createIRI("http://example.com/target4"); IRI target5 = vf.createIRI("http://example.com/target5"); try (SailConnection connection = memoryStore.getConnection()) { connection.begin(IsolationLevels.NONE); connection.addStatement(target1, FOAF.KNOWS, target1); connection.addStatement(target2, FOAF.KNOWS, target2); connection.addStatement(target3, FOAF.KNOWS, target3); connection.addStatement(target4, FOAF.KNOWS, target4); connection.addStatement(target5, FOAF.KNOWS, target5); connection.commit(); ShaclProperties shaclProperties = new ShaclProperties(); Set<Value> targetNode = shaclProperties.getTargetNode(); targetNode.add(target1); targetNode.add(target5); targetNode.add(target2); targetNode.add(target4); targetNode.add(target3); Select select = new Select(connection, "?a ?b ?c", "?a", "?c"); ValuesBackedNode valuesBackedNode = new ValuesBackedNode(shaclProperties.getTargetNode()); PlanNode innerJoin = new InnerJoin(valuesBackedNode, select).getJoined(UnBufferedPlanNode.class); List<Tuple> tuples = new MockConsumePlanNode(innerJoin).asList(); verify(tuples, Arrays.asList(target1.toString(), target1.toString()), Arrays.asList(target2.toString(), target2.toString()), Arrays.asList(target3.toString(), target3.toString()), Arrays.asList(target4.toString(), target4.toString()), Arrays.asList(target5.toString(), target5.toString())); } }
Example 11
Source File: MemoryBenchmark.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 3 votes |
@Benchmark public long duplicates() { MemoryStore memoryStore = new MemoryStore(); memoryStore.initialize(); try (NotifyingSailConnection connection = memoryStore.getConnection()) { connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); connection.commit(); connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); long count = 0; for (int i = 0; i < 10; i++) { count += getCount(connection); } connection.commit(); return count; } }
Example 12
Source File: MemoryBenchmark.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 3 votes |
@Benchmark public long duplicatesFlush() { MemoryStore memoryStore = new MemoryStore(); memoryStore.initialize(); try (NotifyingSailConnection connection = memoryStore.getConnection()) { connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); connection.commit(); connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); connection.flush(); long count = 0; for (int i = 0; i < 10; i++) { count += getCount(connection); } connection.commit(); return count; } }
Example 13
Source File: MemoryBenchmark.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 3 votes |
@Benchmark public long duplicatesAndNewStatements() { MemoryStore memoryStore = new MemoryStore(); memoryStore.initialize(); try (NotifyingSailConnection connection = memoryStore.getConnection()) { connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); connection.commit(); connection.begin(IsolationLevels.valueOf(isolationLevel)); statementList.forEach( st -> connection.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())); ValueFactory vf = memoryStore.getValueFactory(); connection.addStatement(vf.createBNode(), RDFS.LABEL, vf.createLiteral("label")); long count = 0; for (int i = 0; i < 10; i++) { count += getCount(connection); } connection.commit(); return count; } }