From 70ee5a6b3962cef90e5723a7bb6ece8df92ed390 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Thu, 5 Mar 2020 20:04:34 +0100 Subject: [PATCH] Make SQLWhere and SQLOrderBy generic --- src/main/java/fr/pandacube/util/orm/ORM.java | 62 +++++++++---------- .../fr/pandacube/util/orm/SQLElement.java | 11 ++-- .../fr/pandacube/util/orm/SQLElementList.java | 18 +++--- .../java/fr/pandacube/util/orm/SQLField.java | 28 ++++----- .../fr/pandacube/util/orm/SQLOrderBy.java | 20 +++--- .../java/fr/pandacube/util/orm/SQLUpdate.java | 6 +- .../java/fr/pandacube/util/orm/SQLWhere.java | 22 +++---- .../fr/pandacube/util/orm/SQLWhereAnd.java | 7 ++- .../fr/pandacube/util/orm/SQLWhereChain.java | 9 ++- .../fr/pandacube/util/orm/SQLWhereComp.java | 2 +- .../fr/pandacube/util/orm/SQLWhereIn.java | 6 +- .../fr/pandacube/util/orm/SQLWhereLike.java | 6 +- .../fr/pandacube/util/orm/SQLWhereNull.java | 6 +- .../fr/pandacube/util/orm/SQLWhereOr.java | 7 ++- 14 files changed, 101 insertions(+), 109 deletions(-) diff --git a/src/main/java/fr/pandacube/util/orm/ORM.java b/src/main/java/fr/pandacube/util/orm/ORM.java index 2aa8384..a4edcd0 100644 --- a/src/main/java/fr/pandacube/util/orm/ORM.java +++ b/src/main/java/fr/pandacube/util/orm/ORM.java @@ -5,6 +5,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -14,7 +15,6 @@ import java.util.function.Consumer; import org.javatuples.Pair; import fr.pandacube.util.Log; -import fr.pandacube.util.orm.SQLWhereComp.SQLComparator; /** * ORM = Object-Relational Mapping @@ -102,39 +102,35 @@ public final class ORM { return (SQLField) SQLElement.fieldsCache.get(elemClass).get("id"); } - public static > SQLElementList getByIds(Class elemClass, Collection ids) - throws ORMException { - return getByIds(elemClass, ids.toArray(new Integer[ids.size()])); + public static > SQLElementList getByIds(Class elemClass, Integer... ids) throws ORMException { + return getByIds(elemClass, Arrays.asList(ids)); } - public static > SQLElementList getByIds(Class elemClass, Integer... ids) throws ORMException { - SQLField idField = getSQLIdField(elemClass); - SQLWhereChain where = new SQLWhereOr(); - for (Integer id : ids) - if (id != null) where.or(new SQLWhereComp(idField, SQLComparator.EQ, id)); - return getAll(elemClass, where, SQLOrderBy.asc(idField), 1, null); + public static > SQLElementList getByIds(Class elemClass, Collection ids) + throws ORMException { + return getAll(elemClass, getSQLIdField(elemClass).in(ids), SQLOrderBy.asc(getSQLIdField(elemClass)), 1, null); } public static > E getById(Class elemClass, int id) throws ORMException { - return getFirst(elemClass, new SQLWhereComp(getSQLIdField(elemClass), SQLComparator.EQ, id)); + return getFirst(elemClass, getSQLIdField(elemClass).eq(id)); } - public static > E getFirst(Class elemClass, SQLWhere where) + public static > E getFirst(Class elemClass, SQLWhere where) throws ORMException { return getFirst(elemClass, where, null, null); } - public static > E getFirst(Class elemClass, SQLOrderBy orderBy) + public static > E getFirst(Class elemClass, SQLOrderBy orderBy) throws ORMException { return getFirst(elemClass, null, orderBy, null); } - public static > E getFirst(Class elemClass, SQLWhere where, SQLOrderBy orderBy) + public static > E getFirst(Class elemClass, SQLWhere where, SQLOrderBy orderBy) throws ORMException { return getFirst(elemClass, where, orderBy, null); } - public static > E getFirst(Class elemClass, SQLWhere where, SQLOrderBy orderBy, Integer offset) + public static > E getFirst(Class elemClass, SQLWhere where, SQLOrderBy orderBy, Integer offset) throws ORMException { SQLElementList elts = getAll(elemClass, where, orderBy, 1, offset); return (elts.size() == 0) ? null : elts.get(0); @@ -144,22 +140,22 @@ public final class ORM { return getAll(elemClass, null, null, null, null); } - public static > SQLElementList getAll(Class elemClass, SQLWhere where) throws ORMException { + public static > SQLElementList getAll(Class elemClass, SQLWhere where) throws ORMException { return getAll(elemClass, where, null, null, null); } - public static > SQLElementList getAll(Class elemClass, SQLWhere where, - SQLOrderBy orderBy) throws ORMException { + public static > SQLElementList getAll(Class elemClass, SQLWhere where, + SQLOrderBy orderBy) throws ORMException { return getAll(elemClass, where, orderBy, null, null); } - public static > SQLElementList getAll(Class elemClass, SQLWhere where, - SQLOrderBy orderBy, Integer limit) throws ORMException { + public static > SQLElementList getAll(Class elemClass, SQLWhere where, + SQLOrderBy orderBy, Integer limit) throws ORMException { return getAll(elemClass, where, orderBy, limit, null); } - public static > SQLElementList getAll(Class elemClass, SQLWhere where, - SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException { + public static > SQLElementList getAll(Class elemClass, SQLWhere where, + SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException { SQLElementList elmts = new SQLElementList<>(); forEach(elemClass, where, orderBy, limit, offset, elmts::add); return elmts; @@ -169,23 +165,23 @@ public final class ORM { forEach(elemClass, null, null, null, null, action); } - public static > void forEach(Class elemClass, SQLWhere where, + public static > void forEach(Class elemClass, SQLWhere where, Consumer action) throws ORMException { forEach(elemClass, where, null, null, null, action); } - public static > void forEach(Class elemClass, SQLWhere where, - SQLOrderBy orderBy, Consumer action) throws ORMException { + public static > void forEach(Class elemClass, SQLWhere where, + SQLOrderBy orderBy, Consumer action) throws ORMException { forEach(elemClass, where, orderBy, null, null, action); } - public static > void forEach(Class elemClass, SQLWhere where, - SQLOrderBy orderBy, Integer limit, Consumer action) throws ORMException { + public static > void forEach(Class elemClass, SQLWhere where, + SQLOrderBy orderBy, Integer limit, Consumer action) throws ORMException { forEach(elemClass, where, orderBy, limit, null, action); } - public static > void forEach(Class elemClass, SQLWhere where, - SQLOrderBy orderBy, Integer limit, Integer offset, Consumer action) throws ORMException { + public static > void forEach(Class elemClass, SQLWhere where, + SQLOrderBy orderBy, Integer limit, Integer offset, Consumer action) throws ORMException { initTable(elemClass); try { @@ -221,7 +217,7 @@ public final class ORM { return count(elemClass, null); } - public static > long count(Class elemClass, SQLWhere where) throws ORMException { + public static > long count(Class elemClass, SQLWhere where) throws ORMException { initTable(elemClass); try { @@ -276,11 +272,11 @@ public final class ORM { - public static > SQLUpdate update(Class elemClass, SQLWhere where) throws ORMException { + public static > SQLUpdate update(Class elemClass, SQLWhere where) throws ORMException { return new SQLUpdate<>(elemClass, where); } - /* package */ static > int update(Class elemClass, SQLWhere where, Map, Object> values) throws ORMException { + /* package */ static > int update(Class elemClass, SQLWhere where, Map, Object> values) throws ORMException { return new SQLUpdate<>(elemClass, where, values).execute(); } @@ -292,7 +288,7 @@ public final class ORM { * @return The return value of {@link PreparedStatement#executeUpdate()}, for an SQL query {@code DELETE}. * @throws ORMException */ - public static > int delete(Class elemClass, SQLWhere where) throws ORMException { + public static > int delete(Class elemClass, SQLWhere where) throws ORMException { initTable(elemClass); if (where == null) { diff --git a/src/main/java/fr/pandacube/util/orm/SQLElement.java b/src/main/java/fr/pandacube/util/orm/SQLElement.java index bb54bbb..1fb224b 100644 --- a/src/main/java/fr/pandacube/util/orm/SQLElement.java +++ b/src/main/java/fr/pandacube/util/orm/SQLElement.java @@ -21,7 +21,6 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import fr.pandacube.util.Log; -import fr.pandacube.util.orm.SQLWhereComp.SQLComparator; public abstract class SQLElement> { /** cache for fields for each subclass of SQLElement */ @@ -190,8 +189,7 @@ public abstract class SQLElement> { public > P getReferencedEntry(SQLFKField field) throws ORMException { T fkValue = get(field); if (fkValue == null) return null; - return ORM.getFirst(field.getForeignElementClass(), - new SQLWhereComp(field.getPrimaryField(), SQLComparator.EQ, fkValue), null); + return ORM.getFirst(field.getForeignElementClass(), field.getPrimaryField().eq(fkValue), null); } /** @@ -199,11 +197,10 @@ public abstract class SQLElement> { * @param the table class of the foreign key that reference a primary key of this element. * @return all elements in the table F for which the specified foreign key value correspond to the primary key of this element. */ - public > SQLElementList getReferencingForeignEntries(SQLFKField field, SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException { + public > SQLElementList getReferencingForeignEntries(SQLFKField field, SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException { T value = get(field.getPrimaryField()); if (value == null) return new SQLElementList<>(); - return ORM.getAll(field.getSQLElementType(), - new SQLWhereComp(field, SQLComparator.EQ, value), orderBy, limit, offset); + return ORM.getAll(field.getSQLElementType(), field.eq(value), orderBy, limit, offset); } public boolean isValidForSave() { @@ -241,7 +238,7 @@ public abstract class SQLElement> { if (modifiedValues.isEmpty()) return; - ORM.update((Class)getClass(), new SQLWhereComp(getFieldId(), SQLComparator.EQ, getId()), modifiedValues); + ORM.update((Class)getClass(), getFieldId().eq(getId()), modifiedValues); } else { // ajouter dans la base diff --git a/src/main/java/fr/pandacube/util/orm/SQLElementList.java b/src/main/java/fr/pandacube/util/orm/SQLElementList.java index 27806cd..208aa33 100644 --- a/src/main/java/fr/pandacube/util/orm/SQLElementList.java +++ b/src/main/java/fr/pandacube/util/orm/SQLElementList.java @@ -14,7 +14,6 @@ import java.util.stream.Collectors; import com.google.gson.JsonArray; import fr.pandacube.util.Log; -import fr.pandacube.util.orm.SQLWhereComp.SQLComparator; /** * @@ -85,8 +84,7 @@ public class SQLElementList> extends ArrayList { Class classEl = (Class)storedEl.get(0).getClass(); int ret = ORM.update(classEl, - new SQLWhereIn(storedEl.get(0).getFieldId(), - storedEl.stream().map(SQLElement::getId).collect(Collectors.toList()) + storedEl.get(0).getFieldId().in(storedEl.stream().map(SQLElement::getId).collect(Collectors.toList()) ), modifiedValues); @@ -140,7 +138,7 @@ public class SQLElementList> extends ArrayList { - public > 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 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 params = new ArrayList<>(); boolean first = true; - for (SQLWhere w : conditions) { + for (SQLWhere w : conditions) { if (!first) sql += " " + operator.sql + " "; first = false; diff --git a/src/main/java/fr/pandacube/util/orm/SQLWhereComp.java b/src/main/java/fr/pandacube/util/orm/SQLWhereComp.java index 2c719a7..bbe481e 100644 --- a/src/main/java/fr/pandacube/util/orm/SQLWhereComp.java +++ b/src/main/java/fr/pandacube/util/orm/SQLWhereComp.java @@ -5,7 +5,7 @@ import java.util.List; import org.javatuples.Pair; -/* package */ class SQLWhereComp extends SQLWhere { +/* package */ class SQLWhereComp> extends SQLWhere { private SQLField left; private SQLComparator comp; diff --git a/src/main/java/fr/pandacube/util/orm/SQLWhereIn.java b/src/main/java/fr/pandacube/util/orm/SQLWhereIn.java index 526746f..bb1197b 100644 --- a/src/main/java/fr/pandacube/util/orm/SQLWhereIn.java +++ b/src/main/java/fr/pandacube/util/orm/SQLWhereIn.java @@ -6,12 +6,12 @@ import java.util.List; import org.javatuples.Pair; -/* package */ class SQLWhereIn extends SQLWhere { +/* package */ class SQLWhereIn> extends SQLWhere { - private SQLField field; + private SQLField field; private Collection values; - /* package */ SQLWhereIn(SQLField f, Collection v) { + /* package */ SQLWhereIn(SQLField f, Collection v) { if (f == null || v == null) throw new IllegalArgumentException("All arguments for SQLWhereIn constructor can't be null"); field = f; diff --git a/src/main/java/fr/pandacube/util/orm/SQLWhereLike.java b/src/main/java/fr/pandacube/util/orm/SQLWhereLike.java index 4aa2e0c..85dde1f 100644 --- a/src/main/java/fr/pandacube/util/orm/SQLWhereLike.java +++ b/src/main/java/fr/pandacube/util/orm/SQLWhereLike.java @@ -5,9 +5,9 @@ import java.util.List; import org.javatuples.Pair; -/* package */ class SQLWhereLike extends SQLWhere { +/* package */ class SQLWhereLike> extends SQLWhere { - private SQLField field; + private SQLField field; private String likeExpr; /** @@ -16,7 +16,7 @@ import org.javatuples.Pair; * @param f the field at left of the LIKE keyword. Can't be null * @param like the like expression. */ - /* package */ SQLWhereLike(SQLField f, String like) { + /* package */ SQLWhereLike(SQLField f, String like) { if (f == null || like == null) throw new IllegalArgumentException("All arguments for SQLWhereLike constructor can't be null"); field = f; diff --git a/src/main/java/fr/pandacube/util/orm/SQLWhereNull.java b/src/main/java/fr/pandacube/util/orm/SQLWhereNull.java index b8cb409..a78b6c8 100644 --- a/src/main/java/fr/pandacube/util/orm/SQLWhereNull.java +++ b/src/main/java/fr/pandacube/util/orm/SQLWhereNull.java @@ -8,9 +8,9 @@ import org.javatuples.Pair; import fr.pandacube.util.Log; -/* package */ class SQLWhereNull extends SQLWhere { +/* package */ class SQLWhereNull> extends SQLWhere { - private SQLField fild; + private SQLField fild; private boolean nulll; /** @@ -20,7 +20,7 @@ import fr.pandacube.util.Log; * @param isNull true if we want to ckeck if "IS NULL", or false to check if * "IS NOT NULL" */ - /* package */ SQLWhereNull(SQLField field, boolean isNull) { + /* package */ SQLWhereNull(SQLField field, boolean isNull) { if (field == null) throw new IllegalArgumentException("field can't be null"); if (!field.canBeNull) Log.getLogger().log(Level.WARNING, "Useless : Trying to check IS [NOT] NULL on the field " + field.getSQLElementType().getName() + "#" diff --git a/src/main/java/fr/pandacube/util/orm/SQLWhereOr.java b/src/main/java/fr/pandacube/util/orm/SQLWhereOr.java index d64a409..6cb4ab4 100644 --- a/src/main/java/fr/pandacube/util/orm/SQLWhereOr.java +++ b/src/main/java/fr/pandacube/util/orm/SQLWhereOr.java @@ -1,14 +1,15 @@ package fr.pandacube.util.orm; -public class SQLWhereOr extends SQLWhereChain { +public class SQLWhereOr> extends SQLWhereChain { /* package */ SQLWhereOr() { super(SQLBoolOp.OR); } @Override - public SQLWhereOr or(SQLWhere other) { - return (SQLWhereOr) add(other); + public SQLWhereOr or(SQLWhere other) { + add(other); + return this; } }