openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r727084 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/
Date Tue, 16 Dec 2008 16:44:28 GMT
Author: faywang
Date: Tue Dec 16 08:44:26 2008
New Revision: 727084

URL: http://svn.apache.org/viewvc?rev=727084&view=rev
Log:
OPENJPA-782: embeddable support

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMappingInfo.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
    openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java?rev=727084&r1=727083&r2=727084&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
Tue Dec 16 08:44:26 2008
@@ -35,7 +35,6 @@
 import org.apache.openjpa.meta.JavaTypes;
 import org.apache.openjpa.meta.MetaDataContext;
 import org.apache.openjpa.util.MetaDataException;
-import org.apache.openjpa.util.UserException;
 
 /**
  * Information about the mapping from a field to the schema, in raw form.
@@ -180,11 +179,20 @@
                         pos, cols);
             }
         };
-        ClassMapping cls = field.getDefiningMapping();
+        ClassMapping cls = getDefiningMapping(field);
         return createForeignKey(field, "join", cols, def, table, cls, cls,
             false, adapt);
     }
-
+    
+    private ClassMapping getDefiningMapping(FieldMapping field) {
+        ClassMapping clm = field.getDefiningMapping();
+        ValueMappingImpl value = (ValueMappingImpl)clm.getEmbeddingMetaData();
+        if (value == null)
+            return clm;
+        FieldMapping field1 = value.getFieldMapping();
+        return getDefiningMapping(field1);
+    }
+    
     /**
      * Unique constraint on the field join.
      */

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMappingInfo.java?rev=727084&r1=727083&r2=727084&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMappingInfo.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMappingInfo.java
Tue Dec 16 08:44:26 2008
@@ -101,11 +101,24 @@
                         target, inverse, pos, cols);
             }
         };
+        Table table = getTable(val);
         return createForeignKey(val, null, getColumns(), def,
-            val.getFieldMapping().getTable(), val.getFieldMapping().
+            table, val.getFieldMapping().
             getDefiningMapping(), rel, inversable, adapt);
     }
 
+    private Table getTable(ValueMapping val) {
+        FieldMapping field = val.getFieldMapping();
+        Table table = field.getTable();
+        if (table == null) {
+            ClassMapping cls = (ClassMapping)field.getDefiningMetaData();
+            ValueMapping val1 = (ValueMapping)cls.getEmbeddingMetaData();
+            if (val1 != null)
+                return getTable(val1);
+        }
+        return table;
+    }
+    
     /**
      * Return the join from the related type to this value.
      */

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java?rev=727084&r1=727083&r2=727084&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
Tue Dec 16 08:44:26 2008
@@ -844,7 +844,7 @@
             }
 
             FieldMetaData field = (meta == null) ? null
-                : meta.getField(_mappedBy);
+                : getMappedByField(meta, _mappedBy);
             if (field == null)
                 throw new MetaDataException(_loc.get("no-mapped-by", this,
                     _mappedBy));
@@ -856,6 +856,25 @@
         return _mappedByMeta;
     }
 
+    public FieldMetaData getMappedByField(ClassMetaData meta, String mappedBy) {
+        FieldMetaData field = meta.getField(mappedBy);
+        if (field != null)
+            return field;
+        int dotIdx = mappedBy.indexOf("."); 
+        if ( dotIdx == -1)
+            return null;
+        String fieldName = mappedBy.substring(0, dotIdx);
+        FieldMetaData field1 = meta.getField(fieldName);
+        if (field1 == null)
+            return null;
+        ClassMetaData meta1 = field1.getEmbeddedMetaData();
+        if (meta1 == null)
+            return null;
+        String mappedBy1 = mappedBy.substring(dotIdx + 1);
+        return getMappedByField(meta1, mappedBy1);
+    }
+    
+    
     /**
      * Logical inverse field.
      */

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java?rev=727084&r1=727083&r2=727084&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
Tue Dec 16 08:44:26 2008
@@ -23,6 +23,7 @@
 import org.apache.openjpa.jdbc.meta.FieldMapping;
 import org.apache.openjpa.jdbc.meta.MappingDefaultsImpl;
 import org.apache.openjpa.jdbc.meta.ValueMapping;
+import org.apache.openjpa.jdbc.meta.ValueMappingImpl;
 import org.apache.openjpa.jdbc.meta.Version;
 import org.apache.openjpa.jdbc.meta.strats.FlatClassStrategy;
 import org.apache.openjpa.jdbc.meta.strats.MultiColumnVersionStrategy;
@@ -36,6 +37,7 @@
 import org.apache.openjpa.jdbc.schema.Schema;
 import org.apache.openjpa.jdbc.schema.Table;
 import org.apache.openjpa.jdbc.sql.JoinSyntaxes;
+import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.meta.JavaTypes;
 import serp.util.Strings;
 
@@ -130,7 +132,10 @@
     @Override
     public String getTableName(FieldMapping fm, Schema schema) {
         // base name is table of defining type + '_'
-        String name = fm.getDefiningMapping().getTable().getName() + "_";
+        ClassMapping clm = fm.getDefiningMapping();
+        Table table = getTable(clm);
+        
+        String name = table.getName() + "_";
 
         // if this is an assocation table, spec says to suffix with table of
         // the related type. spec doesn't cover other cases; we're going to
@@ -144,6 +149,19 @@
             name += fm.getName();
         return name.replace('$', '_');
     }
+    
+    private Table getTable(ClassMapping clm) {
+        Table table = clm.getTable();
+        if (table == null) {
+            ValueMappingImpl value = (ValueMappingImpl)clm.getEmbeddingMetaData();
+            if (value == null)
+                return table;
+            FieldMetaData field = value.getFieldMetaData();
+            clm = (ClassMapping)field.getDefiningMetaData();
+            return getTable(clm);
+        }
+        return table;
+    }
 
     @Override
     public void populateJoinColumn(FieldMapping fm, Table local, Table foreign,



Mime
View raw message