From b7fe66357b6c964613866b773da5c2739c513e09 Mon Sep 17 00:00:00 2001 From: Patrick Linskey Date: Wed, 8 Aug 2007 00:05:40 +0000 Subject: [PATCH] Tolerate container failure better, now that we can handle non-enhanced types. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@563705 13f79535-47bb-0310-9956-ffa450edef68 --- .../persistence/PersistenceProviderImpl.java | 19 +++++++++++++++++-- .../openjpa/persistence/localizer.properties | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java index 6c362f105..07d43442a 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java @@ -37,6 +37,7 @@ import org.apache.openjpa.kernel.Bootstrap; import org.apache.openjpa.kernel.BrokerFactory; import org.apache.openjpa.lib.conf.ConfigurationProvider; import org.apache.openjpa.lib.conf.Configurations; +import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.meta.MetaDataModes; import org.apache.openjpa.meta.MetaDataRepository; import org.apache.openjpa.util.ClassResolver; @@ -53,6 +54,9 @@ public class PersistenceProviderImpl static final String CLASS_TRANSFORMER_OPTIONS = "ClassTransformerOptions"; + private static final Localizer _loc = Localizer.forPackage( + PersistenceProviderImpl.class); + /** * Loads the entity manager specified by name, applying * the properties in m as overrides to the properties defined @@ -91,10 +95,16 @@ public class PersistenceProviderImpl return null; // add enhancer + Exception transformerException = null; String ctOpts = (String) Configurations.getProperty (CLASS_TRANSFORMER_OPTIONS, pui.getProperties()); - pui.addTransformer(new ClassTransformerImpl(cp, ctOpts, - pui.getNewTempClassLoader())); + try { + pui.addTransformer(new ClassTransformerImpl(cp, ctOpts, + pui.getNewTempClassLoader())); + } catch (Exception e) { + // fail gracefully + transformerException = e; + } // if the BrokerImpl hasn't been specified, switch to the // non-finalizing one, since anything claiming to be a container @@ -107,6 +117,11 @@ public class PersistenceProviderImpl BrokerFactory factory = Bootstrap.newBrokerFactory(cp, pui.getClassLoader()); + if (transformerException != null) + factory.getConfiguration().getLog( + OpenJPAConfiguration.LOG_RUNTIME).warn( + _loc.get("transformer-registration-error", pui), + transformerException); return OpenJPAPersistence.toEntityManagerFactory(factory); } catch (Exception e) { throw PersistenceExceptions.toPersistenceException(e); 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 78a22f9b6..4857778d3 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 @@ -125,6 +125,9 @@ no-setter-for-getter: No setter was found for method {0} in type {1} while \ searching for persistent properties. This method will be ignored. If you \ intended for this to be persistent, please add a corresponding setter, \ or switch to field access for this type hierarchy. +transformer-registration-error: An error occurred while registering a \ + ClassTransformer with {0}. The error is logged along with this warning. \ + Load-time class transformation will not be available. EntityManagerFactory-name: EntityManagerFactory implementation EntityManagerFactory-desc: Allows extension of standard \