You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2008/11/11 04:55:23 UTC

svn commit: r712930 - in /openjpa/branches/1.2.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/

Author: mikedd
Date: Mon Nov 10 19:55:23 2008
New Revision: 712930

URL: http://svn.apache.org/viewvc?rev=712930&view=rev
Log:
OPENJPA-765 Check for isInsertable and isUpdatable in HandlerFieldStrategy - merged to 1.2.x

Added:
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/AbstractNullityTestCase.java
      - copied unchanged from r712928, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/AbstractNullityTestCase.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestReadOnlyNullity.java
      - copied unchanged from r712928, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestReadOnlyNullity.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TimestampedEntity.java
      - copied unchanged from r712928, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TimestampedEntity.java
Modified:
    openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
    openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/BlobValue.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java

Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java?rev=712930&r1=712929&r2=712930&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java (original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java Mon Nov 10 19:55:23 2008
@@ -193,8 +193,9 @@
         BitSet dirty = sm.getDirty();
         for (int i = 0; i < fields.length; i++) {
             if (dirty.get(fields[i].getIndex())
-                && !bufferCustomInsert(fields[i], sm, store, customs))
+                && !bufferCustomInsert(fields[i], sm, store, customs)) {
                 fields[i].insert(sm, store, rowMgr);
+            }
         }
         if (sup == null) {
             Version vers = mapping.getVersion();
@@ -279,8 +280,9 @@
         FieldMapping[] fields = mapping.getDefinedFieldMappings();
         for (int i = 0; i < fields.length; i++) {
             if (dirty.get(fields[i].getIndex())
-                && !bufferCustomUpdate(fields[i], sm, store, customs))
+                && !bufferCustomUpdate(fields[i], sm, store, customs)) {
                 fields[i].update(sm, store, rowMgr);
+            }
         }
 
         ClassMapping sup = mapping.getJoinablePCSuperclassMapping();

Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java?rev=712930&r1=712929&r2=712930&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java (original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java Mon Nov 10 19:55:23 2008
@@ -122,27 +122,31 @@
 
     public void insert(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
         throws SQLException {
-        Row row = field.getRow(sm, store, rm, Row.ACTION_INSERT);
-        if (row != null) {
-            Object value = sm.fetch(field.getIndex());
-            if (!HandlerStrategies.set(field, value, store, row, _cols, _io, 
-            	field.getNullValue() == FieldMapping.NULL_NONE))
-            	if (field.getValueStrategy() != ValueStrategies.AUTOASSIGN)
-            		throw new UserException(_loc.get("cant-set-value", 
-            				row.getFailedObject(), field, value));
+        if (field.getColumnIO().isInsertable(0, false)) {
+            Row row = field.getRow(sm, store, rm, Row.ACTION_INSERT);
+            if (row != null) {
+                Object value = sm.fetch(field.getIndex());
+                if (!HandlerStrategies.set(field, value, store, row, _cols,
+                    _io, field.getNullValue() == FieldMapping.NULL_NONE))
+                    if (field.getValueStrategy() != ValueStrategies.AUTOASSIGN)
+                        throw new UserException(_loc.get("cant-set-value", row
+                            .getFailedObject(), field, value));
+            }
         }
     }
 
     public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
         throws SQLException {
-        Row row = field.getRow(sm, store, rm, Row.ACTION_UPDATE);
-        if (row != null){
-            Object value = sm.fetch(field.getIndex());
-            if (!HandlerStrategies.set(field, value, store, row, _cols, _io,
-                 field.getNullValue() == FieldMapping.NULL_NONE)) 
-            	if (field.getValueStrategy() != ValueStrategies.AUTOASSIGN)
-            	throw new UserException(_loc.get("cant-set-value", 
-            			row.getFailedObject(), field, value));
+        if (field.getColumnIO().isUpdatable(0, false)) {
+            Row row = field.getRow(sm, store, rm, Row.ACTION_UPDATE);
+            if (row != null) {
+                Object value = sm.fetch(field.getIndex());
+                if (!HandlerStrategies.set(field, value, store, row, _cols,
+                    _io, field.getNullValue() == FieldMapping.NULL_NONE))
+                    if (field.getValueStrategy() != ValueStrategies.AUTOASSIGN)
+                        throw new UserException(_loc.get("cant-set-value", row
+                            .getFailedObject(), field, value));
+            }
         }
     }
 
@@ -154,7 +158,7 @@
     public int supportsSelect(Select sel, int type, OpenJPAStateManager sm,
         JDBCStore store, JDBCFetchConfiguration fetch) {
         if ((type == Select.TYPE_JOINLESS && sel.isSelected(field.getTable()))
-            || (_load && type == sel.TYPE_TWO_PART))
+            || (_load && type == Select.TYPE_TWO_PART))
             return 1;
         return 0;
     }

Modified: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/BlobValue.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/BlobValue.java?rev=712930&r1=712929&r2=712930&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/BlobValue.java (original)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/BlobValue.java Mon Nov 10 19:55:23 2008
@@ -30,4 +30,23 @@
     private String  strVal;
     private int     intVal;
     private byte[]  bytes;
+    
+    public String getStrVal() {
+        return strVal;
+    }
+    public void setStrVal(String strVal) {
+        this.strVal = strVal;
+    }
+    public int getIntVal() {
+        return intVal;
+    }
+    public void setIntVal(int intVal) {
+        this.intVal = intVal;
+    }
+    public byte[] getBytes() {
+        return bytes;
+    }
+    public void setBytes(byte[] bytes) {
+        this.bytes = bytes;
+    }
 }

Modified: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java?rev=712930&r1=712929&r2=712930&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java (original)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java Mon Nov 10 19:55:23 2008
@@ -147,4 +147,8 @@
 	public void setNotOptionalBlob(BlobValue notOptionalBlob) {
 		this.notOptionalBlob = notOptionalBlob;
 	}
+	
+	public int getVersion() { 
+	    return version;
+	}
 }

Modified: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java?rev=712930&r1=712929&r2=712930&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java (original)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java Mon Nov 10 19:55:23 2008
@@ -18,13 +18,10 @@
  */
 package org.apache.openjpa.persistence.nullity;
 
-import javax.persistence.EntityManager;
 import javax.persistence.RollbackException;
 
 import org.apache.openjpa.persistence.InvalidStateException;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
-
 
 /**
  * Test @Basic(optional=true|false) and @Column(nullable=true|false) 
@@ -34,8 +31,7 @@
  *
  * @author Pinaki Poddar
  */
-public class TestBasicFieldNullity extends SingleEMFTestCase {
-	private static boolean NEW = true;
+public class TestBasicFieldNullity extends AbstractNullityTestCase {
 
     public void setUp() {
         setUp(CLEAR_TABLES, NullValues.class);
@@ -116,44 +112,6 @@
     	
     	pc.setNotNullableBlob(null);
     	assertCommitFails(pc, !NEW, RollbackException.class);
-    	
-    }
-    
-    /**
-     * Asserts that the given instance can not be committed.
-     */
-    void assertCommitFails(Object pc, boolean isNew, Class expected) {
-    	EntityManager em = emf.createEntityManager();
-    	em.getTransaction().begin();
-    	if (isNew)
-    		em.persist(pc);
-    	else {
-    		Object merged = em.merge(pc);
-    	}
-    	try {
-			em.getTransaction().commit();
-			fail();
-		} catch (Exception e) {
-			if (!expected.isAssignableFrom(e.getClass())) {
-				e.printStackTrace();
-				fail("Expected " + expected.getName());
-			} 
-		}
-    }
-    
-    void assertCommitSucceeds(Object pc, boolean isNew) {
-    	EntityManager em = emf.createEntityManager();
-    	em.getTransaction().begin();
-    	if (isNew)
-    		em.persist(pc);
-    	else 
-    		em.merge(pc);
-    	try {
-			em.getTransaction().commit();
-		} catch (RuntimeException e) {
-			e.printStackTrace();
-			fail();
-		}
     }
 }