openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r713077 - in /openjpa/branches/1.3.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/
Date Tue, 11 Nov 2008 16:40:37 GMT
Author: mikedd
Date: Tue Nov 11 08:40:37 2008
New Revision: 713077

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

Added:
    openjpa/branches/1.3.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.3.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.3.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.3.x/   (props changed)
    openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
    openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/BlobValue.java
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java

Propchange: openjpa/branches/1.3.x/
------------------------------------------------------------------------------
    svn:mergeinfo = /openjpa/trunk:712928

Modified: openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java?rev=713077&r1=713076&r2=713077&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
(original)
+++ openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
Tue Nov 11 08:40:37 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.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java?rev=713077&r1=713076&r2=713077&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
(original)
+++ openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
Tue Nov 11 08:40:37 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.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/BlobValue.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/BlobValue.java?rev=713077&r1=713076&r2=713077&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/BlobValue.java
(original)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/BlobValue.java
Tue Nov 11 08:40:37 2008
@@ -27,7 +27,32 @@
  *
  */
 public class BlobValue implements Serializable {
+    private static final long serialVersionUID = 833553627832894685L;
     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.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java?rev=713077&r1=713076&r2=713077&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java
(original)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java
Tue Nov 11 08:40:37 2008
@@ -147,4 +147,8 @@
 	public void setNotOptionalBlob(BlobValue notOptionalBlob) {
 		this.notOptionalBlob = notOptionalBlob;
 	}
+	
+	public int getVersion() { 
+	    return version;
+	}
 }

Modified: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java?rev=713077&r1=713076&r2=713077&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java
(original)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java
Tue Nov 11 08:40:37 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();
-		}
     }
 }
 



Mime
View raw message