OPENJPA-849 Committing code and corresponding tests contributed by Dianne Richards

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@740989 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jeremy Bauer 2009-02-05 03:30:43 +00:00
parent f99be0c0e0
commit b620c40e3e
7 changed files with 219 additions and 2 deletions

View File

@ -149,6 +149,7 @@ public class OpenJPAConfigurationImpl
public BooleanValue eagerInitialization;
public PluginValue preparedQueryCachePlugin;
public ObjectValue specification;
public IntValue queryTimeout;
// custom values
public BrokerFactoryValue brokerFactoryPlugin;
@ -441,6 +442,7 @@ public class OpenJPAConfigurationImpl
flushBeforeQueries.setAliasListComprehensive(true);
lockTimeout = addInt("LockTimeout");
lockTimeout.addEquivalentKey("javax.persistence.lock.timeout");
lockTimeout.setDefault("-1");
lockTimeout.set(-1);
lockTimeout.setDynamic(true);
@ -544,6 +546,12 @@ public class OpenJPAConfigurationImpl
addValue(specification);
specification.setInstantiatingGetter("getSpecificationInstance");
queryTimeout = addInt("javax.persistence.query.timeout");
queryTimeout.setLoadKey("javax.persistence.query.timeout");
queryTimeout.setDefault("-1");
queryTimeout.set(-1);
queryTimeout.setDynamic(true);
// initialize supported options that some runtimes may not support
supportedOptions.add(OPTION_NONTRANS_READ);
supportedOptions.add(OPTION_OPTIMISTIC);

View File

@ -23,12 +23,16 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.transaction.Transaction;
@ -108,6 +112,9 @@ public abstract class AbstractBrokerFactory
// key under which this instance can be stored in the broker pool
// and later identified
private Object _poolKey;
// Set of properties supported for the EntityManagerFactory
private Set<String> _supportedPropertyNames = new TreeSet<String>();
/**
* Return an internal factory pool key for the given configuration.
@ -427,6 +434,45 @@ public abstract class AbstractBrokerFactory
return props;
}
public Map<String, String> getAllProperties() {
Map<String, String> propertiesMap = _conf.getAllProperties();
Properties properties = getProperties();
Set<Object> propKeys = properties.keySet();
for (Object key : propKeys) {
String keyString = (String) key;
propertiesMap.put(keyString, (String) properties
.getProperty(keyString));
}
return propertiesMap;
}
public Set<String> getSupportedProperties() {
if (_supportedPropertyNames.isEmpty()) {
synchronized (_supportedPropertyNames) {
if (_supportedPropertyNames.isEmpty()) {
_supportedPropertyNames.add("AutoClear");
_supportedPropertyNames.add("AutoDetach");
_supportedPropertyNames.add("DetachState");
_supportedPropertyNames.add("IgnoreChanges");
_supportedPropertyNames.add("LockTimeout");
_supportedPropertyNames.add("Multithreaded");
_supportedPropertyNames.add("NontransactionalRead");
_supportedPropertyNames.add("NontransactionalWrite");
_supportedPropertyNames.add("Optimistic");
_supportedPropertyNames.add("RestoreState");
_supportedPropertyNames.add("RetainState");
}
}
}
Set<String> supportedProperties = new LinkedHashSet<String>();
for (String propertyName : _supportedPropertyNames) {
supportedProperties.addAll(_conf.getPropertyKeys(propertyName));
}
return supportedProperties;
}
public Object getUserObject(Object key) {
lock();
try {

View File

@ -19,6 +19,9 @@
package org.apache.openjpa.kernel;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import javax.transaction.Synchronization;
import org.apache.openjpa.ee.ManagedRuntime;
@ -188,6 +191,24 @@ public interface Broker
* managed objects should be automatically detached in-place.
*/
public void setAutoDetach(int flag, boolean on);
/**
* Retrieve the current properties for this broker Some of these properties
* may have been changed from the original configuration.
*
* @return the changed properties
*
* @since 2.0.0
*/
public Map<String, String> getProperties();
/**
* Return the supported properties for this broker as property keys. If a
* property has multiple keys, all keys will be returned.
*
* @since 2.0.0
*/
public Set<String> getSupportedProperties();
/**
* Whether to treat relations to detached instances during persist

View File

@ -19,7 +19,9 @@
package org.apache.openjpa.kernel;
import java.io.Serializable;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.lib.util.Closeable;
@ -42,6 +44,22 @@ public interface BrokerFactory
* Return properties describing this runtime.
*/
public Properties getProperties();
/**
* Return all of the configured properties plus those returned in
* @see #getProperties().
*
* @since 2.0.0
*/
public Map<String, String> getAllProperties();
/**
* Return all of the supported properties as a set of keys. If a property
* has multiple keys, all keys will be returned.
*
* @since 2.0.0
*/
public Set<String> getSupportedProperties();
/**
* Put the specified key-value pair into the map of user objects.

View File

@ -37,6 +37,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;
@ -59,6 +60,7 @@ import org.apache.openjpa.event.RemoteCommitEventManager;
import org.apache.openjpa.event.TransactionEvent;
import org.apache.openjpa.event.TransactionEventManager;
import org.apache.openjpa.kernel.exps.ExpressionParser;
import org.apache.openjpa.lib.conf.Value;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
@ -225,6 +227,10 @@ public class BrokerImpl
private boolean _cachePreparedQuery = true;
// Map of properties whose values have been changed
private Map<String, String> _changedProperties =
new HashMap<String, String>();
// status
private int _flags = 0;
@ -243,6 +249,9 @@ public class BrokerImpl
private transient boolean _initializeWasInvoked = false;
private LinkedList _fcs;
// Set of supported properties
private Set<String> _supportedPropertyNames;
/**
* Set the persistence manager's authentication. This is the first
@ -461,6 +470,8 @@ public class BrokerImpl
public void setIgnoreChanges(boolean val) {
assertOpen();
_ignoreChanges = val;
_changedProperties.put("IgnoreChanges", String
.valueOf(_ignoreChanges));
}
public boolean getNontransactionalRead() {
@ -479,6 +490,8 @@ public class BrokerImpl
("nontrans-read-not-supported"));
_nontransRead = val;
_changedProperties.put("NontransactionalRead", String
.valueOf(_nontransRead));
}
public boolean getNontransactionalWrite() {
@ -491,6 +504,8 @@ public class BrokerImpl
throw new UserException(_loc.get("illegal-op-in-prestore"));
_nontransWrite = val;
_changedProperties.put("NontransactionalWrite", String
.valueOf(_nontransWrite));
}
public boolean getOptimistic() {
@ -509,6 +524,8 @@ public class BrokerImpl
("optimistic-not-supported"));
_optimistic = val;
_changedProperties.put("Optimistic", String
.valueOf(_optimistic));
}
public int getRestoreState() {
@ -522,6 +539,8 @@ public class BrokerImpl
"Restore"));
_restoreState = val;
_changedProperties.put("RestoreState", String
.valueOf(_restoreState));
}
public boolean getRetainState() {
@ -533,6 +552,8 @@ public class BrokerImpl
if ((_flags & FLAG_PRESTORING) != 0)
throw new UserException(_loc.get("illegal-op-in-prestore"));
_retainState = val;
_changedProperties.put("RetainState", String
.valueOf(_retainState));
}
public int getAutoClear() {
@ -542,6 +563,7 @@ public class BrokerImpl
public void setAutoClear(int val) {
assertOpen();
_autoClear = val;
_changedProperties.put("AutoClear", String.valueOf(_autoClear));
}
public int getAutoDetach() {
@ -551,6 +573,8 @@ public class BrokerImpl
public void setAutoDetach(int detachFlags) {
assertOpen();
_autoDetach = detachFlags;
_changedProperties.put("AutoDetach", String
.valueOf(_autoDetach));
}
public void setAutoDetach(int detachFlag, boolean on) {
@ -559,6 +583,8 @@ public class BrokerImpl
_autoDetach |= detachFlag;
else
_autoDetach &= ~detachFlag;
_changedProperties.put("AutoDetach", String
.valueOf(_autoDetach));
}
public int getDetachState() {
@ -568,6 +594,8 @@ public class BrokerImpl
public void setDetachState(int mode) {
assertOpen();
_detachState = mode;
_changedProperties.put("DetachState", String
.valueOf(_detachState));
}
public boolean isDetachedNew() {
@ -638,9 +666,69 @@ public class BrokerImpl
}
}
//////////
public Map<String, String> getProperties() {
Map<String, String> currentProperties = _conf.getAllProperties();
// Update the properties from the config with properties that may
// have changed for this broker
if (!_changedProperties.isEmpty()) {
Set<String> changedKeys = _changedProperties.keySet();
for (String changedKey : changedKeys) {
Value value = _conf.getValue(changedKey);
String valueKey = value.getLoadKey();
if (valueKey == null) {
valueKey = "openjpa." + value.getProperty();
}
if (currentProperties.containsKey(valueKey)) {
currentProperties.put(valueKey, _changedProperties
.get(changedKey));
}
else {
Set<String> equivalentKeys = value.getEquivalentKeys();
if (!equivalentKeys.isEmpty()) {
for (String equivalentKey : equivalentKeys) {
if (currentProperties.containsKey(equivalentKey)) {
currentProperties.put(equivalentKey,
_changedProperties.get(changedKey));
break;
}
}
}
}
}
}
return currentProperties;
}
public Set<String> getSupportedProperties() {
if (_supportedPropertyNames == null) {
_supportedPropertyNames = new TreeSet<String>();
_supportedPropertyNames.add("AutoClear");
_supportedPropertyNames.add("AutoDetach");
_supportedPropertyNames.add("DetachState");
_supportedPropertyNames.add("IgnoreChanges");
_supportedPropertyNames.add("LockTimeout");
_supportedPropertyNames.add("Multithreaded");
_supportedPropertyNames.add("NontransactionalRead");
_supportedPropertyNames.add("NontransactionalWrite");
_supportedPropertyNames.add("Optimistic");
_supportedPropertyNames.add("javax.persistence.query.timeout");
_supportedPropertyNames.add("RestoreState");
_supportedPropertyNames.add("RetainState");
}
Set<String> supportedProperties = new LinkedHashSet<String>();
for (String propertyName : _supportedPropertyNames) {
supportedProperties.addAll(_conf.getPropertyKeys(propertyName));
}
return supportedProperties;
}
// ////////
// Events
//////////
// ////////
public void addLifecycleListener(Object listener, Class[] classes) {
beginOperation(false);

View File

@ -21,6 +21,8 @@ package org.apache.openjpa.kernel;
import java.util.BitSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.ee.ManagedRuntime;
@ -177,6 +179,22 @@ public class DelegatingBroker
throw translate(re);
}
}
public Map<String, String> getProperties() {
try {
return _broker.getProperties();
} catch (RuntimeException re) {
throw translate(re);
}
}
public Set<String> getSupportedProperties() {
try {
return _broker.getSupportedProperties();
} catch (RuntimeException re) {
throw translate(re);
}
}
public Object find(Object oid, boolean validate, FindCallbacks call) {
try {

View File

@ -18,7 +18,9 @@
*/
package org.apache.openjpa.kernel;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.util.RuntimeExceptionTranslator;
@ -111,6 +113,22 @@ public class DelegatingBrokerFactory
throw translate(re);
}
}
public Set<String> getSupportedProperties() {
try {
return _factory.getSupportedProperties();
} catch (RuntimeException re) {
throw translate(re);
}
}
public Map<String, String> getAllProperties() {
try {
return _factory.getAllProperties();
} catch (RuntimeException re) {
throw translate(re);
}
}
public Object putUserObject(Object key, Object val) {
try {