From 65d173fa0440bd6c67a8bacd3740998208fd55ca Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Wed, 16 Jan 2019 11:15:42 +0100 Subject: [PATCH] refactoring foreigh key method and field --- src/main/java/fr/pandacube/java/util/orm/SQLElement.java | 4 ++-- .../java/fr/pandacube/java/util/orm/SQLElementList.java | 4 ++-- src/main/java/fr/pandacube/java/util/orm/SQLFKField.java | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/pandacube/java/util/orm/SQLElement.java b/src/main/java/fr/pandacube/java/util/orm/SQLElement.java index 08d1e4a..394b7dd 100644 --- a/src/main/java/fr/pandacube/java/util/orm/SQLElement.java +++ b/src/main/java/fr/pandacube/java/util/orm/SQLElement.java @@ -175,11 +175,11 @@ public abstract class SQLElement> { T fkValue = get(field); if (fkValue == null) return null; return ORM.getFirst(field.getForeignElementClass(), - new SQLWhereComp(field.getForeignField(), SQLComparator.EQ, fkValue), null); + new SQLWhereComp(field.getPrimaryField(), SQLComparator.EQ, fkValue), null); } public > SQLElementList getForeignKeySources(SQLFKField field, SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException { - T value = get(field.getForeignField()); + 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); diff --git a/src/main/java/fr/pandacube/java/util/orm/SQLElementList.java b/src/main/java/fr/pandacube/java/util/orm/SQLElementList.java index b3eab1d..b54351f 100644 --- a/src/main/java/fr/pandacube/java/util/orm/SQLElementList.java +++ b/src/main/java/fr/pandacube/java/util/orm/SQLElementList.java @@ -174,13 +174,13 @@ public class SQLElementList> extends ArrayList { } SQLWhereChain where = new SQLWhereChain(SQLBoolOp.OR); - values.forEach(v -> where.add(new SQLWhereComp(foreignKey.getForeignField(), SQLComparator.EQ, v))); + values.forEach(v -> where.add(new SQLWhereComp(foreignKey.getPrimaryField(), SQLComparator.EQ, v))); SQLElementList foreignElemts = ORM.getAll(foreignKey.getForeignElementClass(), where, null, null, null); Map ret = new HashMap<>(); - foreignElemts.forEach(foreignVal -> ret.put(foreignVal.get(foreignKey.getForeignField()), foreignVal)); + foreignElemts.forEach(foreignVal -> ret.put(foreignVal.get(foreignKey.getPrimaryField()), foreignVal)); return ret; } diff --git a/src/main/java/fr/pandacube/java/util/orm/SQLFKField.java b/src/main/java/fr/pandacube/java/util/orm/SQLFKField.java index 25b39d3..ae4ac97 100644 --- a/src/main/java/fr/pandacube/java/util/orm/SQLFKField.java +++ b/src/main/java/fr/pandacube/java/util/orm/SQLFKField.java @@ -4,7 +4,7 @@ import fr.pandacube.java.util.Log; public class SQLFKField, T, F extends SQLElement> extends SQLField { - private SQLField sqlForeignKeyField; + private SQLField sqlPrimaryKeyField; private Class sqlForeignKeyElemClass; protected SQLFKField(SQLType t, boolean nul, T deflt, Class fkEl, SQLField fkF) { @@ -47,12 +47,12 @@ public class SQLFKField, T, F extends SQLElement> ext throw new IllegalArgumentException("foreignKeyField must be from supplied foreignKeyElement"); if (!type.equals(fkF.type)) throw new IllegalArgumentException("foreignKeyField and current Field must have the same SQLType"); - sqlForeignKeyField = fkF; + sqlPrimaryKeyField = fkF; sqlForeignKeyElemClass = fkEl; } - public SQLField getForeignField() { - return sqlForeignKeyField; + public SQLField getPrimaryField() { + return sqlPrimaryKeyField; } public Class getForeignElementClass() {