openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1135776 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ openjpa-project/src/doc/man...
Date Tue, 14 Jun 2011 20:18:21 GMT
Author: ppoddar
Date: Tue Jun 14 20:18:20 2011
New Revision: 1135776

URL: http://svn.apache.org/viewvc?rev=1135776&view=rev
Log:
OPENJPA-2017: Introduce AutoDetach.NONE option to improve batch insert operation

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AutoDetach.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/BrokerImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AutoDetachType.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
    openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AutoDetach.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AutoDetach.java?rev=1135776&r1=1135775&r2=1135776&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AutoDetach.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AutoDetach.java Tue
Jun 14 20:18:20 2011
@@ -43,4 +43,24 @@ public interface AutoDetach {
      * Detach context on failed transaction commit / rollback.
      */
     public static final int DETACH_ROLLBACK = 2 << 3;
+    
+    /**
+     * Never Detach. Useful for batch loading where user application is not
+     * concerned about the referenced objects after the persistent operation.
+     */
+    public static final int DETACH_NONE = 2 << 4;
+    
+    /**
+     * Available integer values of AutoDetach options.
+     */
+	public static final int[] values = {DETACH_NONE, DETACH_CLOSE, DETACH_COMMIT, DETACH_NONTXREAD,

+			DETACH_ROLLBACK};
+	
+    /**
+     * Available user-visible names of AutoDetach options.
+     * Order corresponds to integer values of the options.  
+     */
+	public static final String[] names = {"NONE", "CLOSE", "COMMIT", "NON-TX-READ", "ROLLBACK"};
+
+    
 }

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=1135776&r1=1135775&r2=1135776&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 Tue Jun
14 20:18:20 2011
@@ -183,20 +183,27 @@ public interface Broker
     /**
      * Bit flags marked in {@link AutoDetach} which indicate when persistent
      * managed objects should be automatically detached in-place.
+     * <br>
+     * {@link AutoDetach#DETACH_NONE} is exclusive i.e. can not be specified 
+     * with any other option. 
      */
     public void setAutoDetach(int flags);
 
     /**
      * Bit flags marked in {@link AutoDetach} which indicate when persistent
      * managed objects should be automatically detached in-place.
+     * <br>
+     * {@link AutoDetach#DETACH_NONE} is exclusive i.e. can not be specified 
+     * with any other option. 
+     * 
      */
     public void setAutoDetach(int flag, boolean on);
     
     /**
-     * Retrieve the current properties for this broker Some of these properties
+     * Retrieve the current properties for this broker. Some of these properties
      * may have been changed from the original configuration.
      * 
-     * @return the changed properties
+     * @return the set of properties currently used by this broker.
      * 
      * @since 2.0.0
      */

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=1135776&r1=1135775&r2=1135776&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 Tue
Jun 14 20:18:20 2011
@@ -33,6 +33,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
@@ -618,18 +619,27 @@ public class BrokerImpl
         return _autoDetach;
     }
 
+    /**
+     * Sets automatic detachment option. 
+     * <br>
+     * If the given flag contains {@link AutoDetach#DETACH_NONE} option,
+     * then no other option can be specified.  
+     */
     public void setAutoDetach(int detachFlags) {
         assertOpen();
+        assertAutoDetachValue(detachFlags);
         _autoDetach = detachFlags;
     }
 
     public void setAutoDetach(int detachFlag, boolean on) {
         assertOpen();
+        assertAutoDetachValue(on ? _autoDetach | detachFlag : _autoDetach & ~detachFlag);
         if (on)
             _autoDetach |= detachFlag;
         else
             _autoDetach &= ~detachFlag;
     }
+    
 
     public int getDetachState() {
         return _detachState;
@@ -1817,12 +1827,10 @@ public class BrokerImpl
 
             // make sure the runtime supports it
             if (!_conf.supportedOptions().contains(OpenJPAConfiguration.OPTION_INC_FLUSH))
-                throw new UnsupportedException(_loc.get
-                    ("incremental-flush-not-supported"));
+                throw new UnsupportedException(_loc.get("incremental-flush-not-supported"));
             if (_savepoints != null && !_savepoints.isEmpty()
                 && !_spm.supportsIncrementalFlush())
-                throw new UnsupportedException(_loc.get
-                    ("savepoint-flush-not-supported"));
+                throw new UnsupportedException(_loc.get("savepoint-flush-not-supported"));
 
             try {
                 flushSafe(FLUSH_INC);
@@ -5181,5 +5189,28 @@ public class BrokerImpl
     protected boolean isFlushing() {
         return ((_flags & FLAG_FLUSHING) != 0);
     }
+    
+    /**
+     * Asserts consistencey of given automatic detachment option value.
+     */
+    private void assertAutoDetachValue(int value) {
+    	if (((value & AutoDetach.DETACH_NONE) != 0) && (value != AutoDetach.DETACH_NONE))
{
+    		throw new UserException(_loc.get("detach-none-exclusive", toAutoDetachString(value)));
+    	}
+    }
+    
+    /**
+     * Generates a user-readable String from the given integral value of AutoDetach options.
+     */
+    private String toAutoDetachString(int value) {
+    	List<String> result = new ArrayList<String>();
+    	for (int i = 0; i < AutoDetach.values.length; i++) {
+    		if ((value & AutoDetach.values[i]) != 0) {
+    			result.add(AutoDetach.names[i]);
+    		}
+    	}
+    	return Arrays.toString(result.toArray(new String[result.size()]));
+    }
+
 
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=1135776&r1=1135775&r2=1135776&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Tue Jun 14 20:18:20 2011
@@ -2892,8 +2892,12 @@ public class StateManagerImpl
     /**
      * Replaces all second class object fields with fresh proxied instances
      * containing the same information as the originals.
+     * <br>
+     * <B>Note:</B> Proxying is bypassed if AutoDetach option is set to {@link
AutoDetach#DETACH_NONE}.
      */
     void proxyFields(boolean reset, boolean replaceNull) {
+    	if (getBroker().getAutoDetach() != AutoDetach.DETACH_NONE)
+            return;
         // we only replace nulls if the runtime can't differentiate between
         // null and empty containers.  we replace nulls in this case to
         // maintain consistency whether values are being retained or not

Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties?rev=1135776&r1=1135775&r2=1135776&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
Tue Jun 14 20:18:20 2011
@@ -454,4 +454,6 @@ fill-factory-error: Error while fill dat
 	See nested exception for details.	
 writebehind-cfg-err: Missing required WriteBehind configuration parameter "{0}"
 bad-lock-scope: This lock manager does not recognize lock scope "{0}".
+detach-none-exclusive: Configured AutoDetach option "{0}" is incorrect because \
+NONE option can not be specified with any other option other than CLOSE. 
 

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AutoDetachType.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AutoDetachType.java?rev=1135776&r1=1135775&r2=1135776&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AutoDetachType.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AutoDetachType.java
Tue Jun 14 20:18:20 2011
@@ -30,19 +30,22 @@ import org.apache.openjpa.kernel.AutoDet
  * @published
  */
 public enum AutoDetachType {
+	NONE(AutoDetach.DETACH_NONE),
     CLOSE(AutoDetach.DETACH_CLOSE),
     COMMIT(AutoDetach.DETACH_COMMIT),
     NON_TRANSACTIONAL_READ(AutoDetach.DETACH_NONTXREAD),
     ROLLBACK(AutoDetach.DETACH_ROLLBACK);
 
     private final int autoDetachConstant;
-
+    
     private AutoDetachType(int value) {
         autoDetachConstant = value;
     }
 
     public static EnumSet<AutoDetachType> toEnumSet(int autoDetach) {
         EnumSet<AutoDetachType> types = EnumSet.noneOf(AutoDetachType.class);
+        if ((autoDetach & AutoDetach.DETACH_NONE) != 0) 
+        	types.add(NONE);
         if ((autoDetach & AutoDetach.DETACH_CLOSE) != 0)
             types.add(CLOSE);
         if ((autoDetach & AutoDetach.DETACH_COMMIT) != 0)
@@ -51,6 +54,7 @@ public enum AutoDetachType {
             types.add(NON_TRANSACTIONAL_READ);
         if ((autoDetach & AutoDetach.DETACH_ROLLBACK) != 0)
             types.add(ROLLBACK);
+        
         return types;
     }
 

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java?rev=1135776&r1=1135775&r2=1135776&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
Tue Jun 14 20:18:20 2011
@@ -1828,6 +1828,14 @@ public class EntityManagerImpl
             } else {
                 return Strings.parse((String) value, targetType);
             }
+        } else if (value instanceof AutoDetachType) {
+        	EnumSet<AutoDetachType> autoDetachFlags = EnumSet.noneOf(AutoDetachType.class);
+        	autoDetachFlags.add((AutoDetachType)value);
+        	return autoDetachFlags;
+        } else if (value instanceof AutoDetachType[]) {
+        	EnumSet<AutoDetachType> autoDetachFlags = EnumSet.noneOf(AutoDetachType.class);
+        	autoDetachFlags.addAll(Arrays.asList((AutoDetachType[])value));
+        	return autoDetachFlags;
         }
         return value;
     }

Modified: openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml?rev=1135776&r1=1135775&r2=1135776&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml Tue Jun 14 20:18:20 2011
@@ -571,13 +571,21 @@ AutoDetach</literal>
             </para>
             <para>
 <emphasis role="bold">Possible values: </emphasis><literal>close</literal>,
-<literal>commit</literal>, <literal>nontx-read</literal>, <literal>rollback</literal>
+<literal>commit</literal>, <literal>nontx-read</literal>, <literal>rollback</literal>,
<literal>none</literal>
             </para>
             <para>
 <emphasis role="bold">Description:</emphasis> A comma-separated list of events
 when managed instances will be automatically detached. When using the OpenJPA EntityManager
this defaults to 
 <literal>close</literal>, and <literal>rollback</literal> per the
JPA spec. If you need to change this setting, you
 need to set it directly on an instantiated EntityManager.
+
+<para>
+<literal>none</literal> option is exclusive. It can not be specified with any
other option.
+<literal>none</literal> option implies that managed objects will not be detached
from the persistence context,
+the second-class object fields such as collections or date will <emphasis>not</emphasis>
be proxied unlike normal
+circumstances. This option is relevant for specific use cases where the user application
would not refer to the
+managed objects after the transaction and/or the context ends e.g. typical batch insertion
scenario.  
+</para>
             </para>
         </section>
         <section id="openjpa.BrokerFactory">



Mime
View raw message