openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrba...@apache.org
Subject svn commit: r740989 - in /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa: conf/ kernel/
Date Thu, 05 Feb 2009 03:30:43 GMT
Author: jrbauer
Date: Thu Feb  5 03:30:43 2009
New Revision: 740989

URL: http://svn.apache.org/viewvc?rev=740989&view=rev
Log:
OPENJPA-849 Committing code and corresponding tests contributed by Dianne Richards

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Broker.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java?rev=740989&r1=740988&r2=740989&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
Thu Feb  5 03:30:43 2009
@@ -149,6 +149,7 @@
     public BooleanValue eagerInitialization;
     public PluginValue preparedQueryCachePlugin;
     public ObjectValue specification;
+    public IntValue queryTimeout;
     
     // custom values
     public BrokerFactoryValue brokerFactoryPlugin;
@@ -441,6 +442,7 @@
         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 @@
         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);

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?rev=740989&r1=740988&r2=740989&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
Thu Feb  5 03:30:43 2009
@@ -23,12 +23,16 @@
 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 @@
     // 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 @@
         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 {

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Broker.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Broker.java?rev=740989&r1=740988&r2=740989&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Broker.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Broker.java Thu Feb
 5 03:30:43 2009
@@ -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 @@
      * 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

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java?rev=740989&r1=740988&r2=740989&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
Thu Feb  5 03:30:43 2009
@@ -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 @@
      * 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.

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?rev=740989&r1=740988&r2=740989&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java Thu
Feb  5 03:30:43 2009
@@ -37,6 +37,7 @@
 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.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 @@
     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 @@
 
     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 void setIgnoreChanges(boolean val) {
         assertOpen();
         _ignoreChanges = val;
+        _changedProperties.put("IgnoreChanges", String
+            .valueOf(_ignoreChanges));
     }
 
     public boolean getNontransactionalRead() {
@@ -479,6 +490,8 @@
                 ("nontrans-read-not-supported"));
 
         _nontransRead = val;
+        _changedProperties.put("NontransactionalRead", String
+            .valueOf(_nontransRead));
     }
 
     public boolean getNontransactionalWrite() {
@@ -491,6 +504,8 @@
             throw new UserException(_loc.get("illegal-op-in-prestore"));
 
         _nontransWrite = val;
+        _changedProperties.put("NontransactionalWrite", String
+            .valueOf(_nontransWrite));
     }
 
     public boolean getOptimistic() {
@@ -509,6 +524,8 @@
                 ("optimistic-not-supported"));
 
         _optimistic = val;
+        _changedProperties.put("Optimistic", String
+            .valueOf(_optimistic));
     }
 
     public int getRestoreState() {
@@ -522,6 +539,8 @@
                 "Restore"));
 
         _restoreState = val;
+        _changedProperties.put("RestoreState", String
+            .valueOf(_restoreState));
     }
 
     public boolean getRetainState() {
@@ -533,6 +552,8 @@
         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 void setAutoClear(int val) {
         assertOpen();
         _autoClear = val;
+        _changedProperties.put("AutoClear", String.valueOf(_autoClear));
     }
 
     public int getAutoDetach() {
@@ -551,6 +573,8 @@
     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 @@
             _autoDetach |= detachFlag;
         else
             _autoDetach &= ~detachFlag;
+        _changedProperties.put("AutoDetach", String
+            .valueOf(_autoDetach));
     }
 
     public int getDetachState() {
@@ -568,6 +594,8 @@
     public void setDetachState(int mode) {
         assertOpen();
         _detachState = mode;
+        _changedProperties.put("DetachState", String
+            .valueOf(_detachState));
     }
 
     public boolean isDetachedNew() {
@@ -638,9 +666,69 @@
         }
     }
 
-    //////////
+    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);

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java?rev=740989&r1=740988&r2=740989&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java
Thu Feb  5 03:30:43 2009
@@ -21,6 +21,8 @@
 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 @@
             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 {

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java?rev=740989&r1=740988&r2=740989&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java
Thu Feb  5 03:30:43 2009
@@ -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 @@
             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 {



Mime
View raw message