Author: hthomann Date: Mon Jun 22 18:17:48 2015 New Revision: 1686910 URL: http://svn.apache.org/r1686910 Log: OPENJPA-2539: Query Compilation causing inner join table to be randomly generated incorrectly - ported changes to 2.2.1.x.
Modified: openjpa/branches/2.2.1.x/ (props changed) openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java Propchange: openjpa/branches/2.2.1.x/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Mon Jun 22 18:17:48 2015 @@ -1,5 +1,5 @@ /openjpa/branches/1.0.x:736493 /openjpa/branches/2.0.x:1419659,1484136,1484287,1504611 -/openjpa/branches/2.1.x:1415379,1415398,1436150,1469090,1469949,1484300,1484313,1485010,1505837,1513249,1517838,1529241,1530146,1533218,1533280,1539188,1569528,1575444,1591536,1614935,1636464,1648430,1655218,1662610,1673300,1673491 +/openjpa/branches/2.1.x:1415379,1415398,1436150,1469090,1469949,1484300,1484313,1485010,1505837,1513249,1517838,1529241,1530146,1533218,1533280,1539188,1569528,1575444,1591536,1614935,1636464,1648430,1655218,1662610,1673300,1673491,1686894 /openjpa/branches/2.2.x:1580898,1580939,1591681,1641906,1642555 /openjpa/trunk:1416742,1420324,1430117,1431649,1436957,1436960,1448662,1448796,1451369,1456574,1456614,1459091,1461833,1469646,1469649,1469652,1504282,1600757,1603251 Modified: openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java?rev=1686910&r1=1686909&r2=1686910&view=diff ============================================================================== --- openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java (original) +++ openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java Mon Jun 22 18:17:48 2015 @@ -633,9 +633,9 @@ public class QueryImpl * Find the cached compilation for the current query, creating one if it * does not exist. */ + @SuppressWarnings("unchecked") protected Compilation compilationFromCache() { - Map compCache = - _broker.getConfiguration().getQueryCompilationCacheInstance(); + Map compCache = _broker.getConfiguration().getQueryCompilationCacheInstance(); if (compCache == null || !isParsedQuery()) { return newCompilation(); } else { @@ -649,17 +649,24 @@ public class QueryImpl Compilation comp = (Compilation) compCache.get(key); // parse declarations if needed - boolean cache = false; if (comp == null) { comp = newCompilation(); // only cache those queries that can be compiled - cache = comp.storeData != null; - } else + if (comp.storeData != null) { + + synchronized (compCache) { + Compilation existingComp = (Compilation) compCache.get(key); + if (existingComp == null) { + compCache.put(key, comp); + } else { + comp = existingComp; + } + } + } + } else { _storeQuery.populateFromCompilation(comp.storeData); + } - // cache parsed state if needed - if (cache) - compCache.put(key, comp); return comp; } }