openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r712300 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/ openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persis...
Date Fri, 07 Nov 2008 22:49:13 GMT
Author: ppoddar
Date: Fri Nov  7 14:49:13 2008
New Revision: 712300

URL: http://svn.apache.org/viewvc?rev=712300&view=rev
Log:
Generate unique name for unique constraints created by @Column(unique=true)

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/jdbc/unique/TestUniqueConstraint.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/UniqueA.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/UniqueB.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/unique/orm.xml

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=712300&r1=712299&r2=712300&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 Fri
Nov  7 14:49:13 2008
@@ -28,7 +28,8 @@
  */
 public class Unique
     extends LocalConstraint {
-	private boolean _autoNaming = false;
+    private boolean _autoNaming = false;
+    private static int _counter = 1;
     
 	/**
      * Default constructor without a name.
@@ -110,7 +111,9 @@
 	private String createAutoName() {
 		Column[] columns = getColumns();
 		int l = 32/Math.max(columns.length,1);
-		StringBuffer autoName = new StringBuffer("UNQ_");
+		StringBuffer autoName = new StringBuffer("UNQ_"); 
+		if (columns.length == 0) 
+			autoName.append(_counter++);
 		for (Column column : columns)
 			autoName.append(chop(column.getName(),l));
 		return autoName.toString();

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/TestUniqueConstraint.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/TestUniqueConstraint.java?rev=712300&r1=712299&r2=712300&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/TestUniqueConstraint.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/TestUniqueConstraint.java
Fri Nov  7 14:49:13 2008
@@ -63,8 +63,12 @@
 				"UNIQUE .*\\(GEN1, GEN2\\)");
 		assertSQLFragnments(sqls, "CREATE TABLE UNIQUE_JOINTABLE",
 				"UNIQUE .*\\(FK_A, FK_B\\)");
+		assertSQLFragnments(sqls, "CREATE TABLE UNIQUE_A",
+			    "UNIQUE .*\\(SAME\\)");
+		assertSQLFragnments(sqls, "CREATE TABLE UNIQUE_B",
+			    "UNIQUE .*\\(SAME\\)");
 	}
-	
+		
 	void assertSQLFragnments(List<String> list, String... keys) {
 		if (SQLSniffer.matches(list, keys))
 			return;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/UniqueA.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/UniqueA.java?rev=712300&r1=712299&r2=712300&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/UniqueA.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/UniqueA.java
Fri Nov  7 14:49:13 2008
@@ -67,6 +67,8 @@
 	@Column(nullable=false)
 	private int a4;
 	
+	@Column(name="SAME", unique=true)
+	private int same;
 	
 	private int a5;
 	private int a6;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/UniqueB.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/UniqueB.java?rev=712300&r1=712299&r2=712300&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/UniqueB.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/unique/UniqueB.java
Fri Nov  7 14:49:13 2008
@@ -35,4 +35,6 @@
 	private int b1;
 	@Column(nullable=false)
 	private int b2;
+	@Column(name="SAME", unique=true)
+	private int same;
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/unique/orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/unique/orm.xml?rev=712300&r1=712299&r2=712300&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/unique/orm.xml
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/unique/orm.xml
Fri Nov  7 14:49:13 2008
@@ -65,7 +65,9 @@
 			<basic name="a6">
 				<column name="a6x"/>
 			</basic>
-			
+			<basic name="same">
+				<column name="SAME" unique="true"/>
+			</basic>
 			<basic name="sa1">
 				<column name="sa1x" table="UNIQUE_SECONDARY_XML" />
 			</basic>
@@ -112,6 +114,9 @@
 			<basic name="b2">
 				<column name="b2x"/>
 			</basic>
+            <basic name="same">
+                <column name="SAME" unique="true"/>
+            </basic>
 		</attributes>
 	</entity>
 </entity-mappings>



Mime
View raw message