From 402a813282ba2be19ebdb700f4a73d2f6494979e Mon Sep 17 00:00:00 2001 From: Bruno Guadagnini Date: Thu, 7 Apr 2016 02:10:51 -0300 Subject: [PATCH 1/4] added support for multiple joins --- .../jpa/datatables/repository/DataTablesUtils.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java index e9f5f8e..ac242e3 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java +++ b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java @@ -189,9 +189,16 @@ private static boolean isBoolean(String filterValue) { private static Expression getExpression(Root root, String columnData) { if (columnData.contains(ATTRIBUTE_SEPARATOR)) { - // columnData is like "joinedEntity.attribute" so add a join clause + // columnData is like "joinedEntities.attribute" so add a join clause. example: "person.contact.fone" String[] values = columnData.split("\\" + ATTRIBUTE_SEPARATOR); - return root.join(values[0], JoinType.LEFT).get(values[1]).as(String.class); + + Path path = root.get(values[0]); + + for(int i = 1; i < values.length - 1; i++){ + path = path.get(values[i]); + } + + return path.get(values[values.length - 1]); } else { // columnData is like "attribute" so nothing particular to do return root.get(columnData).as(String.class); From 819996964849234ef5cd2ee18bf4b5a348032216 Mon Sep 17 00:00:00 2001 From: Bruno Guadagnini Date: Thu, 7 Apr 2016 02:10:51 -0300 Subject: [PATCH 2/4] added support for multiple joins --- .../jpa/datatables/repository/DataTablesUtils.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java index e9f5f8e..05be124 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java +++ b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java @@ -10,6 +10,7 @@ import javax.persistence.criteria.JoinType; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import javax.persistence.criteria.Path; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -189,9 +190,16 @@ private static boolean isBoolean(String filterValue) { private static Expression getExpression(Root root, String columnData) { if (columnData.contains(ATTRIBUTE_SEPARATOR)) { - // columnData is like "joinedEntity.attribute" so add a join clause + // columnData is like "joinedEntities.attribute" so add a join clause. example: "person.contact.fone" String[] values = columnData.split("\\" + ATTRIBUTE_SEPARATOR); - return root.join(values[0], JoinType.LEFT).get(values[1]).as(String.class); + + Path path = root.get(values[0]); + + for(int i = 1; i < values.length - 1; i++){ + path = path.get(values[i]); + } + + return path.get(values[values.length - 1]); } else { // columnData is like "attribute" so nothing particular to do return root.get(columnData).as(String.class); From d6c3c78964094ecc85f401bf3d1f7eab8b7aea60 Mon Sep 17 00:00:00 2001 From: Bruno Guadagnini Date: Thu, 7 Apr 2016 02:24:19 -0300 Subject: [PATCH 3/4] Ajust import javax.persistence.criteria.Path; --- .../data/jpa/datatables/repository/DataTablesUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java index ac242e3..05be124 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java +++ b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java @@ -10,6 +10,7 @@ import javax.persistence.criteria.JoinType; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import javax.persistence.criteria.Path; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; From 27b79b0fe08f131f86c8ac5803b39e09f714ee67 Mon Sep 17 00:00:00 2001 From: Bruno Guadagnini Date: Wed, 27 Apr 2016 08:20:58 -0300 Subject: [PATCH 4/4] fix left join expression --- .../data/jpa/datatables/repository/DataTablesUtils.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java index 05be124..18d23d0 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java +++ b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesUtils.java @@ -7,10 +7,10 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Expression; +import javax.persistence.criteria.Join; import javax.persistence.criteria.JoinType; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; -import javax.persistence.criteria.Path; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -192,14 +192,13 @@ private static Expression getExpression(Root root, String columnData) if (columnData.contains(ATTRIBUTE_SEPARATOR)) { // columnData is like "joinedEntities.attribute" so add a join clause. example: "person.contact.fone" String[] values = columnData.split("\\" + ATTRIBUTE_SEPARATOR); - - Path path = root.get(values[0]); + Join joinExpression = root.join(values[0], JoinType.LEFT); for(int i = 1; i < values.length - 1; i++){ - path = path.get(values[i]); + joinExpression = joinExpression.join(values[i], JoinType.LEFT); } - return path.get(values[values.length - 1]); + return joinExpression.get(values[values.length - 1]).as(String.class); } else { // columnData is like "attribute" so nothing particular to do return root.get(columnData).as(String.class);