This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit e3e0875e0d69b273f14dd5d5dcd28c25d7a49561 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Aug 23 18:58:23 2016 +0200 Amélioration de gestion des associations dans les sql batch tables --- .../service/sql/batch/tables/TopiaSqlTable.java | 17 ++++- .../service/sql/batch/tables/TopiaSqlTables.java | 77 ++++++++++++++-------- 2 files changed, 66 insertions(+), 28 deletions(-) diff --git a/observe-topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTable.java b/observe-topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTable.java index df4c94a..6b14739 100644 --- a/observe-topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTable.java +++ b/observe-topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTable.java @@ -46,6 +46,8 @@ public class TopiaSqlTable { * Table name. */ protected final String tableName; + private final boolean associationTable; + private final String joinColumnName; /** * Fully table name (including the schema name). @@ -71,13 +73,17 @@ public class TopiaSqlTable { String tableName, String fromClause, String whereClauseAlias, - ImmutableSet<String> joinClauses) { + ImmutableSet<String> joinClauses, + boolean associationTable, + String joinColumnName) { this.schemaName = schemaName.toLowerCase(); this.tableName = tableName.toLowerCase(); + this.associationTable = associationTable; this.fullyTableName = this.schemaName + "." + this.tableName; this.fromClause = fromClause; this.whereClauseAlias = whereClauseAlias; this.joinClauses = joinClauses; + this.joinColumnName = joinColumnName; } public String getSchemaName() { @@ -118,6 +124,14 @@ public class TopiaSqlTable { return joinClauses; } + public boolean isAssociationTable() { + return associationTable; + } + + public String getJoinColumnName() { + return joinColumnName; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -135,6 +149,7 @@ public class TopiaSqlTable { public String toString() { return MoreObjects.toStringHelper(this) .add("fullyTableName", fullyTableName) + .add("associationTable", associationTable) .toString(); } } diff --git a/observe-topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTables.java b/observe-topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTables.java index 82f1a87..9cef9c7 100644 --- a/observe-topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTables.java +++ b/observe-topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTables.java @@ -27,6 +27,8 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaEntityEnum; import java.util.Collections; @@ -47,6 +49,9 @@ import java.util.TreeMap; */ public class TopiaSqlTables implements Iterable<TopiaSqlTable> { + /** Logger. */ + private static final Log log = LogFactory.getLog(TopiaSqlTables.class); + protected final ImmutableMap<String, TopiaSqlTable> tablesByFullyTableName; protected final ImmutableSet<TopiaSqlTable> orderedTables; @@ -76,14 +81,14 @@ public class TopiaSqlTables implements Iterable<TopiaSqlTable> { @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("orderedTables", orderedTables) - .toString(); + .add("orderedTables", orderedTables) + .toString(); } public TopiaSqlTables reverse() { - List<TopiaSqlTable> reverseList = new LinkedList<>(); + List<TopiaSqlTable> reverseList = new LinkedList<>(); for (TopiaSqlTable orderedTable : orderedTables) { - reverseList.add(0,orderedTable); + reverseList.add(0, orderedTable); } ImmutableSet<TopiaSqlTable> reverseSet = ImmutableSet.copyOf(reverseList); @@ -151,11 +156,7 @@ public class TopiaSqlTables implements Iterable<TopiaSqlTable> { String whereClauseAlias = tableName + ".topiaid"; String fromClause = schemaName + "." + tableName + " " + tableName; - registerTable(schemaName, - tableName, - whereClauseAlias, - fromClause, - ImmutableSet.of()); + registerTable(schemaName, tableName, whereClauseAlias, fromClause, ImmutableSet.of()); return new BuilderStepOnTableImpl(null, entityEnum); } @@ -171,7 +172,7 @@ public class TopiaSqlTables implements Iterable<TopiaSqlTable> { } return new TopiaSqlTables(ImmutableMap.copyOf(tablesByFullyTableName), - orderedTablesBuilder.build()); + orderedTablesBuilder.build()); } protected Builder registerTable(String schemaName, @@ -179,6 +180,28 @@ public class TopiaSqlTables implements Iterable<TopiaSqlTable> { String whereClauseAlias, String fromClause, ImmutableSet<String> joinClauses) { + return registerTable(schemaName, tableName, whereClauseAlias, fromClause, joinClauses, false, null); + + } + + protected Builder registerAssociationTable(String schemaName, + String tableName, + String whereClauseAlias, + String fromClause, + ImmutableSet<String> joinClauses, + String joinColumnName) { + + return registerTable(schemaName, tableName, whereClauseAlias, fromClause, joinClauses, true, joinColumnName); + + } + + private Builder registerTable(String schemaName, + String tableName, + String whereClauseAlias, + String fromClause, + ImmutableSet<String> joinClauses, + boolean associationTable, + String joinColumnName) { //TODO check that this table is not already registred @@ -187,7 +210,13 @@ public class TopiaSqlTables implements Iterable<TopiaSqlTable> { tableName, fromClause, whereClauseAlias, - joinClauses); + joinClauses, + associationTable, + joinColumnName); + + if (log.isInfoEnabled()) { + log.info("new TopiaTable: " + table); + } tablesByFullyTableName.put(table.getFullyTableName(), table); tablesByOrder.put(internalOrder++, table); @@ -273,11 +302,7 @@ public class TopiaSqlTables implements Iterable<TopiaSqlTable> { } - registerTable(schemaName, - tableName, - whereClauseAlias, - fromClause, - joinClauses); + registerTable(schemaName, tableName, whereClauseAlias, fromClause, joinClauses); return this; } @@ -303,12 +328,7 @@ public class TopiaSqlTables implements Iterable<TopiaSqlTable> { ImmutableSet<String> joinClauses = addJoinCause(parentTable.getJoinClauses(), joinClause); - registerTable( - schemaName, - tableName, - whereClauseAlias, - fromClause, - joinClauses); + registerTable(schemaName, tableName, whereClauseAlias, fromClause, joinClauses); invertOrderWithParent(parentTable, entityEnum); return this; @@ -346,11 +366,14 @@ public class TopiaSqlTables implements Iterable<TopiaSqlTable> { joinClauses = parentTable.getJoinClauses(); } - registerTable(schemaName, - tableName, - whereClauseAlias, - fromClause, - joinClauses); + String joinColumnName = parentTable.getTableName(); + + registerAssociationTable(schemaName, + tableName, + whereClauseAlias, + fromClause, + joinClauses, + joinColumnName); return this; } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.