From 68572a9197e1a668442ef463d193686c37c12c09 Mon Sep 17 00:00:00 2001 From: "A. Abram White" Date: Thu, 21 Sep 2006 18:28:06 +0000 Subject: [PATCH] Die in ProductDerivations.load() if given resource/file can't be parsed by any ProductDerivations in the system. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@448625 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/lib/conf/ConfigurationImpl.java | 6 +-- .../openjpa/lib/conf/ProductDerivations.java | 6 ++- .../persistence/PersistenceUnitInfoImpl.java | 39 ++++++++++--------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java index 7851a5504..151f5c5bd 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java @@ -751,7 +751,7 @@ public class ConfigurationImpl */ public void setProperties(String resourceName) throws IOException { ProductDerivations.load(resourceName, null, - getClass().getClassLoader()).setInto(this); + getClass().getClassLoader()).setInto(this); _auto = resourceName; } @@ -761,8 +761,8 @@ public class ConfigurationImpl * propertiesFile value with the name of a file. */ public void setPropertiesFile(File file) throws IOException { - ProductDerivations.load(file, null, - getClass().getClassLoader()).setInto(this); + ProductDerivations.load(file, null, getClass().getClassLoader()). + setInto(this); _auto = file.toString(); } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java index 66a1ad9a1..d97b228b1 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java @@ -133,7 +133,8 @@ public class ProductDerivations { } } reportErrors(errs, resource); - return null; + throw new MissingResourceException(resource, + ProductDerivations.class.getName(), resource); } /** @@ -162,7 +163,8 @@ public class ProductDerivations { } } reportErrors(errs, file.getAbsolutePath()); - return null; + throw new MissingResourceException(file.getAbsolutePath(), + ProductDerivations.class.getName(), file.getAbsolutePath()); } /** diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java index 2973cd92e..bc11de25f 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java @@ -48,6 +48,8 @@ import org.apache.openjpa.util.ClassResolver; public class PersistenceUnitInfoImpl implements PersistenceUnitInfo, SourceTracker { + public static final String KEY_PROVIDER = "javax.persistence.provider"; + private static final Localizer s_loc = Localizer.forPackage (PersistenceUnitInfoImpl.class); @@ -181,8 +183,8 @@ public class PersistenceUnitInfoImpl } public List getJarFileUrls() { - return (_jarFiles == null) - ? (List) Collections.EMPTY_LIST : _jarFiles; + return (_jarFiles == null) ? (List) Collections.EMPTY_LIST + : _jarFiles; } public void addJarFile(URL jar) { @@ -215,8 +217,8 @@ public class PersistenceUnitInfoImpl } } } - throw new IllegalArgumentException(s_loc.get("bad-jar-name", name) - .getMessage()); + throw new IllegalArgumentException(s_loc.get("bad-jar-name", name). + getMessage()); } public List getManagedClassNames() { @@ -269,13 +271,13 @@ public class PersistenceUnitInfoImpl for (Object o : map.entrySet()) { key = ((Map.Entry) o).getKey(); val = ((Map.Entry) o).getValue(); - if ("javax.persistence.provider".equals(key)) + if (KEY_PROVIDER.equals(key)) setPersistenceProviderClassName((String) val); else if ("javax.persistence.transactionType".equals(key)) { PersistenceUnitTransactionType ttype; if (val instanceof String) - ttype = Enum.valueOf - (PersistenceUnitTransactionType.class, (String) val); + ttype = Enum.valueOf(PersistenceUnitTransactionType.class, + (String) val); else ttype = (PersistenceUnitTransactionType) val; setTransactionType(ttype); @@ -320,11 +322,9 @@ public class PersistenceUnitInfoImpl map.put("openjpa.ConnectionFactoryMode", "managed"); hasJta = true; } else if (info instanceof PersistenceUnitInfoImpl - && ((PersistenceUnitInfoImpl) info).getJtaDataSourceName() != null) - { - map.put("openjpa.ConnectionFactoryName", - ((PersistenceUnitInfoImpl) - info).getJtaDataSourceName()); + && ((PersistenceUnitInfoImpl) info).getJtaDataSourceName() != null){ + map.put("openjpa.ConnectionFactoryName", ((PersistenceUnitInfoImpl) + info).getJtaDataSourceName()); map.put("openjpa.ConnectionFactoryMode", "managed"); hasJta = true; } @@ -343,8 +343,7 @@ public class PersistenceUnitInfoImpl if (!hasJta) map.put("openjpa.ConnectionFactoryName", nonJtaName); else - map.put("openjpa.ConnectionFactory2Name", - nonJtaName); + map.put("openjpa.ConnectionFactory2Name", nonJtaName); } if (info.getClassLoader() != null) @@ -354,13 +353,13 @@ public class PersistenceUnitInfoImpl Properties props = info.getProperties(); if (props != null) { map.putAll(props); - // this isn't a real config property; remove it. + // this isn't a real config property; remove it map.remove(PersistenceProviderImpl.CLASS_TRANSFORMER_OPTIONS); } Properties metaFactoryProps = new Properties(); - if (info.getManagedClassNames() != null && - !info.getManagedClassNames().isEmpty()) { + if (info.getManagedClassNames() != null + && !info.getManagedClassNames().isEmpty()) { StringBuffer types = new StringBuffer(); for (String type : info.getManagedClassNames()) { if (types.length() > 0) @@ -404,8 +403,7 @@ public class PersistenceUnitInfoImpl } if (!metaFactoryProps.isEmpty()) { // set persistent class locations as properties of metadata factory - String factory = - (String) map.get("openjpa.MetaDataFactory"); + String factory = (String) map.get("openjpa.MetaDataFactory"); if (factory == null) factory = Configurations.serializeProperties(metaFactoryProps); else { @@ -417,6 +415,9 @@ public class PersistenceUnitInfoImpl } map.put("openjpa.MetaDataFactory", factory); } + + // always record provider name for product derivations to access + map.put(KEY_PROVIDER, info.getPersistenceProviderClassName()); return map; }