Change default MaxFetchDepth to -1 (unlimited). Also move the use of multiple

configuration prefixes to ProductDerivations for simple static access.  Modify
some cases of looking for "openjpa." prefixes to properties to properly look 
for all configured prefixes instead.



git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@450114 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
A. Abram White 2006-09-26 16:54:30 +00:00
parent d3956a7d98
commit 62bc6c997c
25 changed files with 182 additions and 143 deletions

View File

@ -241,7 +241,6 @@ public interface JDBCConfiguration
* <li><code>parallel</code>: When querying for objects, also select for * <li><code>parallel</code>: When querying for objects, also select for
* both 1-1 relations using joins and to-many relations using batched * both 1-1 relations using joins and to-many relations using batched
* selects.</li> * selects.</li>
* </li>
* </ul> * </ul>
*/ */
public void setEagerFetchMode(String mode); public void setEagerFetchMode(String mode);

View File

@ -865,9 +865,15 @@ public class JDBCConfigurationImpl
} }
protected boolean isInvalidProperty(String propName) { protected boolean isInvalidProperty(String propName) {
if (super.isInvalidProperty(propName))
return true;
// handle openjpa.jdbc.SomeMisspelledProperty, but not // handle openjpa.jdbc.SomeMisspelledProperty, but not
// openjpa.someotherimplementation.SomeProperty // openjpa.someotherimplementation.SomeProperty
return super.isInvalidProperty(propName) String[] prefixes = ProductDerivations.getConfigurationPrefixes();
|| propName.toLowerCase().startsWith("openjpa.jdbc"); for (int i = 0; i < prefixes.length; i++)
if (propName.toLowerCase().startsWith(prefixes[i] + ".jdbc"))
return true;
return false;
} }
} }

View File

@ -39,8 +39,7 @@ public class JDBCProductDerivation extends AbstractProductDerivation
public boolean beforeConfigurationConstruct(ConfigurationProvider cp) { public boolean beforeConfigurationConstruct(ConfigurationProvider cp) {
// default to JDBC when no broker factory set // default to JDBC when no broker factory set
if (BrokerFactoryValue.get(cp) == null) { if (BrokerFactoryValue.get(cp) == null) {
cp.addProperty(BrokerFactoryValue.getKey(cp), BrokerFactoryValue.set(cp, JDBCBrokerFactory.class.getName());
JDBCBrokerFactory.class.getName());
return true; return true;
} }
return false; return false;

View File

@ -930,7 +930,7 @@ public class MappingTool
flags.dropTables = opts.removeBooleanProperty flags.dropTables = opts.removeBooleanProperty
("dropTables", "dt", flags.dropTables); ("dropTables", "dt", flags.dropTables);
flags.openjpaTables = opts.removeBooleanProperty flags.openjpaTables = opts.removeBooleanProperty
("openjpaTables", "kt", flags.openjpaTables); ("openjpaTables", "ot", flags.openjpaTables);
flags.dropSequences = opts.removeBooleanProperty flags.dropSequences = opts.removeBooleanProperty
("dropSequences", "dsq", flags.dropSequences); ("dropSequences", "dsq", flags.dropSequences);
flags.readSchema = opts.removeBooleanProperty flags.readSchema = opts.removeBooleanProperty

View File

@ -1376,7 +1376,7 @@ public class SchemaTool {
flags.ignoreErrors = opts.removeBooleanProperty flags.ignoreErrors = opts.removeBooleanProperty
("ignoreErrors", "i", flags.ignoreErrors); ("ignoreErrors", "i", flags.ignoreErrors);
flags.openjpaTables = opts.removeBooleanProperty flags.openjpaTables = opts.removeBooleanProperty
("openjpaTables", "kt", flags.openjpaTables); ("openjpaTables", "ot", flags.openjpaTables);
flags.primaryKeys = opts.removeBooleanProperty flags.primaryKeys = opts.removeBooleanProperty
("primaryKeys", "pk", flags.primaryKeys); ("primaryKeys", "pk", flags.primaryKeys);
flags.foreignKeys = opts.removeBooleanProperty flags.foreignKeys = opts.removeBooleanProperty

View File

@ -80,7 +80,7 @@ public class OracleDictionary
public String autoAssignSequenceName = null; 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. * trigger name for backwards compatibility.
*/ */
public boolean openjpa3GeneratedKeyNames = false; public boolean openjpa3GeneratedKeyNames = false;

View File

@ -264,7 +264,7 @@ tool-usage: Usage: java org.apache.openjpa.jdbc.meta.MappingTool\n\
\t[-foreignKeys/-fk <true/t | false/f>]\n\ \t[-foreignKeys/-fk <true/t | false/f>]\n\
\t[-indexes/-ix <true/t | false/f>]\n\ \t[-indexes/-ix <true/t | false/f>]\n\
\t[-dropTables/-dt <true/t | false/f>]\n\ \t[-dropTables/-dt <true/t | false/f>]\n\
\t[-openjpaTables/-kt <true/t | false/f>]\n\ \t[-openjpaTables/-ot <true/t | false/f>]\n\
\t[-dropSequences/-dsq <true/t | false/f>]\n\ \t[-dropSequences/-dsq <true/t | false/f>]\n\
\t[-sequences/-sq <true/t | false/f>]\n\ \t[-sequences/-sq <true/t | false/f>]\n\
\t[-ignoreErrors/-i <true/t | false/f>]\n\ \t[-ignoreErrors/-i <true/t | false/f>]\n\

View File

@ -54,7 +54,7 @@ tool-usage: Usage: java org.apache.openjpa.jdbc.schema.SchemaTool\n\
\t[-file/-f <stdout | output file or resource>]\n\ \t[-file/-f <stdout | output file or resource>]\n\
\t[-ignoreErrors/-i <true/t | false/f>]\n\ \t[-ignoreErrors/-i <true/t | false/f>]\n\
\t[-dropTables/-dt <true/t | false/f>]\n\ \t[-dropTables/-dt <true/t | false/f>]\n\
\t[-openjpaTables/-kt <true/t | false/f>]\n\ \t[-openjpaTables/-ot <true/t | false/f>]\n\
\t[-dropSequences/-dsq <true/t | false/f>]\n\ \t[-dropSequences/-dsq <true/t | false/f>]\n\
\t[-sequences/-sq <true/t | false/f>]\n\ \t[-sequences/-sq <true/t | false/f>]\n\
\t[-primaryKeys/-pk <true/t | false/f>]\n\ \t[-primaryKeys/-pk <true/t | false/f>]\n\

View File

@ -23,6 +23,7 @@ import org.apache.openjpa.abstractstore.AbstractStoreBrokerFactory;
import org.apache.openjpa.kernel.BrokerFactory; import org.apache.openjpa.kernel.BrokerFactory;
import org.apache.openjpa.lib.conf.ConfigurationProvider; import org.apache.openjpa.lib.conf.ConfigurationProvider;
import org.apache.openjpa.lib.conf.PluginValue; 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 * 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 _aliases = new ArrayList();
private static final List _prefixes = new ArrayList(2); private static final List _prefixes = new ArrayList(2);
static { static {
_prefixes.add("openjpa");
addDefaultAlias("abstractstore", addDefaultAlias("abstractstore",
AbstractStoreBrokerFactory.class.getName()); AbstractStoreBrokerFactory.class.getName());
} }
/**
* Add <code>prefix</code> 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 <code>alias</code> to <code>cls</code> to the list * Add a mapping from <code>alias</code> to <code>cls</code> to the list
* of default aliases for new values created after this invocation. * 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. * Extract the value of this property if set in the given provider.
*/ */
public static Object get(ConfigurationProvider cp) { public static Object get(ConfigurationProvider cp) {
String[] prefixes = ProductDerivations.getConfigurationPrefixes();
Map props = cp.getProperties(); Map props = cp.getProperties();
Object bf; Object bf;
for (int i = 0; i < _prefixes.size (); i++) { for (int i = 0; i < prefixes.length; i++) {
bf = props.get(_prefixes.get(i) + "." + KEY); bf = props.get(prefixes[i] + "." + KEY);
if (bf != null) if (bf != null)
return bf; 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) { public static void set(ConfigurationProvider cp, String value) {
return _prefixes.get(0) + "." + KEY; cp.addProperty("openjpa." + KEY, value);
} }
public BrokerFactoryValue() { public BrokerFactoryValue() {

View File

@ -165,14 +165,6 @@ public class OpenJPAConfigurationImpl
super(false); super(false);
String[] aliases; 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); classResolverPlugin = addPlugin("ClassResolver", true);
aliases = new String[]{ aliases = new String[]{
"default", "org.apache.openjpa.util.ClassResolverImpl", "default", "org.apache.openjpa.util.ClassResolverImpl",
@ -401,8 +393,8 @@ public class OpenJPAConfigurationImpl
fetchBatchSize.set(-1); fetchBatchSize.set(-1);
maxFetchDepth = addInt("MaxFetchDepth"); maxFetchDepth = addInt("MaxFetchDepth");
maxFetchDepth.setDefault("1"); maxFetchDepth.setDefault("-1");
maxFetchDepth.set(1); maxFetchDepth.set(-1);
fetchGroups = addStringList("FetchGroups"); fetchGroups = addStringList("FetchGroups");
fetchGroups.setDefault("default"); fetchGroups.setDefault("default");

View File

@ -3399,8 +3399,8 @@ public class BrokerImpl
default: default:
// use store manager for native sequence // use store manager for native sequence
if (fmd == null) { if (fmd == null) {
// this will return a sequence even for app id classes, which // this will return a sequence even for app id classes,
// is what we want for backwards-compatibility // which is what we want for backwards-compatibility
return _store.getDataStoreIdSequence(meta); return _store.getDataStoreIdSequence(meta);
} }
return _store.getValueSequence(fmd); return _store.getValueSequence(fmd);

View File

@ -297,8 +297,7 @@ public class QueryImpl
_extent = _broker.newExtent(cls, _subclasses); _extent = _broker.newExtent(cls, _subclasses);
_extent.setIgnoreChanges(_ignoreChanges); _extent.setIgnoreChanges(_ignoreChanges);
} else if (_extent != null } else if (_extent != null
&& _extent.getIgnoreChanges() != _ignoreChanges && cls != null) && _extent.getIgnoreChanges() != _ignoreChanges && cls != null){
{
_extent = _broker.newExtent(cls, _extent.hasSubclasses()); _extent = _broker.newExtent(cls, _extent.hasSubclasses());
_extent.setIgnoreChanges(_ignoreChanges); _extent.setIgnoreChanges(_ignoreChanges);
} }

View File

@ -27,6 +27,10 @@ import java.util.Map;
public abstract class AbstractProductDerivation public abstract class AbstractProductDerivation
implements ProductDerivation { implements ProductDerivation {
public String getConfigurationPrefix() {
return null;
}
public ConfigurationProvider loadGlobals(ClassLoader loader) public ConfigurationProvider loadGlobals(ClassLoader loader)
throws Exception { throws Exception {
return null; return null;

View File

@ -78,8 +78,7 @@ public interface Configuration
public String getProductName(); public String getProductName();
/** /**
* Set the product name. The set name will automatically be added to * Set the product name.
* the property prefixes.
*/ */
public void setProductName(String name); public void setProductName(String name);
@ -160,14 +159,6 @@ public interface Configuration
*/ */
public void fromProperties(Map map); public void fromProperties(Map map);
/**
* Add <code>prefix</code> 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 * Adds a listener for any property changes. The property events fired
* will <b>not</b> include the old value. * will <b>not</b> include the old value.

View File

@ -108,7 +108,6 @@ public class ConfigurationImpl
private boolean _globals = false; private boolean _globals = false;
private String _auto = null; private String _auto = null;
private final List _vals = new ArrayList(); private final List _vals = new ArrayList();
private List _prefixes = new ArrayList(2);
// property listener helper // property listener helper
private PropertyChangeSupport _changeSupport = null; private PropertyChangeSupport _changeSupport = null;
@ -131,11 +130,12 @@ public class ConfigurationImpl
* @param loadGlobals whether to attempt to load the global properties * @param loadGlobals whether to attempt to load the global properties
*/ */
public ConfigurationImpl(boolean loadGlobals) { public ConfigurationImpl(boolean loadGlobals) {
setProductName("openjpa"); // also adds as prop prefix setProductName("openjpa");
logFactoryPlugin = addPlugin("Log", true); logFactoryPlugin = addPlugin("Log", true);
String[] aliases = new String[]{ String[] aliases = new String[]{
"true", LogFactoryImpl.class.getName(), "true", LogFactoryImpl.class.getName(),
"openjpa", LogFactoryImpl.class.getName(),
"commons", "org.apache.openjpa.lib.log.CommonsLogFactory", "commons", "org.apache.openjpa.lib.log.CommonsLogFactory",
"log4j", "org.apache.openjpa.lib.log.Log4JLogFactory", "log4j", "org.apache.openjpa.lib.log.Log4JLogFactory",
"none", NoneLogFactory.class.getName(), "none", NoneLogFactory.class.getName(),
@ -183,7 +183,6 @@ public class ConfigurationImpl
public void setProductName(String name) { public void setProductName(String name) {
_product = name; _product = name;
addPropertyPrefix(name);
} }
public LogFactory getLogFactory() { public LogFactory getLogFactory() {
@ -307,8 +306,8 @@ public class ConfigurationImpl
// keep cached props up to date // keep cached props up to date
if (_props != null) { if (_props != null) {
if (newString == null) if (newString == null)
remove(_props, val); Configurations.removeProperty(val.getProperty(), _props);
else if (containsKey(_props, val) else if (Configurations.containsProperty(val.getProperty(), _props)
|| val.getDefault() == null || val.getDefault() == null
|| !val.getDefault().equals(newString)) || !val.getDefault().equals(newString))
put(_props, val, newString); put(_props, val, newString);
@ -534,11 +533,6 @@ public class ConfigurationImpl
// To/from maps // To/from maps
//////////////// ////////////////
public void addPropertyPrefix(String prefix) {
if (!_prefixes.contains(prefix))
_prefixes.add(prefix);
}
public Map toProperties(boolean storeDefaults) { public Map toProperties(boolean storeDefaults) {
// clone properties before making any modifications; we need to keep // clone properties before making any modifications; we need to keep
// the internal properties instance consistent to maintain equals and // 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 // if key in existing properties, we already know value is up
// to date // to date
val = (Value) _vals.get(i); val = (Value) _vals.get(i);
if (_props != null && containsKey(_props, val)) if (_props != null && Configurations.containsProperty
(val.getProperty(), _props))
continue; continue;
str = val.getString(); str = val.getString();
@ -605,14 +600,13 @@ public class ConfigurationImpl
ser &= o instanceof Serializable; ser &= o instanceof Serializable;
val.setObject(o); val.setObject(o);
} }
remove(remaining, val); Configurations.removeProperty(val.getProperty(), remaining);
} }
// convention is to point product at a resource with the // convention is to point product at a resource with the
// <prefix>.properties System property; remove that property so we // <prefix>.properties System property; remove that property so we
// we don't warn about it // we don't warn about it
for (int i = 0; i < _prefixes.size(); i++) Configurations.removeProperty("properties", remaining);
remaining.remove(_prefixes.get(i) + ".properties");
// now warn if there are any remaining properties that there // now warn if there are any remaining properties that there
// is an unhandled prop // is an unhandled prop
@ -637,39 +631,20 @@ public class ConfigurationImpl
private void put(Map map, Value val, Object o) { private void put(Map map, Value val, Object o) {
Object key = val.getLoadKey(); Object key = val.getLoadKey();
if (key == null) if (key == null)
key = _prefixes.get(0) + "." + val.getProperty(); key = "openjpa." + val.getProperty();
map.put(key, o); map.put(key, o);
} }
/**
* Return whether <code>map</code> contains an entry for <code>val</code>.
*/
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 <code>val</code> from <code>map</code>. 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. * Look up the given value, testing all available prefixes.
*/ */
private Object get(Map map, Value val, boolean setLoadKey) { private Object get(Map map, Value val, boolean setLoadKey) {
String[] prefixes = ProductDerivations.getConfigurationPrefixes();
String firstKey = null; String firstKey = null;
String key; String key;
Object o = null; Object o = null;
for (int i = 0; i < _prefixes.size(); i++) { for (int i = 0; i < prefixes.length; i++) {
key = _prefixes.get(i) + "." + val.getProperty(); key = prefixes[i] + "." + val.getProperty();
if (firstKey == null) { if (firstKey == null) {
o = map.get(key); o = map.get(key);
if (o != null) if (o != null)
@ -712,11 +687,11 @@ public class ConfigurationImpl
* Return a comprehensive list of recognized map keys. * Return a comprehensive list of recognized map keys.
*/ */
private Collection newPropertyList() { 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 i = 0; i < _vals.size(); i++) {
for (int j = 0; j < _prefixes.size(); j++) for (int j = 0; j < prefixes.length; j++)
l.add(_prefixes.get(j) + "." l.add(prefixes[j] + "." + ((Value) _vals.get(i)).getProperty());
+ ((Value) _vals.get(i)).getProperty());
} }
return l; return l;
} }
@ -729,12 +704,11 @@ public class ConfigurationImpl
// handle warnings for openjpa.SomeString, but not for // handle warnings for openjpa.SomeString, but not for
// openjpa.some.subpackage.SomeString, since it might be valid for some // openjpa.some.subpackage.SomeString, since it might be valid for some
// specific implementation of OpenJPA // specific implementation of OpenJPA
String prefix; String[] prefixes = ProductDerivations.getConfigurationPrefixes();
for (int i = 0; i < _prefixes.size(); i++) { for (int i = 0; i < prefixes.length; i++) {
prefix = (String) _prefixes.get(i) + "."; if (propName.toLowerCase().startsWith(prefixes[i])
if (propName.toLowerCase().startsWith(prefix) && propName.length() > prefixes[i].length()
&& propName.length() > prefix.length() && propName.indexOf('.', prefixes[i].length()) == -1)
&& propName.indexOf('.', prefix.length()) == -1)
return true; return true;
} }
return false; return false;
@ -861,7 +835,6 @@ public class ConfigurationImpl
public void readExternal(ObjectInput in) public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException { throws IOException, ClassNotFoundException {
fromProperties((Map) in.readObject()); fromProperties((Map) in.readObject());
_prefixes = (List) in.readObject();
_globals = in.readBoolean(); _globals = in.readBoolean();
} }
@ -874,7 +847,6 @@ public class ConfigurationImpl
out.writeObject(_props); out.writeObject(_props);
else else
out.writeObject(toProperties(false)); out.writeObject(toProperties(false));
out.writeObject(_prefixes);
out.writeBoolean(_globals); out.writeBoolean(_globals);
} }
@ -888,8 +860,6 @@ public class ConfigurationImpl
(new Class[]{ boolean.class }); (new Class[]{ boolean.class });
ConfigurationImpl clone = (ConfigurationImpl) cons.newInstance ConfigurationImpl clone = (ConfigurationImpl) cons.newInstance
(new Object[]{ Boolean.FALSE }); (new Object[]{ Boolean.FALSE });
clone._prefixes.clear();
clone._prefixes.addAll(_prefixes);
clone._globals = _globals; clone._globals = _globals;
clone.fromProperties(toProperties(true)); clone.fromProperties(toProperties(true));
return clone; return clone;

View File

@ -468,4 +468,53 @@ public class Configurations {
try { ctx.close(); } catch (Exception e) {} 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;
}
} }

View File

@ -40,6 +40,11 @@ public interface ProductDerivation {
*/ */
public int getType(); 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 * Load globals into the returned ConfigurationProvider, or return null if
* no globals is found. * no globals is found.

View File

@ -34,6 +34,7 @@ import org.apache.openjpa.lib.util.Services;
public class ProductDerivations { public class ProductDerivations {
private static final ProductDerivation[] _derivations; private static final ProductDerivation[] _derivations;
private static final String[] _prefixes;
static { static {
Class[] pdcls = Services.getImplementorClasses(ProductDerivation.class, Class[] pdcls = Services.getImplementorClasses(ProductDerivation.class,
ProductDerivation.class.getClassLoader()); ProductDerivation.class.getClassLoader());
@ -59,6 +60,24 @@ public class ProductDerivations {
Collections.sort(derivations, new ProductDerivationComparator()); Collections.sort(derivations, new ProductDerivationComparator());
_derivations = (ProductDerivation[]) derivations.toArray _derivations = (ProductDerivation[]) derivations.toArray
(new ProductDerivation[derivations.size()]); (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;
} }
/** /**

View File

@ -69,8 +69,8 @@ public class TestPersistence
// openjpa-facade test // openjpa-facade test
assertTrue(em instanceof OpenJPAEntityManager); assertTrue(em instanceof OpenJPAEntityManager);
OpenJPAEntityManager ojem = (OpenJPAEntityManager) em; OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
ojem.getFetchPlan().setMaxFetchDepth(-1); ojem.getFetchPlan().setMaxFetchDepth(1);
assertEquals(-1, ojem.getFetchPlan().getMaxFetchDepth()); assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
em.close(); em.close();
} }

View File

@ -34,6 +34,8 @@ import org.apache.openjpa.kernel.BrokerFactory;
import org.apache.openjpa.kernel.DelegatingBrokerFactory; import org.apache.openjpa.kernel.DelegatingBrokerFactory;
import org.apache.openjpa.kernel.DelegatingFetchConfiguration; import org.apache.openjpa.kernel.DelegatingFetchConfiguration;
import org.apache.openjpa.kernel.FetchConfiguration; 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.conf.Value;
import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.util.ImplHelper; import org.apache.openjpa.util.ImplHelper;
@ -145,42 +147,42 @@ public class EntityManagerFactoryImpl
props = new HashMap(props); props = new HashMap(props);
OpenJPAConfiguration conf = getConfiguration(); OpenJPAConfiguration conf = getConfiguration();
String user = String user = (String) Configurations.removeProperty
(String) props.remove("openjpa.ConnectionUserName"); ("ConnectionUserName", props);
if (user == null) if (user == null)
user = conf.getConnectionUserName(); user = conf.getConnectionUserName();
String pass = String pass = (String) Configurations.removeProperty
(String) props.remove("openjpa.ConnectionPassword"); ("ConnectionPassword", props);
if (pass == null) if (pass == null)
pass = conf.getConnectionPassword(); pass = conf.getConnectionPassword();
String str = String str = (String) Configurations.removeProperty
(String) props.remove("openjpa.TransactionMode"); ("TransactionMode", props);
boolean managed; boolean managed;
if (str == null) if (str == null)
managed = conf.isTransactionModeManaged(); managed = conf.isTransactionModeManaged();
else { else {
Value val = conf.getValue("openjpa.TransactionMode"); Value val = conf.getValue("TransactionMode");
managed = Boolean.parseBoolean(val.unalias(str)); managed = Boolean.parseBoolean(val.unalias(str));
} }
Object obj = props.remove("openjpa.ConnectionRetainMode"); Object obj = Configurations.removeProperty("ConnectionRetainMode",
props);
int retainMode; int retainMode;
if (obj instanceof Number) if (obj instanceof Number)
retainMode = ((Number) obj).intValue(); retainMode = ((Number) obj).intValue();
else if (obj != null) { else if (obj == null)
Value val = retainMode = conf.getConnectionRetainModeConstant();
conf.getValue("openjpa.ConnectionRetainMode"); else {
Value val = conf.getValue("ConnectionRetainMode");
try { try {
retainMode = Integer.parseInt(val.unalias((String) obj)); retainMode = Integer.parseInt(val.unalias((String) obj));
} catch (Exception e) { } catch (Exception e) {
throw new ArgumentException(_loc.get("bad-em-prop", throw new ArgumentException(_loc.get("bad-em-prop",
"openjpa.ConnectionRetainMode", obj), "openjpa.ConnectionRetainMode", obj),
new Throwable[]{ e }, new Throwable[]{ e }, obj, true);
obj, true); }
} }
} else
retainMode = conf.getConnectionRetainModeConstant();
Broker broker = _factory.newBroker(user, pass, managed, retainMode, Broker broker = _factory.newBroker(user, pass, managed, retainMode,
false); false);
@ -191,15 +193,23 @@ public class EntityManagerFactoryImpl
OpenJPAEntityManager em = newEntityManagerImpl(broker); OpenJPAEntityManager em = newEntityManagerImpl(broker);
// allow setting of other bean properties of EM // allow setting of other bean properties of EM
String[] prefixes = ProductDerivations.getConfigurationPrefixes();
List<RuntimeException> errs = null; List<RuntimeException> errs = null;
Method setter = null; Method setter = null;
String prop; String prop, prefix;
Object val; Object val;
for (Map.Entry entry : (Set<Map.Entry>) props.entrySet()) { for (Map.Entry entry : (Set<Map.Entry>) props.entrySet()) {
prop = (String) entry.getKey(); prop = (String) entry.getKey();
if (!prop.startsWith("openjpa.")) prefix = null;
for (int i = 0; i < prefixes.length; i++) {
prefix = prefixes[i] + ".";
if (prop.startsWith(prefix))
break;
prefix = null;
}
if (prefix == null)
continue; continue;
prop = prop.substring("openjpa.".length()); prop = prop.substring(prefix.length());
try { try {
setter = ImplHelper.getSetter(em.getClass(), prop); setter = ImplHelper.getSetter(em.getClass(), prop);
} catch (OpenJPAException ke) { } catch (OpenJPAException ke) {

View File

@ -32,6 +32,7 @@ import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.conf.OpenJPAConfigurationImpl; import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
import org.apache.openjpa.conf.OpenJPAProductDerivation; import org.apache.openjpa.conf.OpenJPAProductDerivation;
import org.apache.openjpa.lib.conf.AbstractProductDerivation; 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.Configuration;
import org.apache.openjpa.lib.conf.ConfigurationProvider; import org.apache.openjpa.lib.conf.ConfigurationProvider;
import org.apache.openjpa.lib.conf.MapConfigurationProvider; import org.apache.openjpa.lib.conf.MapConfigurationProvider;
@ -180,7 +181,10 @@ public class PersistenceProductDerivation
@Override @Override
public ConfigurationProvider loadGlobals(ClassLoader loader) public ConfigurationProvider loadGlobals(ClassLoader loader)
throws IOException { 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); boolean explicit = !StringUtils.isEmpty(rsrc);
String anchor = null; String anchor = null;
int idx = (!explicit) ? -1 : rsrc.lastIndexOf('#'); int idx = (!explicit) ? -1 : rsrc.lastIndexOf('#');

View File

@ -50,8 +50,7 @@ import org.apache.openjpa.meta.MetaDataRepository;
public class PersistenceProviderImpl public class PersistenceProviderImpl
implements PersistenceProvider { implements PersistenceProvider {
static final String CLASS_TRANSFORMER_OPTIONS = static final String CLASS_TRANSFORMER_OPTIONS = "ClassTransformerOptions";
"openjpa.ClassTransformerOptions";
/** /**
* Loads the entity manager specified by <code>name</code>, applying * Loads the entity manager specified by <code>name</code>, applying
@ -71,8 +70,6 @@ public class PersistenceProviderImpl
if (cp == null) if (cp == null)
return null; return null;
if (m != null)
cp.addProperties(m);
BrokerFactory factory = Bootstrap.newBrokerFactory(cp, null); BrokerFactory factory = Bootstrap.newBrokerFactory(cp, null);
return OpenJPAPersistence.toEntityManagerFactory(factory); return OpenJPAPersistence.toEntityManagerFactory(factory);
} catch (Exception e) { } catch (Exception e) {
@ -97,9 +94,8 @@ public class PersistenceProviderImpl
OpenJPAEntityManagerFactory emf = OpenJPAEntityManagerFactory emf =
OpenJPAPersistence.toEntityManagerFactory(factory); OpenJPAPersistence.toEntityManagerFactory(factory);
Properties p = pui.getProperties(); Properties p = pui.getProperties();
String ctOpts = null; String ctOpts = (String) Configurations.getProperty
if (p != null) (CLASS_TRANSFORMER_OPTIONS, p);
ctOpts = p.getProperty(CLASS_TRANSFORMER_OPTIONS);
pui.addTransformer(new ClassTransformerImpl(emf.getConfiguration(), pui.addTransformer(new ClassTransformerImpl(emf.getConfiguration(),
ctOpts, pui.getNewTempClassLoader())); ctOpts, pui.getNewTempClassLoader()));
return emf; return emf;

View File

@ -403,7 +403,8 @@ public class PersistenceUnitInfoImpl
} }
if (!metaFactoryProps.isEmpty()) { if (!metaFactoryProps.isEmpty()) {
// set persistent class locations as properties of metadata factory // 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) if (factory == null)
factory = Configurations.serializeProperties(metaFactoryProps); factory = Configurations.serializeProperties(metaFactoryProps);
else { else {
@ -417,6 +418,7 @@ public class PersistenceUnitInfoImpl
} }
// always record provider name for product derivations to access // always record provider name for product derivations to access
if (info.getPersistenceProviderClassName() != null)
map.put(KEY_PROVIDER, info.getPersistenceProviderClassName()); map.put(KEY_PROVIDER, info.getPersistenceProviderClassName());
return map; return map;
} }

View File

@ -2120,11 +2120,11 @@ object-to-datastore mapping to use.
MaxFetchDepth</literal> MaxFetchDepth</literal>
</para> </para>
<para> <para>
<emphasis role="bold">Default:</emphasis><literal>1</literal> <emphasis role="bold">Default:</emphasis><literal>-1</literal>
</para> </para>
<para> <para>
<emphasis role="bold">Description:</emphasis> The maximum depth of relations to <emphasis role="bold">Description:</emphasis> 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
<xref linkend="ref_guide_perfpack_eager"/> for details on eager fetching. <xref linkend="ref_guide_perfpack_eager"/> for details on eager fetching.
</para> </para>
</section> </section>

View File

@ -1828,15 +1828,17 @@ fetch group names.
You can also set the system's default maximum fetch depth with the You can also set the system's default maximum fetch depth with the
<link linkend="openjpa.MaxFetchDepth"><literal>openjpa.MaxFetchDepth</literal> <link linkend="openjpa.MaxFetchDepth"><literal>openjpa.MaxFetchDepth</literal>
</link> configuration property. The maximum fetch depth determines how "deep" </link> configuration property. The maximum fetch depth determines how "deep"
into the object graph to traverse when loading an instance. The default maximum into the object graph to traverse when loading an instance. For example, with
depth is 1, meaning that OpenJPA will load at most the target instance and its a <literal>MaxFetchDepth</literal> of 1, OpenJPA will load at most the target
immediate relations. By increasing the depth, you can allow OpenJPA to also instance and its immediate relations. With a <literal>MaxFetchDepth</literal>
load relations of relations, to arbitrary depth. A value of -1 symbolizes an of 2, OpenJPA may load the target instance, its immediate relations, and
infinite maximum, telling OpenJPA to fetch configured relations until it reaches the relations of those relations. This works to arbitrary depth. In fact,
the edges of the object graph. Of course, which relation fields are loaded the default <literal>MaxFetchDepth</literal> value is -1, which symbolizes
depends on whether the fields are eager or lazy, and on the active fetch groups. infinite depth. Under this setting, OpenJPA will fetch configured relations
A fetch group member's recursion depth may also limit the fetch depth to until it reaches the edges of the object graph. Of course, which relation
something less than the configured maximum. 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.
</para> </para>
<para> <para>
OpenJPA's <classname>OpenJPAEntityManager</classname> and <classname> OpenJPA's <classname>OpenJPAEntityManager</classname> and <classname>