diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/BeanCollectionWrapper.java b/src/main/java/com/avaje/ebeaninternal/server/query/BeanCollectionWrapper.java index e024ee53f..5f053979e 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/query/BeanCollectionWrapper.java +++ b/src/main/java/com/avaje/ebeaninternal/server/query/BeanCollectionWrapper.java @@ -1,18 +1,16 @@ package com.avaje.ebeaninternal.server.query; -import java.util.Collection; -import java.util.Map; - import com.avaje.ebean.bean.BeanCollection; import com.avaje.ebean.bean.EntityBean; import com.avaje.ebeaninternal.api.SpiQuery; -import com.avaje.ebeaninternal.server.core.OrmQueryRequest; import com.avaje.ebeaninternal.server.core.RelationalQueryRequest; import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; -import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany; import com.avaje.ebeaninternal.server.util.BeanCollectionFactory; import com.avaje.ebeaninternal.server.util.BeanCollectionParams; +import java.util.Collection; +import java.util.Map; + /** * Wraps a BeanCollection with helper methods to add beans. *

@@ -73,41 +71,6 @@ public final class BeanCollectionWrapper { this.map = getMap(isMap); } - /** - * Create based on a Find. - */ - public BeanCollectionWrapper(OrmQueryRequest request) { - - this.desc = request.getBeanDescriptor(); - this.queryType = request.getQueryType(); - this.mapKey = request.getQuery().getMapKey(); - this.isMap = SpiQuery.Type.MAP.equals(queryType); - - this.beanCollection = createBeanCollection(queryType); - this.collection = getCollection(isMap); - this.map = getMap(isMap); - } - - /** - * Create based on a ManyType and mapKey. Note the mapKey is only used if - * the manyType is a Map. - *

- * modifyListening is set to true if this is a collection used to hold - * ManyToMany associated objects. - *

- */ - public BeanCollectionWrapper(BeanPropertyAssocMany manyProp) { - - this.queryType = manyProp.getManyType().getQueryType(); - this.mapKey = manyProp.getMapKey(); - this.desc = manyProp.getTargetDescriptor(); - this.isMap = SpiQuery.Type.MAP.equals(queryType); - - this.beanCollection = createBeanCollection(queryType); - this.collection = getCollection(isMap); - this.map = getMap(isMap); - } - @SuppressWarnings({ "unchecked", "rawtypes" }) private Map getMap(boolean isMap) { return isMap ? (Map)beanCollection : null; @@ -169,7 +132,7 @@ public final class BeanCollectionWrapper { } rowCount++; if (isMap) { - Object keyValue = null; + Object keyValue; if (mapKey != null) { // use the value for the property keyValue = desc.getValue(bean, mapKey); diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/CQuery.java b/src/main/java/com/avaje/ebeaninternal/server/query/CQuery.java index 222dd1955..8997b168c 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/query/CQuery.java +++ b/src/main/java/com/avaje/ebeaninternal/server/query/CQuery.java @@ -485,6 +485,7 @@ public class CQuery implements DbReadContext, CancelableQuery { /** * Read version beans and their effective dates. */ + @SuppressWarnings("unchecked") public List> readVersions() throws SQLException { List> versionList = new ArrayList>(); diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/CQueryBuilder.java b/src/main/java/com/avaje/ebeaninternal/server/query/CQueryBuilder.java index 082b3b3e7..97d30fbc8 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/query/CQueryBuilder.java +++ b/src/main/java/com/avaje/ebeaninternal/server/query/CQueryBuilder.java @@ -225,7 +225,7 @@ public class CQueryBuilder { queryPlan = new CQueryPlanRawSql(request, res, sqlTree, predicates.getLogWhereSql()); } else { - queryPlan = new CQueryPlan(request, res, sqlTree, rawSql, predicates.getLogWhereSql()); + queryPlan = new CQueryPlan(request, res, sqlTree, false, predicates.getLogWhereSql()); } // cache the query plan because we can reuse it and also diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/CQueryEngine.java b/src/main/java/com/avaje/ebeaninternal/server/query/CQueryEngine.java index 54ffa1938..4c23b55c1 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/query/CQueryEngine.java +++ b/src/main/java/com/avaje/ebeaninternal/server/query/CQueryEngine.java @@ -1,18 +1,8 @@ package com.avaje.ebeaninternal.server.query; -import java.sql.SQLException; -import java.util.Collections; -import java.util.List; -import java.util.Map; - +import com.avaje.ebean.QueryIterator; import com.avaje.ebean.ValuePair; import com.avaje.ebean.Version; -import com.avaje.ebeaninternal.server.core.DiffHelp; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.avaje.ebean.QueryIterator; import com.avaje.ebean.bean.BeanCollection; import com.avaje.ebean.bean.BeanCollectionTouched; import com.avaje.ebean.bean.EntityBean; @@ -20,10 +10,19 @@ import com.avaje.ebean.bean.ObjectGraphNode; import com.avaje.ebean.config.dbplatform.DatabasePlatform; import com.avaje.ebeaninternal.api.BeanIdList; import com.avaje.ebeaninternal.api.SpiQuery; +import com.avaje.ebeaninternal.server.core.DiffHelp; import com.avaje.ebeaninternal.server.core.OrmQueryRequest; +import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; import com.avaje.ebeaninternal.server.lib.util.Str; import com.avaje.ebeaninternal.server.persist.Binder; import com.avaje.ebeaninternal.server.transaction.TransactionManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.SQLException; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; /** * Handles the Object Relational fetching. @@ -215,7 +214,7 @@ public class CQueryEngine { current = next; } // put an empty map into the last one - current.setDiff(Collections.EMPTY_MAP); + current.setDiff(new LinkedHashMap()); } private void deriveVersionDiff(Version current, Version prior, BeanDescriptor descriptor) { diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/CQueryPredicates.java b/src/main/java/com/avaje/ebeaninternal/server/query/CQueryPredicates.java index f2a66d48f..b24851b62 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/query/CQueryPredicates.java +++ b/src/main/java/com/avaje/ebeaninternal/server/query/CQueryPredicates.java @@ -48,11 +48,6 @@ public class CQueryPredicates { private final Object idValue; - /** - * Flag set if this is a SqlSelect type query. - */ - private boolean rawSql; - /** * Named bind parameters. */ @@ -459,10 +454,7 @@ public class CQueryPredicates { return orderBy; } - if (idPos > -1 && idPos < manyPos) { - // its all ok, id property appears before a many property - - } else { + if (idPos <= -1 || idPos >= manyPos) { if (idPos > manyPos) { // there was an error with the order by... String msg = "A Query on [" + desc + "] includes a join to a 'many' association [" + manyProp.getName(); @@ -529,38 +521,8 @@ public class CQueryPredicates { return orderByIncludes; } - /** - * The where sql with named bind parameters converted to ?. - */ - public String getWhereRawSql() { - return whereRawSql; - } - - /** - * The where sql from the expression objects. - */ - public String getWhereExpressionSql() { - return whereExprSql; - } - - /** - * The having sql with named bind parameters converted to ?. - */ - public String getHavingRawSql() { - return havingRawSql; - } - - /** - * The having sql from the expression objects. - */ - public String getHavingExpressionSql() { - return havingExprSql; - } - public String getLogWhereSql() { - if (rawSql) { - return ""; - } + if (dbWhere == null && dbFilterMany == null) { return ""; } diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/CQueryRowCount.java b/src/main/java/com/avaje/ebeaninternal/server/query/CQueryRowCount.java index 0fc8f6a4f..036666c9f 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/query/CQueryRowCount.java +++ b/src/main/java/com/avaje/ebeaninternal/server/query/CQueryRowCount.java @@ -1,21 +1,19 @@ package com.avaje.ebeaninternal.server.query; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import javax.persistence.PersistenceException; - import com.avaje.ebeaninternal.api.SpiQuery; import com.avaje.ebeaninternal.api.SpiTransaction; import com.avaje.ebeaninternal.server.core.OrmQueryRequest; -import com.avaje.ebeaninternal.server.core.SpiOrmQueryRequest; import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; import com.avaje.ebeaninternal.server.type.DataBind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.persistence.PersistenceException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + /** * Executes the select row count query. */ @@ -100,10 +98,6 @@ public class CQueryRowCount { public String getGeneratedSql() { return sql; } - - public SpiOrmQueryRequest getQueryRequest() { - return request; - } /** * Execute the query returning the row count. diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/SqlBeanLoad.java b/src/main/java/com/avaje/ebeaninternal/server/query/SqlBeanLoad.java index 9ca61d2f2..7f03d2ed8 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/query/SqlBeanLoad.java +++ b/src/main/java/com/avaje/ebeaninternal/server/query/SqlBeanLoad.java @@ -1,16 +1,13 @@ package com.avaje.ebeaninternal.server.query; -import java.sql.SQLException; - -import javax.persistence.PersistenceException; - import com.avaje.ebean.bean.EntityBean; import com.avaje.ebean.bean.EntityBeanIntercept; import com.avaje.ebeaninternal.api.SpiQuery.Mode; import com.avaje.ebeaninternal.server.deploy.BeanProperty; -import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany; import com.avaje.ebeaninternal.server.deploy.DbReadContext; +import javax.persistence.PersistenceException; + /** * Controls the loading of property data into a bean. *

diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/SqlTree.java b/src/main/java/com/avaje/ebeaninternal/server/query/SqlTree.java index 82fb447d3..094f50f83 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/query/SqlTree.java +++ b/src/main/java/com/avaje/ebeaninternal/server/query/SqlTree.java @@ -21,10 +21,6 @@ public class SqlTree { */ private final BeanPropertyAssocMany manyProperty; - private final String manyPropertyName; - - private final ElPropertyValue manyPropEl; - private final Set includes; /** @@ -50,8 +46,7 @@ public class SqlTree { * Create the SqlSelectClause. */ public SqlTree(String summary, SqlTreeNode rootNode, String selectSql, String fromSql, String inheritanceWhereSql, - BeanProperty[] encryptedProps, BeanPropertyAssocMany manyProperty, String manyPropertyName, - ElPropertyValue manyPropEl, Set includes) { + BeanProperty[] encryptedProps, BeanPropertyAssocMany manyProperty, Set includes) { this.summary = summary; this.rootNode = rootNode; @@ -60,8 +55,6 @@ public class SqlTree { this.inheritanceWhereSql = inheritanceWhereSql; this.encryptedProps = encryptedProps; this.manyProperty = manyProperty; - this.manyPropertyName = manyPropertyName; - this.manyPropEl = manyPropEl; this.includes = includes; } @@ -76,8 +69,6 @@ public class SqlTree { this.inheritanceWhereSql = null; this.encryptedProps = null; this.manyProperty = null; - this.manyPropertyName = null; - this.manyPropEl = null; this.includes = null; } @@ -141,21 +132,6 @@ public class SqlTree { return manyProperty; } - public String getManyPropertyName() { - return manyPropertyName; - } - - public ElPropertyValue getManyPropertyEl() { - return manyPropEl; - } - - /** - * Return true if this query includes a Many association. - */ - public boolean isManyIncluded() { - return (manyProperty != null); - } - public BeanProperty[] getEncryptedProps() { return encryptedProps; } diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/SqlTreeBuilder.java b/src/main/java/com/avaje/ebeaninternal/server/query/SqlTreeBuilder.java index e104773ac..967429669 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/query/SqlTreeBuilder.java +++ b/src/main/java/com/avaje/ebeaninternal/server/query/SqlTreeBuilder.java @@ -52,8 +52,6 @@ public class SqlTreeBuilder { */ private BeanPropertyAssocMany manyProperty; - private String manyPropertyName; - private final SqlTreeAlias alias; private final DefaultDbSqlContext ctx; @@ -141,13 +139,8 @@ public class SqlTreeBuilder { encryptedProps = ctx.getEncryptedProps(); } - ElPropertyValue manyPropEl = null; - if (manyPropertyName != null) { - manyPropEl = desc.getElGetValue(manyPropertyName); - } - return new SqlTree(summary.toString(), rootNode, selectSql, fromSql, inheritanceWhereSql, encryptedProps, - manyProperty, manyPropertyName, manyPropEl, queryDetail.getIncludes()); + manyProperty, queryDetail.getIncludes()); } private String buildSelectClause() { @@ -213,7 +206,7 @@ public class SqlTreeBuilder { BeanPropertyAssocOne[] ones = desc.propertiesOne(); for (int i = 0; i < ones.length; i++) { String propPrefix = SplitName.add(prefix, ones[i].getName()); - if (isIncludeBean(propPrefix, ones[i])) { + if (isIncludeBean(propPrefix)) { selectIncludes.add(propPrefix); buildSelectChain(propPrefix, ones[i], ones[i].getTargetDescriptor(), myJoinList); } @@ -222,7 +215,7 @@ public class SqlTreeBuilder { BeanPropertyAssocMany[] manys = desc.propertiesMany(); for (int i = 0; i < manys.length; i++) { String propPrefix = SplitName.add(prefix, manys[i].getName()); - if (isIncludeMany(prefix, propPrefix, manys[i])) { + if (isIncludeMany(propPrefix, manys[i])) { selectIncludes.add(propPrefix); buildSelectChain(propPrefix, manys[i], manys[i].getTargetDescriptor(), myJoinList); } @@ -331,8 +324,7 @@ public class SqlTreeBuilder { * This means it can included individual properties of an embedded bean. *

*/ - private void addPropertyToSubQuery(SqlTreeProperties selectProps, BeanDescriptor desc, - OrmQueryProperties queryProps, String propName) { + private void addPropertyToSubQuery(SqlTreeProperties selectProps, BeanDescriptor desc, String propName) { BeanProperty p = desc.findBeanProperty(propName); if (p == null) { @@ -354,7 +346,7 @@ public class SqlTreeBuilder { OrmQueryProperties queryProps, String propName) { if (subQuery) { - addPropertyToSubQuery(selectProps, desc, queryProps, propName); + addPropertyToSubQuery(selectProps, desc, propName); return; } @@ -472,7 +464,7 @@ public class SqlTreeBuilder { /** * Return true if this many node should be included in the query. */ - private boolean isIncludeMany(String prefix, String propName, BeanPropertyAssocMany manyProp) { + private boolean isIncludeMany(String propName, BeanPropertyAssocMany manyProp) { if (queryDetail.isJoinsEmpty()) { return false; @@ -489,7 +481,6 @@ public class SqlTreeBuilder { } manyProperty = manyProp; - manyPropertyName = propName; summary.append(" +many:").append(propName); return true; } @@ -504,7 +495,7 @@ public class SqlTreeBuilder { * is added and false is returned. *

*/ - private boolean isIncludeBean(String prefix, BeanPropertyAssocOne prop) { + private boolean isIncludeBean(String prefix) { if (queryDetail.includes(prefix)) { // explicitly included