diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java index 67ddf131c..c85af3142 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java @@ -241,7 +241,6 @@ public interface JDBCConfiguration *
  • parallel: When querying for objects, also select for * both 1-1 relations using joins and to-many relations using batched * selects.
  • - * * */ public void setEagerFetchMode(String mode); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java index 1bb95d5a6..8b9140d57 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java @@ -865,9 +865,15 @@ public class JDBCConfigurationImpl } protected boolean isInvalidProperty(String propName) { + if (super.isInvalidProperty(propName)) + return true; + // handle openjpa.jdbc.SomeMisspelledProperty, but not // openjpa.someotherimplementation.SomeProperty - return super.isInvalidProperty(propName) - || propName.toLowerCase().startsWith("openjpa.jdbc"); + String[] prefixes = ProductDerivations.getConfigurationPrefixes(); + for (int i = 0; i < prefixes.length; i++) + if (propName.toLowerCase().startsWith(prefixes[i] + ".jdbc")) + return true; + return false; } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java index bb0c46142..d9d5b6cff 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java @@ -39,8 +39,7 @@ public class JDBCProductDerivation extends AbstractProductDerivation public boolean beforeConfigurationConstruct(ConfigurationProvider cp) { // default to JDBC when no broker factory set if (BrokerFactoryValue.get(cp) == null) { - cp.addProperty(BrokerFactoryValue.getKey(cp), - JDBCBrokerFactory.class.getName()); + BrokerFactoryValue.set(cp, JDBCBrokerFactory.class.getName()); return true; } return false; diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java index 8c2b2dcde..28aa8905e 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java @@ -930,7 +930,7 @@ public class MappingTool flags.dropTables = opts.removeBooleanProperty ("dropTables", "dt", flags.dropTables); flags.openjpaTables = opts.removeBooleanProperty - ("openjpaTables", "kt", flags.openjpaTables); + ("openjpaTables", "ot", flags.openjpaTables); flags.dropSequences = opts.removeBooleanProperty ("dropSequences", "dsq", flags.dropSequences); flags.readSchema = opts.removeBooleanProperty diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java index 4eb2633f6..034695967 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java @@ -1376,7 +1376,7 @@ public class SchemaTool { flags.ignoreErrors = opts.removeBooleanProperty ("ignoreErrors", "i", flags.ignoreErrors); flags.openjpaTables = opts.removeBooleanProperty - ("openjpaTables", "kt", flags.openjpaTables); + ("openjpaTables", "ot", flags.openjpaTables); flags.primaryKeys = opts.removeBooleanProperty ("primaryKeys", "pk", flags.primaryKeys); flags.foreignKeys = opts.removeBooleanProperty diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java index 729d26889..4f6e5a3d3 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java @@ -80,7 +80,7 @@ public class OracleDictionary public String autoAssignSequenceName = null; /** - * Flag to use OpenJPA 3 style naming for auto assign sequence name and + * Flag to use OpenJPA 0.3 style naming for auto assign sequence name and * trigger name for backwards compatibility. */ public boolean openjpa3GeneratedKeyNames = false; diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties index 8bb1d52f1..79ae9bb60 100644 --- a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties +++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties @@ -264,7 +264,7 @@ tool-usage: Usage: java org.apache.openjpa.jdbc.meta.MappingTool\n\ \t[-foreignKeys/-fk ]\n\ \t[-indexes/-ix ]\n\ \t[-dropTables/-dt ]\n\ - \t[-openjpaTables/-kt ]\n\ + \t[-openjpaTables/-ot ]\n\ \t[-dropSequences/-dsq ]\n\ \t[-sequences/-sq ]\n\ \t[-ignoreErrors/-i ]\n\ diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties index 75e0d4e90..db1703cc8 100644 --- a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties +++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties @@ -54,7 +54,7 @@ tool-usage: Usage: java org.apache.openjpa.jdbc.schema.SchemaTool\n\ \t[-file/-f ]\n\ \t[-ignoreErrors/-i ]\n\ \t[-dropTables/-dt ]\n\ - \t[-openjpaTables/-kt ]\n\ + \t[-openjpaTables/-ot ]\n\ \t[-dropSequences/-dsq ]\n\ \t[-sequences/-sq ]\n\ \t[-primaryKeys/-pk ]\n\ diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/BrokerFactoryValue.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/BrokerFactoryValue.java index fa4229484..170bd3607 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/BrokerFactoryValue.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/BrokerFactoryValue.java @@ -23,6 +23,7 @@ import org.apache.openjpa.abstractstore.AbstractStoreBrokerFactory; import org.apache.openjpa.kernel.BrokerFactory; import org.apache.openjpa.lib.conf.ConfigurationProvider; import org.apache.openjpa.lib.conf.PluginValue; +import org.apache.openjpa.lib.conf.ProductDerivations; /** * Value type used to represent the {@link BrokerFactory}. This type is @@ -40,20 +41,10 @@ public class BrokerFactoryValue private static final List _aliases = new ArrayList(); private static final List _prefixes = new ArrayList(2); static { - _prefixes.add("openjpa"); addDefaultAlias("abstractstore", AbstractStoreBrokerFactory.class.getName()); } - - /** - * Add prefix to the list of prefixes under which configuration - * properties may be scoped. - */ - public static void addPropertyPrefix(String prefix) { - if (!_prefixes.contains(prefix)) - _prefixes.add(prefix); - } - + /** * Add a mapping from alias to cls to the list * of default aliases for new values created after this invocation. @@ -67,10 +58,11 @@ public class BrokerFactoryValue * Extract the value of this property if set in the given provider. */ public static Object get(ConfigurationProvider cp) { + String[] prefixes = ProductDerivations.getConfigurationPrefixes(); Map props = cp.getProperties(); Object bf; - for (int i = 0; i < _prefixes.size (); i++) { - bf = props.get(_prefixes.get(i) + "." + KEY); + for (int i = 0; i < prefixes.length; i++) { + bf = props.get(prefixes[i] + "." + KEY); if (bf != null) return bf; } @@ -78,10 +70,10 @@ public class BrokerFactoryValue } /** - * Return the key to use for this property. + * Set the value of this property in the given provider. */ - public static String getKey(ConfigurationProvider cp) { - return _prefixes.get(0) + "." + KEY; + public static void set(ConfigurationProvider cp, String value) { + cp.addProperty("openjpa." + KEY, value); } public BrokerFactoryValue() { diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java index cee8b43db..3c4eeea86 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java @@ -165,14 +165,6 @@ public class OpenJPAConfigurationImpl super(false); String[] aliases; - // setup super's log factory plugin - logFactoryPlugin.setProperty("Log"); - logFactoryPlugin.setAlias("openjpa", - "org.apache.openjpa.lib.log.LogFactoryImpl"); - aliases = logFactoryPlugin.getAliases(); - logFactoryPlugin.setDefault(aliases[0]); - logFactoryPlugin.setString(aliases[0]); - classResolverPlugin = addPlugin("ClassResolver", true); aliases = new String[]{ "default", "org.apache.openjpa.util.ClassResolverImpl", @@ -401,8 +393,8 @@ public class OpenJPAConfigurationImpl fetchBatchSize.set(-1); maxFetchDepth = addInt("MaxFetchDepth"); - maxFetchDepth.setDefault("1"); - maxFetchDepth.set(1); + maxFetchDepth.setDefault("-1"); + maxFetchDepth.set(-1); fetchGroups = addStringList("FetchGroups"); fetchGroups.setDefault("default"); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java index e7ce0fdeb..f36f5f131 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java @@ -3399,8 +3399,8 @@ public class BrokerImpl default: // use store manager for native sequence if (fmd == null) { - // this will return a sequence even for app id classes, which - // is what we want for backwards-compatibility + // this will return a sequence even for app id classes, + // which is what we want for backwards-compatibility return _store.getDataStoreIdSequence(meta); } return _store.getValueSequence(fmd); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java index e5d2affab..78a8d8c83 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java @@ -297,8 +297,7 @@ public class QueryImpl _extent = _broker.newExtent(cls, _subclasses); _extent.setIgnoreChanges(_ignoreChanges); } else if (_extent != null - && _extent.getIgnoreChanges() != _ignoreChanges && cls != null) - { + && _extent.getIgnoreChanges() != _ignoreChanges && cls != null){ _extent = _broker.newExtent(cls, _extent.hasSubclasses()); _extent.setIgnoreChanges(_ignoreChanges); } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java index 472f532d5..acfd42ee2 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java @@ -27,6 +27,10 @@ import java.util.Map; public abstract class AbstractProductDerivation implements ProductDerivation { + public String getConfigurationPrefix() { + return null; + } + public ConfigurationProvider loadGlobals(ClassLoader loader) throws Exception { return null; diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java index a9d79a753..03d302ad8 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java @@ -78,8 +78,7 @@ public interface Configuration public String getProductName(); /** - * Set the product name. The set name will automatically be added to - * the property prefixes. + * Set the product name. */ public void setProductName(String name); @@ -160,14 +159,6 @@ public interface Configuration */ public void fromProperties(Map map); - /** - * Add prefix to the list of prefixes to use - * to identify valid configuration properties. "openjpa" and any - * product name set with {@link #setProductName} will automatically - * be added. - */ - public void addPropertyPrefix(String prefix); - /** * Adds a listener for any property changes. The property events fired * will not include the old value. 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 151f5c5bd..00f15493e 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 @@ -108,7 +108,6 @@ public class ConfigurationImpl private boolean _globals = false; private String _auto = null; private final List _vals = new ArrayList(); - private List _prefixes = new ArrayList(2); // property listener helper private PropertyChangeSupport _changeSupport = null; @@ -131,11 +130,12 @@ public class ConfigurationImpl * @param loadGlobals whether to attempt to load the global properties */ public ConfigurationImpl(boolean loadGlobals) { - setProductName("openjpa"); // also adds as prop prefix + setProductName("openjpa"); logFactoryPlugin = addPlugin("Log", true); String[] aliases = new String[]{ "true", LogFactoryImpl.class.getName(), + "openjpa", LogFactoryImpl.class.getName(), "commons", "org.apache.openjpa.lib.log.CommonsLogFactory", "log4j", "org.apache.openjpa.lib.log.Log4JLogFactory", "none", NoneLogFactory.class.getName(), @@ -183,7 +183,6 @@ public class ConfigurationImpl public void setProductName(String name) { _product = name; - addPropertyPrefix(name); } public LogFactory getLogFactory() { @@ -307,8 +306,8 @@ public class ConfigurationImpl // keep cached props up to date if (_props != null) { if (newString == null) - remove(_props, val); - else if (containsKey(_props, val) + Configurations.removeProperty(val.getProperty(), _props); + else if (Configurations.containsProperty(val.getProperty(), _props) || val.getDefault() == null || !val.getDefault().equals(newString)) put(_props, val, newString); @@ -534,11 +533,6 @@ public class ConfigurationImpl // To/from maps //////////////// - public void addPropertyPrefix(String prefix) { - if (!_prefixes.contains(prefix)) - _prefixes.add(prefix); - } - public Map toProperties(boolean storeDefaults) { // clone properties before making any modifications; we need to keep // the internal properties instance consistent to maintain equals and @@ -560,7 +554,8 @@ public class ConfigurationImpl // if key in existing properties, we already know value is up // to date val = (Value) _vals.get(i); - if (_props != null && containsKey(_props, val)) + if (_props != null && Configurations.containsProperty + (val.getProperty(), _props)) continue; str = val.getString(); @@ -605,14 +600,13 @@ public class ConfigurationImpl ser &= o instanceof Serializable; val.setObject(o); } - remove(remaining, val); + Configurations.removeProperty(val.getProperty(), remaining); } // convention is to point product at a resource with the // .properties System property; remove that property so we // we don't warn about it - for (int i = 0; i < _prefixes.size(); i++) - remaining.remove(_prefixes.get(i) + ".properties"); + Configurations.removeProperty("properties", remaining); // now warn if there are any remaining properties that there // is an unhandled prop @@ -637,39 +631,20 @@ public class ConfigurationImpl private void put(Map map, Value val, Object o) { Object key = val.getLoadKey(); if (key == null) - key = _prefixes.get(0) + "." + val.getProperty(); + key = "openjpa." + val.getProperty(); map.put(key, o); } - /** - * Return whether map contains an entry for val. - */ - private boolean containsKey(Map map, Value val) { - for (int i = 0; i < _prefixes.size(); i++) - if (map.containsKey(_prefixes.get(i) + "." + val.getProperty())) - return true; - return false; - } - - /** - * Removes val from map. Use this method - * instead of attempting to remove the value directly because this will - * account for any duplicate-but-same-valued keys in the map. - */ - private void remove(Map map, Value val) { - for (int i = 0; i < _prefixes.size(); i++) - map.remove(_prefixes.get(i) + "." + val.getProperty()); - } - /** * Look up the given value, testing all available prefixes. */ private Object get(Map map, Value val, boolean setLoadKey) { + String[] prefixes = ProductDerivations.getConfigurationPrefixes(); String firstKey = null; String key; Object o = null; - for (int i = 0; i < _prefixes.size(); i++) { - key = _prefixes.get(i) + "." + val.getProperty(); + for (int i = 0; i < prefixes.length; i++) { + key = prefixes[i] + "." + val.getProperty(); if (firstKey == null) { o = map.get(key); if (o != null) @@ -712,11 +687,11 @@ public class ConfigurationImpl * Return a comprehensive list of recognized map keys. */ private Collection newPropertyList() { - List l = new ArrayList(_vals.size() * _prefixes.size()); + String[] prefixes = ProductDerivations.getConfigurationPrefixes(); + List l = new ArrayList(_vals.size() * prefixes.length); for (int i = 0; i < _vals.size(); i++) { - for (int j = 0; j < _prefixes.size(); j++) - l.add(_prefixes.get(j) + "." - + ((Value) _vals.get(i)).getProperty()); + for (int j = 0; j < prefixes.length; j++) + l.add(prefixes[j] + "." + ((Value) _vals.get(i)).getProperty()); } return l; } @@ -729,12 +704,11 @@ public class ConfigurationImpl // handle warnings for openjpa.SomeString, but not for // openjpa.some.subpackage.SomeString, since it might be valid for some // specific implementation of OpenJPA - String prefix; - for (int i = 0; i < _prefixes.size(); i++) { - prefix = (String) _prefixes.get(i) + "."; - if (propName.toLowerCase().startsWith(prefix) - && propName.length() > prefix.length() - && propName.indexOf('.', prefix.length()) == -1) + String[] prefixes = ProductDerivations.getConfigurationPrefixes(); + for (int i = 0; i < prefixes.length; i++) { + if (propName.toLowerCase().startsWith(prefixes[i]) + && propName.length() > prefixes[i].length() + && propName.indexOf('.', prefixes[i].length()) == -1) return true; } return false; @@ -861,7 +835,6 @@ public class ConfigurationImpl public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { fromProperties((Map) in.readObject()); - _prefixes = (List) in.readObject(); _globals = in.readBoolean(); } @@ -874,7 +847,6 @@ public class ConfigurationImpl out.writeObject(_props); else out.writeObject(toProperties(false)); - out.writeObject(_prefixes); out.writeBoolean(_globals); } @@ -888,8 +860,6 @@ public class ConfigurationImpl (new Class[]{ boolean.class }); ConfigurationImpl clone = (ConfigurationImpl) cons.newInstance (new Object[]{ Boolean.FALSE }); - clone._prefixes.clear(); - clone._prefixes.addAll(_prefixes); clone._globals = _globals; clone.fromProperties(toProperties(true)); return clone; diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java index 7a3304569..3c765b41b 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java @@ -468,4 +468,53 @@ public class Configurations { try { ctx.close(); } catch (Exception e) {} } } + + /** + * Test whether the map contains the given key, prefixed with any possible + * configuration prefix. + */ + public static boolean containsProperty(String key, Map props) { + if (key == null || props == null) + return false; + String[] prefixes = ProductDerivations.getConfigurationPrefixes(); + for (int i = 0; i < prefixes.length; i++) + if (props.containsKey(prefixes[i] + "." + key)) + return true; + return false; + } + + /** + * Get the property under the given key, prefixed with any possible + * configuration prefix. + */ + public static Object getProperty(String key, Map props) { + if (key == null || props == null) + return null; + String[] prefixes = ProductDerivations.getConfigurationPrefixes(); + Object val; + for (int i = 0; i < prefixes.length; i++) { + val = props.get(prefixes[i] + "." + key); + if (val != null) + return val; + } + return null; + } + + /** + * Remove the property under the given key, prefixed with any possible + * configuration prefix. + */ + public static Object removeProperty(String key, Map props) { + if (key == null || props == null) + return null; + String[] prefixes = ProductDerivations.getConfigurationPrefixes(); + Object val = null; + Object cur; + for (int i = 0; i < prefixes.length; i++) { + cur = props.remove(prefixes[i] + "." + key); + if (cur != null && val == null) + val = cur; + } + return val; + } } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java index 283923a31..68f0b8d7d 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java @@ -40,6 +40,11 @@ public interface ProductDerivation { */ public int getType(); + /** + * Return the configuration prefix for properties of this product. + */ + public String getConfigurationPrefix(); + /** * Load globals into the returned ConfigurationProvider, or return null if * no globals is found. 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 d97b228b1..95c36bb2b 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 @@ -34,6 +34,7 @@ import org.apache.openjpa.lib.util.Services; public class ProductDerivations { private static final ProductDerivation[] _derivations; + private static final String[] _prefixes; static { Class[] pdcls = Services.getImplementorClasses(ProductDerivation.class, ProductDerivation.class.getClassLoader()); @@ -59,6 +60,24 @@ public class ProductDerivations { Collections.sort(derivations, new ProductDerivationComparator()); _derivations = (ProductDerivation[]) derivations.toArray (new ProductDerivation[derivations.size()]); + + List prefixes = new ArrayList(2); + for (int i = 0; i < _derivations.length; i++) { + if (_derivations[i].getConfigurationPrefix() != null + && !"openjpa".equals(_derivations[i].getConfigurationPrefix())) + prefixes.add(_derivations[i].getConfigurationPrefix()); + } + _prefixes = new String[1 + prefixes.size()]; + _prefixes[0] = "openjpa"; + for (int i = 0; i < prefixes.size(); i++) + _prefixes[i + 1] = (String) prefixes.get(i); + } + + /** + * Return the recognized prefixes for configuration properties. + */ + public static String[] getConfigurationPrefixes() { + return _prefixes; } /** diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java index fc0282f14..6ac77cb54 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java @@ -69,8 +69,8 @@ public class TestPersistence // openjpa-facade test assertTrue(em instanceof OpenJPAEntityManager); OpenJPAEntityManager ojem = (OpenJPAEntityManager) em; - ojem.getFetchPlan().setMaxFetchDepth(-1); - assertEquals(-1, ojem.getFetchPlan().getMaxFetchDepth()); + ojem.getFetchPlan().setMaxFetchDepth(1); + assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth()); em.close(); } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java index 9d4014b04..2f6cb5a36 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java @@ -34,6 +34,8 @@ import org.apache.openjpa.kernel.BrokerFactory; import org.apache.openjpa.kernel.DelegatingBrokerFactory; import org.apache.openjpa.kernel.DelegatingFetchConfiguration; import org.apache.openjpa.kernel.FetchConfiguration; +import org.apache.openjpa.lib.conf.Configurations; +import org.apache.openjpa.lib.conf.ProductDerivations; import org.apache.openjpa.lib.conf.Value; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.util.ImplHelper; @@ -145,42 +147,42 @@ public class EntityManagerFactoryImpl props = new HashMap(props); OpenJPAConfiguration conf = getConfiguration(); - String user = - (String) props.remove("openjpa.ConnectionUserName"); + String user = (String) Configurations.removeProperty + ("ConnectionUserName", props); if (user == null) user = conf.getConnectionUserName(); - String pass = - (String) props.remove("openjpa.ConnectionPassword"); + String pass = (String) Configurations.removeProperty + ("ConnectionPassword", props); if (pass == null) pass = conf.getConnectionPassword(); - String str = - (String) props.remove("openjpa.TransactionMode"); + String str = (String) Configurations.removeProperty + ("TransactionMode", props); boolean managed; if (str == null) managed = conf.isTransactionModeManaged(); else { - Value val = conf.getValue("openjpa.TransactionMode"); + Value val = conf.getValue("TransactionMode"); managed = Boolean.parseBoolean(val.unalias(str)); } - Object obj = props.remove("openjpa.ConnectionRetainMode"); + Object obj = Configurations.removeProperty("ConnectionRetainMode", + props); int retainMode; if (obj instanceof Number) retainMode = ((Number) obj).intValue(); - else if (obj != null) { - Value val = - conf.getValue("openjpa.ConnectionRetainMode"); + else if (obj == null) + retainMode = conf.getConnectionRetainModeConstant(); + else { + Value val = conf.getValue("ConnectionRetainMode"); try { retainMode = Integer.parseInt(val.unalias((String) obj)); } catch (Exception e) { throw new ArgumentException(_loc.get("bad-em-prop", "openjpa.ConnectionRetainMode", obj), - new Throwable[]{ e }, - obj, true); + new Throwable[]{ e }, obj, true); } - } else - retainMode = conf.getConnectionRetainModeConstant(); + } Broker broker = _factory.newBroker(user, pass, managed, retainMode, false); @@ -191,15 +193,23 @@ public class EntityManagerFactoryImpl OpenJPAEntityManager em = newEntityManagerImpl(broker); // allow setting of other bean properties of EM + String[] prefixes = ProductDerivations.getConfigurationPrefixes(); List errs = null; Method setter = null; - String prop; + String prop, prefix; Object val; for (Map.Entry entry : (Set) props.entrySet()) { prop = (String) entry.getKey(); - if (!prop.startsWith("openjpa.")) - continue; - prop = prop.substring("openjpa.".length()); + prefix = null; + for (int i = 0; i < prefixes.length; i++) { + prefix = prefixes[i] + "."; + if (prop.startsWith(prefix)) + break; + prefix = null; + } + if (prefix == null) + continue; + prop = prop.substring(prefix.length()); try { setter = ImplHelper.getSetter(em.getClass(), prop); } catch (OpenJPAException ke) { 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 daeb70975..858c3f371 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 @@ -32,6 +32,7 @@ import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.conf.OpenJPAConfigurationImpl; import org.apache.openjpa.conf.OpenJPAProductDerivation; import org.apache.openjpa.lib.conf.AbstractProductDerivation; +import org.apache.openjpa.lib.conf.ProductDerivations; import org.apache.openjpa.lib.conf.Configuration; import org.apache.openjpa.lib.conf.ConfigurationProvider; import org.apache.openjpa.lib.conf.MapConfigurationProvider; @@ -180,7 +181,10 @@ public class PersistenceProductDerivation @Override public ConfigurationProvider loadGlobals(ClassLoader loader) throws IOException { - String rsrc = System.getProperty("openjpa.properties"); + String[] prefixes = ProductDerivations.getConfigurationPrefixes(); + String rsrc = null; + for (int i = 0; i < prefixes.length && StringUtils.isEmpty(rsrc); i++) + rsrc = System.getProperty(prefixes[i] + ".properties"); boolean explicit = !StringUtils.isEmpty(rsrc); String anchor = null; int idx = (!explicit) ? -1 : rsrc.lastIndexOf('#'); 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 6dedee7ff..ff78ba75f 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 @@ -50,8 +50,7 @@ import org.apache.openjpa.meta.MetaDataRepository; public class PersistenceProviderImpl implements PersistenceProvider { - static final String CLASS_TRANSFORMER_OPTIONS = - "openjpa.ClassTransformerOptions"; + static final String CLASS_TRANSFORMER_OPTIONS = "ClassTransformerOptions"; /** * Loads the entity manager specified by name, applying @@ -71,8 +70,6 @@ public class PersistenceProviderImpl if (cp == null) return null; - if (m != null) - cp.addProperties(m); BrokerFactory factory = Bootstrap.newBrokerFactory(cp, null); return OpenJPAPersistence.toEntityManagerFactory(factory); } catch (Exception e) { @@ -97,9 +94,8 @@ public class PersistenceProviderImpl OpenJPAEntityManagerFactory emf = OpenJPAPersistence.toEntityManagerFactory(factory); Properties p = pui.getProperties(); - String ctOpts = null; - if (p != null) - ctOpts = p.getProperty(CLASS_TRANSFORMER_OPTIONS); + String ctOpts = (String) Configurations.getProperty + (CLASS_TRANSFORMER_OPTIONS, p); pui.addTransformer(new ClassTransformerImpl(emf.getConfiguration(), ctOpts, pui.getNewTempClassLoader())); return emf; 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 bc11de25f..3439642b6 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 @@ -403,7 +403,8 @@ 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) Configurations.getProperty + ("MetaDataFactory", map); if (factory == null) factory = Configurations.serializeProperties(metaFactoryProps); else { @@ -417,7 +418,8 @@ public class PersistenceUnitInfoImpl } // always record provider name for product derivations to access - map.put(KEY_PROVIDER, info.getPersistenceProviderClassName()); + if (info.getPersistenceProviderClassName() != null) + map.put(KEY_PROVIDER, info.getPersistenceProviderClassName()); return map; } diff --git a/openjpa-project/src/doc/manual/ref_guide_conf.xml b/openjpa-project/src/doc/manual/ref_guide_conf.xml index e2cd8f08f..2fc6f91fb 100644 --- a/openjpa-project/src/doc/manual/ref_guide_conf.xml +++ b/openjpa-project/src/doc/manual/ref_guide_conf.xml @@ -2120,11 +2120,11 @@ object-to-datastore mapping to use. MaxFetchDepth -Default:1 +Default:-1 Description: The maximum depth of relations to -traverse when eager fetching. Use -1 for no limit. Defaults to 1. See +traverse when eager fetching. Use -1 for no limit. Defaults to no limit. See for details on eager fetching. diff --git a/openjpa-project/src/doc/manual/ref_guide_pc.xml b/openjpa-project/src/doc/manual/ref_guide_pc.xml index 0975e29ab..408f8c508 100644 --- a/openjpa-project/src/doc/manual/ref_guide_pc.xml +++ b/openjpa-project/src/doc/manual/ref_guide_pc.xml @@ -1828,15 +1828,17 @@ fetch group names. You can also set the system's default maximum fetch depth with the openjpa.MaxFetchDepth configuration property. The maximum fetch depth determines how "deep" -into the object graph to traverse when loading an instance. The default maximum -depth is 1, meaning that OpenJPA will load at most the target instance and its -immediate relations. By increasing the depth, you can allow OpenJPA to also -load relations of relations, to arbitrary depth. A value of -1 symbolizes an -infinite maximum, telling OpenJPA to fetch configured relations until it reaches -the edges of the object graph. Of course, which relation fields are loaded -depends on whether the fields are eager or lazy, and on the active fetch groups. -A fetch group member's recursion depth may also limit the fetch depth to -something less than the configured maximum. +into the object graph to traverse when loading an instance. For example, with +a MaxFetchDepth of 1, OpenJPA will load at most the target +instance and its immediate relations. With a MaxFetchDepth +of 2, OpenJPA may load the target instance, its immediate relations, and +the relations of those relations. This works to arbitrary depth. In fact, +the default MaxFetchDepth value is -1, which symbolizes +infinite depth. Under this setting, OpenJPA will fetch configured relations +until it reaches the edges of the object graph. Of course, which relation +fields are loaded depends on whether the fields are eager or lazy, and on the +active fetch groups. A fetch group member's recursion depth may also limit +the fetch depth to something less than the configured maximum. OpenJPA's OpenJPAEntityManager and