openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r941362 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/
Date Wed, 05 May 2010 16:17:31 GMT
Author: ppoddar
Date: Wed May  5 16:17:31 2010
New Revision: 941362

URL: http://svn.apache.org/viewvc?rev=941362&view=rev
Log:
OPENJPA-1387: Unique should not impose non-null constraint automatically.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java?rev=941362&r1=941361&r2=941362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java Wed
May  5 16:17:31 2010
@@ -52,18 +52,7 @@ public class Unique
     public boolean isLogical() {
         return false;
     }
-    
-    /**
-     * Adds the given column. 
-     * The added column is set to non-nullable because a unique constraint
-     * on the database requires that its constituent columns are NOT NULL. 
-     * @see Column#setNotNull(boolean)
-     */
-    public void addColumn(Column col) {
-    	super.addColumn(col);
-    	col.setNotNull(true);
-    }
-    
+        
     /**
      * Set the name of the constraint. This method cannot be called if the
      * constraint already belongs to a table. 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java?rev=941362&r1=941361&r2=941362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/NullValues.java
Wed May  5 16:17:31 2010
@@ -23,6 +23,8 @@ import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.UniqueConstraint;
 import javax.persistence.Version;
 
 /**
@@ -32,6 +34,7 @@ import javax.persistence.Version;
  *
  */
 @Entity
+@Table(uniqueConstraints=@UniqueConstraint(name="UniqueNullable", columnNames={"UNS"}))
 public class NullValues {
 	@Id
 	@GeneratedValue
@@ -61,6 +64,9 @@ public class NullValues {
 	@Basic(optional=false)
 	private BlobValue notOptionalBlob;
 	
+	@Column(name="UNS")
+	private String uniqueNullable;
+	
 	@Version
 	private int version;
 	
@@ -148,6 +154,14 @@ public class NullValues {
 		this.notOptionalBlob = notOptionalBlob;
 	}
 	
+    public String getUniqueNullable() {
+        return uniqueNullable;
+    }
+	
+    public void setUniqueNullable(String s) {
+        uniqueNullable = s;
+    }
+    
 	public int getVersion() { 
 	    return version;
 	}

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java?rev=941362&r1=941361&r2=941362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/nullity/TestBasicFieldNullity.java
Wed May  5 16:17:31 2010
@@ -18,11 +18,16 @@
  */
 package org.apache.openjpa.persistence.nullity;
 
+import java.util.List;
+
+import javax.persistence.EntityManager;
 import javax.persistence.RollbackException;
 
 import org.apache.openjpa.persistence.InvalidStateException;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
 
+import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException;
+
 /**
  * Test @Basic(optional=true|false) and @Column(nullable=true|false) 
  * specification is honored. 
@@ -34,7 +39,7 @@ import org.apache.openjpa.persistence.Op
 public class TestBasicFieldNullity extends AbstractNullityTestCase {
 
     public void setUp() {
-        setUp(CLEAR_TABLES, NullValues.class);
+        setUp(CLEAR_TABLES, RETAIN_DATA, NullValues.class);
     }
 
     public void testNullOnOptionalFieldIsAllowed() {
@@ -113,5 +118,44 @@ public class TestBasicFieldNullity exten
     	pc.setNotNullableBlob(null);
     	assertCommitFails(pc, !NEW, RollbackException.class);
     }
+    
+    
+    public void testUniqueStringColumnCanBeNull() {
+        NullValues pc = new NullValues();
+        pc.setUniqueNullable(null);
+        assertCommitSucceeds(pc, NEW);
+    }
+    
+    public void testUniqueStringColumnAsNull() {
+        NullValues pc = new NullValues();
+        pc.setUniqueNullable(null);
+        assertCommitSucceeds(pc, NEW);
+        
+        String jpql = "select n from NullValues n where n.uniqueNullable = :p";
+        EntityManager em = emf.createEntityManager();
+        List<NullValues> result = em.createQuery(jpql, NullValues.class)
+                                    .setParameter("p", null)
+                                    .getResultList();
+        assertFalse(result.isEmpty());
+        for (NullValues n : result)
+            assertNull(n.getUniqueNullable());
+    }
+    
+    public void testUniqueStringColumnAsEmpty() {
+        String EMPTY_STRING = "";
+        NullValues pc = new NullValues();
+        pc.setUniqueNullable(EMPTY_STRING);
+        assertCommitSucceeds(pc, NEW);
+        
+        String jpql = "select n from NullValues n where n.uniqueNullable = :p";
+        EntityManager em = emf.createEntityManager();
+        List<NullValues> result = em.createQuery(jpql, NullValues.class)
+                                    .setParameter("p", EMPTY_STRING)
+                                    .getResultList();
+        assertFalse(result.isEmpty());
+        for (NullValues n : result)
+            assertEquals(EMPTY_STRING, n.getUniqueNullable());
+        
+    }
 }
 



Mime
View raw message