From 6ff774756728632064ed34789a282a2d6098a54d Mon Sep 17 00:00:00 2001 From: Martin Ledvinka Date: Mon, 2 Sep 2024 15:40:49 +0200 Subject: [PATCH 1/2] Remove setting query target ontology from query, use only query hints. Also switch to using transactional snapshot for query processing in Jena and OWLAPI to provide more consistent transactional behavior. --- .../cvut/kbss/jopa/model/AbstractQuery.java | 1 - .../jopa/test/query/runner/QueryRunner.java | 22 +++++++++++++--- .../ontodriver/jena/query/JenaStatement.java | 2 +- .../jena/query/JenaPreparedStatementTest.java | 24 ++++++++---------- .../jena/query/JenaStatementTest.java | 25 ++++++++++++------- .../owlapi/query/OwlapiStatement.java | 2 +- 6 files changed, 48 insertions(+), 28 deletions(-) diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/model/AbstractQuery.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/model/AbstractQuery.java index b1ccfb630..8af8ddc5d 100644 --- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/model/AbstractQuery.java +++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/model/AbstractQuery.java @@ -126,7 +126,6 @@ public void executeUpdate() { private Statement initQueryStatement() { final Statement stmt = connection.createStatement(); - stmt.useOntology(Statement.StatementOntology.TRANSACTIONAL); applyQueryHints(stmt); logQuery(); return stmt; diff --git a/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/query/runner/QueryRunner.java b/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/query/runner/QueryRunner.java index 806668e78..b1316bbae 100644 --- a/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/query/runner/QueryRunner.java +++ b/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/query/runner/QueryRunner.java @@ -23,7 +23,12 @@ import cz.cvut.kbss.jopa.model.annotations.OWLClass; import cz.cvut.kbss.jopa.model.query.Query; import cz.cvut.kbss.jopa.query.QueryHints; -import cz.cvut.kbss.jopa.test.*; +import cz.cvut.kbss.jopa.test.OWLClassA; +import cz.cvut.kbss.jopa.test.OWLClassB; +import cz.cvut.kbss.jopa.test.OWLClassD; +import cz.cvut.kbss.jopa.test.OWLClassE; +import cz.cvut.kbss.jopa.test.OWLClassT; +import cz.cvut.kbss.jopa.test.Vocabulary; import cz.cvut.kbss.jopa.test.environment.DataAccessor; import cz.cvut.kbss.jopa.test.environment.Generators; import cz.cvut.kbss.jopa.test.environment.Quad; @@ -36,13 +41,24 @@ import org.slf4j.Logger; import java.net.URI; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasItem; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public abstract class QueryRunner extends BaseQueryRunner { diff --git a/ontodriver-jena/src/main/java/cz/cvut/kbss/ontodriver/jena/query/JenaStatement.java b/ontodriver-jena/src/main/java/cz/cvut/kbss/ontodriver/jena/query/JenaStatement.java index d10d3d9eb..7018e3362 100644 --- a/ontodriver-jena/src/main/java/cz/cvut/kbss/ontodriver/jena/query/JenaStatement.java +++ b/ontodriver-jena/src/main/java/cz/cvut/kbss/ontodriver/jena/query/JenaStatement.java @@ -31,7 +31,7 @@ public class JenaStatement implements Statement { private final StatementExecutor executor; - private StatementOntology targetOntology = StatementOntology.SHARED; + private StatementOntology targetOntology = StatementOntology.TRANSACTIONAL; private boolean open = true; private AbstractResultSet currentResultSet; diff --git a/ontodriver-jena/src/test/java/cz/cvut/kbss/ontodriver/jena/query/JenaPreparedStatementTest.java b/ontodriver-jena/src/test/java/cz/cvut/kbss/ontodriver/jena/query/JenaPreparedStatementTest.java index bb07040de..31c17f73f 100644 --- a/ontodriver-jena/src/test/java/cz/cvut/kbss/ontodriver/jena/query/JenaPreparedStatementTest.java +++ b/ontodriver-jena/src/test/java/cz/cvut/kbss/ontodriver/jena/query/JenaPreparedStatementTest.java @@ -23,21 +23,24 @@ import cz.cvut.kbss.ontodriver.util.StatementHolder; import cz.cvut.kbss.ontodriver.util.Vocabulary; import org.apache.jena.query.QueryFactory; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import java.lang.reflect.Field; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +@ExtendWith(MockitoExtension.class) public class JenaPreparedStatementTest { private static final String QUERY = "SELECT * WHERE { ?x ?y ?z . }"; @@ -50,13 +53,6 @@ public class JenaPreparedStatementTest { private JenaPreparedStatement statement; - @BeforeEach - public void setUp() throws Exception { - MockitoAnnotations.openMocks(this); - when(executor.executeSelectQuery(any(), any())).thenReturn(resultSet); - when(executor.executeAskQuery(any(), any())).thenReturn(resultSet); - } - @Test public void constructorAnalyzesQueryPassedAsParameter() throws Exception { this.statement = new JenaPreparedStatement(executor, QUERY); @@ -99,13 +95,14 @@ public void setParameterThrowsIllegalStateOnClosedStatement() throws Exception { @Test public void executeQueryExecutesStatementWithParameter() throws Exception { + when(executor.executeSelectQuery(any(), any())).thenReturn(resultSet); this.statement = new JenaPreparedStatement(executor, QUERY); final String value = "<" + Vocabulary.RDF_TYPE + ">"; statement.setObject("y", value); final String expected = QUERY.replace("?y", value); statement.executeQuery(); verify(executor) - .executeSelectQuery(eq(QueryFactory.create(expected)), eq(Statement.StatementOntology.SHARED)); + .executeSelectQuery(eq(QueryFactory.create(expected)), eq(Statement.StatementOntology.TRANSACTIONAL)); } @Test @@ -124,7 +121,7 @@ public void executeUpdateExecutesUpdateStatement() throws Exception { statement.setObject("type", value); final String expected = update.replace("?type", value); statement.executeUpdate(); - verify(executor).executeUpdate(eq(expected), eq(Statement.StatementOntology.SHARED)); + verify(executor).executeUpdate(eq(expected), eq(Statement.StatementOntology.TRANSACTIONAL)); } @Test @@ -138,13 +135,14 @@ public void executeUpdateThrowsIllegalStateForClosedStatement() throws Exception @Test public void clearParametersClearsAlreadySetParameters() throws Exception { + when(executor.executeSelectQuery(any(), any())).thenReturn(resultSet); this.statement = new JenaPreparedStatement(executor, QUERY); final String value = "<" + Vocabulary.RDF_TYPE + ">"; statement.setObject("y", value); statement.clearParameters(); statement.executeQuery(); verify(executor) - .executeSelectQuery(eq(QueryFactory.create(QUERY)), eq(Statement.StatementOntology.SHARED)); + .executeSelectQuery(eq(QueryFactory.create(QUERY)), eq(Statement.StatementOntology.TRANSACTIONAL)); } @Test diff --git a/ontodriver-jena/src/test/java/cz/cvut/kbss/ontodriver/jena/query/JenaStatementTest.java b/ontodriver-jena/src/test/java/cz/cvut/kbss/ontodriver/jena/query/JenaStatementTest.java index 2e2ec9092..1959b4fc4 100644 --- a/ontodriver-jena/src/test/java/cz/cvut/kbss/ontodriver/jena/query/JenaStatementTest.java +++ b/ontodriver-jena/src/test/java/cz/cvut/kbss/ontodriver/jena/query/JenaStatementTest.java @@ -29,8 +29,15 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class JenaStatementTest { @@ -51,7 +58,7 @@ public void executeQueryExecutesSelect() throws JenaDriverException { when(executor.executeSelectQuery(any(), any())).thenReturn(rsMock); final String query = "SELECT * WHERE { ?x ?y ?z .}"; final ResultSet rs = statement.executeQuery(query); - verify(executor).executeSelectQuery(any(Query.class), eq(Statement.StatementOntology.SHARED)); + verify(executor).executeSelectQuery(any(Query.class), eq(Statement.StatementOntology.TRANSACTIONAL)); assertSame(rsMock, rs); } @@ -61,7 +68,7 @@ public void executeQueryExecutesAsk() throws JenaDriverException { when(executor.executeAskQuery(any(), any())).thenReturn(rsMock); final String query = "ASK { ?x a . }"; final ResultSet rs = statement.executeQuery(query); - verify(executor).executeAskQuery(any(Query.class), eq(Statement.StatementOntology.SHARED)); + verify(executor).executeAskQuery(any(Query.class), eq(Statement.StatementOntology.TRANSACTIONAL)); assertSame(rsMock, rs); } @@ -72,7 +79,7 @@ public void executeQueryExecutesAskWhenPrefixesAreDeclared() throws JenaDriverEx final String query = "PREFIX foaf: \n" + "ASK { ?x a foaf:Person . }"; statement.executeQuery(query); - verify(executor).executeAskQuery(any(Query.class), eq(Statement.StatementOntology.SHARED)); + verify(executor).executeAskQuery(any(Query.class), eq(Statement.StatementOntology.TRANSACTIONAL)); } @Test @@ -112,7 +119,7 @@ public void executeQueryClosesCurrentResultSet() throws JenaDriverException { public void executeUpdateExecutesUpdateQuery() throws JenaDriverException { final String query = "INSERT DATA { _:b1 a . }"; statement.executeUpdate(query); - verify(executor).executeUpdate(query, Statement.StatementOntology.SHARED); + verify(executor).executeUpdate(query, Statement.StatementOntology.TRANSACTIONAL); } @Test @@ -149,10 +156,10 @@ public void settingTargetOntologyIsReflectedInQueryExecutionParameter() throws E final SelectResultSet rsMock = mock(SelectResultSet.class); when(executor.executeSelectQuery(any(), any())).thenReturn(rsMock); final String query = "SELECT * WHERE { ?x ?y ?z .}"; - statement.useOntology(Statement.StatementOntology.TRANSACTIONAL); - assertEquals(Statement.StatementOntology.TRANSACTIONAL, statement.getStatementOntology()); + statement.useOntology(Statement.StatementOntology.SHARED); + assertEquals(Statement.StatementOntology.SHARED, statement.getStatementOntology()); final ResultSet rs = statement.executeQuery(query); - verify(executor).executeSelectQuery(any(Query.class), eq(Statement.StatementOntology.TRANSACTIONAL)); + verify(executor).executeSelectQuery(any(Query.class), eq(Statement.StatementOntology.SHARED)); assertSame(rsMock, rs); } } diff --git a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/query/OwlapiStatement.java b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/query/OwlapiStatement.java index 9540f6c80..392591a77 100644 --- a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/query/OwlapiStatement.java +++ b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/query/OwlapiStatement.java @@ -26,7 +26,7 @@ public class OwlapiStatement implements Statement { - private StatementOntology targetOntology; + private StatementOntology targetOntology = StatementOntology.TRANSACTIONAL; private boolean open; private boolean disableInference; From 88909b4a49bfd98f318a867313dd10557f514527 Mon Sep 17 00:00:00 2001 From: Martin Ledvinka Date: Tue, 3 Sep 2024 13:17:09 +0200 Subject: [PATCH 2/2] [2.0.5] Bump version, update changelog. Signed-off-by: Martin Ledvinka --- CHANGELOG.md | 3 +++ datatype/pom.xml | 2 +- jopa-api/pom.xml | 2 +- jopa-distribution/pom.xml | 2 +- jopa-impl/pom.xml | 2 +- jopa-integration-tests-jena/pom.xml | 2 +- jopa-integration-tests-owlapi/pom.xml | 2 +- jopa-integration-tests-rdf4j/pom.xml | 2 +- jopa-integration-tests/pom.xml | 2 +- jopa-maven-plugin/pom.xml | 2 +- jopa-owl2java/pom.xml | 2 +- jopa-owlapi-utils/pom.xml | 2 +- modelgen/pom.xml | 2 +- ontodriver-api/pom.xml | 2 +- ontodriver-jena/pom.xml | 2 +- ontodriver-owlapi/pom.xml | 2 +- ontodriver-rdf4j/pom.xml | 2 +- pom.xml | 2 +- 18 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2909aa4db..d0ec91f4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # JOPA - Change Log +## 2.0.5 - 2024-09-03 +- Modify target ontology selection in queries (use only query hints) to prevent RDF4J driver from spanning application log. + ## 2.0.4 - 2024-08-15 - Fix an issue with cloning instances of `AbstractImmutableMap` (produced by `Map.of`) (Bug #264). - Ensure changes done by `@PreUpdate` callback inherited by entity are propagated to repository (Bug #265). diff --git a/datatype/pom.xml b/datatype/pom.xml index 9fc448e64..43dfd7c43 100644 --- a/datatype/pom.xml +++ b/datatype/pom.xml @@ -6,7 +6,7 @@ jopa-all cz.cvut.kbss.jopa - 2.0.4 + 2.0.5 ../pom.xml diff --git a/jopa-api/pom.xml b/jopa-api/pom.xml index cc705668a..c90e5d5e7 100644 --- a/jopa-api/pom.xml +++ b/jopa-api/pom.xml @@ -6,7 +6,7 @@ cz.cvut.kbss.jopa jopa-all - 2.0.4 + 2.0.5 ../pom.xml diff --git a/jopa-distribution/pom.xml b/jopa-distribution/pom.xml index c92af3f20..75560d07e 100644 --- a/jopa-distribution/pom.xml +++ b/jopa-distribution/pom.xml @@ -6,7 +6,7 @@ cz.cvut.kbss.jopa jopa-all - 2.0.4 + 2.0.5 ../pom.xml diff --git a/jopa-impl/pom.xml b/jopa-impl/pom.xml index 8072ecba5..04cb1ad90 100644 --- a/jopa-impl/pom.xml +++ b/jopa-impl/pom.xml @@ -6,7 +6,7 @@ cz.cvut.kbss.jopa jopa-all - 2.0.4 + 2.0.5 ../pom.xml diff --git a/jopa-integration-tests-jena/pom.xml b/jopa-integration-tests-jena/pom.xml index b9d0fb233..a35985505 100644 --- a/jopa-integration-tests-jena/pom.xml +++ b/jopa-integration-tests-jena/pom.xml @@ -5,7 +5,7 @@ cz.cvut.kbss.jopa jopa-all - 2.0.4 + 2.0.5 ../pom.xml 4.0.0 diff --git a/jopa-integration-tests-owlapi/pom.xml b/jopa-integration-tests-owlapi/pom.xml index 42f637215..2ac8ff218 100644 --- a/jopa-integration-tests-owlapi/pom.xml +++ b/jopa-integration-tests-owlapi/pom.xml @@ -5,7 +5,7 @@ cz.cvut.kbss.jopa jopa-all - 2.0.4 + 2.0.5 ../pom.xml 4.0.0 diff --git a/jopa-integration-tests-rdf4j/pom.xml b/jopa-integration-tests-rdf4j/pom.xml index 6ba745617..96bcf0d75 100644 --- a/jopa-integration-tests-rdf4j/pom.xml +++ b/jopa-integration-tests-rdf4j/pom.xml @@ -6,7 +6,7 @@ cz.cvut.kbss.jopa jopa-all - 2.0.4 + 2.0.5 ../pom.xml jopa-integration-tests-rdf4j diff --git a/jopa-integration-tests/pom.xml b/jopa-integration-tests/pom.xml index 5a94de709..7e3498f3c 100644 --- a/jopa-integration-tests/pom.xml +++ b/jopa-integration-tests/pom.xml @@ -6,7 +6,7 @@ cz.cvut.kbss.jopa jopa-all - 2.0.4 + 2.0.5 ../pom.xml 4.0.0 diff --git a/jopa-maven-plugin/pom.xml b/jopa-maven-plugin/pom.xml index 6c0cad3c9..efb50d5e2 100644 --- a/jopa-maven-plugin/pom.xml +++ b/jopa-maven-plugin/pom.xml @@ -5,7 +5,7 @@ jopa-all cz.cvut.kbss.jopa - 2.0.4 + 2.0.5 ../pom.xml 4.0.0 diff --git a/jopa-owl2java/pom.xml b/jopa-owl2java/pom.xml index 0230b27d6..2e1d5b256 100644 --- a/jopa-owl2java/pom.xml +++ b/jopa-owl2java/pom.xml @@ -6,7 +6,7 @@ cz.cvut.kbss.jopa jopa-all - 2.0.4 + 2.0.5 ../pom.xml diff --git a/jopa-owlapi-utils/pom.xml b/jopa-owlapi-utils/pom.xml index d3d7bf422..5768051c5 100644 --- a/jopa-owlapi-utils/pom.xml +++ b/jopa-owlapi-utils/pom.xml @@ -6,7 +6,7 @@ cz.cvut.kbss.jopa jopa-all - 2.0.4 + 2.0.5 ../pom.xml diff --git a/modelgen/pom.xml b/modelgen/pom.xml index 60fd3981d..62492f9b5 100644 --- a/modelgen/pom.xml +++ b/modelgen/pom.xml @@ -6,7 +6,7 @@ jopa-all cz.cvut.kbss.jopa - 2.0.4 + 2.0.5 ../pom.xml diff --git a/ontodriver-api/pom.xml b/ontodriver-api/pom.xml index 21422b852..8ed15b392 100644 --- a/ontodriver-api/pom.xml +++ b/ontodriver-api/pom.xml @@ -6,7 +6,7 @@ jopa-all cz.cvut.kbss.jopa - 2.0.4 + 2.0.5 ../pom.xml diff --git a/ontodriver-jena/pom.xml b/ontodriver-jena/pom.xml index bdf481580..2f7a8e39f 100644 --- a/ontodriver-jena/pom.xml +++ b/ontodriver-jena/pom.xml @@ -8,7 +8,7 @@ cz.cvut.kbss.jopa jopa-all - 2.0.4 + 2.0.5 ../pom.xml diff --git a/ontodriver-owlapi/pom.xml b/ontodriver-owlapi/pom.xml index 5c04b547d..a2c46f4f0 100644 --- a/ontodriver-owlapi/pom.xml +++ b/ontodriver-owlapi/pom.xml @@ -11,7 +11,7 @@ cz.cvut.kbss.jopa jopa-all - 2.0.4 + 2.0.5 ../pom.xml diff --git a/ontodriver-rdf4j/pom.xml b/ontodriver-rdf4j/pom.xml index 19a1ed314..d68dabfb2 100644 --- a/ontodriver-rdf4j/pom.xml +++ b/ontodriver-rdf4j/pom.xml @@ -10,7 +10,7 @@ jopa-all cz.cvut.kbss.jopa - 2.0.4 + 2.0.5 diff --git a/pom.xml b/pom.xml index cb5abb279..b7395ba59 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 cz.cvut.kbss.jopa - 2.0.4 + 2.0.5 jopa-all pom JOPA