From df02d831e2dce80e0d00ec0febf0c708f02bacb3 Mon Sep 17 00:00:00 2001 From: "A. Abram White" Date: Mon, 26 Mar 2007 20:52:14 +0000 Subject: [PATCH] Only process registered classes that are listed as belonging to this persistence unit. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@522623 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/kernel/QueryFlushModes.java | 3 ++- .../apache/openjpa/meta/ClassMetaData.java | 2 +- .../openjpa/meta/MetaDataRepository.java | 27 ++++++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryFlushModes.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryFlushModes.java index cafbfdafe..7d6fa6b3f 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryFlushModes.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryFlushModes.java @@ -29,7 +29,8 @@ public interface QueryFlushModes { * Constant denoting that queries should flush data to the * database automatically whenever OpenJPA determines that relevant * modifications have been made and IgnoreCache is - * false. See {@link OpenJPAConfiguration#getFlushBeforeQueries} + * false. See + * {@link OpenJPAConfiguration#getFlushBeforeQueries} * for more info. */ public static final int FLUSH_TRUE = 0; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java index 33777e524..b74920058 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java @@ -310,7 +310,7 @@ public class ClassMetaData if (_owner != null) return _repos.EMPTY_CLASSES; - _repos.processRegisteredClasses(); + _repos.processRegisteredClasses(_loader); if (_subs == null) { Collection subs = _repos.getPCSubclasses(_type); _subs = (Class[]) subs.toArray(new Class[subs.size()]); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java index e47b65ebd..9d3e46fcd 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java @@ -304,7 +304,7 @@ public class MetaDataRepository return null; // check cache - processRegisteredClasses(); + processRegisteredClasses(envLoader); List classList = (List) _aliases.get(alias); // multiple classes may have been defined with the same alias: we @@ -322,8 +322,8 @@ public class MetaDataRepository // if we have specified a list of persistent clases, // also check to ensure that the class is in that list - if (pcNames == null || pcNames.size() == 0 || - pcNames.contains(nc.getName())) { + if (pcNames == null || pcNames.size() == 0 + || pcNames.contains(nc.getName())) { cls = nc; if (!classList.contains(cls)) classList.add(cls); @@ -375,7 +375,7 @@ public class MetaDataRepository // dev time so that user can manipulate persistent classes he's writing // before adding them to the list if ((_validate & VALIDATE_RUNTIME) != 0) { - Set pcNames = _factory.getPersistentTypeNames(false, envLoader); + Set pcNames = getPersistentTypeNames(false, envLoader); if (pcNames != null && !pcNames.contains(cls.getName())) return meta; } @@ -930,7 +930,7 @@ public class MetaDataRepository } // check cache - processRegisteredClasses(); + processRegisteredClasses(envLoader); Class cls = (Class) _oids.get(oid.getClass()); if (cls != null) return getMetaData(cls, envLoader, mustExist); @@ -946,7 +946,7 @@ public class MetaDataRepository // if still not match, register any classes that look similar to the // oid class and check again resolveIdentityClass(oid); - if (processRegisteredClasses().length > 0) { + if (processRegisteredClasses(envLoader).length > 0) { cls = (Class) _oids.get(oid.getClass()); if (cls != null) return getMetaData(cls, envLoader, mustExist); @@ -1201,7 +1201,7 @@ public class MetaDataRepository */ public synchronized Collection loadPersistentTypes(boolean devpath, ClassLoader envLoader) { - Set names = _factory.getPersistentTypeNames(devpath, envLoader); + Set names = getPersistentTypeNames(devpath, envLoader); if (names == null || names.isEmpty()) return Collections.EMPTY_LIST; @@ -1264,7 +1264,7 @@ public class MetaDataRepository * Parses the metadata for all registered classes. */ private void loadRegisteredClassMetaData(ClassLoader envLoader) { - Class[] reg = processRegisteredClasses(); + Class[] reg = processRegisteredClasses(envLoader); for (int i = 0; i < reg.length; i++) { try { getMetaData(reg[i], envLoader, false); @@ -1278,7 +1278,7 @@ public class MetaDataRepository /** * Updates our datastructures with the latest registered classes. */ - Class[] processRegisteredClasses() { + Class[] processRegisteredClasses(ClassLoader envLoader) { if (_registered.isEmpty()) return EMPTY_CLASSES; @@ -1290,8 +1290,15 @@ public class MetaDataRepository _registered.clear(); } + Collection pcNames = getPersistentTypeNames(false, envLoader); Collection failed = null; for (int i = 0; i < reg.length; i++) { + // don't process types that aren't listed by the user; may belong + // to a different persistence unit + if (pcNames != null && !pcNames.isEmpty() + && !pcNames.contains(reg[i].getName())) + continue; + try { processRegisteredClass(reg[i]); } catch (Throwable t) { @@ -1492,7 +1499,7 @@ public class MetaDataRepository if (meta == null && mustExist) { if (cls == null) { throw new MetaDataException(_loc.get - ("no-named-query-null-class", + ("no-named-query-null-class", getPersistentTypeNames(false, envLoader), name)); } else { throw new MetaDataException(_loc.get("no-named-query",