openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1141556 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/spring/ openjpa-persist...
Date Thu, 30 Jun 2011 14:54:32 GMT
Author: ppoddar
Date: Thu Jun 30 14:54:31 2011
New Revision: 1141556

URL: http://svn.apache.org/viewvc?rev=1141556&view=rev
Log:
OPENJPA-2017: Adding DEATCH.NONE option. Retry commit after local test run

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/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-jdbc/src/test/java/org/apache/openjpa/persistence/spring/TestLibService.java
    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-persistence/src/test/java/org/apache/openjpa/persistence/TestEnumToKernelConstantMappings.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=1141556&r1=1141555&r2=1141556&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 Thu
Jun 30 14:54:31 2011
@@ -43,4 +43,12 @@ public interface AutoDetach {
      * Detach context on failed transaction commit / rollback.
      */
     public static final int DETACH_ROLLBACK = 2 << 3;
+    
+    /**
+     * Do not detach at all. Skips proxying second-class containers.
+     */
+    public static final int DETACH_NONE = 2 << 4;
+    
+    public static final String[] names = {"CLOSE", "COMMIT", "NONTXREAD", "ROLLBACK", "NONE"};
+    public static final int[] values = {DETACH_CLOSE, DETACH_COMMIT, DETACH_NONTXREAD, DETACH_ROLLBACK,
DETACH_NONE};
 }

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=1141556&r1=1141555&r2=1141556&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
Jun 30 14:54:31 2011
@@ -617,20 +617,27 @@ public class BrokerImpl
     public int getAutoDetach() {
         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();
-        _autoDetach = detachFlags;
+         assertOpen();
+         assertAutoDetachValue(detachFlags);
+         _autoDetach = detachFlags;
     }
 
     public void setAutoDetach(int detachFlag, boolean on) {
-        assertOpen();
-        if (on)
-            _autoDetach |= detachFlag;
-        else
-            _autoDetach &= ~detachFlag;
+         assertOpen();
+         assertAutoDetachValue(on ? _autoDetach | detachFlag : _autoDetach & ~detachFlag);
+         if (on)
+             _autoDetach |= detachFlag;
+         else
+             _autoDetach &= ~detachFlag;
     }
-
+ 
     public int getDetachState() {
         return _detachState;
     }
@@ -5188,5 +5195,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=1141556&r1=1141555&r2=1141556&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
Thu Jun 30 14:54:31 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 {@link AutoDetach#DETACH_NONE} option
is set.
      */
     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=1141556&r1=1141555&r2=1141556&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
Thu Jun 30 14:54:31 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-jdbc/src/test/java/org/apache/openjpa/persistence/spring/TestLibService.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/spring/TestLibService.java?rev=1141556&r1=1141555&r2=1141556&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/spring/TestLibService.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/spring/TestLibService.java
Thu Jun 30 14:54:31 2011
@@ -37,6 +37,7 @@ public class TestLibService extends Sing
     public EntityManager getTransactionalEntityManager() {
         // return a transactionally scoped entity manager
         OpenJPAEntityManager em = emf.createEntityManager();
+        txScope.remove(AutoDetachType.NONE);
         em.setAutoDetach(txScope);
         return em;
     }

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=1141556&r1=1141555&r2=1141556&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
Thu Jun 30 14:54:31 2011
@@ -30,6 +30,7 @@ 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),
@@ -43,6 +44,8 @@ public enum AutoDetachType {
 
     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)

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=1141556&r1=1141555&r2=1141556&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
Thu Jun 30 14:54:31 2011
@@ -1833,7 +1833,15 @@ public class EntityManagerImpl
                 return null;
             } 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-persistence/src/test/java/org/apache/openjpa/persistence/TestEnumToKernelConstantMappings.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestEnumToKernelConstantMappings.java?rev=1141556&r1=1141555&r2=1141556&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestEnumToKernelConstantMappings.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestEnumToKernelConstantMappings.java
Thu Jun 30 14:54:31 2011
@@ -171,11 +171,13 @@ public class TestEnumToKernelConstantMap
 
         assertEquals(EnumSet.allOf(AutoDetachType.class),
             AutoDetachType.toEnumSet(
-                AutoDetach.DETACH_CLOSE
+            		  AutoDetach.DETACH_NONE
+                    | AutoDetach.DETACH_CLOSE
                     | AutoDetach.DETACH_COMMIT
                     | AutoDetach.DETACH_NONTXREAD
                     | AutoDetach.DETACH_ROLLBACK));
-        assertEquals(AutoDetach.DETACH_CLOSE
+        assertEquals( AutoDetach.DETACH_NONE
+        		    | AutoDetach.DETACH_CLOSE
                     | AutoDetach.DETACH_COMMIT
                     | AutoDetach.DETACH_NONTXREAD
                     | AutoDetach.DETACH_ROLLBACK,

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=1141556&r1=1141555&r2=1141556&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 Thu Jun 30 14:54:31 2011
@@ -571,7 +571,7 @@ 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
@@ -579,6 +579,15 @@ when managed instances will be automatic
 <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>
+            
+            <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>
+            
         </section>
         <section id="openjpa.BrokerFactory">
             <title>



Mime
View raw message