Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,65 @@ private Expression<?> getExpression(AttributeConstraint c) {
@SuppressWarnings("unchecked")
private <T> Expression<T> getExpression(AttributeConstraint c, Class<T> type) {
Expression<?> expression = root.get(c.getAttribute());
expression.getJavaType().asSubclass(type);
boxed(expression.getJavaType()).asSubclass(type);
return (Expression<T>) expression;
}


private static Class<?> boxed(Class<?> type) {
if (type.isPrimitive()) {
if (type==boolean.class) return Boolean.class;
if (type==int.class) return Integer.class;
if (type==long.class) return Long.class;
if (type==byte.class) return Byte.class;
if (type==short.class) return Short.class;
if (type==char.class) return Character.class;
if (type==float.class) return Float.class;
if (type==double.class) return Double.class;
}
return type;
}

@Override
protected Predicate transformNegatedConstraint(NegatedConstraint c) {
return criteriaBuilder.not(transform(c.getConstraint()));
}

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Predicate transformRelationalConstraint(AttributeRelationalConstraint c) {
c.getAttribute();
Expression<Comparable> x = getExpression(c, Comparable.class);
Comparable y = c.getValue();
switch (c.getOperator()) {
case RelationalConstraint.EQ:
case RelationalConstraint.NE:
return transformEqualityConstraint(c);
default:
return transformComparisonConstraint(c);
}
}

private Predicate transformEqualityConstraint(AttributeRelationalConstraint c) {
Expression<?> x = getExpression(c);
Object y = (Comparable<?>) c.getValue();

switch (c.getOperator()) {
case RelationalConstraint.EQ: return criteriaBuilder.equal(x, y);
case RelationalConstraint.NE: return criteriaBuilder.notEqual(x, y);
default: return null;
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
private Predicate transformComparisonConstraint(AttributeRelationalConstraint c) {
Expression<Comparable> x = getExpression(c, Comparable.class);
Comparable y = (Comparable<?>) c.getValue();

switch (c.getOperator()) {
case RelationalConstraint.LE: return criteriaBuilder.lessThanOrEqualTo(x, y);
case RelationalConstraint.LT: return criteriaBuilder.lessThan(x, y);
case RelationalConstraint.GE: return criteriaBuilder.greaterThan(x, y);
case RelationalConstraint.GT: return criteriaBuilder.greaterThanOrEqualTo(x, y);
default: return null;
}
}

@Override
protected Predicate transformLikeConstraint(AttributeLikeConstraint c) {
return criteriaBuilder.like(getExpression(c, String.class), c.getPattern());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="person">
<class>com.appjars.saturn.model.Person</class>
<class>com.appjars.saturn.model.impl.Person</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
Expand Down

This file was deleted.

This file was deleted.

66 changes: 0 additions & 66 deletions commons-data/src/test/java/com/appjars/saturn/model/Person.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public Constraint not(Constraint c) {
return new NegatedConstraint(c);
}

public Constraint equal(String attribute, Comparable<?> value) {
public Constraint equal(String attribute, Object value) {
return new AttributeRelationalConstraint(attribute, value, RelationalConstraint.EQ);
}

public Constraint notEqual(String attribute, Comparable<?> value) {
public Constraint notEqual(String attribute, Object value) {
return new AttributeRelationalConstraint(attribute, value, RelationalConstraint.NE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class AttributeRelationalConstraint implements AttributeConstraint, RelationalConstraint {

@NonNull String attribute;
@NonNull Comparable<?> value;
@NonNull Object value;
@NonNull String operator;

}