From 24c51d9fe60896520b2a810fbc6f88ff019a0d35 Mon Sep 17 00:00:00 2001 From: Pinaki Poddar Date: Thu, 28 Sep 2006 03:00:31 +0000 Subject: [PATCH] Adding informative messages when non-default Persistence Provider is configured. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@450674 13f79535-47bb-0310-9956-ffa450edef68 --- .../PersistenceProductDerivation.java | 24 +++++++++++++++---- .../openjpa/persistence/localizer.properties | 7 +++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java index c73d0a48b..a47986ec9 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java @@ -248,6 +248,8 @@ public class PersistenceProductDerivation rsrc, String.valueOf(name)).getMessage(), getClass().getName(), rsrc); } else if (!isOpenJPAPersistenceProvider(pinfo, loader)) { + if (!explicit) + return Boolean.FALSE; throw new MissingResourceException(_loc.get("unknown-provider", rsrc, name, pinfo.getPersistenceProviderClassName()). getMessage(), getClass().getName(), rsrc); @@ -307,19 +309,31 @@ public class PersistenceProductDerivation */ private static boolean isOpenJPAPersistenceProvider (PersistenceUnitInfo pinfo, ClassLoader loader) { - String name = pinfo.getPersistenceProviderClassName(); - if (StringUtils.isEmpty(name) - || PersistenceProviderImpl.class.getName().equals(name)) + String provider = pinfo.getPersistenceProviderClassName(); + if (StringUtils.isEmpty(provider) + || PersistenceProviderImpl.class.getName().equals(provider)) return true; if (loader == null) loader = Thread.currentThread().getContextClassLoader(); try { - return PersistenceProviderImpl.class.isAssignableFrom - (Class.forName(name, false, loader)); + if (PersistenceProviderImpl.class.isAssignableFrom + (Class.forName(provider, false, loader))) { + // log not configured yet + warn(_loc.get("extended-provider", provider).getMessage()); + return true; + } } catch (Throwable t) { + warn(_loc.get("unloadable-provider", provider, t). + getMessage()); return false; } + warn(_loc.get("unrecognized-provider", provider).getMessage()); + return false; + } + + private static void warn(String msg) { + System.err.println(msg); } /** diff --git a/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties b/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties index 28cbf3a56..7d7355b22 100644 --- a/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties +++ b/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties @@ -93,7 +93,12 @@ multiple-methods-on-callback-error: Class "{0}" declares method "{1}" as well \ missing-no-arg-constructor: Entity listener class "{0}" must declare a no-arg \ constructor. "AllowsNoArgConstructorCallback" property of MetaDataDefaults \ can be set to true to ignore this exception. - +extended-provider: WARNING: Configured to use extended Persistence Provider \ + "{0}". +unloadable-provider: WARNING: Can not load configured Persistence Provider \ + "{0}" due to "{1}" +unrecognized-provider: WARNING: Configured to use non-recognized Persistence \ + Provider "{0}" EntityManagerFactory-name: EntityManagerFactory implementation EntityManagerFactory-desc: Allows extension of standard \ org.apache.openjpa.persistence.EntityManagerFactoryImpl for custom behavior.