From 65056611c3abff728ad67b402f3c511f202e6062 Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Thu, 18 Oct 2018 04:12:41 +0000 Subject: [PATCH] Fix QueryBuilder chained join Fix the chained join() method in the QueryBuilder, which takes another Join as an argument to join from a table to a table which are both not the QueryBuilder's T type. --- .../greendao/query/QueryBuilder.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/DaoCore/src/main/java/org/greenrobot/greendao/query/QueryBuilder.java b/DaoCore/src/main/java/org/greenrobot/greendao/query/QueryBuilder.java index a27810031..99d3d922c 100644 --- a/DaoCore/src/main/java/org/greenrobot/greendao/query/QueryBuilder.java +++ b/DaoCore/src/main/java/org/greenrobot/greendao/query/QueryBuilder.java @@ -57,7 +57,7 @@ public class QueryBuilder { private StringBuilder orderBuilder; private final List values; - private final List> joins; + private final List> joins; private final AbstractDao dao; private final String tablePrefix; @@ -81,7 +81,7 @@ protected QueryBuilder(AbstractDao dao, String tablePrefix) { this.dao = dao; this.tablePrefix = tablePrefix; values = new ArrayList(); - joins = new ArrayList>(); + joins = new ArrayList>(); whereCollector = new WhereCollector(dao, tablePrefix); stringOrderCollation = " COLLATE NOCASE"; } @@ -178,7 +178,7 @@ public Join join(Class destinationEntityClass, Property destination public Join join(Property sourceProperty, Class destinationEntityClass) { AbstractDao destinationDao = (AbstractDao) dao.getSession().getDao(destinationEntityClass); Property destinationProperty = destinationDao.getPkProperty(); - return addJoin(tablePrefix, sourceProperty, destinationDao, destinationProperty); + return (Join) addJoin(tablePrefix, sourceProperty, destinationDao, destinationProperty); } /** @@ -187,7 +187,7 @@ public Join join(Property sourceProperty, Class destinationEntityCl */ public Join join(Property sourceProperty, Class destinationEntityClass, Property destinationProperty) { AbstractDao destinationDao = (AbstractDao) dao.getSession().getDao(destinationEntityClass); - return addJoin(tablePrefix, sourceProperty, destinationDao, destinationProperty); + return (Join) addJoin(tablePrefix, sourceProperty, destinationDao, destinationProperty); } /** @@ -196,16 +196,16 @@ public Join join(Property sourceProperty, Class destinationEntityCl * as the source for the new join to add. In this way, it is possible to compose complex "join of joins" across * several entities if required. */ - public Join join(Join sourceJoin, Property sourceProperty, Class destinationEntityClass, + public Join join(Join sourceJoin, Property sourceProperty, Class destinationEntityClass, Property destinationProperty) { - AbstractDao destinationDao = (AbstractDao) dao.getSession().getDao(destinationEntityClass); - return addJoin(sourceJoin.tablePrefix, sourceProperty, destinationDao, destinationProperty); + AbstractDao destinationDao = (AbstractDao) dao.getSession().getDao(destinationEntityClass); + return (Join) addJoin(sourceJoin.tablePrefix, sourceProperty, destinationDao, destinationProperty); } - private Join addJoin(String sourceTablePrefix, Property sourceProperty, AbstractDao destinationDao, + private Join addJoin(String sourceTablePrefix, Property sourceProperty, AbstractDao destinationDao, Property destinationProperty) { String joinTablePrefix = "J" + (joins.size() + 1); - Join join = new Join(sourceTablePrefix, sourceProperty, destinationDao, destinationProperty, + Join join = new Join<>(sourceTablePrefix, sourceProperty, destinationDao, destinationProperty, joinTablePrefix); joins.add(join); return join; @@ -391,7 +391,7 @@ private void checkLog(String sql) { private void appendJoinsAndWheres(StringBuilder builder, String tablePrefixOrNull) { values.clear(); - for (Join join : joins) { + for (Join join : joins) { builder.append(" JOIN "); builder.append('"').append(join.daoDestination.getTablename()).append('"').append(' '); builder.append(join.tablePrefix).append(" ON "); @@ -403,7 +403,7 @@ private void appendJoinsAndWheres(StringBuilder builder, String tablePrefixOrNul builder.append(" WHERE "); whereCollector.appendWhereClause(builder, tablePrefixOrNull, values); } - for (Join join : joins) { + for (Join join : joins) { if (!join.whereCollector.isEmpty()) { if (!whereAppended) { builder.append(" WHERE ");