openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r525606 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/
Date Wed, 04 Apr 2007 21:13:20 GMT
Author: awhite
Date: Wed Apr  4 14:13:19 2007
New Revision: 525606

URL: http://svn.apache.org/viewvc?view=rev&rev=525606
Log:
Cleanup bugfix relating to use of a default schema declared in orm.xml:
- Removed prepending of schema name in PersistenceMappingDefaults.getTableName
  methods as unnecessary.
- Moved storage of default schema name to ClassMappingInfo as that's the only
  place we use it for now.
- Moved setting of default schema name into the more efficient endClassMapping
  method of XMLPersistenceMappingParser.
- Fixed MappingInfo.createTable logic to pass the full table name to 
  SchemaGroup.findTable.  This is important b/c the DynamicSchemaGroup (used
  during the mappingtool's buildSchema action, the default for JPA) dynamically
  adds the table to itself during the findTable operation.  Without the full
  table name it would always add the table to the default schema.


Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/FlatClassStrategy.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java

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=525606&r1=525605&r2=525606
==============================================================================
--- 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
Wed Apr  4 14:13:19 2007
@@ -54,6 +54,7 @@
 
     private String _className = Object.class.getName();
     private String _tableName = null;
+    private String _schemaName = null;
     private boolean _joined = false;
     private Map _seconds = null;
     private String _subStrat = null;
@@ -105,6 +106,20 @@
     }
 
     /**
+     * The default schema name for unqualified tables.
+     */
+    public String getSchemaName() {
+        return _schemaName;
+    }
+
+    /**
+     * The default schema name for unqualified tables.
+     */
+    public void setSchemaName(String schema) {
+        _schemaName = schema;
+    }
+
+    /**
      * Whether there is a join to the superclass table.
      */
     public boolean isJoinedSubclass() {
@@ -215,7 +230,7 @@
                 return cls.getMappingRepository().getMappingDefaults().
                     getTableName(cls, schema);
             }
-        }, null, _tableName, adapt);
+        }, _schemaName, _tableName, adapt);
     }
 
     /**

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java?view=diff&rev=525606&r1=525605&r2=525606
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
Wed Apr  4 14:13:19 2007
@@ -118,7 +118,8 @@
             return null;
 
         Table table = field.getDefiningMapping().getTable();
-        Schema schema = (table == null) ? null : table.getSchema();
+        String schemaName = (table == null) ? null 
+            : table.getSchema().getName();
 
         // if we have no join columns defined, there may be class-level join
         // information with a more fully-qualified name for our table
@@ -134,7 +135,7 @@
                 return field.getMappingRepository().getMappingDefaults().
                     getTableName(field, schema);
             }
-        }, schema, tableName, adapt);
+        }, schemaName, tableName, adapt);
     }
 
     /**

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java?view=diff&rev=525606&r1=525605&r2=525606
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
Wed Apr  4 14:13:19 2007
@@ -70,7 +70,6 @@
     private boolean _canFK = true;
     private int _join = JOIN_NONE;
     private ColumnIO _io = null;
-    private String _defaultSchemaName = null;
 
     /**
      * Mapping strategy name.
@@ -423,58 +422,56 @@
      *
      * @param context the mapping that uses the table
      * @param def default table name provider
-     * @param schema default schema if known, or null
+     * @param schemaName default schema if known, or null
      * @param given given table name
      * @param adapt whether we can alter the schema or mappings
      */
     public Table createTable(MetaDataContext context, TableDefaults def,
-        Schema schema, String given, boolean adapt) {
+        String schemaName, String given, boolean adapt) {
         MappingRepository repos = (MappingRepository) context.getRepository();
         if (given == null && (def == null || (!adapt
             && !repos.getMappingDefaults().defaultMissingInfo())))
             throw new MetaDataException(_loc.get("no-table", context));
 
+        if (schemaName == null)
+            schemaName = Schemas.getNewTableSchema((JDBCConfiguration)
+                repos.getConfiguration());
+
         // if no given and adapting or defaulting missing info, use template
         SchemaGroup group = repos.getSchemaGroup();
-        String schemaName = null;
+        Schema schema = null;
         if (given == null) {
-            if (schema == null) {
-                schemaName = Schemas.getNewTableSchema((JDBCConfiguration)
-                    repos.getConfiguration());
-                if (StringUtils.isEmpty(schemaName)) { 
-                   schemaName = _defaultSchemaName;
-                }
-                schema = group.getSchema(schemaName);
-                if (schema == null)
-                    schema = group.addSchema(schemaName);
-            }
+            schema = group.getSchema(schemaName);
+            if (schema == null)
+                schema = group.addSchema(schemaName);
             given = def.get(schema);
         }
 
-        // look for named table
-        Table table = group.findTable(given);
-        if (table != null)
-            return table;
-        if (!adapt)
-            throw new MetaDataException(_loc.get("bad-table", given, context));
-
-        // named table doesn't exist; figure out what schema to create new
-        // table in
+        String fullName;
         int dotIdx = given.lastIndexOf('.');
-        if (dotIdx != -1) {
+        if (dotIdx == -1)
+            fullName = (schemaName == null) ? given : schemaName + "." + given;
+        else {
+            fullName = given;
             schema = null;
             schemaName = given.substring(0, dotIdx);
             given = given.substring(dotIdx + 1);
-        } else if (schema == null)
-            schemaName = Schemas.getNewTableSchema((JDBCConfiguration)
-                repos.getConfiguration());
+        }
 
+        // look for named table using full name and findTable, which allows
+        // the dynamic schema factory to create the table if needed
+        Table table = group.findTable(fullName);
+        if (table != null)
+            return table;
+        if (!adapt)
+            throw new MetaDataException(_loc.get("bad-table", given, context));
+
+        // named table doesn't exist; create it
         if (schema == null) {
             schema = group.getSchema(schemaName);
             if (schema == null)
                 schema = group.addSchema(schemaName);
         }
-
         table = schema.getTable(given);
         if (table == null)
             table = schema.addTable(given);
@@ -1769,12 +1766,4 @@
         public void populate(Table local, Table foreign, Column col,
             Object target, boolean inverse, int pos, int cols);
 	}
-    
-    public String getDefaultSchemaName() {
-        return _defaultSchemaName;
-    }
-
-    public void setDefaultSchemaName(String schemaName) {
-        _defaultSchemaName = schemaName;
-    }
 }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/FlatClassStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/FlatClassStrategy.java?view=diff&rev=525606&r1=525605&r2=525606
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/FlatClassStrategy.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/FlatClassStrategy.java
Wed Apr  4 14:13:19 2007
@@ -47,7 +47,7 @@
         info.assertNoSchemaComponents(cls, true);
 
         if (info.getTableName() != null) {
-            Table table = info.createTable(cls, null, null,
+            Table table = info.createTable(cls, null, info.getSchemaName(),
                 info.getTableName(), false);
             if (table != sup.getTable())
                 throw new MetaDataException(_loc.get("flat-table", cls,

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java?view=diff&rev=525606&r1=525605&r2=525606
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
Wed Apr  4 14:13:19 2007
@@ -115,30 +115,15 @@
 
     @Override
     public String getTableName(ClassMapping cls, Schema schema) {
-        String name = "";
-        if (StringUtils.isNotEmpty(schema.getName())) {
-            name += schema.getName() + '.';
-        }
-
         if (cls.getTypeAlias() != null)
-            name += cls.getTypeAlias();
-        
-        else
-            name += Strings.getClassName(cls.getDescribedType()).replace('$',
-                '_');
-        
-        return name;
+            return cls.getTypeAlias();
+        return Strings.getClassName(cls.getDescribedType()).replace('$', '_');
     }
 
     @Override
     public String getTableName(FieldMapping fm, Schema schema) {
-        String name = ""; 
-        if (StringUtils.isNotEmpty(schema.getName())) {
-            name += schema.getName() + '.';
-        }
-        
         // base name is table of defining type + '_'
-        name += fm.getDefiningMapping().getTable().getName() + "_";
+        String name = fm.getDefiningMapping().getTable().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

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java?view=diff&rev=525606&r1=525605&r2=525606
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
Wed Apr  4 14:13:19 2007
@@ -304,6 +304,9 @@
     protected void endClassMapping(ClassMetaData meta)
         throws SAXException {
         ClassMapping cm = (ClassMapping) meta;
+        if (_schema != null)
+            cm.getMappingInfo().setSchemaName(_schema);
+
         if (_supJoinCols != null)
             cm.getMappingInfo().setColumns(_supJoinCols);
 
@@ -769,10 +772,9 @@
     private String toTableName(String schema, String table) {
         if (StringUtils.isEmpty(table))
             return null;
-        schema = StringUtils.isEmpty(schema) ? _schema : schema;
         if (StringUtils.isEmpty(schema))
-            return table;
-        return schema + "." + table;
+            schema = _schema;
+        return (StringUtils.isEmpty(schema)) ? table : schema + "." + table;
     }
 
     /**
@@ -911,18 +913,4 @@
 		TRUE,
 		FALSE
 	}
-    
-    @Override
-    protected void endClass(String elem)
-        throws SAXException {
-        if (StringUtils.isNotEmpty(_schema)) {
-            Class cls = classForName(currentClassName());
-
-            MetaDataRepository repos = getRepository();
-            ClassMapping meta = (ClassMapping) repos.getCachedMetaData(cls);
-
-            meta.getMappingInfo().setDefaultSchemaName(_schema);
-        }
-        super.endClass(elem);
-    }
 }



Mime
View raw message