> SQLElementList getReferencedEntries(SQLFKField foreignKey, SQLOrderBy orderBy) throws ORMException {
+ public > SQLElementList getReferencedEntries(SQLFKField foreignKey, SQLOrderBy orderBy) throws ORMException {
Set values = new HashSet<>();
forEach(v -> {
T val = v.get(foreignKey);
@@ -152,8 +150,8 @@ public class SQLElementList> extends ArrayList {
return new SQLElementList<>();
}
- SQLWhereChain where = SQLWhereChain.or();
- values.forEach(v -> where.or(new SQLWhereComp(foreignKey.getPrimaryField(), SQLComparator.EQ, v)));
+ SQLWhereOr where = SQLWhere.or();
+ values.forEach(v -> where.or(foreignKey.getPrimaryField().eq(v)));
return ORM.getAll(foreignKey.getForeignElementClass(), where, orderBy, null, null);
@@ -171,7 +169,7 @@ public class SQLElementList> extends ArrayList {
- public > SQLElementList getReferencingForeignEntries(SQLFKField foreignKey, SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException {
+ public > SQLElementList getReferencingForeignEntries(SQLFKField foreignKey, SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException {
Set values = new HashSet<>();
forEach(v -> {
T val = v.get(foreignKey.getPrimaryField());
@@ -183,15 +181,15 @@ public class SQLElementList> extends ArrayList {
return new SQLElementList<>();
}
- SQLWhereChain where = SQLWhere.or();
- values.forEach(v -> where.or(new SQLWhereComp(foreignKey, SQLComparator.EQ, v)));
+ SQLWhereOr where = SQLWhere.or();
+ values.forEach(v -> where.or(foreignKey.eq(v)));
return ORM.getAll(foreignKey.getSQLElementType(), where, orderBy, limit, offset);
}
- public > Map> getReferencingForeignEntriesInGroups(SQLFKField foreignKey, SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException {
+ public > Map> getReferencingForeignEntriesInGroups(SQLFKField foreignKey, SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException {
SQLElementList foreignElements = getReferencingForeignEntries(foreignKey, orderBy, limit, offset);
Map> map = new HashMap<>();
diff --git a/src/main/java/fr/pandacube/util/orm/SQLField.java b/src/main/java/fr/pandacube/util/orm/SQLField.java
index 4e73199..2a53907 100644
--- a/src/main/java/fr/pandacube/util/orm/SQLField.java
+++ b/src/main/java/fr/pandacube/util/orm/SQLField.java
@@ -92,43 +92,43 @@ public class SQLField, T> {
- public SQLWhere eq(T r) {
+ public SQLWhere eq(T r) {
return comp(SQLComparator.EQ, r);
}
- public SQLWhere geq(T r) {
+ public SQLWhere geq(T r) {
return comp(SQLComparator.GEQ, r);
}
- public SQLWhere gt(T r) {
+ public SQLWhere gt(T r) {
return comp(SQLComparator.GT, r);
}
- public SQLWhere leq(T r) {
+ public SQLWhere leq(T r) {
return comp(SQLComparator.LEQ, r);
}
- public SQLWhere lt(T r) {
+ public SQLWhere lt(T r) {
return comp(SQLComparator.LT, r);
}
- public SQLWhere neq(T r) {
+ public SQLWhere neq(T r) {
return comp(SQLComparator.NEQ, r);
}
- private SQLWhere comp(SQLComparator c, T r) {
- return new SQLWhereComp(this, c, r);
+ private SQLWhere comp(SQLComparator c, T r) {
+ return new SQLWhereComp<>(this, c, r);
}
- public SQLWhere in(Collection v) {
- return new SQLWhereIn(this, v);
+ public SQLWhere in(Collection v) {
+ return new SQLWhereIn<>(this, v);
}
- public SQLWhere isNull() {
- return new SQLWhereNull(this, true);
+ public SQLWhere isNull() {
+ return new SQLWhereNull<>(this, true);
}
- public SQLWhere isNotNull() {
- return new SQLWhereNull(this, false);
+ public SQLWhere isNotNull() {
+ return new SQLWhereNull<>(this, false);
}
}
diff --git a/src/main/java/fr/pandacube/util/orm/SQLOrderBy.java b/src/main/java/fr/pandacube/util/orm/SQLOrderBy.java
index 401337a..2e98c48 100644
--- a/src/main/java/fr/pandacube/util/orm/SQLOrderBy.java
+++ b/src/main/java/fr/pandacube/util/orm/SQLOrderBy.java
@@ -3,7 +3,7 @@ package fr.pandacube.util.orm;
import java.util.ArrayList;
import java.util.List;
-public class SQLOrderBy {
+public class SQLOrderBy> {
private List orderByFields = new ArrayList<>();
@@ -19,7 +19,7 @@ public class SQLOrderBy {
* @param d le sens de tri (croissant ASC ou décroissant DESC)
* @return l'objet courant (permet de chainer les ajouts de champs)
*/
- private SQLOrderBy add(SQLField, ?> field, Direction d) {
+ private SQLOrderBy add(SQLField field, Direction d) {
orderByFields.add(new OBField(field, d));
return this;
}
@@ -30,7 +30,7 @@ public class SQLOrderBy {
* @param field le champ SQL à ordonner
* @return l'objet courant (permet de chainer les ajouts de champs)
*/
- public SQLOrderBy thenAsc(SQLField, ?> field) {
+ public SQLOrderBy thenAsc(SQLField field) {
return add(field, Direction.ASC);
}
@@ -40,7 +40,7 @@ public class SQLOrderBy {
* @param field le champ SQL à ordonner
* @return l'objet courant (permet de chainer les ajouts de champs)
*/
- public SQLOrderBy thenDesc(SQLField, ?> field) {
+ public SQLOrderBy thenDesc(SQLField field) {
return add(field, Direction.DESC);
}
@@ -61,10 +61,10 @@ public class SQLOrderBy {
}
private class OBField {
- public final SQLField, ?> field;
+ public final SQLField field;
public final Direction direction;
- public OBField(SQLField, ?> f, Direction d) {
+ public OBField(SQLField f, Direction d) {
field = f;
direction = d;
}
@@ -83,12 +83,12 @@ public class SQLOrderBy {
- public static SQLOrderBy asc(SQLField, ?> field) {
- return new SQLOrderBy().thenAsc(field);
+ public static > SQLOrderBy asc(SQLField field) {
+ return new SQLOrderBy().thenAsc(field);
}
- public static SQLOrderBy desc(SQLField, ?> field) {
- return new SQLOrderBy().thenDesc(field);
+ public static > SQLOrderBy desc(SQLField field) {
+ return new SQLOrderBy().thenDesc(field);
}
diff --git a/src/main/java/fr/pandacube/util/orm/SQLUpdate.java b/src/main/java/fr/pandacube/util/orm/SQLUpdate.java
index 295ab2f..b1922ec 100644
--- a/src/main/java/fr/pandacube/util/orm/SQLUpdate.java
+++ b/src/main/java/fr/pandacube/util/orm/SQLUpdate.java
@@ -12,16 +12,16 @@ import fr.pandacube.util.Log;
public class SQLUpdate> {
private final Class elemClass;
- private final SQLWhere where;
+ private final SQLWhere where;
private final Map, Object> values;
- /* package */ SQLUpdate(Class el, SQLWhere w) {
+ /* package */ SQLUpdate(Class el, SQLWhere w) {
elemClass = el;
where = w;
values = new HashMap<>();
}
- /* package */ SQLUpdate(Class el, SQLWhere w, Map, Object> v) {
+ /* package */ SQLUpdate(Class el, SQLWhere w, Map, Object> v) {
elemClass = el;
where = w;
values = v;
diff --git a/src/main/java/fr/pandacube/util/orm/SQLWhere.java b/src/main/java/fr/pandacube/util/orm/SQLWhere.java
index 6819cde..74641b3 100644
--- a/src/main/java/fr/pandacube/util/orm/SQLWhere.java
+++ b/src/main/java/fr/pandacube/util/orm/SQLWhere.java
@@ -6,7 +6,7 @@ import org.javatuples.Pair;
import fr.pandacube.util.Log;
-public abstract class SQLWhere {
+public abstract class SQLWhere> {
public abstract Pair> toSQL() throws ORMException;
@@ -20,26 +20,26 @@ public abstract class SQLWhere {
}
}
- public SQLWhereAnd and(SQLWhere other) {
- return and().and(this).and(other);
+ public SQLWhereAnd and(SQLWhere other) {
+ return new SQLWhereAnd().and(this).and(other);
}
- public SQLWhereOr or(SQLWhere other) {
- return or().or(this).or(other);
+ public SQLWhereOr or(SQLWhere other) {
+ return new SQLWhereOr().or(this).or(other);
}
- public static SQLWhereAnd and() {
- return new SQLWhereAnd();
+ public static > SQLWhereAnd and() {
+ return new SQLWhereAnd<>();
}
- public static SQLWhereOr or() {
- return new SQLWhereOr();
+ public static > SQLWhereOr or() {
+ return new SQLWhereOr<>();
}
- public static SQLWhere like(SQLField, String> f, String like) {
- return new SQLWhereLike(f, like);
+ public static > SQLWhere like(SQLField f, String like) {
+ return new SQLWhereLike(f, like);
}
}
diff --git a/src/main/java/fr/pandacube/util/orm/SQLWhereAnd.java b/src/main/java/fr/pandacube/util/orm/SQLWhereAnd.java
index b71cdf2..b30966a 100644
--- a/src/main/java/fr/pandacube/util/orm/SQLWhereAnd.java
+++ b/src/main/java/fr/pandacube/util/orm/SQLWhereAnd.java
@@ -1,14 +1,15 @@
package fr.pandacube.util.orm;
-public class SQLWhereAnd extends SQLWhereChain {
+public class SQLWhereAnd> extends SQLWhereChain {
/* package */ SQLWhereAnd() {
super(SQLBoolOp.AND);
}
@Override
- public SQLWhereAnd and(SQLWhere other) {
- return (SQLWhereAnd) add(other);
+ public SQLWhereAnd and(SQLWhere other) {
+ add(other);
+ return this;
}
}
diff --git a/src/main/java/fr/pandacube/util/orm/SQLWhereChain.java b/src/main/java/fr/pandacube/util/orm/SQLWhereChain.java
index b482405..550f72a 100644
--- a/src/main/java/fr/pandacube/util/orm/SQLWhereChain.java
+++ b/src/main/java/fr/pandacube/util/orm/SQLWhereChain.java
@@ -5,20 +5,19 @@ import java.util.List;
import org.javatuples.Pair;
-public abstract class SQLWhereChain extends SQLWhere {
+public abstract class SQLWhereChain> extends SQLWhere {
private SQLBoolOp operator;
- protected List conditions = new ArrayList<>();
+ protected List> conditions = new ArrayList<>();
/* package */ SQLWhereChain(SQLBoolOp op) {
if (op == null) throw new IllegalArgumentException("op can't be null");
operator = op;
}
- protected SQLWhereChain add(SQLWhere sqlWhere) {
+ protected void add(SQLWhere sqlWhere) {
if (sqlWhere == null) throw new IllegalArgumentException("sqlWhere can't be null");
conditions.add(sqlWhere);
- return this;
}
@Override
@@ -31,7 +30,7 @@ public abstract class SQLWhereChain extends SQLWhere {
List