Skip to content

Commit

Permalink
Merge pull request #158 from kbss-cvut/development
Browse files Browse the repository at this point in the history
[0.22.0] release
  • Loading branch information
ledsoft authored Apr 26, 2023
2 parents aaf0e68 + 0dc8344 commit e4c2ad5
Show file tree
Hide file tree
Showing 107 changed files with 2,064 additions and 659 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# JOPA - Release Notes

## 0.22.0 - 2023-04-26
- Allow selecting entities by identifier in SOQL/Criteria API (Enhancement #138).
- Extend SOQL/Criteria API with additional functions - `lower`, `upper`, `length`, `abs`, `ceil`, `floor` (Enhancement #152).
- Fix an issue with interaction of lazy loading with inferred-valued attributes (Bug #150).
- Fix a possible NPX when unpersisted empty entity is referenced in another entity's equals/hashCode.

## 0.21.1 - 2023-03-21
- Allow using generic types as plural attribute value elements.

Expand Down
2 changes: 1 addition & 1 deletion datatype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>jopa-all</artifactId>
<groupId>cz.cvut.kbss.jopa</groupId>
<version>0.21.1</version>
<version>0.22.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion jopa-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>0.21.1</version>
<version>0.22.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public static CollectionType fromClass(Class<?> cls) {
return type;
}
}
throw new IllegalArgumentException("Unsupported collection class " + cls);
throw new IllegalArgumentException("Unsupported collection type " + cls);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @param <X> Declaring class
* @param <E> Type of the ID field
*/
public interface Identifier<X, E> extends FieldSpecification<X, E> {
public interface Identifier<X, E> extends FieldSpecification<X, E>, Bindable<E> {

void accept(IdentifierVisitor i);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ enum BooleanOperator {
AND("AND"),
OR("OR");

private final String booleanOperator;
private final String operator;

BooleanOperator(String booleanOperator) {
this.booleanOperator = booleanOperator;
BooleanOperator(String operator) {
this.operator = operator;
}

@Override
public String toString() {
return booleanOperator;
return operator;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
*/
package cz.cvut.kbss.jopa.model.query.criteria;

import cz.cvut.kbss.jopa.model.query.TupleElement;

import java.util.List;

public interface Selection<X> {
public interface Selection<X> extends TupleElement<X> {

/**
* Whether the selection item is a compound selection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,128 @@
*/
package cz.cvut.kbss.jopa.sessions;

import cz.cvut.kbss.jopa.model.query.criteria.*;
import cz.cvut.kbss.jopa.model.query.criteria.CriteriaQuery;
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;

/**
* Used to construct criteria queries, compound selections, expressions, predicates, orderings.
*/
public interface CriteriaBuilder extends PredicateFactory {


/**
* Create a CriteriaQuery object with the specified result type.
*
* @param resultClass type of the query result
* @return criteria query object
*/
<T> CriteriaQuery<T> createQuery(Class<T> resultClass);

/**
* Create an aggregate expression applying the count operation.
* Return type of count function in SPARQL is xsd:integer which JOPA internally represents as Integer.
* Create an expression that returns the absolute value of its argument.
*
* @param x expression
* @return absolute value
*/
<N extends Number> Expression<N> abs(Expression<N> x);

/**
* Create an expression that returns the smallest (closest to negative infinity) numeric value that is greater than
* or equal to the argument and is equal to a mathematical integer.
*
* @param x expression
* @return ceiling value
*/
<N extends Number> Expression<N> ceil(Expression<N> x);

/**
* Create an expression that returns the largest (closest to positive infinity) numeric value that is less than or
* equal to the argument and is equal to a mathematical integer.
*
* @param x expression
* @return floor value
*/
<N extends Number> Expression<N> floor(Expression<N> x);

/**
* Create an aggregate expression applying the count operation. Return type of count function in SPARQL is
* xsd:integer which JOPA internally represents as Integer.
*
* @param x expression representing input value to count operation
* @return count expression
*/
Expression<Integer> count(Expression<?> x);

/**
* Create expression to return length of a string.
*
* @param x string expression
* @return length expression
*/
Expression<Integer> length(Expression<String> x);

/**
* Create a parameter expression.
* @param paramClass - parameter class
*
* @param paramClass parameter class
* @return parameter expression
*/
<T> ParameterExpression<T> parameter(Class<T> paramClass);

/**
* Create a parameter expression with the given name.
* @param paramClass - parameter class
* @param name - name that can be used to refer to the parameter
*
* @param paramClass parameter class
* @param name name that can be used to refer to the parameter
* @return parameter expression
*/
<T> ParameterExpression<T> parameter(Class<T> paramClass, String name);

/**
* Create an expression for a literal.
*
* @param value - value represented by the expression
* @param value value represented by the expression
* @return expression literal
*/
<T> Expression<T> literal(T value);

/**
* Create an expression for a string literal with language tag.
* @param value - string value represented by the expression
* @param languageTag - string language tag
*
* @param value string value represented by the expression
* @param languageTag string language tag
* @return expression literal
*/
Expression<String> literal(String value, String languageTag);

/**
* Create expression for converting a string to lowercase.
*
* @param x string expression
* @return expression to convert to lowercase
*/
Expression<String> lower(Expression<String> x);

/**
* Create expression for converting a string to uppercase.
*
* @param x string expression
* @return expression to convert to uppercase
*/
Expression<String> upper(Expression<String> x);

/**
* Create an ordering by the ascending value of the expression.
*
* @param x expression used to define the ordering
* @return ascending ordering corresponding to the expression
*/
Order asc(Expression<?> x);

/**
* Create an ordering by the descending value of the expression.
*
* @param x expression used to define the ordering
* @return descending ordering corresponding to the expression
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cz.cvut.kbss.jopa.model.metamodel;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.*;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class CollectionTypeTest {

@ParameterizedTest
@MethodSource("fromClassTestValues")
void fromClassReturnsMatchingEnumConstant(CollectionType expected, Class<?> cls) {
assertEquals(expected, CollectionType.fromClass(cls));
}

static Stream<Arguments> fromClassTestValues() {
return Stream.of(
Arguments.of(CollectionType.LIST, List.class),
Arguments.of(CollectionType.SET, Set.class),
Arguments.of(CollectionType.MAP, Map.class),
Arguments.of(CollectionType.COLLECTION, Collection.class),
// Test also some implementation classes
Arguments.of(CollectionType.LIST, ArrayList.class),
Arguments.of(CollectionType.SET, HashSet.class),
Arguments.of(CollectionType.MAP, HashMap.class)
);
}

@Test
void fromClassThrowsIllegalArgumentExceptionForUnsupportedClass() {
assertThrows(IllegalArgumentException.class, () -> CollectionType.fromClass(String.class));
}
}
2 changes: 1 addition & 1 deletion jopa-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>0.21.1</version>
<version>0.22.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion jopa-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>0.21.1</version>
<version>0.22.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
64 changes: 55 additions & 9 deletions jopa-impl/src/main/antlr4/cz/cvut/kbss/jopa/query/soql/Soql.g4
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ objWithOutAttr: object ;

distinct: DISTINCT ;

object: TEXT ;
object: IDENTIFICATION_VARIABLE ;

attribute: TEXT ;
attribute: IDENTIFICATION_VARIABLE ;

joinedParams: object DOT attribute (DOT attribute)+ ;



tables: tableWithName ;

table: TEXT ;
table: IDENTIFICATION_VARIABLE ;

tableName: TEXT ;
tableName: IDENTIFICATION_VARIABLE ;

tableWithName: table tableName ;

Expand Down Expand Up @@ -78,15 +78,60 @@ literal
;

likeExpression
: whereClauseParam ('NOT')? LIKE whereClauseValue
: stringExpression ('NOT')? LIKE whereClauseValue
;

comparisonExpression: whereClauseParam COMPARISON_OPERATOR whereClauseValue;
comparisonExpression
: stringExpression COMPARISON_OPERATOR stringExpression
| simpleArithmeticExpression COMPARISON_OPERATOR simpleArithmeticExpression
| whereClauseParam COMPARISON_OPERATOR ( whereClauseParam | whereClauseValue )
;

whereClauseValue: (QMARK TEXT QMARK) | COLONTEXT ;
whereClauseValue: (QMARK TEXT QMARK) | inputParameter ;

whereClauseParam: param | joinedParams ;

stringExpression
: whereClauseParam
| inputParameter
| functionsReturningStrings
;

functionsReturningStrings
: 'CONCAT' '(' stringExpression ',' stringExpression ')'
| 'SUBSTRING' '(' stringExpression ',' simpleArithmeticExpression ',' simpleArithmeticExpression ')'
| 'LOWER' '(' stringExpression ')'
| 'UPPER' '(' stringExpression ')'
;

simpleArithmeticExpression
: (arithmeticTerm) (('+' | '-') arithmeticTerm)*
;

arithmeticTerm
: (arithmeticFactor) (('*' | '/') arithmeticFactor)*
;

arithmeticFactor
: ('+' | '-')? arithmeticPrimary
;

arithmeticPrimary
: param
| literal
| '(' simpleArithmeticExpression ')'
| inputParameter
| functionsReturningNumerics
;

functionsReturningNumerics
: 'LENGTH' '(' stringExpression ')'
| 'ABS' '(' simpleArithmeticExpression ')'
| 'ROUND' '(' simpleArithmeticExpression ')'
| 'CEIL' '(' simpleArithmeticExpression ')'
| 'FLOOR' '(' simpleArithmeticExpression ')'
;

orderByClause: ORDERBY orderByFullFormComma orderByFullFormComma* ;

orderByFullFormComma: orderByFullForm ','? ;
Expand All @@ -101,6 +146,7 @@ groupByParamComma: groupByParam ','? ;

groupByParam: object DOT attribute (DOT attribute)* ;

inputParameter: COLON IDENTIFICATION_VARIABLE ;


SELECT: 'SELECT' ;
Expand Down Expand Up @@ -143,9 +189,9 @@ QMARK: '"' ;

COLON: ':' ;

TEXT: (LOWERCASE | UPPERCASE | DIGIT)+ ;
IDENTIFICATION_VARIABLE: (LOWERCASE | UPPERCASE | '_') (LOWERCASE | UPPERCASE | DIGIT | '_')* ;

COLONTEXT: COLON TEXT ;
TEXT: (LOWERCASE | UPPERCASE | DIGIT)+ ;

UPPERCASE: ('A'..'Z');

Expand Down
Loading

0 comments on commit e4c2ad5

Please sign in to comment.