openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1576505 - /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
Date Tue, 11 Mar 2014 21:12:12 GMT
Author: curtisr7
Date: Tue Mar 11 21:12:12 2014
New Revision: 1576505

URL: http://svn.apache.org/r1576505
Log:
OPENJPA-2482: Cache column alias on colum+pathjoins rather than just column.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=1576505&r1=1576504&r2=1576505&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java Tue
Mar 11 21:12:12 2014
@@ -55,8 +55,8 @@ import org.apache.openjpa.jdbc.schema.Co
 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<Column, Object> cachedColumnAlias_ = null;
+        private Map<CachedColumnAliasKey, Object> 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<Column, Object>();
-                    cachedColumnAlias_.put((Column) obj, columnAlias);
+                    if (cachedColumnAlias_ == null) {
+                        cachedColumnAlias_ = new HashMap<CachedColumnAliasKey, Object>();
+                    }
+                    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



Mime
View raw message