From 51e2b70be5d42530dbb97cae436f28968c7f1182 Mon Sep 17 00:00:00 2001 From: "Richard G. Curtis" Date: Tue, 11 Mar 2014 21:12:12 +0000 Subject: [PATCH] OPENJPA-2482: Cache column alias on colum+pathjoins rather than just column. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1576505 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/openjpa/jdbc/sql/SelectImpl.java | 65 ++++++++++++++++--- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java index c2b7d6f22..929d7be1b 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java @@ -55,8 +55,8 @@ import org.apache.openjpa.jdbc.schema.Column; import org.apache.openjpa.jdbc.schema.ForeignKey; import org.apache.openjpa.jdbc.schema.Table; import org.apache.openjpa.kernel.StoreContext; -import org.apache.openjpa.kernel.exps.Value; import org.apache.openjpa.kernel.exps.Context; +import org.apache.openjpa.kernel.exps.Value; import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.util.ApplicationIds; @@ -2321,7 +2321,7 @@ public class SelectImpl implements PathJoins { private SelectImpl _sel = null; - private Map cachedColumnAlias_ = null; + private Map cachedColumnAlias_ = null; // position in selected columns list where we expect the next load private int _pos = 0; @@ -2405,9 +2405,10 @@ public class SelectImpl if (pj != null && pj.path() != null) { Object columnAlias = getColumnAlias((Column) obj, pj); if (joins == null) { - if (cachedColumnAlias_ == null) - cachedColumnAlias_ = new HashMap(); - cachedColumnAlias_.put((Column) obj, columnAlias); + if (cachedColumnAlias_ == null) { + cachedColumnAlias_ = new HashMap(); + } + cachedColumnAlias_.put(new CachedColumnAliasKey((Column) obj, pj), columnAlias); } return columnAlias != null && _sel._selects.contains(columnAlias); } @@ -2449,6 +2450,7 @@ public class SelectImpl protected int findObject(Object obj, Joins joins) throws SQLException { + Object orig = obj; if (_pos == _sel._selects.size()) _pos = 0; @@ -2460,9 +2462,10 @@ public class SelectImpl Column col = (Column) obj; pk = (col.isPrimaryKey()) ? Boolean.TRUE : Boolean.FALSE; if (joins == null && cachedColumnAlias_ != null) { - obj = cachedColumnAlias_.get(col); - if (obj == null) + obj = cachedColumnAlias_.get(new CachedColumnAliasKey((Column) obj, pj)); + if (obj == null) { obj = getColumnAlias(col, pj); + } } else { obj = getColumnAlias(col, pj); } @@ -2641,6 +2644,48 @@ public class SelectImpl public void moveJoinsToParent() { } + + private static final class CachedColumnAliasKey { + private final Column col; + private final PathJoins pjs; + + public CachedColumnAliasKey(Column c, PathJoins p) { + col = c; + pjs = p; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((col == null) ? 0 : col.hashCode()); + result = prime * result + ((pjs == null) ? 0 : pjs.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CachedColumnAliasKey other = (CachedColumnAliasKey) obj; + if (col == null) { + if (other.col != null) + return false; + } else if (!col.equals(other.col)) + return false; + if (pjs == null) { + if (other.pjs != null) + return false; + } else if (!pjs.equals(other.pjs)) + return false; + return true; + } + + } } /** @@ -2775,11 +2820,11 @@ public class SelectImpl + String.valueOf(path); } - public void moveJoinsToParent() { - } + public void moveJoinsToParent() { } +} - /** +/** * Joins implementation. */ private static class SelectJoins