> getDeclaredPluralAttributes();
// String-based:
/**
- * Return the attribute of the managed type that corresponds to the
- * specified name.
+ * Return the attribute of the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return attribute with given name
- * @throws IllegalArgumentException if attribute of the given
- *
- * name is not present in the managed type
+ * @throws IllegalArgumentException if attribute of the given name is not present in the managed type
*/
Attribute super X, ?> getAttribute(String name);
/**
- * Return the attribute declared by the managed type that corresponds to the
- * specified name.
+ * Return the attribute declared by the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return attribute with given name
- * @throws IllegalArgumentException if attribute of the given
- *
- * name is not declared in the managed type
+ * @throws IllegalArgumentException if attribute of the given name is not declared in the managed type
*/
Attribute getDeclaredAttribute(String name);
/**
- * Return the single-valued attribute of the managed type that corresponds
- * to the specified name.
+ * Return the single-valued attribute of the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return single-valued attribute with the given name
@@ -232,20 +213,16 @@ MapAttribute getDeclaredMap(String name, Class keyType,
SingularAttribute super X, ?> getSingularAttribute(String name);
/**
- * Return the single-valued attribute declared by the managed type that
- * corresponds to the specified name.
+ * Return the single-valued attribute declared by the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
- * @return declared single-valued attribute of the given
- *
- * name
+ * @return declared single-valued attribute of the given name
* @throws IllegalArgumentException if attribute of the given name is not declared in the managed type
*/
SingularAttribute getDeclaredSingularAttribute(String name);
/**
- * Return the Collection-valued attribute of the managed type that
- * corresponds to the specified name.
+ * Return the Collection-valued attribute of the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return CollectionAttribute of the given name
@@ -254,8 +231,7 @@ MapAttribute getDeclaredMap(String name, Class keyType,
CollectionAttribute super X, ?> getCollection(String name);
/**
- * Return the Collection-valued attribute declared by the managed type that
- * corresponds to the specified name.
+ * Return the Collection-valued attribute declared by the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return declared CollectionAttribute of the given name
@@ -264,8 +240,7 @@ MapAttribute getDeclaredMap(String name, Class keyType,
CollectionAttribute getDeclaredCollection(String name);
/**
- * Return the Set-valued attribute of the managed type that corresponds to
- * the specified name.
+ * Return the Set-valued attribute of the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return SetAttribute of the given name
@@ -274,8 +249,7 @@ MapAttribute getDeclaredMap(String name, Class keyType,
SetAttribute super X, ?> getSet(String name);
/**
- * Return the Set-valued attribute declared by the managed type that
- * corresponds to the specified name.
+ * Return the Set-valued attribute declared by the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return declared SetAttribute of the given name
@@ -284,8 +258,7 @@ MapAttribute getDeclaredMap(String name, Class keyType,
SetAttribute getDeclaredSet(String name);
/**
- * Return the List-valued attribute of the managed type that corresponds to
- * the specified name.
+ * Return the List-valued attribute of the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return ListAttribute of the given name
@@ -294,8 +267,7 @@ MapAttribute getDeclaredMap(String name, Class keyType,
ListAttribute super X, ?> getList(String name);
/**
- * Return the List-valued attribute declared by the managed type that
- * corresponds to the specified name.
+ * Return the List-valued attribute declared by the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return declared ListAttribute of the given name
@@ -304,8 +276,7 @@ MapAttribute getDeclaredMap(String name, Class keyType,
ListAttribute getDeclaredList(String name);
/**
- * Return the Map-valued attribute of the managed type that corresponds to
- * the specified name.
+ * Return the Map-valued attribute of the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return MapAttribute of the given name
@@ -314,8 +285,7 @@ MapAttribute getDeclaredMap(String name, Class keyType,
MapAttribute super X, ?, ?> getMap(String name);
/**
- * Return the Map-valued attribute declared by the managed type that
- * corresponds to the specified name.
+ * Return the Map-valued attribute declared by the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return declared MapAttribute of the given name
@@ -331,8 +301,7 @@ MapAttribute getDeclaredMap(String name, Class keyType,
Set> getQueryAttributes();
/**
- * Check if a query based attribute of the managed type that corresponds to the
- * specified name exists.
+ * Check if a query based attribute of the managed type that corresponds to the specified name exists.
*
* @param name the name of the represented attribute
* @return {@code true} if the query attribute exists
@@ -340,14 +309,11 @@ MapAttribute getDeclaredMap(String name, Class keyType,
boolean hasQueryAttribute(String name);
/**
- * Return the query based attribute of the managed type that corresponds to the
- * specified name.
+ * Return the query based attribute of the managed type that corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return attribute with given name
- * @throws IllegalArgumentException if attribute of the given
- *
- * name is not present in the managed type
+ * @throws IllegalArgumentException if attribute of the given name is not present in the managed type
*/
QueryAttribute super X, ?> getQueryAttribute(String name);
@@ -371,8 +337,8 @@ MapAttribute getDeclaredMap(String name, Class keyType,
/**
* Gets specification of a field with the specified name.
*
- * In contrast to {@link #getAttribute(String)}, calling this method can also return field specification for
- * a query based attribute, types or properties field.
+ * In contrast to {@link #getAttribute(String)}, calling this method can also return field specification for a query
+ * based attribute, types or properties field.
*
* @param fieldName Name of the field
* @return Field specification
@@ -384,8 +350,8 @@ MapAttribute getDeclaredMap(String name, Class keyType,
/**
* Gets all field specifications of this entity type.
*
- * In contrast to {@link #getAttributes()}, this method returns also specifications of query based attributes, types and properties (if
- * present).
+ * In contrast to {@link #getAttributes()}, this method returns also specifications of query based attributes, types
+ * and properties (if present).
*
* @return Field specifications
*/
diff --git a/jopa-api/src/main/java/cz/cvut/kbss/jopa/sessions/CriteriaBuilder.java b/jopa-api/src/main/java/cz/cvut/kbss/jopa/sessions/CriteriaBuilder.java
index 3acb7cf53..b11051101 100644
--- a/jopa-api/src/main/java/cz/cvut/kbss/jopa/sessions/CriteriaBuilder.java
+++ b/jopa-api/src/main/java/cz/cvut/kbss/jopa/sessions/CriteriaBuilder.java
@@ -18,6 +18,7 @@
import cz.cvut.kbss.jopa.model.query.criteria.Expression;
import cz.cvut.kbss.jopa.model.query.criteria.Order;
import cz.cvut.kbss.jopa.model.query.criteria.ParameterExpression;
+import cz.cvut.kbss.jopa.model.query.criteria.Path;
/**
* Used to construct criteria queries, compound selections, expressions, predicates, orderings.
@@ -125,6 +126,14 @@ public interface CriteriaBuilder extends PredicateFactory {
*/
Expression upper(Expression x);
+ /**
+ * Create expression for extracting language tag from a string literal.
+ *
+ * @param x String-valued attribute
+ * @return Expression to extract language tag
+ */
+ Expression lang(Path x);
+
/**
* Create an ordering by the ascending value of the expression.
*
diff --git a/jopa-api/src/main/java/cz/cvut/kbss/jopa/sessions/PredicateFactory.java b/jopa-api/src/main/java/cz/cvut/kbss/jopa/sessions/PredicateFactory.java
index c9c16b26e..5e485f3d9 100644
--- a/jopa-api/src/main/java/cz/cvut/kbss/jopa/sessions/PredicateFactory.java
+++ b/jopa-api/src/main/java/cz/cvut/kbss/jopa/sessions/PredicateFactory.java
@@ -17,6 +17,8 @@
import cz.cvut.kbss.jopa.model.query.criteria.Expression;
import cz.cvut.kbss.jopa.model.query.criteria.Predicate;
+import java.util.Collection;
+
public interface PredicateFactory {
/**
@@ -112,7 +114,8 @@ public interface PredicateFactory {
* @param y expression
* @return greaterThanOrEqual predicate
*/
- > Predicate greaterThanOrEqual(Expression extends Y> x, Expression extends Y> y);
+ > Predicate greaterThanOrEqual(Expression extends Y> x,
+ Expression extends Y> y);
/**
* Create a predicate for testing whether the first argument is greater than or equal to the second.
@@ -186,6 +189,26 @@ public interface PredicateFactory {
*/
Predicate notLike(Expression x, String pattern);
+ /**
+ * Creates a predicate that tests whether an element is a member of a collection.
+ *
+ * If the collection is empty, the predicate will be false.
+ * @param elem Element
+ * @param collection Expression
+ * @return is-member predicate
+ */
+ > Predicate isMember(E elem, Expression collection);
+
+ /**
+ * Creates a predicate that tests whether an element is not a member of a collection.
+ *
+ * If the collection is empty, the predicate will be true.
+ * @param elem Element
+ * @param collection Expression
+ * @return is-member predicate
+ */
+ > Predicate isNotMember(E elem, Expression collection);
+
/**
* Create a negation of the given restriction.
* @param restriction restriction expression
diff --git a/jopa-distribution/pom.xml b/jopa-distribution/pom.xml
index f19d69e7e..45447aac2 100644
--- a/jopa-distribution/pom.xml
+++ b/jopa-distribution/pom.xml
@@ -6,7 +6,7 @@
cz.cvut.kbss.jopa
jopa-all
- 1.0.0
+ 1.1.0
../pom.xml
diff --git a/jopa-impl/pom.xml b/jopa-impl/pom.xml
index 45607fd60..6ddaf75a1 100644
--- a/jopa-impl/pom.xml
+++ b/jopa-impl/pom.xml
@@ -6,7 +6,7 @@
cz.cvut.kbss.jopa
jopa-all
- 1.0.0
+ 1.1.0
../pom.xml
diff --git a/jopa-impl/src/main/antlr4/cz/cvut/kbss/jopa/query/soql/Soql.g4 b/jopa-impl/src/main/antlr4/cz/cvut/kbss/jopa/query/soql/Soql.g4
index ac9ba1fc3..4d105890b 100644
--- a/jopa-impl/src/main/antlr4/cz/cvut/kbss/jopa/query/soql/Soql.g4
+++ b/jopa-impl/src/main/antlr4/cz/cvut/kbss/jopa/query/soql/Soql.g4
@@ -62,6 +62,7 @@ simpleConditionalExpression
: comparisonExpression
| likeExpression
| inExpression
+ | memberOfExpression
;
inExpression
@@ -78,9 +79,13 @@ literal
;
likeExpression
- : stringExpression ('NOT')? LIKE whereClauseValue
+ : stringExpression (NOT)? LIKE whereClauseValue
;
+memberOfExpression
+ : inItem (NOT)? MEMBEROF whereClauseParam
+ ;
+
comparisonExpression
: stringExpression COMPARISON_OPERATOR stringExpression
| simpleArithmeticExpression COMPARISON_OPERATOR simpleArithmeticExpression
@@ -102,6 +107,7 @@ functionsReturningStrings
| 'SUBSTRING' '(' stringExpression ',' simpleArithmeticExpression ',' simpleArithmeticExpression ')'
| 'LOWER' '(' stringExpression ')'
| 'UPPER' '(' stringExpression ')'
+ | 'LANG' '(' whereClauseParam ')'
;
simpleArithmeticExpression
@@ -181,6 +187,8 @@ LIKE: 'LIKE' ;
IN: 'IN' ;
+MEMBEROF: 'MEMBER OF' ;
+
COMPARISON_OPERATOR: '>' | '<' | '>=' | '<=' | '=' | '<>' | '!=' ;
DOT: '.' ;
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/exception/SoqlException.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/exception/SoqlException.java
new file mode 100644
index 000000000..792495192
--- /dev/null
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/exception/SoqlException.java
@@ -0,0 +1,13 @@
+package cz.cvut.kbss.jopa.exception;
+
+import cz.cvut.kbss.jopa.exceptions.OWLPersistenceException;
+
+/**
+ * Indicates an error during parsing and translation of SOQL to SPARQL.
+ */
+public class SoqlException extends OWLPersistenceException {
+
+ public SoqlException(String message) {
+ super(message);
+ }
+}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/DefaultClasspathScanner.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/DefaultClasspathScanner.java
index be469134d..66db6f527 100644
--- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/DefaultClasspathScanner.java
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/DefaultClasspathScanner.java
@@ -26,7 +26,11 @@
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import java.util.function.Consumer;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -107,7 +111,7 @@ protected static boolean isJar(String filePath) {
protected static JarFile createJarFile(URL elementUrl) throws IOException {
final String jarPath = sanitizePath(elementUrl).replaceFirst("[.]jar[!].*", JAR_FILE_SUFFIX)
- .replaceFirst("file:", "");
+ .replaceFirst("file:", "");
return new JarFile(jarPath);
}
@@ -135,7 +139,8 @@ protected void processJarFile(final JarFile jarFile) {
final String entryName = entry.getName();
if (entryName.endsWith(CLASS_FILE_SUFFIX) && entryName.contains(pathPattern)) {
String className = entryName.substring(entryName.indexOf(pathPattern));
- className = className.replace(JAVA_CLASSPATH_SEPARATOR, JAVA_PACKAGE_SEPARATOR).replace(WINDOWS_FILE_SEPARATOR, JAVA_PACKAGE_SEPARATOR);
+ className = className.replace(JAVA_CLASSPATH_SEPARATOR, JAVA_PACKAGE_SEPARATOR)
+ .replace(WINDOWS_FILE_SEPARATOR, JAVA_PACKAGE_SEPARATOR);
className = className.substring(0, className.length() - CLASS_FILE_SUFFIX.length());
processClass(className);
}
@@ -154,8 +159,9 @@ protected void processClass(String className) {
try {
final Class> cls = Class.forName(className, true, classLoader);
listeners.forEach(listener -> listener.accept(cls));
- } catch (ClassNotFoundException e) {
- throw new OWLPersistenceException("Unexpected ClassNotFoundException when scanning for entities.", e);
+ } catch (Throwable e) {
+ LOG.debug("Unable to load class {}, got error {}: {}. Skipping the class. If it is an entity class, ensure it is available on classpath and is built with supported Java version.", className, e.getClass()
+ .getName(), e.getMessage());
}
}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/PersistenceUnitClassFinder.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/PersistenceUnitClassFinder.java
index 9224511a9..443711e64 100644
--- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/PersistenceUnitClassFinder.java
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/PersistenceUnitClassFinder.java
@@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.stream.Stream;
/**
* Scans classpath to discover classes relevant to persistence unit building.
@@ -53,18 +54,13 @@ public class PersistenceUnitClassFinder {
*/
public void scanClasspath(Configuration configuration) {
Objects.requireNonNull(configuration);
- if (!configuration.contains(JOPAPersistenceProperties.SCAN_PACKAGE)) {
- throw new IllegalArgumentException("Missing the " + JOPAPersistenceProperties.SCAN_PACKAGE + " property.");
- }
- String toScan = configuration.get(JOPAPersistenceProperties.SCAN_PACKAGE);
- if (toScan.isEmpty()) {
- throw new IllegalArgumentException(JOPAPersistenceProperties.SCAN_PACKAGE + " property cannot be empty.");
- }
+ String scanPackageConfig = configuration.get(JOPAPersistenceProperties.SCAN_PACKAGE, "");
+ final String[] toScan = scanPackageConfig.split(",");
final ClasspathScanner classpathScanner = resolveClasspathScanner(configuration);
classpathScanner.addListener(entityLoader);
classpathScanner.addListener(resultSetMappingLoader);
classpathScanner.addListener(converterLoader);
- classpathScanner.processClasses(toScan);
+ Stream.of(toScan).map(String::trim).forEach(classpathScanner::processClasses);
this.scanned = true;
}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/CriteriaBuilderImpl.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/CriteriaBuilderImpl.java
index 6ff10f6d5..4173da98a 100644
--- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/CriteriaBuilderImpl.java
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/CriteriaBuilderImpl.java
@@ -15,12 +15,39 @@
package cz.cvut.kbss.jopa.query.criteria;
import cz.cvut.kbss.jopa.model.CriteriaQueryImpl;
-import cz.cvut.kbss.jopa.model.query.criteria.*;
-import cz.cvut.kbss.jopa.query.criteria.expressions.*;
+import cz.cvut.kbss.jopa.model.query.criteria.Expression;
+import cz.cvut.kbss.jopa.model.query.criteria.Order;
+import cz.cvut.kbss.jopa.model.query.criteria.ParameterExpression;
+import cz.cvut.kbss.jopa.model.query.criteria.Path;
+import cz.cvut.kbss.jopa.model.query.criteria.Predicate;
+import cz.cvut.kbss.jopa.query.criteria.expressions.AbsFunction;
+import cz.cvut.kbss.jopa.query.criteria.expressions.AbstractExpression;
+import cz.cvut.kbss.jopa.query.criteria.expressions.AbstractPathExpression;
+import cz.cvut.kbss.jopa.query.criteria.expressions.CeilFunction;
+import cz.cvut.kbss.jopa.query.criteria.expressions.CountFunction;
+import cz.cvut.kbss.jopa.query.criteria.expressions.ExpressionEqualImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.ExpressionGreaterThanImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.ExpressionGreaterThanOrEqualImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.ExpressionInImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.ExpressionLessThanImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.ExpressionLessThanOrEqualImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.ExpressionLikeImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.ExpressionLiteralImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.ExpressionNotEqualImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.ExpressionNotLikeImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.FloorFunction;
+import cz.cvut.kbss.jopa.query.criteria.expressions.IsMemberExpression;
+import cz.cvut.kbss.jopa.query.criteria.expressions.LangFunction;
+import cz.cvut.kbss.jopa.query.criteria.expressions.LengthFunction;
+import cz.cvut.kbss.jopa.query.criteria.expressions.LowerFunction;
+import cz.cvut.kbss.jopa.query.criteria.expressions.OrderImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.ParameterExpressionImpl;
+import cz.cvut.kbss.jopa.query.criteria.expressions.UpperFunction;
import cz.cvut.kbss.jopa.sessions.CriteriaBuilder;
import cz.cvut.kbss.jopa.sessions.UnitOfWorkImpl;
import java.util.Arrays;
+import java.util.Collection;
public class CriteriaBuilderImpl implements CriteriaBuilder {
@@ -31,7 +58,7 @@ public CriteriaBuilderImpl(UnitOfWorkImpl uow) {
}
@Override
- public CriteriaQuery createQuery(Class resultClass) {
+ public CriteriaQueryImpl createQuery(Class resultClass) {
return new CriteriaQueryImpl<>(new CriteriaQueryHolder<>(resultClass), uow.getMetamodel(), this);
}
@@ -41,6 +68,12 @@ public Expression abs(Expression x) {
return new AbsFunction<>((Class) x.getJavaType(), (AbstractPathExpression) x, this);
}
+ private void validateFunctionArgument(Expression> x) {
+ if (!(x instanceof AbstractPathExpression)) {
+ throw new IllegalArgumentException("Function can be applied only to path expressions.");
+ }
+ }
+
@Override
public Expression count(Expression> x) {
validateFunctionArgument(x);
@@ -101,10 +134,10 @@ public Expression upper(Expression x) {
return new UpperFunction((AbstractPathExpression) x, this);
}
- private void validateFunctionArgument(Expression> x) {
- if (!(x instanceof AbstractPathExpression)) {
- throw new IllegalArgumentException("Function can be applied only to path expressions.");
- }
+ @Override
+ public Expression lang(Path x) {
+ validateFunctionArgument(x);
+ return new LangFunction((AbstractPathExpression) x, this);
}
@Override
@@ -219,6 +252,18 @@ public In notIn(Expression extends T> expression) {
return inExpression;
}
+ @Override
+ public > Predicate isMember(E elem, Expression collection) {
+ return new IsMemberExpression<>(elem, collection, this);
+ }
+
+ @Override
+ public > Predicate isNotMember(E elem, Expression collection) {
+ final IsMemberExpression expr = new IsMemberExpression<>(elem, collection, this);
+ expr.not();
+ return expr;
+ }
+
@Override
public > Predicate greaterThan(Expression extends Y> x,
Expression extends Y> y) {
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/PathImpl.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/PathImpl.java
index a3dabc3cb..5bcf0bd46 100644
--- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/PathImpl.java
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/PathImpl.java
@@ -17,6 +17,7 @@
import cz.cvut.kbss.jopa.model.metamodel.Bindable;
import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
import cz.cvut.kbss.jopa.model.metamodel.Metamodel;
+import cz.cvut.kbss.jopa.model.metamodel.TypesSpecification;
import cz.cvut.kbss.jopa.model.query.criteria.Path;
import cz.cvut.kbss.jopa.query.criteria.expressions.AbstractPathExpression;
import cz.cvut.kbss.jopa.sessions.CriteriaBuilder;
@@ -34,6 +35,9 @@ public PathImpl(Metamodel metamodel, AbstractPathExpression pathSource, FieldSpe
}
private static Class resolveBindableJavaType(FieldSpecification, ?> attribute) {
+ if (attribute instanceof TypesSpecification) {
+ return ((TypesSpecification) attribute).getElementType();
+ }
assert attribute instanceof Bindable;
return ((Bindable) attribute).getBindableJavaType();
}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/expressions/AbstractPathExpression.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/expressions/AbstractPathExpression.java
index 67a4f6b78..0cd60bf7c 100644
--- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/expressions/AbstractPathExpression.java
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/expressions/AbstractPathExpression.java
@@ -1,16 +1,14 @@
/**
* Copyright (C) 2023 Czech Technical University in Prague
- *
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any
- * later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details. You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details. You should have received a copy of the GNU General Public License along with this program. If not, see
+ * .
*/
package cz.cvut.kbss.jopa.query.criteria.expressions;
@@ -27,7 +25,8 @@ public abstract class AbstractPathExpression extends AbstractExpression im
protected AbstractPathExpression pathSource;
protected final Metamodel metamodel;
- public AbstractPathExpression(Class type, AbstractPathExpression pathSource, Metamodel metamodel, CriteriaBuilder cb) {
+ public AbstractPathExpression(Class type, AbstractPathExpression pathSource, Metamodel metamodel,
+ CriteriaBuilder cb) {
super(type, cb);
this.pathSource = pathSource;
this.metamodel = metamodel;
@@ -38,6 +37,8 @@ public Path getAttr(String attributeName) {
final FieldSpecification super X, ?> fs;
if (et.getIdentifier().getName().equals(attributeName)) {
fs = et.getIdentifier();
+ } else if (et.getTypes() != null && et.getTypes().getName().equals(attributeName)) {
+ fs = et.getTypes();
} else {
fs = et.getAttribute(attributeName);
}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/expressions/IsMemberExpression.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/expressions/IsMemberExpression.java
new file mode 100644
index 000000000..53f42689b
--- /dev/null
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/expressions/IsMemberExpression.java
@@ -0,0 +1,45 @@
+package cz.cvut.kbss.jopa.query.criteria.expressions;
+
+import cz.cvut.kbss.jopa.model.query.criteria.Expression;
+import cz.cvut.kbss.jopa.model.query.criteria.Predicate;
+import cz.cvut.kbss.jopa.query.criteria.AbstractPredicate;
+import cz.cvut.kbss.jopa.query.criteria.CriteriaParameterFiller;
+import cz.cvut.kbss.jopa.query.soql.SoqlConstants;
+import cz.cvut.kbss.jopa.sessions.CriteriaBuilder;
+
+import java.util.Collection;
+import java.util.List;
+
+public class IsMemberExpression extends AbstractPredicate {
+
+ private final Expression extends Collection> collectionExpression;
+ private final Y value;
+
+ public IsMemberExpression(Y value, Expression extends Collection> collectionExpression, CriteriaBuilder cb) {
+ super(BooleanOperator.AND, cb);
+ this.value = value;
+ this.collectionExpression = collectionExpression;
+ }
+
+ @Override
+ public Predicate not() {
+ super.negate();
+ return this;
+ }
+
+ @Override
+ public List> getExpressions() {
+ return List.of(this);
+ }
+
+ @Override
+ public void setExpressionToQuery(StringBuilder query, CriteriaParameterFiller parameterFiller) {
+ final AbstractExpression> param = (AbstractExpression>) cb.literal(value);
+ param.setExpressionToQuery(query, parameterFiller);
+ if (negated) {
+ query.append(' ').append(SoqlConstants.NOT);
+ }
+ query.append(' ').append(SoqlConstants.MEMBER_OF).append(' ');
+ ((AbstractExpression>) collectionExpression).setExpressionToQuery(query, parameterFiller);
+ }
+}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/expressions/LangFunction.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/expressions/LangFunction.java
new file mode 100644
index 000000000..c32d54ee6
--- /dev/null
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/criteria/expressions/LangFunction.java
@@ -0,0 +1,19 @@
+package cz.cvut.kbss.jopa.query.criteria.expressions;
+
+import cz.cvut.kbss.jopa.query.soql.SoqlConstants;
+import cz.cvut.kbss.jopa.sessions.CriteriaBuilder;
+
+/**
+ * Represents the SOQL {@link SoqlConstants.Functions#LANG} function.
+ */
+public class LangFunction extends AbstractFunctionExpression {
+
+ public LangFunction(AbstractPathExpression internExpression, CriteriaBuilder cb) {
+ super(String.class, internExpression, cb);
+ }
+
+ @Override
+ public String getFunctionName() {
+ return SoqlConstants.Functions.LANG;
+ }
+}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/MemberOfOperator.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/MemberOfOperator.java
new file mode 100644
index 000000000..54b9c0cef
--- /dev/null
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/MemberOfOperator.java
@@ -0,0 +1,21 @@
+package cz.cvut.kbss.jopa.query.soql;
+
+/**
+ * SOQL ({@code NOT}) {@code MEMBER OF} operator.
+ */
+public class MemberOfOperator implements FilterableExpression {
+
+ @Override
+ public String toFilterExpression(String parameter, String value) {
+ return "";
+ }
+
+ @Override
+ public boolean requiresFilterExpression() {
+ return false;
+ }
+
+ static MemberOfOperator memberOf() {
+ return new MemberOfOperator();
+ }
+}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlAttribute.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlAttribute.java
index a53e5495b..372b8a0c0 100644
--- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlAttribute.java
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlAttribute.java
@@ -14,6 +14,7 @@
*/
package cz.cvut.kbss.jopa.query.soql;
+import cz.cvut.kbss.jopa.query.sparql.SparqlConstants;
import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
import java.util.Collections;
@@ -162,6 +163,7 @@ public String getBasicGraphPattern(String rootVariable) {
}
private static String toIri(SoqlNode node) {
- return IdentifierTransformer.stringifyIri(node.getIri());
+ final String nodeIri = node.getIri();
+ return SparqlConstants.RDF_TYPE_SHORTCUT.equals(nodeIri) ? nodeIri : IdentifierTransformer.stringifyIri(nodeIri);
}
}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlConstants.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlConstants.java
index 337b0036e..afb7f7b01 100644
--- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlConstants.java
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlConstants.java
@@ -44,6 +44,11 @@ public class SoqlConstants {
*/
public static final String IN = "IN";
+ /**
+ * {@code MEMBER OF} operator.
+ */
+ public static final String MEMBER_OF = "MEMBER OF";
+
/**
* {@code NOT} operator.
*/
@@ -121,6 +126,11 @@ public static class Functions {
*/
public static final String FLOOR = "FLOOR";
+ /**
+ * Returns language tag of a literal, if it has one. Returns an empty string if it has no language tag.
+ */
+ public static final String LANG = "LANG";
+
private Functions() {
throw new AssertionError();
}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlFunctionTranslator.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlFunctionTranslator.java
index f48befa7e..037f8f76d 100644
--- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlFunctionTranslator.java
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlFunctionTranslator.java
@@ -35,6 +35,7 @@ private static Map initFunctions() {
map.put(SoqlConstants.Functions.ABS, "ABS");
map.put(SoqlConstants.Functions.CEIL, "CEIL");
map.put(SoqlConstants.Functions.FLOOR, "FLOOR");
+ map.put(SoqlConstants.Functions.LANG, "lang");
return map;
}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlQueryListener.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlQueryListener.java
index 868508b46..bc8389ccf 100644
--- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlQueryListener.java
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/soql/SoqlQueryListener.java
@@ -14,6 +14,7 @@
*/
package cz.cvut.kbss.jopa.query.soql;
+import cz.cvut.kbss.jopa.exception.SoqlException;
import cz.cvut.kbss.jopa.model.MetamodelImpl;
import cz.cvut.kbss.jopa.model.metamodel.Attribute;
import cz.cvut.kbss.jopa.model.metamodel.EntityType;
@@ -21,6 +22,7 @@
import cz.cvut.kbss.jopa.model.metamodel.PluralAttribute;
import cz.cvut.kbss.jopa.model.metamodel.SingularAttribute;
import cz.cvut.kbss.jopa.model.metamodel.Type;
+import cz.cvut.kbss.jopa.query.sparql.SparqlConstants;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.ParseTree;
@@ -168,7 +170,7 @@ public void enterCount(SoqlParser.CountContext ctx) {
@Override
public void exitCount(SoqlParser.CountContext ctx) {
- this.projectedVariable = ctx.getChild(1).getText();
+ this.projectedVariable = ctx.getChild(2).getText();
}
@Override
@@ -366,6 +368,22 @@ public void exitLikeExpression(SoqlParser.LikeExpressionContext ctx) {
this.isInObjectIdentifierExpression = false;
}
+ @Override
+ public void enterMemberOfExpression(SoqlParser.MemberOfExpressionContext ctx) {
+
+ }
+
+ @Override
+ public void exitMemberOfExpression(SoqlParser.MemberOfExpressionContext ctx) {
+ if (ctx.getChildCount() > 2 && ctx.getChild(1).getText().equals(SoqlConstants.NOT)) {
+ attrPointer.setNot(true);
+ }
+ attrPointer.setOperator(MemberOfOperator.memberOf());
+ ParseTree whereClauseValue = ctx.getChild(0);
+ attrPointer.setValue(whereClauseValue.getText());
+ this.isInObjectIdentifierExpression = false;
+ }
+
@Override
public void enterComparisonExpression(SoqlParser.ComparisonExpressionContext ctx) {
}
@@ -689,14 +707,24 @@ private IdentifiableEntityType> getEntityType(String name) {
}
private void setAllNodesIris(EntityType> entityType, SoqlNode node) {
- if (entityType.getIdentifier().getName().equals(node.getValue())) {
+ final String nodeName = node.getValue();
+ if (entityType.getIdentifier().getName().equals(nodeName)) {
return;
}
- final Attribute, ?> abstractAttribute = entityType.getAttribute(node.getValue());
+ if (entityType.getTypes() != null && entityType.getTypes().getName().equals(node.getValue())) {
+ node.setIri(SparqlConstants.RDF_TYPE_SHORTCUT);
+ return;
+ }
+ final Attribute, ?> att;
+ try {
+ att = entityType.getAttribute(node.getValue());
+ } catch (IllegalArgumentException e) {
+ throw new SoqlException("No matching attribute with name '" + node.getValue() + "' found on entity type '" + entityType.getName() + "'.");
+ }
//not implemented case of 3 or more fragments (chained SoqlNodes)
- node.setIri(abstractAttribute.getIRI().toString());
+ node.setIri(att.getIRI().toString());
if (node.hasChild()) {
- final Type> type = resolveBindableType(abstractAttribute);
+ final Type> type = resolveBindableType(att);
if (type.getPersistenceType() != Type.PersistenceType.ENTITY) {
return;
}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/sparql/SparqlConstants.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/sparql/SparqlConstants.java
new file mode 100644
index 000000000..874fa1e39
--- /dev/null
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/sparql/SparqlConstants.java
@@ -0,0 +1,26 @@
+package cz.cvut.kbss.jopa.query.sparql;
+
+/**
+ * Constants of SPARQL.
+ */
+public class SparqlConstants {
+
+ /**
+ * The {@literal SELECT} keyword.
+ */
+ public static final String SELECT = "SELECT";
+
+ /**
+ * The {@literal WHERE} keyword.
+ */
+ public static final String WHERE = "WHERE";
+
+ /**
+ * The {@literal a} keyword representing the rdf:type IRI.
+ */
+ public static final String RDF_TYPE_SHORTCUT = "a";
+
+ private SparqlConstants() {
+ throw new AssertionError();
+ }
+}
diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/sparql/SparqlQueryParser.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/sparql/SparqlQueryParser.java
index 67ae3a8f1..b24e3f16a 100644
--- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/sparql/SparqlQueryParser.java
+++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/sparql/SparqlQueryParser.java
@@ -34,9 +34,6 @@
*/
public class SparqlQueryParser implements QueryParser {
- private static final String SELECT = "SELECT";
- private static final String WHERE = "WHERE";
-
private final ParameterValueFactory parameterValueFactory;
private String query;
@@ -195,9 +192,9 @@ private QueryParameter> getQueryParameter(Integer position) {
}
private void wordEnd() {
- if (SELECT.equalsIgnoreCase(currentWord.toString())) {
+ if (SparqlConstants.SELECT.equalsIgnoreCase(currentWord.toString())) {
this.inProjection = true;
- } else if (inProjection && WHERE.equalsIgnoreCase(currentWord.toString())) {
+ } else if (inProjection && SparqlConstants.WHERE.equalsIgnoreCase(currentWord.toString())) {
this.inProjection = false;
}
currentWord = new StringBuilder();
diff --git a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/OWLClassF.java b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/OWLClassF.java
index da2374667..6485bbd5f 100644
--- a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/OWLClassF.java
+++ b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/OWLClassF.java
@@ -34,8 +34,7 @@ public class OWLClassF {
@OWLDataProperty(iri = Vocabulary.p_f_stringAttribute)
private String secondStringAttribute;
- @Sequence(type = SequenceType.simple, ObjectPropertyHasNextIRI = "http://krizik.felk.cvut.cz/ontologies/jopa/attributes#F-hasSimpleNext")
- @OWLObjectProperty(iri = "http://krizik.felk.cvut.cz/ontologies/jopa/attributes#F-hasSimpleSequence")
+ @OWLObjectProperty(iri = Vocabulary.p_f_setAttribute)
private Set simpleSet;
public OWLClassF() {
diff --git a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/Person.java b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/Person.java
index 9056c733c..61a6d3020 100644
--- a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/Person.java
+++ b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/Person.java
@@ -14,12 +14,10 @@
*/
package cz.cvut.kbss.jopa.environment;
-import cz.cvut.kbss.jopa.model.annotations.Id;
-import cz.cvut.kbss.jopa.model.annotations.OWLClass;
-import cz.cvut.kbss.jopa.model.annotations.OWLDataProperty;
-import cz.cvut.kbss.jopa.model.annotations.OWLObjectProperty;
+import cz.cvut.kbss.jopa.model.annotations.*;
import java.net.URI;
+import java.util.Set;
@OWLClass(iri = Vocabulary.c_Person)
public class Person {
@@ -38,4 +36,7 @@ public class Person {
@OWLObjectProperty(iri = Vocabulary.p_p_hasPhone)
private Phone phone;
+
+ @Types
+ private Set types;
}
diff --git a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/Vocabulary.java b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/Vocabulary.java
index aea54f9d9..ee37aec5e 100644
--- a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/Vocabulary.java
+++ b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/Vocabulary.java
@@ -38,6 +38,7 @@ public class Vocabulary {
public static final String c_Phone = CLASS_BASE + "Phone";
public static final String p_f_stringAttribute = ATTRIBUTE_BASE + "f-stringAttribute";
+ public static final String p_f_setAttribute = ATTRIBUTE_BASE + "f-hasA";
public static final String p_g_hasH = ATTRIBUTE_BASE + "hasH";
public static final String p_h_hasA = ATTRIBUTE_BASE + "hasA";
diff --git a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/utils/MetamodelFactory.java b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/utils/MetamodelFactory.java
index a8f58a1fb..084792dae 100644
--- a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/utils/MetamodelFactory.java
+++ b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/utils/MetamodelFactory.java
@@ -74,6 +74,7 @@ public static void initOWLClassAMocks(IdentifiableEntityType etMock,
when(strAttMock.getFetchType()).thenReturn(FetchType.EAGER);
when(strAttMock.hasLanguage()).thenReturn(true);
when(strAttMock.getLanguage()).thenReturn(Generators.LANG);
+ when(etMock.getFieldSpecification(strAttMock.getName())).thenReturn(strAttMock);
when(typesMock.getJavaField()).thenReturn(OWLClassA.getTypesField());
when(typesMock.getName()).thenReturn(OWLClassA.getTypesField().getName());
when(typesMock.getDeclaringType()).thenReturn(etMock);
@@ -81,7 +82,6 @@ public static void initOWLClassAMocks(IdentifiableEntityType etMock,
when(typesMock.getElementType()).thenReturn(String.class);
when(typesMock.isCollection()).thenReturn(true);
when(typesMock.getFetchType()).thenReturn(FetchType.EAGER);
- when(etMock.getFieldSpecification(strAttMock.getName())).thenReturn(strAttMock);
when(etMock.getFieldSpecification(typesMock.getName())).thenReturn(typesMock);
when(etMock.getIdentifier()).thenReturn(idMock);
@@ -321,6 +321,7 @@ public static void initOWLClassFMocks(IdentifiableEntityType etMock,
when(setAMock.getBindableJavaType()).thenReturn(OWLClassA.class);
when(setAMock.getConstraints()).thenReturn(new ParticipationConstraint[]{});
when(setAMock.getDeclaringType()).thenReturn(etMock);
+ when(setAMock.getName()).thenReturn(OWLClassF.getSimpleSetField().getName());
when(etMock.getAttribute(OWLClassF.getSimpleSetField().getName())).thenReturn(setAMock);
when(etMock.getFieldSpecification(OWLClassF.getSimpleSetField().getName())).thenReturn(setAMock);
@@ -341,6 +342,7 @@ public static void initOWLClassFMocks(IdentifiableEntityType etMock,
when(etMock.getIdentifier()).thenReturn(idMock);
when(idMock.getJavaField()).thenReturn(OWLClassF.class.getDeclaredField("uri"));
when(idMock.getDeclaringType()).thenReturn(etMock);
+ when(idMock.getName()).thenReturn("uri");
when(etMock.getLifecycleListenerManager()).thenReturn(EntityLifecycleListenerManager.empty());
}
@@ -1286,6 +1288,7 @@ static void initOwlClassUMocks(IdentifiableEntityType et, SingularAtt
when(et.getJavaType()).thenReturn(OWLClassU.class);
when(id.getJavaField()).thenReturn(OWLClassU.getIdField());
when(id.getDeclaringType()).thenReturn(et);
+ when(id.getName()).thenReturn(OWLClassU.getIdField().getName());
when(et.getIRI()).thenReturn(IRI.create(OWLClassU.getClassIri()));
when(et.getName()).thenReturn(OWLClassU.class.getSimpleName());
when(et.getFieldSpecifications())
@@ -1426,6 +1429,7 @@ public static void initPersonMocks(IdentifiableEntityType etMock, Abstra
AbstractAttribute genderAttMock,
AbstractAttribute ageAttMock, SingularAttributeImpl phoneAttMock,
AbstractIdentifiableType etPhone,
+ TypesSpecification typesMock,
Identifier idMock) throws NoSuchFieldException, SecurityException {
when(etMock.getJavaType()).thenReturn(Person.class);
when(etMock.getPersistenceType()).thenReturn(Type.PersistenceType.ENTITY);
@@ -1474,5 +1478,15 @@ public static void initPersonMocks(IdentifiableEntityType etMock, Abstra
when(phoneAttMock.getName()).thenReturn(Person.class.getDeclaredField("phone").getName());
when(phoneAttMock.getType()).thenReturn(etPhone);
when(etMock.getAttribute(Person.class.getDeclaredField("phone").getName())).thenReturn(phoneAttMock);
+
+ when(typesMock.getJavaField()).thenReturn(Person.class.getDeclaredField("types"));
+ when(typesMock.getName()).thenReturn(Person.class.getDeclaredField("types").getName());
+ when(typesMock.getDeclaringType()).thenReturn(etMock);
+ when(typesMock.getJavaType()).thenReturn(Set.class);
+ when(typesMock.getElementType()).thenReturn(String.class);
+ when(typesMock.isCollection()).thenReturn(true);
+ when(typesMock.getFetchType()).thenReturn(FetchType.EAGER);
+ when(etMock.getTypes()).thenReturn(typesMock);
+ when(etMock.getFieldSpecification("types")).thenReturn(typesMock);
}
}
diff --git a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/utils/MetamodelMocks.java b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/utils/MetamodelMocks.java
index 58075dd6f..640ada740 100644
--- a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/utils/MetamodelMocks.java
+++ b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/utils/MetamodelMocks.java
@@ -326,6 +326,8 @@ public class MetamodelMocks {
private SingularAttributeImpl personAgeAtt;
@Mock
private SingularAttributeImpl personPhoneAtt;
+ @Mock
+ private TypesSpecification personTypes;
@Mock
private IdentifiableEntityType etPhone;
@@ -373,7 +375,7 @@ public MetamodelMocks() throws Exception {
qaEntityAtt, idQA);
MetamodelFactory.initPhoneMocks(etPhone, phoneNumberAtt, idPhone);
MetamodelFactory.initPersonMocks(etPerson, personUsernameAtt, personGenderAtt, personAgeAtt, personPhoneAtt,
- etPhone, idPerson);
+ etPhone, personTypes, idPerson);
}
public void setMocks(Metamodel metamodel) {
@@ -1003,5 +1005,9 @@ public SingularAttributeImpl ageAttribute() {
public SingularAttributeImpl phoneAttribute() {
return MetamodelMocks.this.personPhoneAtt;
}
+
+ public TypesSpecification typesSpecification() {
+ return MetamodelMocks.this.personTypes;
+ }
}
}
diff --git a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/loaders/DefaultClasspathScannerTest.java b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/loaders/DefaultClasspathScannerTest.java
new file mode 100644
index 000000000..541b5caba
--- /dev/null
+++ b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/loaders/DefaultClasspathScannerTest.java
@@ -0,0 +1,33 @@
+package cz.cvut.kbss.jopa.loaders;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.function.Consumer;
+
+import static org.mockito.Mockito.verify;
+
+@ExtendWith(MockitoExtension.class)
+class DefaultClasspathScannerTest {
+
+ @Mock
+ private Consumer> listener;
+
+ @InjectMocks
+ private DefaultClasspathScanner sut;
+
+ @BeforeEach
+ void setUp() {
+ sut.addListener(listener);
+ }
+
+ @Test
+ void processClassesFindsAllClassesOnClassPathWhenProvidedPackageIsEmpty() {
+ sut.processClasses("");
+ PersistenceUnitClassFinderTest.ENTITY_CLASSES.forEach(cls -> verify(listener).accept(cls));
+ }
+}
diff --git a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/loaders/PersistenceUnitClassFinderTest.java b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/loaders/PersistenceUnitClassFinderTest.java
index 45235744a..5be1599d5 100644
--- a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/loaders/PersistenceUnitClassFinderTest.java
+++ b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/loaders/PersistenceUnitClassFinderTest.java
@@ -14,21 +14,51 @@
*/
package cz.cvut.kbss.jopa.loaders;
-import cz.cvut.kbss.jopa.environment.*;
+import cz.cvut.kbss.jopa.environment.OWLClassA;
+import cz.cvut.kbss.jopa.environment.OWLClassB;
+import cz.cvut.kbss.jopa.environment.OWLClassC;
+import cz.cvut.kbss.jopa.environment.OWLClassD;
+import cz.cvut.kbss.jopa.environment.OWLClassE;
+import cz.cvut.kbss.jopa.environment.OWLClassF;
+import cz.cvut.kbss.jopa.environment.OWLClassG;
+import cz.cvut.kbss.jopa.environment.OWLClassH;
+import cz.cvut.kbss.jopa.environment.OWLClassI;
+import cz.cvut.kbss.jopa.environment.OWLClassJ;
+import cz.cvut.kbss.jopa.environment.OWLClassK;
+import cz.cvut.kbss.jopa.environment.OWLClassL;
+import cz.cvut.kbss.jopa.environment.OWLClassM;
+import cz.cvut.kbss.jopa.environment.OWLClassN;
+import cz.cvut.kbss.jopa.environment.OWLClassO;
+import cz.cvut.kbss.jopa.environment.OWLClassP;
+import cz.cvut.kbss.jopa.environment.OWLClassQ;
+import cz.cvut.kbss.jopa.environment.OWLClassR;
+import cz.cvut.kbss.jopa.environment.OWLClassS;
+import cz.cvut.kbss.jopa.environment.OWLClassT;
+import cz.cvut.kbss.jopa.environment.OWLClassU;
+import cz.cvut.kbss.jopa.environment.OWLClassWithQueryAttr;
+import cz.cvut.kbss.jopa.environment.Person;
+import cz.cvut.kbss.jopa.environment.Phone;
import cz.cvut.kbss.jopa.model.JOPAPersistenceProperties;
import cz.cvut.kbss.jopa.model.annotations.SparqlResultSetMapping;
import cz.cvut.kbss.jopa.utils.Configuration;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import java.util.*;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import java.util.function.Consumer;
-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.assertTrue;
public class PersistenceUnitClassFinderTest {
- private static final Set> ENTITY_CLASSES = initEntityClasses();
+ static final Set> ENTITY_CLASSES = initEntityClasses();
private static Set> initEntityClasses() {
final Set> set = new HashSet<>();
@@ -61,21 +91,19 @@ private static Set> initEntityClasses() {
private final PersistenceUnitClassFinder sut = new PersistenceUnitClassFinder();
- @BeforeEach
- void setUp() {
- TestClasspathScanner.invoked = false;
- }
-
@Test
- public void throwsExceptionWhenScanPackageIsNotSupplied() {
- final Map properties = Collections.emptyMap();
- assertThrows(IllegalArgumentException.class, () -> sut.scanClasspath(new Configuration(properties)));
+ public void scanClasspathScansWholeClasspathWhenPackageIsNotProvided() {
+ sut.scanClasspath(new Configuration(Map.of(JOPAPersistenceProperties.CLASSPATH_SCANNER_CLASS, TestClasspathScanner.class.getName())));
+ assertEquals(Map.of(0, ""), TestClasspathScanner.invocations);
}
@Test
- public void throwsExceptionWhenScanPackageIsEmpty() {
- final Map properties = Collections.singletonMap(JOPAPersistenceProperties.SCAN_PACKAGE, "");
- assertThrows(IllegalArgumentException.class, () -> sut.scanClasspath(new Configuration(properties)));
+ public void scanClasspathScansWholeClasspathWhenPackageIsEmpty() {
+ sut.scanClasspath(new Configuration(Map.of(
+ JOPAPersistenceProperties.SCAN_PACKAGE, "",
+ JOPAPersistenceProperties.CLASSPATH_SCANNER_CLASS, TestClasspathScanner.class.getName()
+ )));
+ assertEquals(Map.of(0, ""), TestClasspathScanner.invocations);
}
@Test
@@ -99,7 +127,7 @@ public void loadsEntityClassesWhenAncestorPackageIsSet() {
final Map properties = new HashMap<>();
properties.put(JOPAPersistenceProperties.SCAN_PACKAGE, "cz.cvut.kbss.jopa");
properties.put(JOPAPersistenceProperties.CLASSPATH_SCANNER_CLASS,
- cz.cvut.kbss.jopa.environment.utils.TestClasspathScanner.class.getCanonicalName());
+ cz.cvut.kbss.jopa.environment.utils.TestClasspathScanner.class.getCanonicalName());
sut.scanClasspath(new Configuration(properties));
assertTrue(sut.getEntities().containsAll(ENTITY_CLASSES));
}
@@ -134,14 +162,25 @@ void usesConfiguredClasspathScanner() {
properties.put(JOPAPersistenceProperties.SCAN_PACKAGE, "cz.cvut.kbss.jopa.environment");
properties.put(JOPAPersistenceProperties.CLASSPATH_SCANNER_CLASS, TestClasspathScanner.class.getName());
sut.scanClasspath(new Configuration(properties));
- assertTrue(TestClasspathScanner.invoked);
+ assertEquals(Map.of(0, "cz.cvut.kbss.jopa.environment"), TestClasspathScanner.invocations);
+ }
+
+ @Test
+ void scanClasspathUsesClasspathScannerToFindEntityClassesInAllProvidedPackages() {
+ sut.scanClasspath(new Configuration(Map.of(
+ JOPAPersistenceProperties.SCAN_PACKAGE, "cz.cvut.kbss.jopa.environment,org.example",
+ JOPAPersistenceProperties.CLASSPATH_SCANNER_CLASS, TestClasspathScanner.class.getName()
+ )));
+ assertEquals(Map.of(0, "cz.cvut.kbss.jopa.environment",
+ 1, "org.example"), TestClasspathScanner.invocations);
}
public static class TestClasspathScanner implements ClasspathScanner {
- private static boolean invoked = false;
+ private static Map invocations;
public TestClasspathScanner() {
+ invocations = new LinkedHashMap<>();
}
@Override
@@ -151,7 +190,7 @@ public void addListener(Consumer> listener) {
@Override
public void processClasses(String scanPackage) {
- invoked = true;
+ invocations.put(invocations.size(), scanPackage);
}
}
}
diff --git a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/query/criteria/CriteriaBuilderTest.java b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/query/criteria/CriteriaBuilderTest.java
index 6dfc0187e..94b6709a6 100644
--- a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/query/criteria/CriteriaBuilderTest.java
+++ b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/query/criteria/CriteriaBuilderTest.java
@@ -14,7 +14,7 @@
*/
package cz.cvut.kbss.jopa.query.criteria;
-import cz.cvut.kbss.jopa.environment.*;
+import cz.cvut.kbss.jopa.environment.OWLClassA;
import cz.cvut.kbss.jopa.environment.utils.MetamodelMocks;
import cz.cvut.kbss.jopa.model.MetamodelImpl;
import cz.cvut.kbss.jopa.model.query.criteria.CriteriaQuery;
@@ -24,18 +24,28 @@
import cz.cvut.kbss.jopa.sessions.CriteriaBuilder;
import cz.cvut.kbss.jopa.sessions.MetamodelProvider;
import cz.cvut.kbss.jopa.sessions.UnitOfWorkImpl;
-import org.junit.jupiter.api.*;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+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 org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
import java.util.Collections;
-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.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
public class CriteriaBuilderTest {
@Mock
@@ -50,7 +60,6 @@ static void init() {
@BeforeEach
void setUp() throws Exception {
- MockitoAnnotations.openMocks(this);
final MetamodelImpl metamodel = mock(MetamodelImpl.class);
new MetamodelMocks().setMocks(metamodel);
final MetamodelProvider mpp = mock(MetamodelProvider.class);
diff --git a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/query/criteria/CriteriaQueryTranslateQueryTest.java b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/query/criteria/CriteriaQueryTranslateQueryTest.java
index 366fbfd3f..dd962d2c8 100644
--- a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/query/criteria/CriteriaQueryTranslateQueryTest.java
+++ b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/query/criteria/CriteriaQueryTranslateQueryTest.java
@@ -14,22 +14,30 @@
*/
package cz.cvut.kbss.jopa.query.criteria;
-import cz.cvut.kbss.jopa.environment.*;
+import cz.cvut.kbss.jopa.environment.OWLClassA;
+import cz.cvut.kbss.jopa.environment.OWLClassA_;
+import cz.cvut.kbss.jopa.environment.OWLClassD;
+import cz.cvut.kbss.jopa.environment.OWLClassD_;
+import cz.cvut.kbss.jopa.environment.OWLClassF;
+import cz.cvut.kbss.jopa.environment.OWLClassM;
+import cz.cvut.kbss.jopa.environment.OWLClassU;
+import cz.cvut.kbss.jopa.environment.utils.Generators;
import cz.cvut.kbss.jopa.environment.utils.MetamodelMocks;
import cz.cvut.kbss.jopa.model.CriteriaQueryImpl;
import cz.cvut.kbss.jopa.model.MetamodelImpl;
-import cz.cvut.kbss.jopa.model.query.criteria.CriteriaQuery;
import cz.cvut.kbss.jopa.model.query.criteria.ParameterExpression;
import cz.cvut.kbss.jopa.model.query.criteria.Predicate;
import cz.cvut.kbss.jopa.model.query.criteria.Root;
-import cz.cvut.kbss.jopa.sessions.CriteriaBuilder;
import cz.cvut.kbss.jopa.sessions.MetamodelProvider;
import cz.cvut.kbss.jopa.sessions.UnitOfWorkImpl;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
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 org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
import java.util.ArrayList;
import java.util.Collections;
@@ -41,17 +49,18 @@
import static org.mockito.Mockito.when;
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
public class CriteriaQueryTranslateQueryTest {
@Mock
private UnitOfWorkImpl uowMock;
- private CriteriaBuilder cb;
+ private CriteriaBuilderImpl cb;
private CriteriaParameterFiller criteriaParameterFiller;
@BeforeEach
void setUp() throws Exception {
- MockitoAnnotations.openMocks(this);
final MetamodelImpl metamodel = mock(MetamodelImpl.class);
new MetamodelMocks().setMocks(metamodel);
final MetamodelProvider mpp = mock(MetamodelProvider.class);
@@ -60,64 +69,61 @@ void setUp() throws Exception {
when(metamodel.getEntities()).thenReturn(Collections.emptySet());
when(mpp.isEntityType(any())).thenAnswer(inv -> metamodel.isEntityType(inv.getArgument(0)));
- cb = new CriteriaBuilderImpl(uowMock);
- criteriaParameterFiller = new CriteriaParameterFiller();
+ this.cb = new CriteriaBuilderImpl(uowMock);
+ this.criteriaParameterFiller = new CriteriaParameterFiller();
}
@Test
public void testTranslateQuerySelectAll() {
- CriteriaQuery query = cb.createQuery(OWLClassA.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassA.class);
Root root = query.from(OWLClassA.class);
query.select(root);
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery = "SELECT owlclassa FROM OWLClassA owlclassa";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
}
@Test
public void testTranslateQuerySelectDistinctAll() {
- CriteriaQuery query = cb.createQuery(OWLClassA.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassA.class);
Root root = query.from(OWLClassA.class);
query.select(root).distinct(true);
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery = "SELECT DISTINCT owlclassa FROM OWLClassA owlclassa";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
}
@Test
public void testTranslateQueryCount() {
- CriteriaQuery query = cb.createQuery(Integer.class);
+ CriteriaQueryImpl query = cb.createQuery(Integer.class);
Root root = query.from(OWLClassA.class);
query.select(cb.count(root));
- final String generatedSoqlQuery = ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery = "SELECT COUNT(owlclassa) FROM OWLClassA owlclassa";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
}
@Test
public void testTranslateQueryDistinctCount() {
- CriteriaQuery query = cb.createQuery(Integer.class);
+ CriteriaQueryImpl query = cb.createQuery(Integer.class);
Root root = query.from(OWLClassA.class);
query.select(cb.count(root)).distinct(true);
- final String generatedSoqlQuery = ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery = "SELECT DISTINCT COUNT(owlclassa) FROM OWLClassA owlclassa";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
}
@Test
public void testTranslateQuerySelectAllOrderByEntityDesc() {
- CriteriaQuery query = cb.createQuery(OWLClassA.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassA.class);
Root root = query.from(OWLClassA.class);
query.select(root).orderBy(cb.desc(root));
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery = "SELECT owlclassa FROM OWLClassA owlclassa ORDER BY owlclassa DESC";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
}
@@ -127,36 +133,33 @@ public void testTranslateQuerySelectAllOrderByEntityDesc() {
class StringBasedPropertyQueryTests {
@Test
public void testTranslateQuerySelectProperty() {
- CriteriaQuery query = cb.createQuery(String.class);
+ CriteriaQueryImpl query = cb.createQuery(String.class);
Root root = query.from(OWLClassA.class);
query.select(root.getAttr("stringAttribute"));
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery = "SELECT owlclassa.stringAttribute FROM OWLClassA owlclassa";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
}
@Test
public void testTranslateQuerySelectPropertyPath() {
- CriteriaQuery query = cb.createQuery(String.class);
+ CriteriaQueryImpl query = cb.createQuery(String.class);
Root root = query.from(OWLClassD.class);
query.select(root.getAttr("owlClassA").getAttr("stringAttribute"));
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery = "SELECT owlclassd.owlClassA.stringAttribute FROM OWLClassD owlclassd";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
}
@Test
public void testTranslateQueryEqualRestriction() {
- CriteriaQuery query = cb.createQuery(OWLClassA.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassA.class);
Root root = query.from(OWLClassA.class);
query.select(root).where(cb.equal(root.getAttr("stringAttribute"), "value"));
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery =
"SELECT owlclassa FROM OWLClassA owlclassa WHERE owlclassa.stringAttribute = :generatedName0";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
@@ -164,12 +167,11 @@ public void testTranslateQueryEqualRestriction() {
@Test
public void testTranslateQueryNotEqualRestriction() {
- CriteriaQuery query = cb.createQuery(OWLClassA.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassA.class);
Root root = query.from(OWLClassA.class);
query.select(root).where(cb.notEqual(root.getAttr("stringAttribute"), "value"));
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery =
"SELECT owlclassa FROM OWLClassA owlclassa WHERE owlclassa.stringAttribute <> :generatedName0";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
@@ -177,12 +179,11 @@ public void testTranslateQueryNotEqualRestriction() {
@Test
public void testTranslateQueryGreaterThanRestriction() {
- CriteriaQuery query = cb.createQuery(OWLClassM.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassM.class);
Root root = query.from(OWLClassM.class);
query.select(root).where(cb.greaterThan(root.getAttr("intAttribute"), 1));
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery =
"SELECT owlclassm FROM OWLClassM owlclassm WHERE owlclassm.intAttribute > :generatedName0";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
@@ -190,12 +191,11 @@ public void testTranslateQueryGreaterThanRestriction() {
@Test
public void testTranslateQueryGreaterThanNegated() {
- CriteriaQuery query = cb.createQuery(OWLClassM.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassM.class);
Root root = query.from(OWLClassM.class);
query.select(root).where(cb.greaterThan(root.getAttr("intAttribute"), 1).not());
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery =
"SELECT owlclassm FROM OWLClassM owlclassm WHERE owlclassm.intAttribute <= :generatedName0";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
@@ -203,12 +203,11 @@ public void testTranslateQueryGreaterThanNegated() {
@Test
public void testTranslateQueryGreaterThanOrEqualRestriction() {
- CriteriaQuery query = cb.createQuery(OWLClassM.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassM.class);
Root root = query.from(OWLClassM.class);
query.select(root).where(cb.greaterThanOrEqual(root.getAttr("intAttribute"), 1));
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery =
"SELECT owlclassm FROM OWLClassM owlclassm WHERE owlclassm.intAttribute >= :generatedName0";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
@@ -216,12 +215,11 @@ public void testTranslateQueryGreaterThanOrEqualRestriction() {
@Test
public void testTranslateQueryGreaterOrEqualNegated() {
- CriteriaQuery query = cb.createQuery(OWLClassM.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassM.class);
Root root = query.from(OWLClassM.class);
query.select(root).where(cb.greaterThanOrEqual(root.getAttr("intAttribute"), 1).not());
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery =
"SELECT owlclassm FROM OWLClassM owlclassm WHERE owlclassm.intAttribute < :generatedName0";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
@@ -229,12 +227,11 @@ public void testTranslateQueryGreaterOrEqualNegated() {
@Test
public void testTranslateQueryLessThanRestriction() {
- CriteriaQuery query = cb.createQuery(OWLClassM.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassM.class);
Root root = query.from(OWLClassM.class);
query.select(root).where(cb.lessThan(root.getAttr("intAttribute"), 1));
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery =
"SELECT owlclassm FROM OWLClassM owlclassm WHERE owlclassm.intAttribute < :generatedName0";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
@@ -242,12 +239,11 @@ public void testTranslateQueryLessThanRestriction() {
@Test
public void testTranslateQueryLessThanNegated() {
- CriteriaQuery query = cb.createQuery(OWLClassM.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassM.class);
Root root = query.from(OWLClassM.class);
query.select(root).where(cb.lessThan(root.getAttr("intAttribute"), 1).not());
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl) query).translateQuery(criteriaParameterFiller);
+ final String generatedSoqlQuery = query.translateQuery(criteriaParameterFiller);
final String expectedSoqlQuery =
"SELECT owlclassm FROM OWLClassM owlclassm WHERE owlclassm.intAttribute >= :generatedName0";
assertEquals(expectedSoqlQuery, generatedSoqlQuery);
@@ -255,12 +251,11 @@ public void testTranslateQueryLessThanNegated() {
@Test
public void testTranslateQueryLessOrEqualRestriction() {
- CriteriaQuery query = cb.createQuery(OWLClassM.class);
+ CriteriaQueryImpl query = cb.createQuery(OWLClassM.class);
Root root = query.from(OWLClassM.class);
query.select(root).where(cb.lessThanOrEqual(root.getAttr("intAttribute"), 1));
- final String generatedSoqlQuery =
- ((CriteriaQueryImpl