openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r495800 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/ openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/ openjp...
Date Sat, 13 Jan 2007 00:35:46 GMT
Author: ppoddar
Date: Fri Jan 12 16:35:45 2007
New Revision: 495800

URL: http://svn.apache.org/viewvc?view=rev&rev=495800
Log:
ClassMappingInfo.addUnique() accepts a Unique instance rather than an array of column names

Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/org/apache/openjpa/persistence/jdbc/localizer.properties

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java?view=diff&rev=495800&r1=495799&r2=495800
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
Fri Jan 12 16:35:45 2007
@@ -322,22 +322,12 @@
            _uniques = new ArrayList(cinfo._uniques);
     }
 
-    public void addUnique(String name, String[] columnNames) {
-        if (columnNames == null || columnNames.length == 0)
+    public void addUnique(Unique unique) {
+        if (unique == null)
             return;
         if (_uniques == null)
             _uniques = new ArrayList();
-        Unique uniqueConstraint = new Unique();
-        uniqueConstraint.setName(name);
-        for (int i=0; i<columnNames.length; i++) {
-            if (StringUtils.isEmpty(columnNames[i]))
-                throw new UserException(_loc.get("empty-unique-column", 
-                    getClassName()));
-            Column column = new Column();
-            column.setName(columnNames[i]);
-            uniqueConstraint.addColumn(column);
-         }
-        _uniques.add(uniqueConstraint);
+        _uniques.add(unique);
     }
     
     public Unique[] getUniques(ClassMapping cm, boolean adapt) {

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties?view=diff&rev=495800&r1=495799&r2=495800
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
Fri Jan 12 16:35:45 2007
@@ -403,7 +403,4 @@
 	attempts to map a field that does not have exactly 1 column.
 missing-unique-column: A unique constraint specified in mapping of class "{0}" \
     to table "{1}" includes a column "{2}". However, the column does not \
-	exist in "{1}" table. 
-empty-unique-column: A unique constraint specified in mapping of class "{0}" \
-    includes an empty column "{2}".
-	
\ No newline at end of file
+	exist in "{1}" table.

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java?view=diff&rev=495800&r1=495799&r2=495800
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
Fri Jan 12 16:35:45 2007
@@ -66,6 +66,7 @@
 import org.apache.openjpa.jdbc.meta.strats.FullClassStrategy;
 import org.apache.openjpa.jdbc.meta.strats.VerticalClassStrategy;
 import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.Unique;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
@@ -76,6 +77,7 @@
 import org.apache.openjpa.util.InternalException;
 import org.apache.openjpa.util.MetaDataException;
 import org.apache.openjpa.util.UnsupportedException;
+import org.apache.openjpa.util.UserException;
 
 /**
  * Persistence annotation mapping parser.
@@ -460,9 +462,9 @@
         if (tableName != null)
             cm.getMappingInfo().setTableName(tableName);
 
-        for (UniqueConstraint unique:table.uniqueConstraints()) {
-            ((ClassMappingInfo)cm.getMappingInfo())
-                .addUnique(null, unique.columnNames());
+        for (UniqueConstraint uniqueConstraint:table.uniqueConstraints()) {
+            Unique unique = newUnique(cm, null, uniqueConstraint.columnNames());
+            cm.getMappingInfo().addUnique(unique);
         }
     }
 
@@ -682,14 +684,15 @@
     /**
      * Set unique data on the given mapping info.
      */
-    private void parseUnique(FieldMapping fm, Unique anno) {
+    private void parseUnique(FieldMapping fm, 
+        org.apache.openjpa.persistence.jdbc.Unique anno) {
         ValueMappingInfo info = fm.getValueInfo();
         if (!anno.enabled()) {
             info.setCanUnique(false);
             return;
         }
 
-        org.apache.openjpa.jdbc.schema.Unique unq =
+        org.apache.openjpa.jdbc.schema.Unique unq = 
             new org.apache.openjpa.jdbc.schema.Unique();
         if (!StringUtils.isEmpty(anno.name()))
             unq.setName(anno.name());
@@ -879,7 +882,8 @@
                     fm.getValueInfo().setStrategy(((Strategy) anno).value());
                     break;
                 case UNIQUE:
-                    parseUnique(fm, (Unique) anno);
+                    parseUnique(fm, 
+                        (org.apache.openjpa.persistence.jdbc.Unique) anno);
                     break;
                 case X_JOIN_COL:
                     parseXJoinColumns(fm, fm.getValueInfo(), true,
@@ -1325,4 +1329,21 @@
 		col.setFlag (Column.FLAG_UNUPDATABLE, !join.updatable ());
 		return col;
 	}
+    
+    private static Unique newUnique(ClassMapping cm, String name, 
+        String[] columnNames) {
+        if (columnNames == null || columnNames.length == 0)
+            return null;
+        Unique uniqueConstraint = new Unique();
+        uniqueConstraint.setName(name);
+        for (int i=0; i<columnNames.length; i++) {
+            if (StringUtils.isEmpty(columnNames[i]))
+                throw new UserException(_loc.get("empty-unique-column", 
+                    Arrays.toString(columnNames), cm));
+            Column column = new Column();
+            column.setName(columnNames[i]);
+            uniqueConstraint.addColumn(column);
+        }
+        return uniqueConstraint;
+    }
 }

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/org/apache/openjpa/persistence/jdbc/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/org/apache/openjpa/persistence/jdbc/localizer.properties?view=diff&rev=495800&r1=495799&r2=495800
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/org/apache/openjpa/persistence/jdbc/localizer.properties
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/org/apache/openjpa/persistence/jdbc/localizer.properties
Fri Jan 12 16:35:45 2007
@@ -43,3 +43,5 @@
 	Version columns must always be in the primary table of the class.
 not-embedded: Attempt to declare mapping overrides on non-embedded field "{0}".
 no-gen-table: No generated table found at "{0}".
+empty-unique-column: A unique constraint "{0}" specified in mapping of class  \
+    "{1}" includes an empty column.
\ No newline at end of file



Mime
View raw message