openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrba...@apache.org
Subject svn commit: r899784 [3/11] - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/jav...
Date Fri, 15 Jan 2010 19:38:26 GMT
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCColumnOrder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCColumnOrder.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCColumnOrder.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCColumnOrder.java Fri Jan 15 19:38:18 2010
@@ -20,6 +20,7 @@
 
 import java.util.Comparator;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ColumnIO;
 import org.apache.openjpa.jdbc.sql.Joins;
@@ -30,6 +31,7 @@
  *
  * @author Abe White
  */
+@SuppressWarnings("serial")
 class JDBCColumnOrder
     implements JDBCOrder {
 
@@ -64,15 +66,22 @@
         _io = io;
     }
 
+    /**
+     * @deprecated
+     */
     public String getName() {
         return (_col == null) ? "" : _col.getName();
     }
 
+    public DBIdentifier getIdentifier() {
+        return (_col == null) ? DBIdentifier.newColumn("") : _col.getIdentifier();
+    }
+
     public boolean isAscending() {
         return true;
     }
 
-    public Comparator getComparator() {
+    public Comparator<?> getComparator() {
         return null;
     }
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCOrder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCOrder.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCOrder.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCOrder.java Fri Jan 15 19:38:18 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.openjpa.jdbc.meta;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.meta.Order;
@@ -43,4 +44,7 @@
      * we're selecting
      */
     public void order(Select sel, ClassMapping elem, Joins joins);
+    
+    public DBIdentifier getIdentifier();
+
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java Fri Jan 15 19:38:18 2010
@@ -20,6 +20,7 @@
 
 import java.util.Comparator;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.lib.util.Localizer;
@@ -30,6 +31,7 @@
  *
  * @author Abe White
  */
+@SuppressWarnings("serial")
 class JDBCRelatedFieldOrder
     implements JDBCOrder {
 
@@ -49,15 +51,22 @@
         _asc = asc;
     }
 
+    /**
+     * @deprecated
+     */
     public String getName() {
         return _fm.getName();
     }
 
+    public DBIdentifier getIdentifier() {
+        return DBIdentifier.newColumn(_fm.getName());
+    }
+
     public boolean isAscending() {
         return _asc;
     }
 
-    public Comparator getComparator() {
+    public Comparator<?> getComparator() {
         return null;
     }
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCValueOrder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCValueOrder.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCValueOrder.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCValueOrder.java Fri Jan 15 19:38:18 2010
@@ -20,6 +20,7 @@
 
 import java.util.Comparator;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.meta.Order;
@@ -30,11 +31,13 @@
  *
  * @author Abe White
  */
+@SuppressWarnings("serial")
 class JDBCValueOrder
     implements JDBCOrder {
 
     private final FieldMapping _fm;
     private final boolean _asc;
+    private static final DBIdentifier SQL_ELEMENT = DBIdentifier.newColumn(Order.ELEMENT);
 
     public JDBCValueOrder(FieldMapping fm, boolean asc) {
         _fm = fm;
@@ -45,11 +48,15 @@
         return Order.ELEMENT;
     }
 
+    public DBIdentifier getIdentifier() {
+        return SQL_ELEMENT;
+    }
+
     public boolean isAscending() {
         return _asc;
     }
 
-    public Comparator getComparator() {
+    public Comparator<?> getComparator() {
         return null;
     }
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JavaSQLTypes.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JavaSQLTypes.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JavaSQLTypes.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JavaSQLTypes.java Fri Jan 15 19:38:18 2010
@@ -68,7 +68,7 @@
     /**
      * Return the proper date typecode.
      */
-    public static int getDateTypeCode(Class dtype) {
+    public static int getDateTypeCode(Class<?> dtype) {
         if (dtype == java.util.Date.class)
             return DATE;
         if (dtype == java.sql.Date.class)

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaults.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaults.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaults.java Fri Jan 15 19:38:18 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.openjpa.jdbc.meta;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
 import org.apache.openjpa.jdbc.schema.Index;
@@ -87,7 +88,7 @@
      * @param adapt whether we can adapt the mapping or schema
      * @return the handler/strategy alias or instance, or null
      */
-    public Object getStrategy(ValueMapping vm, Class type, boolean adapt);
+    public Object getStrategy(ValueMapping vm, Class<?> type, boolean adapt);
 
     /**
      * Return the default discriminator value for the given instance.
@@ -97,17 +98,32 @@
     /**
      * Return the default table name for the given class. This method is
      * only called for classes mapped to their own table.
+     * @deprecated
      */
     public String getTableName(ClassMapping cls, Schema defaultSchema);
 
     /**
+     * Return the default table name for the given class. This method is
+     * only called for classes mapped to their own table.
+     */
+    public DBIdentifier getTableIdentifier(ClassMapping cls, Schema defaultSchema);
+
+    /**
      * Return the default secondary table name for the given field. This
      * method is only called for fields whose strategy requires a secondary
      * table.
+     * @deprecated
      */
     public String getTableName(FieldMapping fm, Schema defaultSchema);
 
     /**
+     * Return the default secondary table name for the given field. This
+     * method is only called for fields whose strategy requires a secondary
+     * table.
+     */
+    public DBIdentifier getTableIdentifier(FieldMapping fm, Schema defaultSchema);
+
+    /**
      * Fill in default information for the given datastore identity columns.
      * The columns' name and Java type will already be populated with generic
      * defaults that may be replaced.
@@ -170,22 +186,51 @@
      * @param inverse whether this is an inverse foreign key
      * @param pos the index of this column in the logical foreign key
      * @param cols the number of columns in the logical foreign key
+     * @deprecated
      */
     public void populateForeignKeyColumn(ValueMapping vm, String name,
         Table local, Table foreign, Column col, Object target, boolean inverse,
         int pos, int cols);
 
     /**
+     * Fill in default information for the given column used to join a value
+     * to its related type. The column will be a clone of the target
+     * column, or have its name and Java type set in the case of a constant
+     * target.
+     *
+     * @param name base name for value, as decided by mapping
+     * @param target the target of this column in the join; may be
+     * another column or a constant value
+     * @param inverse whether this is an inverse foreign key
+     * @param pos the index of this column in the logical foreign key
+     * @param cols the number of columns in the logical foreign key
+     */
+    public void populateForeignKeyColumn(ValueMapping vm, DBIdentifier name,
+        Table local, Table foreign, Column col, Object target, boolean inverse,
+        int pos, int cols);
+
+    /**
      * Fill in default information for the given value columns.
      * The columns' name and Java type will already be populated with generic
      * defaults that may be replaced.
      *
      * @param name base name for value, as decided by mapping
+     * @deprecated
      */
     public void populateColumns(ValueMapping vm, String name, Table table,
         Column[] cols);
 
     /**
+     * Fill in default information for the given value columns.
+     * The columns' name and Java type will already be populated with generic
+     * defaults that may be replaced.
+     *
+     * @param name base name for value, as decided by mapping
+     */
+    public void populateColumns(ValueMapping vm, DBIdentifier name, Table table,
+        Column[] cols);
+
+    /**
      * Fill in default information for the given order columns.
      * The columns' name and Java type will already be populated with generic
      * defaults that may be replaced.
@@ -206,11 +251,25 @@
      * @return false if the given value should not have null indicator
      * columns by default; fill in default information even
      * when returning false in case the user forces an indicator
+     * @deprecated
      */
     public boolean populateNullIndicatorColumns(ValueMapping vm, String name,
         Table table, Column[] cols);
 
     /**
+     * Fill in default information for the given null indicator columns.
+     * The columns' name and Java type will already be populated with generic
+     * defaults that may be replaced.
+     *
+     * @param name base name for value, as decided by mapping
+     * @return false if the given value should not have null indicator
+     * columns by default; fill in default information even
+     * when returning false in case the user forces an indicator
+     */
+    public boolean populateNullIndicatorColumns(ValueMapping vm, DBIdentifier name,
+        Table table, Column[] cols);
+
+    /**
      * Return a default foreign key for the join from this class' table to its
      * superclass' table, or null for a logical foreign key only. Do not
      * add columns to the key or add the key to the table; only fill in
@@ -236,11 +295,24 @@
      *
      * @param name base name for value, as decided by mapping
      * @param inverse whether this is an inverse key
+     * @deprecated
      */
     public ForeignKey getForeignKey(ValueMapping vm, String name, Table local,
         Table foreign, boolean inverse);
 
     /**
+     * Return a default foreign key for the join from this value to its
+     * related type, or null for a logical foreign key only. Do not
+     * add columns to the key or add the key to the table; only fill in
+     * its information such as name, delete action, etc.
+     *
+     * @param name base name for value, as decided by mapping
+     * @param inverse whether this is an inverse key
+     */
+    public ForeignKey getForeignKey(ValueMapping vm, DBIdentifier name, Table local,
+        Table foreign, boolean inverse);
+
+    /**
      * Return a default index for the join, or null if the
      * join columns should not be indexed by default. Do not
      * add columns to the index or add the index to the table; only fill in
@@ -255,11 +327,23 @@
      * uniqueness, etc.
      *
      * @param name base name for value, as decided by mapping
+     * @deprecated
      */
     public Index getIndex(ValueMapping vm, String name, Table table,
         Column[] cols);
 
     /**
+     * Return a default index for the value, or null if the value columns
+     * should not be indexed by default. Do not add columns to the index or
+     * add the index to the table; only fill in its information such as name,
+     * uniqueness, etc.
+     *
+     * @param name base name for value, as decided by mapping
+     */
+    public Index getIndex(ValueMapping vm, DBIdentifier name, Table table,
+        Column[] cols);
+
+    /**
      * Return a default index for the version, or null if the
      * version columns should not be indexed by default. Do not
      * add columns to the index or add the index to the table; only fill in
@@ -290,17 +374,36 @@
      * information such as name, deferrability, etc.
      *
      * @param name base name for value, as decided by mapping
+     * @deprecated
      */
     public Unique getUnique(ValueMapping vm, String name, Table table,
         Column[] cols);
 
     /**
+     * Return a default constraint for the value, or null if the value columns
+     * should not be constrained by default. Do not add columns to the
+     * constraint or add the constraint to the table; only fill in its
+     * information such as name, deferrability, etc.
+     *
+     * @param name base name for value, as decided by mapping
+     */
+    public Unique getUnique(ValueMapping vm, DBIdentifier name, Table table,
+        Column[] cols);
+
+    /**
      * Return the name of the primary key for the table of the given class,
      * or null for database default.
+     * @deprecated
      */
     public String getPrimaryKeyName(ClassMapping cm, Table table);
 
     /**
+     * Return the name of the primary key for the table of the given class,
+     * or null for database default.
+     */
+    public DBIdentifier getPrimaryKeyIdentifier(ClassMapping cm, Table table);
+
+    /**
      * If desired, install a primary key on the given secondary table.
      */
     public void installPrimaryKey(FieldMapping fm, Table table);

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java Fri Jan 15 19:38:18 2010
@@ -24,6 +24,8 @@
 import java.util.Properties;
 
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.identifier.Normalizer;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.meta.strats.UntypedPCValueHandler;
 import org.apache.openjpa.jdbc.meta.strats.EnumValueHandler;
 import org.apache.openjpa.jdbc.schema.Column;
@@ -36,7 +38,8 @@
 import org.apache.openjpa.lib.conf.Configurable;
 import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.conf.Configurations;
-import org.apache.openjpa.lib.util.JavaVersions;
+import org.apache.openjpa.lib.identifier.Identifier;
+import org.apache.openjpa.lib.identifier.IdentifierUtil;
 import org.apache.openjpa.meta.JavaTypes;
 import serp.util.Strings;
 
@@ -66,11 +69,11 @@
     private boolean _addNullInd = false;
     private boolean _ordinalEnum = false;
     private boolean _stringifyUnmapped = false;
-    private String _dsIdName = null;
-    private String _versName = null;
-    private String _discName = null;
-    private String _orderName = null;
-    private String _nullIndName = null;
+    private DBIdentifier _dsIdName = DBIdentifier.NULL;
+    private DBIdentifier _versName = DBIdentifier.NULL;
+    private DBIdentifier _discName = DBIdentifier.NULL;
+    private DBIdentifier _orderName = DBIdentifier.NULL;
+    private DBIdentifier _nullIndName = DBIdentifier.NULL;
     private boolean _removeHungarianNotation = false;
 
     public boolean isRemoveHungarianNotation() {
@@ -333,83 +336,133 @@
     /**
      * Default base name for datastore identity columns, or null to the
      * mapping's built-in name.
+     * @deprecated
      */
     public String getDataStoreIdColumnName() {
-        return _dsIdName;
+        return getDataStoreIdColumnIdentifier().getName();
+    }
+
+    public DBIdentifier getDataStoreIdColumnIdentifier() {
+        return _dsIdName == null ? DBIdentifier.NULL : _dsIdName;
     }
 
     /**
      * Default base name for datastore identity columns, or null to the
      * mapping's built-in name.
+     * @deprecated
      */
     public void setDataStoreIdColumnName(String dsIdName) {
+        setDataStoreIdColumnIdentifier(DBIdentifier.newColumn(dsIdName));
+    }
+
+    public void setDataStoreIdColumnIdentifier(DBIdentifier dsIdName) {
         _dsIdName = dsIdName;
     }
 
     /**
      * Default base name for version identity columns, or null to the mapping's
      * built-in name.
+     * @deprecated
      */
     public String getVersionColumnName() {
-        return _versName;
+        return getVersionColumnIdentifier().getName();
+    }
+
+    public DBIdentifier getVersionColumnIdentifier() {
+        return _versName == null ? DBIdentifier.NULL : _versName;
     }
 
     /**
      * Default base name for version identity columns, or null to the mapping's
      * built-in name.
+     * @deprecated
      */
     public void setVersionColumnName(String versName) {
+        setVersionColumnIdentifier(DBIdentifier.newColumn(versName));
+    }
+
+    public void setVersionColumnIdentifier(DBIdentifier versName) {
         _versName = versName;
     }
 
     /**
      * Default base name for discriminator columns, or null to the mapping's
      * built-in name.
+     * @deprecated
      */
     public String getDiscriminatorColumnName() {
-        return _discName;
+        return getDiscriminatorColumnIdentifier().getName();
+    }
+
+    public DBIdentifier getDiscriminatorColumnIdentifier() {
+        return _discName == null ? DBIdentifier.NULL : _discName;
     }
 
     /**
      * Default base name for discriminator columns, or null to the mapping's
      * built-in name.
+     * @deprecated
      */
     public void setDiscriminatorColumnName(String discName) {
+        setDiscriminatorColumnIdentifier(DBIdentifier.newColumn(discName));
+    }
+
+    public void setDiscriminatorColumnIdentifier(DBIdentifier discName) {
         _discName = discName;
     }
 
     /**
      * Default base name for order columns, or null to the mapping's
      * built-in name.
+     * @deprecated
      */
     public String getOrderColumnName() {
-        return _orderName;
+        return getOrderColumnIdentifier().getName();
+    }
+
+    public DBIdentifier getOrderColumnIdentifier() {
+        return _orderName == null ? DBIdentifier.NULL : _orderName;
     }
 
     /**
      * Default base name for order columns, or null to the mapping's
      * built-in name.
+     * @deprecated
      */
     public void setOrderColumnName(String orderName) {
+        setOrderColumnIdentifier(DBIdentifier.newColumn(orderName));
+    }
+
+    public void setOrderColumnIdentifier(DBIdentifier orderName) {
         _orderName = orderName;
     }
 
     /**
      * Default base name for null indicator columns, or null to the mapping's
      * built-in name.
+     * @deprecated
      */
     public String getNullIndicatorColumnName() {
-        return _nullIndName;
+        return getNullIndicatorColumnIdentifier().getName();
+    }
+
+    public DBIdentifier getNullIndicatorColumnIdentifier() {
+        return _nullIndName == null ? DBIdentifier.NULL : _nullIndName;
     }
 
     /**
      * Default base name for null indicator columns, or null to the mapping's
      * built-in name.
+     * @deprecated
      */
     public void setNullIndicatorColumnName(String nullIndName) {
+        setNullIndicatorColumnIdentifier(DBIdentifier.newColumn(nullIndName));
+    }
+    
+    public void setNullIndicatorColumnIdentifier(DBIdentifier nullIndName) {
         _nullIndName = nullIndName;
     }
-
+    
     public boolean defaultMissingInfo() {
         return _defMissing;
     }
@@ -451,7 +504,7 @@
         return null;
     }
 
-    public Object getStrategy(ValueMapping vm, Class type, boolean adapt) {
+    public Object getStrategy(ValueMapping vm, Class<?> type, boolean adapt) {
         Object ret = _fieldMap.get(type.getName());
         if (ret != null)
             return ret;
@@ -511,33 +564,39 @@
 
     public String getTableName(ClassMapping cls, Schema schema) {
         String name = Strings.getClassName(cls.getDescribedType()).
-            replace('$', '_');
+            replace(IdentifierUtil.DOLLAR_CHAR, IdentifierUtil.UNDERSCORE_CHAR);
         if (!_defMissing)
             name = dict.getValidTableName(name, schema);
         return name;
     }
 
+    public DBIdentifier getTableIdentifier(ClassMapping cls, Schema schema) {
+        return DBIdentifier.newTable(getTableName(cls, schema));
+    }
+
     public String getTableName(FieldMapping fm, Schema schema) {
-        String name = fm.getName();
+        return getTableIdentifier(fm, schema).getName();
+    }
+
+    public DBIdentifier getTableIdentifier(FieldMapping fm, Schema schema) {
+        DBIdentifier sName = DBIdentifier.newTable(fm.getName());
         Table table = fm.getDefiningMapping().getTable();
         if (table != null) {
-            String tableName = table.getName();
-            if (tableName.length() > 5)
-                tableName = tableName.substring(0, 5);
-            name = tableName + "_" + name;
+            DBIdentifier tableName = DBIdentifier.truncate(table.getIdentifier(),5);
+            sName = DBIdentifier.append(tableName, fm.getName());
         }
         if (!_defMissing)
-            name = dict.getValidTableName(name, schema);
-        return name;
+            sName = dict.getValidTableName(sName, schema);
+        return sName;
     }
 
     public void populateDataStoreIdColumns(ClassMapping cls, Table table,
         Column[] cols) {
         for (int i = 0; i < cols.length; i++) {
-            if (_dsIdName != null && cols.length == 1)
-                cols[i].setName(_dsIdName);
-            else if (_dsIdName != null)
-                cols[i].setName(_dsIdName + i);
+            if (!DBIdentifier.isNull(_dsIdName) && cols.length == 1)
+                cols[i].setIdentifier(_dsIdName);
+            else if (!DBIdentifier.isNull(_dsIdName))
+                cols[i].setIdentifier(DBIdentifier.append(_dsIdName, Integer.toString(i)));
             correctName(table, cols[i]);
         }
     }
@@ -548,41 +607,31 @@
     protected void correctName(Table table, Column col) {
         if (!_defMissing || _removeHungarianNotation)
         {
-            String name = col.getName();
+            DBIdentifier name = col.getIdentifier();
             if (_removeHungarianNotation)
-                name = removeHungarianNotation(name);
-            String correctedName = dict.getValidColumnName(name, table);
-            col.setName(correctedName);
+                name = DBIdentifier.removeHungarianNotation(name);
+            DBIdentifier correctedName = dict.getValidColumnName(name, table);
+            col.setIdentifier(correctedName);
             table.addCorrectedColumnName(correctedName, true);
         }
     }
 
     protected String removeHungarianNotation(String columnName) {
-        char[] name = columnName.toCharArray();
-        int newStart = 0;
-
-        for (int i = 0; i < name.length; i++) {
-            if (Character.isUpperCase(name[i]))
-            {
-                newStart = i;
-                break;
-            }
-        }
-
-        return columnName.substring(newStart);
+        return Normalizer.removeHungarianNotation(columnName);
     }
 
     public void populateColumns(Version vers, Table table, Column[] cols) {
         for (int i = 0; i < cols.length; i++) {
-            if (_versName != null && cols.length == 1)
-                cols[i].setName(_versName);
-            else if (_versName != null) {
-                if (i == 0)
-                    cols[i].setName(_versName);
-                else
-                    cols[i].setName(_versName + "_" + i);
-            } else if (_versName != null)
-                cols[i].setName(_versName + i);
+            if (!DBIdentifier.isNull(_versName) && cols.length == 1)
+                cols[i].setIdentifier(_versName);
+            else if (!DBIdentifier.isNull(_versName)) {
+                if (i == 0) {
+                    cols[i].setIdentifier(_versName);
+                } else {
+                    cols[i].setIdentifier(DBIdentifier.append(_versName, Integer.toString(i)));
+                }
+            } else if (!DBIdentifier.isNull(_versName))
+                cols[i].setIdentifier(DBIdentifier.append(_versName, Integer.toString(i)));
             correctName(table, cols[i]);
         }
     }
@@ -590,10 +639,10 @@
     public void populateColumns(Discriminator disc, Table table,
         Column[] cols) {
         for (int i = 0; i < cols.length; i++) {
-            if (_discName != null && cols.length == 1)
-                cols[i].setName(_discName);
-            else if (_discName != null)
-                cols[i].setName(_discName + i);
+            if (!DBIdentifier.isNull(_discName) && cols.length == 1)
+                cols[i].setIdentifier(_discName);
+            else if (!DBIdentifier.isNull(_discName))
+                cols[i].setIdentifier(DBIdentifier.append(_discName, Integer.toString(i)));
             correctName(table, cols[i]);
         }
     }
@@ -608,18 +657,33 @@
         correctName(local, col);
     }
 
+    /**
+     * @deprecated
+     */
     public void populateForeignKeyColumn(ValueMapping vm, String name,
         Table local, Table foreign, Column col, Object target, boolean inverse,
         int pos, int cols) {
+        populateForeignKeyColumn(vm, DBIdentifier.newColumn(name), local, foreign, col,
+            target, inverse, pos, cols);
+    }
+
+    public void populateForeignKeyColumn(ValueMapping vm, DBIdentifier name,
+        Table local, Table foreign, Column col, Object target, boolean inverse,
+        int pos, int cols) {
         if (cols == 1)
-            col.setName(name);
+            col.setIdentifier(name);
         else if (target instanceof Column)
-            col.setName(name + "_" + ((Column) target).getName());
+            col.setIdentifier(DBIdentifier.combine(name,((Column) target).getIdentifier().getName()));
         correctName(local, col);
     }
 
     public void populateColumns(ValueMapping vm, String name, Table table,
         Column[] cols) {
+        populateColumns(vm, DBIdentifier.newColumn(name), table, cols);
+    }
+
+    public void populateColumns(ValueMapping vm, DBIdentifier name, Table table,
+        Column[] cols) {
         for (int i = 0; i < cols.length; i++)
             correctName(table, cols[i]);
     }
@@ -627,23 +691,31 @@
     public boolean populateOrderColumns(FieldMapping fm, Table table,
         Column[] cols) {
         for (int i = 0; i < cols.length; i++) {
-            if (_orderName != null && cols.length == 1)
-                cols[i].setName(_orderName);
-            else if (_orderName != null)
-                cols[i].setName(_orderName + i);
+            if (!DBIdentifier.isNull(_orderName) && cols.length == 1)
+                cols[i].setIdentifier(_orderName);
+            else if (!DBIdentifier.isNull(_orderName))
+                cols[i].setIdentifier(DBIdentifier.append(_orderName, Integer.toString(i)));
             correctName(table, cols[i]);
         }
         return _orderLists && (JavaTypes.ARRAY == fm.getTypeCode()
             || List.class.isAssignableFrom(fm.getType()));
     }
 
+    /**
+     * @deprecated
+     */
     public boolean populateNullIndicatorColumns(ValueMapping vm, String name,
         Table table, Column[] cols) {
+        return populateNullIndicatorColumns(vm, DBIdentifier.newColumn(name), table, cols);
+    }
+
+    public boolean populateNullIndicatorColumns(ValueMapping vm, DBIdentifier name,
+        Table table, Column[] cols) {
         for (int i = 0; i < cols.length; i++) {
-            if (_nullIndName != null && cols.length == 1)
-                cols[i].setName(_nullIndName);
-            else if (_nullIndName != null)
-                cols[i].setName(_nullIndName + i);
+            if (!DBIdentifier.isNull(_nullIndName) && cols.length == 1)
+                cols[i].setIdentifier(_nullIndName);
+            else if (!DBIdentifier.isNull(_nullIndName))
+                cols[i].setIdentifier(DBIdentifier.append(_nullIndName, Integer.toString(i)));
             correctName(table, cols[i]);
         }
         return _addNullInd;
@@ -669,8 +741,16 @@
         return fk;
     }
 
+    /**
+     * @deprecated
+     */
     public ForeignKey getForeignKey(ValueMapping vm, String name, Table local,
         Table foreign, boolean inverse) {
+        return getForeignKey(vm, DBIdentifier.newForeignKey(name), local, foreign, inverse);
+    }
+        
+    public ForeignKey getForeignKey(ValueMapping vm, DBIdentifier name, Table local,
+        Table foreign, boolean inverse) {
         if (_fkAction == ForeignKey.ACTION_NONE)
             return null;
         ForeignKey fk = new ForeignKey();
@@ -687,7 +767,7 @@
             return null;
 
         Index idx = new Index();
-        idx.setName(getIndexName(null, table, cols));
+        idx.setIdentifier(getIndexName(DBIdentifier.NULL, table, cols));
         return idx;
     }
 
@@ -703,21 +783,35 @@
 
     /**
      * Generate an index name.
+     * @deprecated
      */
     protected String getIndexName(String name, Table table, Column[] cols) {
+        return getIndexName(DBIdentifier.newIndex(name), table, cols).getName();
+    }
+
+    protected DBIdentifier getIndexName(DBIdentifier name, Table table, Column[] cols) {
         // always use dict for index names because no spec mandates them
         // based on defaults
-        if (name == null)
-            name = cols[0].getName();
+        DBIdentifier sName = name;
+        if (DBIdentifier.isNull(sName))
+            sName = cols[0].getIdentifier();
 
         if (_removeHungarianNotation)
-            name = removeHungarianNotation(name);
+            sName = DBIdentifier.removeHungarianNotation(sName);
 
-        return dict.getValidIndexName(name, table);
+        return dict.getValidIndexName(sName, table);
     }
 
+    /**
+     * @deprecated
+     */
     public Index getIndex(ValueMapping vm, String name, Table table,
         Column[] cols) {
+        return getIndex(vm, DBIdentifier.newIndex(name), table, cols);
+    }
+
+    public Index getIndex(ValueMapping vm, DBIdentifier name, Table table,
+        Column[] cols) {
         if (!_indexFK || vm.getForeignKey() == null
             || !vm.getForeignKey().isLogical())
             return null;
@@ -725,7 +819,7 @@
             return null;
 
         Index idx = new Index();
-        idx.setName(getIndexName(name, table, cols));
+        idx.setIdentifier(getIndexName(name, table, cols));
         return idx;
     }
 
@@ -733,7 +827,7 @@
         if (!_indexVers)
             return null;
         Index idx = new Index();
-        idx.setName(getIndexName(_versName, table, cols));
+        idx.setIdentifier(getIndexName(_versName, table, cols));
         return idx;
     }
 
@@ -741,7 +835,7 @@
         if (!_indexDisc)
             return null;
         Index idx = new Index();
-        idx.setName(getIndexName(_discName, table, cols));
+        idx.setIdentifier(getIndexName(_discName, table, cols));
         return idx;
     }
 
@@ -749,15 +843,30 @@
         return null;
     }
 
+    /**
+     * @deprecated
+     */
     public Unique getUnique(ValueMapping vm, String name, Table table,
         Column[] cols) {
         return null;
     }
 
+    public Unique getUnique(ValueMapping vm, DBIdentifier name, Table table,
+        Column[] cols) {
+        return null;
+    }
+
+    /**
+     * @deprecated
+     */
     public String getPrimaryKeyName(ClassMapping cm, Table table) {
         return null;
     }
 
+    public DBIdentifier getPrimaryKeyIdentifier(ClassMapping cm, Table table) {
+        return DBIdentifier.NULL;
+    }
+
     public void installPrimaryKey(FieldMapping fm, Table table) {
     }
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java Fri Jan 15 19:38:18 2010
@@ -26,6 +26,9 @@
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.identifier.Normalizer;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ColumnIO;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
@@ -51,6 +54,7 @@
  *
  * @author Abe White
  */
+@SuppressWarnings("serial")
 public abstract class MappingInfo
     implements Serializable {
 
@@ -64,7 +68,7 @@
         (MappingInfo.class);
 
     private String _strategy = null;
-    private List _cols = null;
+    private List<Column> _cols = null;
     private Index _idx = null;
     private Unique _unq = null;
     private ForeignKey _fk = null;
@@ -92,19 +96,30 @@
     /**
      * Raw column data.
      */
-    public List getColumns() {
-        return (_cols == null) ? Collections.EMPTY_LIST : _cols;
+    public List<Column> getColumns() {
+        if (_cols == null) {
+            return Collections.emptyList();
+        }
+        return _cols;
     }
     
     /**
      * Gets the columns whose table name matches the given table name. 
+     * @deprecated
+     */
+    public List<Column> getColumns(String tableName) {
+        return getColumns(DBIdentifier.newTable(tableName));
+    }
+
+    /**
+     * Gets the columns whose table name matches the given table name. 
      */
-    public List getColumns(String tableName) {
+    public List<Column> getColumns(DBIdentifier tableName) {
         if (_cols == null) 
-        	return Collections.EMPTY_LIST;
-        List result = new ArrayList();
-        for (Object col : _cols) {
-        	if (StringUtils.equals(((Column)col).getTableName(), 
+        	return Collections.emptyList();
+        List<Column> result = new ArrayList<Column>();
+        for (Column col : _cols) {
+        	if (DBIdentifier.equal(col.getTableIdentifier(), 
         			tableName)) 
         		result.add(col);
         }
@@ -114,7 +129,7 @@
     /**
      * Raw column data.
      */
-    public void setColumns(List cols) {
+    public void setColumns(List<Column> cols) {
         _cols = cols;
     }
 
@@ -321,12 +336,12 @@
                 _canFK = info.canForeignKey();
         }
         _implicitRelation = info.isImplicitRelation();
-        List cols = getColumns();
-        List icols = info.getColumns();
+        List<Column> cols = getColumns();
+        List<Column> icols = info.getColumns();
         if (!icols.isEmpty() && (cols.isEmpty()
             || cols.size() == icols.size())) {
             if (cols.isEmpty())
-                cols = new ArrayList(icols.size());
+                cols = new ArrayList<Column>(icols.size());
             for (int i = 0; i < icols.size(); i++) {
                 if (cols.size() == i)
                     cols.add(new Column());
@@ -448,7 +463,7 @@
             Column col;
             for (int i = 0; !join && i < _cols.size(); i++) {
                 col = (Column) _cols.get(i);
-                if (col.getTarget() != null)
+                if (!DBIdentifier.isNull(col.getTargetIdentifier()))
                     join = true;
             }
         }
@@ -469,43 +484,48 @@
      * @param schemaName default schema if known, or null
      * @param given given table name
      * @param adapt whether we can alter the schema or mappings
+     * @deprecated
      */
     public Table createTable(MetaDataContext context, TableDefaults def,
         String schemaName, String given, boolean adapt) {
+        return createTable(context, def, DBIdentifier.newSchema(schemaName), 
+            DBIdentifier.newTable(given), adapt);
+    }
+
+    public Table createTable(MetaDataContext context, TableDefaults def,
+        DBIdentifier schemaName, DBIdentifier given, boolean adapt) {
         MappingRepository repos = (MappingRepository) context.getRepository();
-        if (given == null && (def == null || (!adapt
+        if (DBIdentifier.isNull(given) && (def == null || (!adapt
             && !repos.getMappingDefaults().defaultMissingInfo())))
             throw new MetaDataException(_loc.get("no-table", context));
 
-        if (schemaName == null)
-            schemaName = Schemas.getNewTableSchema((JDBCConfiguration)
+        if (DBIdentifier.isNull(schemaName))
+            schemaName = Schemas.getNewTableSchemaIdentifier((JDBCConfiguration)
                 repos.getConfiguration());
 
         // if no given and adapting or defaulting missing info, use template
         SchemaGroup group = repos.getSchemaGroup();
         Schema schema = null;
-        if (given == null) {
+        if (DBIdentifier.isNull(given)) {
             schema = group.getSchema(schemaName);
             if (schema == null)
                 schema = group.addSchema(schemaName);
-            given = def.get(schema);
+            given = def.getIdentifier(schema);
         }
 
-        String fullName;
-        String sep = repos.getDBDictionary().catalogSeparator;
-        int dotIdx = given.lastIndexOf(sep);
-        if (dotIdx == -1)
-            fullName = (schemaName == null) ? given : schemaName + sep + given;
-        else {
-            fullName = given;
+        QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(given);
+        if (DBIdentifier.isNull(path.getSchemaName())) {
+            if (!DBIdentifier.isNull(schemaName)) {
+                path.setSchemaName(schemaName);
+            }
+        } else {
+            schemaName = path.getSchemaName();
             schema = null;
-            schemaName = given.substring(0, dotIdx);
-            given = given.substring(dotIdx + 1);
         }
 
         // 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);
+        Table table = group.findTable(path);
         if (table != null)
             return table;
         if (!adapt)
@@ -543,7 +563,7 @@
         // mapping, or none at all if we're adapting.  can't just given one of
         // n columns because we don't know which of the n columns the info
         // applies to
-        List given = getColumns();
+        List<Column> given = getColumns();
         
         if (context instanceof FieldMapping && ((FieldMapping)context).hasMapsIdCols())
             given = ((FieldMapping)context).getValueInfo().getMapsIdColumns();
@@ -553,7 +573,7 @@
         if ((!given.isEmpty() || (!adapt && !fill))
             && given.size() != tmplates.length) {
         	// also consider when this info has columns from multiple tables
-        	given = getColumns(table.getName());
+        	given = getColumns(table.getIdentifier());
         	if ((!adapt && !fill) && given.size() != tmplates.length) {
         		// try default table
         		given = getColumns("");
@@ -577,7 +597,7 @@
         return cols;
     }
     
-    boolean canMerge(List given, Column[] templates, boolean adapt,
+    boolean canMerge(List<Column> given, Column[] templates, boolean adapt,
             boolean fill) {
     	return !((!given.isEmpty() || (!adapt && !fill)) 
     			&& given.size() != templates.length);
@@ -627,8 +647,8 @@
         assertTable(context, table);
 
         // if not adapting must provide column name at a minimum
-        String colName = (given == null) ? null : given.getName();
-        if (colName == null && !adapt && !fill)
+        DBIdentifier colName = (given == null) ? DBIdentifier.NULL : given.getIdentifier();
+        if (DBIdentifier.isNull(colName) && !adapt && !fill)
             throw new MetaDataException(_loc.get(prefix + "-no-col-name",
                 context));
 
@@ -638,15 +658,15 @@
         // determine the column name based on given info, or template if none;
         // also make sure that if the user gave a column name, he didn't try
         // to put the column in an unexpected table
-        if (colName == null)
-            colName = tmplate.getName();
-        int dotIdx = colName.lastIndexOf(dict.catalogSeparator);
-        if (dotIdx == 0)
-            colName = colName.substring(1);
-        else if (dotIdx != -1) {
-            findTable(context, colName.substring(0, dotIdx), table,
+        if (DBIdentifier.isNull(colName))
+            colName = tmplate.getIdentifier();
+        QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(colName);
+        if (path.isUnqualifiedColumn()) {
+            colName = path.getIdentifier();
+        } else if (!DBIdentifier.isNull(path.getObjectTableName())) {
+            findTable(context, path.getObjectTableName(), table,
                 null, null);
-            colName = colName.substring(dotIdx + 1);
+            colName = path.getUnqualifiedName();
         }
 
         // find existing column
@@ -658,8 +678,8 @@
             // should seldom if ever occur as long as the database dictionaries
             // are kept up-to-date. 
             // 
-            if ((colName.length() > dict.maxColumnNameLength) || 
-               dict.getInvalidColumnWordSet().contains(colName.toUpperCase()) &&
+            if ((colName.getName().length() > dict.maxColumnNameLength) || 
+               dict.getInvalidColumnWordSet().contains(DBIdentifier.toUpper(colName).getName()) &&
               !(table.getClass().getName().contains("DynamicTable"))) {
                 colName=dict.getValidColumnName(colName, new Table());
                 col = table.getColumn(colName);
@@ -814,7 +834,7 @@
      * @param rel if we're finding the target table of a join, the
      * joined-to type; allows us to also look in its superclass tables
      */
-    private static Table findTable(MetaDataContext context, String name,
+    private static Table findTable(MetaDataContext context, DBIdentifier name,
         Table expected, Table inverse, ClassMapping rel) {
         // is this the expected table?
         if (expected == null && rel != null)
@@ -837,15 +857,15 @@
 
         // none of the possible tables
         throw new MetaDataException(_loc.get("col-wrong-table", context,
-            expected, name));
+            expected, name.getName()));
     }
 
     /**
      * Return whether the given name matches the given table.
      */
-    private static boolean isTableName(String name, Table table) {
-        return name.equalsIgnoreCase(table.getName())
-            || name.equalsIgnoreCase(table.getFullName());
+    private static boolean isTableName(DBIdentifier name, Table table) {
+        return DBIdentifier.equal(name, table.getIdentifier())
+            || DBIdentifier.equal(name, table.getFullIdentifier());
     }
 
     /**
@@ -910,10 +930,10 @@
         if (_idx == null && (tmplate == null || (!adapt && !fill)))
             return null;
 
-        String name = null;
+        DBIdentifier name = DBIdentifier.NULL;
         boolean unq;
         if (_idx != null) {
-            name = _idx.getName();
+            name = _idx.getIdentifier();
             unq = _idx.isUnique();
             // preserve multiple columns if they are specified in the index
             if (_idx.getColumns() != null && _idx.getColumns().length > 1)
@@ -922,11 +942,11 @@
             unq = tmplate.isUnique();
 
         // if no name provided by user info, make one
-        if (name == null) {
+        if (DBIdentifier.isNull(name)) {
             if (tmplate != null)
-                name = tmplate.getName();
+                name = tmplate.getIdentifier();
             else {
-                name = cols[0].getName();
+                name = cols[0].getIdentifier();
                 name = repos.getDBDictionary().getValidIndexName(name, table);
             }
         }
@@ -1009,13 +1029,13 @@
         if (!adapt && !fill && _unq == null)
             return null;
 
-        String name;
+        DBIdentifier name = DBIdentifier.NULL;
         boolean deferred;
         if (_unq != null) {
-            name = _unq.getName();
+            name = _unq.getIdentifier();
             deferred = _unq.isDeferred();
         } else {
-            name = tmplate.getName();
+            name = tmplate.getIdentifier();
             deferred = tmplate.isDeferred();
         }
 
@@ -1027,8 +1047,8 @@
             deferred = false;
         }
         
-        if (StringUtils.isEmpty(name)) {
-        	name = cols[0].getName();
+        if (DBIdentifier.isEmpty(name)) {
+        	name = cols[0].getIdentifier();
         	name = repos.getDBDictionary().getValidUniqueName(name, table);
         }
         
@@ -1054,7 +1074,7 @@
      * @param adapt whether we can modify the existing mapping or schema
      */
     protected ForeignKey createForeignKey(MetaDataContext context,
-        String prefix, List given, ForeignKeyDefaults def, Table table,
+        String prefix, List<Column> given, ForeignKeyDefaults def, Table table,
         ClassMapping cls, ClassMapping rel, boolean inversable, boolean adapt) {
         assertTable(context, table);
         if (prefix == null)
@@ -1116,10 +1136,10 @@
         if (exist != null) {
             // make existing key logical?
             if (!_canFK) {
-                if (exist.getDeleteAction() != exist.ACTION_NONE && !adapt)
+                if (exist.getDeleteAction() != ForeignKey.ACTION_NONE && !adapt)
                     throw new MetaDataException(_loc.get(prefix
                         + "-fk-exists", context));
-                exist.setDeleteAction(exist.ACTION_NONE);
+                exist.setDeleteAction(ForeignKey.ACTION_NONE);
             }
 
             if (_fk != null && _fk.isDeferred() && !exist.isDeferred()) {
@@ -1140,7 +1160,7 @@
             return exist;
         }
 
-        String name = null;
+        DBIdentifier name = DBIdentifier.NULL;
         int delAction = ForeignKey.ACTION_NONE;
         int upAction = ForeignKey.ACTION_NONE;
         boolean deferred = false;
@@ -1149,22 +1169,22 @@
             : def.get(local, foreign, _join == JOIN_INVERSE);
         if (_fk != null && (tmplate == null || (!adapt && !fill))) {
             // if not adapting or no template info use given data
-            name = _fk.getName();
+            name = _fk.getIdentifier();
             delAction = _fk.getDeleteAction();
             upAction = _fk.getUpdateAction();
             deferred = _fk.isDeferred();
         } else if (_canFK && (adapt || fill)) {
             if (_fk == null && tmplate != null) {
                 // no user given info; use template data
-                name = tmplate.getName();
+                name = tmplate.getIdentifier();
                 delAction = tmplate.getDeleteAction();
                 upAction = tmplate.getUpdateAction();
                 deferred = tmplate.isDeferred();
             } else if (_fk != null && tmplate != null) {
                 // merge user and template data, always letting user info win
-                name = _fk.getName();
-                if (name == null && tmplate.getName() != null)
-                    name = tmplate.getName();
+                name = _fk.getIdentifier();
+                if (DBIdentifier.isNull(name) && !DBIdentifier.isNull(tmplate.getIdentifier()))
+                    name = tmplate.getIdentifier();
                 delAction = _fk.getDeleteAction();
                 if (delAction == ForeignKey.ACTION_NONE)
                     delAction = tmplate.getDeleteAction();
@@ -1216,7 +1236,7 @@
      * Use the join information to populate our internal column I/O data.
      */
     private void setIOFromJoins(ForeignKey fk, Object[][] joins) {
-        List cols = getColumns();
+        List<Column> cols = getColumns();
         _io = null;
         if (cols.isEmpty())
             return;
@@ -1255,7 +1275,7 @@
      */
     private Object[][] createJoins(MetaDataContext context,
         String prefix, Table table, ClassMapping cls, ClassMapping rel,
-        List given, ForeignKeyDefaults def, boolean inversable, boolean adapt) {
+        List<Column> given, ForeignKeyDefaults def, boolean inversable, boolean adapt) {
         MappingRepository repos = (MappingRepository) context.getRepository();
         boolean fill = repos.getMappingDefaults().defaultMissingInfo();
         Object[][] joins;
@@ -1271,7 +1291,7 @@
             Column tmplate;
             for (int i = 0; i < targets.length; i++) {
                 tmplate = new Column();
-                tmplate.setName(targets[i].getName());
+                tmplate.setIdentifier(targets[i].getIdentifier());
                 tmplate.setJavaType(targets[i].getJavaType());
                 tmplate.setType(targets[i].getType());
                 tmplate.setTypeName(targets[i].getTypeName());
@@ -1328,16 +1348,16 @@
         ClassMapping rel, ForeignKeyDefaults def, boolean inversable,
         boolean adapt, boolean fill) {
         // default to the primary key column name if this is a pk join
-        String name = given.getName();
-        if (name == null && given != null
+        DBIdentifier name = given.getIdentifier();
+        if (DBIdentifier.isNull(name) && given != null
             && given.getFlag(Column.FLAG_PK_JOIN) && cls != null) {
             Column[] pks = cls.getPrimaryKeyColumns();
             if (pks.length == 1)
-                name = pks[0].getName();
+                name = pks[0].getIdentifier();
         }
 
         // if we can't adapt, then the user must at least give a column name
-        if (name == null && !adapt && !fill)
+        if (DBIdentifier.isNull(name) && !adapt && !fill)
             throw new MetaDataException(_loc.get(prefix + "-no-fkcol-name",
                 context));
 
@@ -1347,18 +1367,16 @@
         Table foreign = rel.getTable();
         boolean fullName = false;
         boolean inverse = false;
-        if (name != null) {
-            int dotIdx = name.lastIndexOf('.');
-            if (dotIdx != -1) {
-                // allow use of '.' without prefix to mean "use expected
-                // foreign table"
-                if (dotIdx == 0)
+        if (!DBIdentifier.isNull(name)) {
+            QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(name);
+            if (!DBIdentifier.isNull(path.getObjectTableName())) {
+                if (DBIdentifier.isEmpty(path.getObjectTableName()))
                     local = foreign;
                 else
-                    local = findTable(context, name.substring(0, dotIdx),
+                    local = findTable(context, path.getObjectTableName(),
                         local, foreign, null);
                 fullName = true;
-                name = name.substring(dotIdx + 1);
+                name = path.getIdentifier().getUnqualifiedName();
 
                 // if inverse join, then swap local and foreign tables
                 if (local != table) {
@@ -1375,28 +1393,27 @@
         }
 
         // determine target
-        String targetName = given.getTarget();
+        DBIdentifier targetName = given.getTargetIdentifier();
         Object target = null;
         Table ttable = null;
         boolean constant = false;
         boolean fullTarget = false;
-        if (targetName == null && given.getTargetField() != null) {
+        if (DBIdentifier.isNull(targetName) && given.getTargetField() != null) {
             ClassMapping tcls = (inverse) ? cls : rel;
             String fieldName = given.getTargetField();
-            int dotIdx = fieldName.lastIndexOf('.');
-            fullTarget = dotIdx != -1;
+            String[] names = Normalizer.splitName(fieldName);
+            fullTarget = names.length > 1;
 
-            if (dotIdx == 0) {
+            if (names.length > 1 && StringUtils.isEmpty(names[0])) {
                 // allow use of '.' without prefix to mean "use expected local
                 // cls"; but if we already inversed no need to switch again
                 if (!inverse)
                     tcls = cls;
-                fieldName = fieldName.substring(1);
-            } else if (dotIdx > 0) {
+                fieldName = names[1];
+            } else if (names.length > 1) {
                 // must be class + field name
-                tcls = findClassMapping(context, fieldName.substring
-                    (0, dotIdx), cls, rel);
-                fieldName = fieldName.substring(dotIdx + 1);
+                tcls = findClassMapping(context, names[0], cls, rel);
+                fieldName = names[1];
             }
             if (tcls == null)
                 throw new MetaDataException(_loc.get(prefix
@@ -1412,39 +1429,40 @@
                     + "-fktargetfield-cols", context, fieldName, name));
             ttable = (field.getJoinForeignKey() != null) ? field.getTable()
                 : field.getDefiningMapping().getTable();
-            targetName = field.getColumns()[0].getName();
-        } else if (targetName != null) {
-            if (targetName.charAt(0) == '\'') {
+            targetName = field.getColumns()[0].getIdentifier();
+        } else if (!DBIdentifier.isNull(targetName)) {
+            String targetNameStr = targetName.getName();
+            if (targetNameStr.charAt(0) == '\'') {
                 constant = true;
-                target = targetName.substring(1, targetName.length() - 1);
-            } else if (targetName.charAt(0) == '-'
-                || targetName.charAt(0) == '.'
-                || Character.isDigit(targetName.charAt(0))) {
+                target = targetNameStr.substring(1, targetNameStr.length() - 1);
+            } else if (targetNameStr.charAt(0) == '-'
+                || targetNameStr.charAt(0) == '.'
+                || Character.isDigit(targetNameStr.charAt(0))) {
                 constant = true;
                 try {
-                    if (targetName.indexOf('.') == -1)
-                        target = new Integer(targetName);
+                    if (targetNameStr.indexOf('.') == -1)
+                        target = new Integer(targetNameStr);
                     else
-                        target = new Double(targetName);
+                        target = new Double(targetNameStr);
                 } catch (RuntimeException re) {
                     throw new MetaDataException(_loc.get(prefix
                         + "-bad-fkconst", context, targetName, name));
                 }
-            } else if ("null".equalsIgnoreCase(targetName))
+            } else if ("null".equalsIgnoreCase(targetNameStr))
                 constant = true;
             else {
-                int dotIdx = targetName.lastIndexOf('.');
-                fullTarget = dotIdx != -1;
-                if (dotIdx == 0) {
+                QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(targetName); 
+                fullTarget = (!DBIdentifier.isNull(path.getObjectTableName()));
+                if (!DBIdentifier.isNull(path.getObjectTableName()) && 
+                    DBIdentifier.isEmpty(path.getObjectTableName())) {
                     // allow use of '.' without prefix to mean "use expected
                     // local table", but ignore if we're already inversed
                     if (!inverse)
                         ttable = local;
-                    targetName = targetName.substring(1);
-                } else if (dotIdx != -1) {
-                    ttable = findTable(context, targetName.substring(0,
-                        dotIdx), foreign, local, (inverse) ? cls : rel);
-                    targetName = targetName.substring(dotIdx + 1);
+                    targetName = path.getIdentifier().getUnqualifiedName();
+                } else if (!DBIdentifier.isNull(path.getObjectTableName())) {
+                    ttable = findTable(context, path.getObjectTableName(), foreign, local, (inverse) ? cls : rel);
+                    targetName = path.getIdentifier().getUnqualifiedName();
                 }
             }
         }
@@ -1468,7 +1486,7 @@
         // in the column name, but not in the column target, or if the user
         // gives no column name but a full target name
         inverse = inverse || local != table || (local == foreign
-            && ((fullName && !fullTarget) || (name == null && fullTarget)));
+            && ((fullName && !fullTarget) || (DBIdentifier.isNull(name) && fullTarget)));
         if (!inversable && !constant && inverse) {
             if (local == foreign)
                 throw new MetaDataException(_loc.get(prefix
@@ -1476,11 +1494,11 @@
             throw new MetaDataException(_loc.get(prefix + "-bad-fk-inverse",
                 context, local, table));
         }
-        if (name == null && constant)
+        if (DBIdentifier.isNull(name) && constant)
             throw new MetaDataException(_loc.get(prefix
                 + "-no-fkcol-name-adapt", context));
 
-        if (name == null && targetName == null) {
+        if (DBIdentifier.isNull(name) && DBIdentifier.isNull(targetName)) {
             // if no name or target is provided and there's more than one likely
             // join possibility, too ambiguous
             PrimaryKey pk = foreign.getPrimaryKey();
@@ -1489,13 +1507,13 @@
                     + "-no-fkcol-name-adapt", context));
 
             // assume target is pk column
-            targetName = pk.getColumns()[0].getName();
-        } else if (name != null && targetName == null) {
+            targetName = pk.getColumns()[0].getIdentifier();
+        } else if (!DBIdentifier.isNull(name) && DBIdentifier.isNull(targetName)) {
             // if one primary key column use it for target; if multiple joins
             // look for a foreign column with same name as local column
             PrimaryKey pk = foreign.getPrimaryKey();
             if (joins.length == 1 && pk != null && pk.getColumns().length == 1) {
-                targetName = pk.getColumns()[0].getName();
+                targetName = pk.getColumns()[0].getIdentifier();
             }
             else if (foreign.getColumn(name) != null) {
                 targetName = name;
@@ -1509,15 +1527,15 @@
         // find the target column, and create template for local column based
         // on it
         Column tmplate = new Column();
-        tmplate.setName(name);
+        tmplate.setIdentifier(name);
         if (!constant) {
             Column tcol = foreign.getColumn(targetName);
             if (tcol == null)
                 throw new MetaDataException(_loc.get(prefix + "-bad-fktarget",
                     new Object[]{ context, targetName, name, foreign }));
 
-            if (name == null)
-                tmplate.setName(tcol.getName());
+            if (DBIdentifier.isNull(name))
+                tmplate.setIdentifier(tcol.getIdentifier());
             tmplate.setJavaType(tcol.getJavaType());
             tmplate.setType(tcol.getType());
             tmplate.setTypeName(tcol.getTypeName());
@@ -1535,8 +1553,8 @@
         if (def != null)
             def.populate(local, foreign, tmplate, target, inverse, idx,
                 joins.length);
-        if (name != null)
-            tmplate.setName(name);
+        if (!DBIdentifier.isNull(name))
+            tmplate.setIdentifier(name);
 
         // create or merge local column
         Column col = mergeColumn(context, prefix, tmplate, true, given, local,
@@ -1589,7 +1607,7 @@
         if (cols == null || cols.length == 0)
             _cols = null;
         else {
-            _cols = new ArrayList(cols.length);
+            _cols = new ArrayList<Column>(cols.length);
             Column col;
             for (int i = 0; i < cols.length; i++) {
                 col = syncColumn(context, cols[i], cols.length,
@@ -1621,7 +1639,7 @@
 
         _canIdx = true;
         _idx = new Index();
-        _idx.setName(idx.getName());
+        _idx.setIdentifier(idx.getIdentifier());
         _idx.setUnique(idx.isUnique());
         if (idx.getColumns() != null && idx.getColumns().length > 1)
             _idx.setColumns(idx.getColumns());
@@ -1638,7 +1656,7 @@
 
         _canUnq = true;
         _unq = new Unique();
-        _unq.setName(unq.getName());
+        _unq.setIdentifier(unq.getIdentifier());
         _unq.setDeferred(unq.isDeferred());
     }
     
@@ -1665,7 +1683,7 @@
         else {
             _canFK = true;
             _fk = new ForeignKey();
-            _fk.setName(fk.getName());
+            _fk.setIdentifier(fk.getIdentifier());
             _fk.setDeleteAction(fk.getDeleteAction());
             _fk.setUpdateAction(fk.getUpdateAction());
             _fk.setDeferred(fk.isDeferred());
@@ -1679,7 +1697,7 @@
         Object[] cpks = fk.getPrimaryKeyConstants();
 
         int size = cols.length + ccols.length + cpkCols.length;
-        _cols = new ArrayList(size);
+        _cols = new ArrayList<Column>(size);
         Column col;
         for (int i = 0; i < cols.length; i++) {
             col = syncColumn(context, cols[i], size, false, local,
@@ -1725,27 +1743,28 @@
             getDBDictionary();
         Column copy = new Column();
         if (col.getTable() != colTable || inverse)
-            copy.setName(dict.getFullName(col.getTable(), true)
-                + dict.catalogSeparator + col.getName());
+            copy.setIdentifier(QualifiedDBIdentifier.newPath(dict.getFullIdentifier(col.getTable(), true),
+                col.getIdentifier()));
         else
-            copy.setName(col.getName());
+            copy.setIdentifier(col.getIdentifier());
 
         // set target if not default
         if (target != null) {
             if (target == NULL)
-                copy.setTarget("null");
+                copy.setTargetIdentifier(DBIdentifier.newColumn("null"));
             else if (target instanceof Column) {
                 Column tcol = (Column) target;
                 if ((!inverse && tcol.getTable() != targetTable)
                     || (inverse && tcol.getTable() != colTable))
-                    copy.setTarget(dict.getFullName(tcol.getTable(), true)
-                        + dict.catalogSeparator + tcol.getName());
+                    copy.setTargetIdentifier(
+                        QualifiedDBIdentifier.newPath(dict.getFullIdentifier(tcol.getTable(), true),
+                        tcol.getIdentifier()));
                 else if (!defaultTarget(col, tcol, num))
-                    copy.setTarget(tcol.getName());
+                    copy.setTargetIdentifier(tcol.getIdentifier());
             } else if (target instanceof Number)
-                copy.setTarget(target.toString());
+                copy.setTargetIdentifier(DBIdentifier.newConstant(target.toString()));
             else
-                copy.setTarget("'" + target + "'");
+                copy.setTargetIdentifier(DBIdentifier.newConstant("'" + target + "'"));
         } else if (num > 1)
             copy.setTargetField(col.getTargetField());
 
@@ -1839,7 +1858,7 @@
      */
     private static boolean defaultTarget(Column col, Column targetCol,
         int num) {
-        if (col.getName().equals(targetCol.getName()))
+        if (col.getIdentifier().equals(targetCol.getIdentifier()))
             return true;
         if (num > 1)
             return false;
@@ -1857,8 +1876,10 @@
 
         /**
          * Return the default table name.
+         * @deprecated
          */
         public String get(Schema schema);
+        public DBIdentifier getIdentifier(Schema schema);
     }
 
     /**

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java Fri Jan 15 19:38:18 2010
@@ -30,6 +30,7 @@
 
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.meta.strats.BlobValueHandler;
 import org.apache.openjpa.jdbc.meta.strats.ByteArrayValueHandler;
 import org.apache.openjpa.jdbc.meta.strats.CharArrayStreamValueHandler;
@@ -112,7 +113,8 @@
     private transient DBDictionary _dict = null;
     private transient MappingDefaults _defaults = null;
     
-    private Map _results = new HashMap(); // object->queryresultmapping
+    // object->queryresultmapping
+    private Map<Object, QueryResultMapping> _results = new HashMap<Object, QueryResultMapping>(); 
     private SchemaGroup _schema = null;
     private StrategyInstaller _installer = null;
 
@@ -344,11 +346,11 @@
      * Return a unique key for the given class / name. The class argument
      * can be null.
      */
-    private static Object getQueryResultKey(Class cls, String name) {
+    private static Object getQueryResultKey(Class<?> cls, String name) {
         return getQueryKey(cls, name);
     }
 
-    public ClassMapping getMapping(Class cls, ClassLoader envLoader,
+    public ClassMapping getMapping(Class<?> cls, ClassLoader envLoader,
         boolean mustExist) {
         return (ClassMapping) super.getMetaData(cls, envLoader, mustExist);
     }
@@ -362,7 +364,7 @@
         return (ClassMapping) super.getMetaData(oid, envLoader, mustExist);
     }
 
-    public ClassMapping[] getImplementorMappings(Class cls,
+    public ClassMapping[] getImplementorMappings(Class<?> cls,
         ClassLoader envLoader, boolean mustExist) {
         return (ClassMapping[]) super.getImplementorMetaDatas(cls, envLoader,
             mustExist);
@@ -415,7 +417,7 @@
         mapping.resolveNonRelationMappings();
     }
 
-    protected ClassMetaData newClassMetaData(Class type) {
+    protected ClassMetaData newClassMetaData(Class<?> type) {
         return new ClassMapping(type, this);
     }
 
@@ -423,7 +425,7 @@
         return new ClassMapping[length];
     }
 
-    protected FieldMetaData newFieldMetaData(String name, Class type,
+    protected FieldMetaData newFieldMetaData(String name, Class<?> type,
         ClassMetaData owner) {
         return new FieldMapping(name, type, (ClassMapping) owner);
     }
@@ -530,7 +532,7 @@
 
         String props = Configurations.getProperties(name);
         name = Configurations.getClassName(name);
-        Class strat = null;
+        Class<?> strat = null;
 
         // base and vertical strategies use same alias; differentiate on join
         if (FullClassStrategy.ALIAS.equals(name))
@@ -575,7 +577,7 @@
         String props = Configurations.getProperties(name);
         name = Configurations.getClassName(name);
         try {
-            Class c = JavaTypes.classForName(name, field,
+            Class<?> c = JavaTypes.classForName(name, field,
                 AccessController.doPrivileged(
                     J2DoPrivHelper.getClassLoaderAction(FieldStrategy.class)));
             if (FieldStrategy.class.isAssignableFrom(c)) {
@@ -636,7 +638,7 @@
 
         String props = Configurations.getProperties(name);
         name = Configurations.getClassName(name);
-        Class strat = null;
+        Class<?> strat = null;
 
         if (ClassNameDiscriminatorStrategy.ALIAS.equals(name))
             strat = ClassNameDiscriminatorStrategy.class;
@@ -698,7 +700,7 @@
 
         String props = Configurations.getProperties(name);
         name = Configurations.getClassName(name);
-        Class strat = null;
+        Class<?> strat = null;
 
         if (NumberVersionStrategy.ALIAS.equals(name))
             strat = NumberVersionStrategy.class;
@@ -729,7 +731,7 @@
     /**
      * Instantiate the given version strategy.
      */
-    protected VersionStrategy instantiateVersionStrategy(Class strat,
+    protected VersionStrategy instantiateVersionStrategy(Class<?> strat,
         Version version, String props) {
         try {
             VersionStrategy strategy = (VersionStrategy)
@@ -824,7 +826,7 @@
     protected FieldStrategy defaultStrategy(FieldMapping field,
         boolean installHandlers, boolean adapting) {
         // not persistent?
-        if (field.getManagement() != field.MANAGE_PERSISTENT
+        if (field.getManagement() != FieldMetaData.MANAGE_PERSISTENT
             || field.isVersion())
             return NoneFieldStrategy.getInstance();
         if (field.getDefiningMapping().getStrategy() ==
@@ -1038,7 +1040,7 @@
         // an association table
         FieldMappingInfo info = field.getMappingInfo();
         ValueMapping elem = field.getElementMapping();
-        boolean useInverseKeyMapping = info.getTableName() == null && info.getColumns().isEmpty()
+        boolean useInverseKeyMapping = DBIdentifier.isNull(info.getTableIdentifier()) && info.getColumns().isEmpty()
             && !elem.getValueInfo().getColumns().isEmpty();
         
         // JPA 2.0: non-default mapping: uni-/1-M/JoinColumn ==> foreign key strategy
@@ -1157,7 +1159,7 @@
     }
     
     public boolean hasJoinTable(FieldMapping field) {
-        boolean hasJoinTable = field.getMappingInfo().getTableName() != null ? true : false;
+        boolean hasJoinTable = !DBIdentifier.isNull(field.getMappingInfo().getTableIdentifier()) ? true : false;
         return hasJoinTable;
     }
 
@@ -1179,7 +1181,7 @@
     /**
      * Check the given value against mapped strategies.
      */
-    private Object mappedStrategy(ValueMapping val, Class type,
+    private Object mappedStrategy(ValueMapping val, Class<?> type,
         boolean adapting) {
         if (type == null || type == Object.class)
             return null;
@@ -1200,7 +1202,7 @@
         String props = Configurations.getProperties(name);
         name = Configurations.getClassName(name);
         try {
-            Class c = JavaTypes.classForName(name, val,
+            Class<?> c = JavaTypes.classForName(name, val,
                 AccessController.doPrivileged(
                     J2DoPrivHelper.getClassLoaderAction(FieldStrategy.class)));
             Object o = AccessController.doPrivileged(
@@ -1227,7 +1229,7 @@
         String props = Configurations.getProperties(name);
         name = Configurations.getClassName(name);
         try {
-            Class c = JavaTypes.classForName(name, val,
+            Class<?> c = JavaTypes.classForName(name, val,
                 AccessController.doPrivileged(
                     J2DoPrivHelper.getClassLoaderAction(ValueHandler.class)));
             if (ValueHandler.class.isAssignableFrom(c)) {
@@ -1344,7 +1346,7 @@
      * Checks for hints as to whether the given column is a CLOB.
      */
     private boolean isClob(ValueMapping val, boolean warn) {
-        List cols = val.getValueInfo().getColumns();
+        List<Column> cols = val.getValueInfo().getColumns();
         if (cols.size() != 1)
             return false;
 
@@ -1511,12 +1513,12 @@
                 // persistent subclasses may not have been resolved yet.  
                 // run through the persistent types to see if any of them 
                 // or their superclass is a subclass of this class.
-                Collection classes = loadPersistentTypes(false, 
+                Collection<Class<?>> classes = loadPersistentTypes(false, 
                         mapping.getEnvClassLoader());
-                Class cls;
-                for (Iterator itr = classes.iterator(); itr.hasNext();) {
-                    cls = (Class) itr.next();
-                    Class supcl = cls.getSuperclass();
+                Class<?> cls;
+                for (Iterator<Class<?>> itr = classes.iterator(); itr.hasNext();) {
+                    cls = itr.next();
+                    Class<?> supcl = cls.getSuperclass();
                     while (supcl != null && 
                            !supcl.getClass().equals(java.lang.Object.class)) {
                         if (!supcl.isInterface() &&

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingStrategyInstaller.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingStrategyInstaller.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingStrategyInstaller.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingStrategyInstaller.java Fri Jan 15 19:38:18 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.openjpa.jdbc.meta;
 
+import org.apache.openjpa.meta.MetaDataModes;
+
 /**
  * Installer used during mapping that attempts to use the given mapping
  * information (if any), and fails if it does not work.
@@ -26,6 +28,7 @@
  * @nojavadoc
  * @since 0.4.0
  */
+@SuppressWarnings("serial")
 public class MappingStrategyInstaller
     extends StrategyInstaller {
 
@@ -45,7 +48,7 @@
         if (strat == null)
             strat = repos.defaultStrategy(cls, true);
         cls.setStrategy(strat, Boolean.TRUE);
-        cls.setSourceMode(cls.MODE_MAPPING, true);
+        cls.setSourceMode(MetaDataModes.MODE_MAPPING, true);
     }
 
     public void installStrategy(FieldMapping field) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java Fri Jan 15 19:38:18 2010
@@ -52,6 +52,8 @@
 import org.apache.openjpa.lib.conf.Configurations;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.meta.ClassArgParser;
+import org.apache.openjpa.lib.meta.MetaDataSerializer;
+import org.apache.openjpa.lib.meta.SourceTracker;
 import org.apache.openjpa.lib.util.Files;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
@@ -62,6 +64,7 @@
 import org.apache.openjpa.meta.JavaTypes;
 import org.apache.openjpa.meta.MetaDataFactory;
 import org.apache.openjpa.meta.MetaDataModes;
+import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.meta.QueryMetaData;
 import org.apache.openjpa.meta.SequenceMetaData;
 import org.apache.openjpa.meta.ValueStrategies;
@@ -123,8 +126,8 @@
     private Writer _schemaWriter = null;
 
     // buffer metadatas to be dropped
-    private Set _dropCls = null;
-    private Set _dropMap = null;
+    private Set<Class<?>> _dropCls = null;
+    private Set<ClassMapping> _dropMap = null;
     private boolean _flush = false;
     private boolean _flushSchema = false;
 
@@ -377,7 +380,7 @@
         if (_repos == null) {
             _repos = _conf.newMappingRepositoryInstance();
             _repos.setSchemaGroup(getSchemaGroup());
-            _repos.setValidate(_repos.VALIDATE_UNENHANCED, false);
+            _repos.setValidate(MetaDataRepository.VALIDATE_UNENHANCED, false);
         }
         return _repos;
     }
@@ -467,7 +470,7 @@
 
         try {
             if (_dropCls != null && !_dropCls.isEmpty()) {
-                Class[] cls = (Class[]) _dropCls.toArray
+                Class<?>[] cls = (Class[]) _dropCls.toArray
                     (new Class[_dropCls.size()]);
                 if (!io.drop(cls, _mode, null))
                     _log.warn(_loc.get("bad-drop", _dropCls));
@@ -508,7 +511,7 @@
                     // serialize the planned schema to the stream
                     SchemaSerializer ser = new XMLSchemaSerializer(_conf);
                     ser.addAll(getSchemaGroup());
-                    ser.serialize(_schemaWriter, ser.PRETTY);
+                    ser.serialize(_schemaWriter, MetaDataSerializer.PRETTY);
                     _schemaWriter.flush();
                 }
             }
@@ -517,21 +520,21 @@
 
             QueryMetaData[] queries = repos.getQueryMetaDatas();
             SequenceMetaData[] seqs = repos.getSequenceMetaDatas();
-            Map output = null;
+            Map<File, String> output = null;
 
             // if we're outputting to stream, set all metas to same file so
             // they get placed in single string
             if (_mappingWriter != null) {
-                output = new HashMap();
+                output = new HashMap<File, String>();
                 File tmp = new File("openjpatmp");
                 for (int i = 0; i < mappings.length; i++)
-                    mappings[i].setSource(tmp, mappings[i].SRC_OTHER);
+                    mappings[i].setSource(tmp, SourceTracker.SRC_OTHER);
                 for (int i = 0; i < queries.length; i++)
                     queries[i].setSource(tmp, queries[i].getSourceScope(),
-                        queries[i].SRC_OTHER);
+                        SourceTracker.SRC_OTHER);
                 for (int i = 0; i < seqs.length; i++)
                     seqs[i].setSource(tmp, seqs[i].getSourceScope(),
-                        seqs[i].SRC_OTHER);
+                        SourceTracker.SRC_OTHER);
             }
 
             // store
@@ -541,9 +544,9 @@
             // write to stream
             if (_mappingWriter != null) {
                 PrintWriter out = new PrintWriter(_mappingWriter);
-                for (Iterator itr = output.values().iterator();
+                for (Iterator<String> itr = output.values().iterator();
                     itr.hasNext();)
-                    out.println((String) itr.next());
+                    out.println(itr.next());
                 out.flush();
             }
         }
@@ -634,7 +637,7 @@
     /**
      * Run the configured action on the given instance.
      */
-    public void run(Class cls) {
+    public void run(Class<?> cls) {
         if (ACTION_ADD.equals(_action)) {
             if (_meta)
                 addMeta(cls);
@@ -653,7 +656,7 @@
     /**
      * Add the mapping for the given instance.
      */
-    private void add(Class cls) {
+    private void add(Class<?> cls) {
         if (cls == null)
             return;
 
@@ -669,7 +672,7 @@
      * Return the mapping for the given type, or null if the type is
      * persistence-aware.
      */
-    private static ClassMapping getMapping(MappingRepository repos, Class cls,
+    private static ClassMapping getMapping(MappingRepository repos, Class<?> cls,
         boolean validate) {
         // this will parse all possible metadata rsrcs looking for cls, so
         // will detect if p-aware
@@ -685,7 +688,7 @@
     /**
      * Create a metadata for the given instance.
      */
-    private void addMeta(Class cls) {
+    private void addMeta(Class<?> cls) {
         if (cls == null)
             return;
 
@@ -710,7 +713,7 @@
     /**
      * Refresh or add the mapping for the given instance.
      */
-    private void refresh(Class cls) {
+    private void refresh(Class<?> cls) {
         if (cls == null)
             return;
 
@@ -725,7 +728,7 @@
     /**
      * Validate the mappings for the given class and its fields.
      */
-    private void validate(Class cls) {
+    private void validate(Class<?> cls) {
         if (cls == null)
             return;
 
@@ -739,7 +742,7 @@
     /**
      * Create the schema using the mapping for the given instance.
      */
-    private void buildSchema(Class cls) {
+    private void buildSchema(Class<?> cls) {
         if (cls == null)
             return;
 
@@ -770,12 +773,12 @@
     /**
      * Drop mapping for given class.
      */
-    private void drop(Class cls) {
+    private void drop(Class<?> cls) {
         if (cls == null)
             return;
 
         if (_dropCls == null)
-            _dropCls = new HashSet();
+            _dropCls = new HashSet<Class<?>>();
         _dropCls.add(cls);
         if (!contains(_schemaActions,SchemaTool.ACTION_DROP))
             return;
@@ -791,7 +794,7 @@
         if (mapping != null) {
             _flushSchema = true;
             if (_dropMap == null)
-                _dropMap = new HashSet();
+                _dropMap = new HashSet<ClassMapping>();
             _dropMap.add(mapping);
         } else
             _log.warn(_loc.get("no-drop-meta", cls));
@@ -1003,7 +1006,7 @@
 
         // collect the classes to act on
         Log log = conf.getLog(OpenJPAConfiguration.LOG_TOOL);
-        Collection classes = null;
+        Collection<Class<?>> classes = null;
         if (args.length == 0) {
             if (ACTION_IMPORT.equals(flags.action))
                 return false;
@@ -1011,18 +1014,18 @@
             classes = conf.getMappingRepositoryInstance().
                 loadPersistentTypes(true, loader);
         } else {
-            classes = new HashSet();
+            classes = new HashSet<Class<?>>();
             ClassArgParser classParser = conf.getMetaDataRepositoryInstance().
                 getMetaDataFactory().newClassArgParser();
             classParser.setClassLoader(loader);
-            Class[] parsed;
+            Class<?>[] parsed;
             for (int i = 0; args != null && i < args.length; i++) {
                 parsed = classParser.parseTypes(args[i]);
                 classes.addAll(Arrays.asList(parsed));
             }
         }
 
-        Class[] act = (Class[]) classes.toArray(new Class[classes.size()]);
+        Class<?>[] act = (Class[]) classes.toArray(new Class[classes.size()]);
         if (ACTION_EXPORT.equals(flags.action)) {
             // run exports until the first export succeeds
             ImportExport[] instances = newImportExports();
@@ -1081,7 +1084,7 @@
      */
     private static ImportExport[] newImportExports() {
         try {
-            Class[] types = Services.getImplementorClasses(ImportExport.class);
+            Class<?>[] types = Services.getImplementorClasses(ImportExport.class);
             ImportExport[] instances = new ImportExport[types.length];
             for (int i = 0; i < types.length; i++)
                 instances[i] = (ImportExport) AccessController.doPrivileged(
@@ -1129,14 +1132,14 @@
         /**
          * Import mappings for the given classes based on the given arguments.
          */
-        public boolean importMappings(JDBCConfiguration conf, Class[] act,
+        public boolean importMappings(JDBCConfiguration conf, Class<?>[] act,
             String[] args, boolean meta, Log log, ClassLoader loader)
             throws IOException;
 
         /**
          * Export mappings for the given classes based on the given arguments.
          */
-        public boolean exportMappings(JDBCConfiguration conf, Class[] act,
+        public boolean exportMappings(JDBCConfiguration conf, Class<?>[] act,
             boolean meta, Log log, Writer writer)
             throws IOException;
     }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/NoneMappingDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/NoneMappingDefaults.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/NoneMappingDefaults.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/NoneMappingDefaults.java Fri Jan 15 19:38:18 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.openjpa.jdbc.meta;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
 import org.apache.openjpa.jdbc.schema.Index;
@@ -63,7 +64,7 @@
         return null;
     }
 
-    public Object getStrategy(ValueMapping vm, Class type, boolean adapt) {
+    public Object getStrategy(ValueMapping vm, Class<?> type, boolean adapt) {
         return null;
     }
 
@@ -98,11 +99,17 @@
         Column col, Object target, int pos, int cols) {
     }
 
+    /**
+     * @deprecated
+     */
     public void populateForeignKeyColumn(ValueMapping vm, String name,
         Table local, Table foreign, Column col, Object target, boolean inverse,
         int pos, int cols) {
     }
 
+    /**
+     * @deprecated
+     */
     public void populateColumns(ValueMapping vm, String name, Table table,
         Column[] cols) {
     }
@@ -112,6 +119,9 @@
         return false;
     }
 
+    /**
+     * @deprecated
+     */
     public boolean populateNullIndicatorColumns(ValueMapping vm, String name,
         Table table, Column[] cols) {
         return false;
@@ -127,6 +137,9 @@
         return null;
     }
 
+    /**
+     * @deprecated
+     */
     public ForeignKey getForeignKey(ValueMapping vm, String name, Table local,
         Table foreign, boolean inverse) {
         return null;
@@ -164,4 +177,45 @@
 
     public void installPrimaryKey(FieldMapping fm, Table table) {
     }
+
+    public ForeignKey getForeignKey(ValueMapping vm, DBIdentifier name, Table local,
+        Table foreign, boolean inverse) {
+        return null;
+    }
+
+    public Index getIndex(ValueMapping vm, DBIdentifier name, Table table,
+        Column[] cols) {
+        return null;
+    }
+
+    public Unique getUnique(ValueMapping vm, DBIdentifier name, Table table,
+        Column[] cols) {
+        return null;
+    }
+
+    public void populateColumns(ValueMapping vm, DBIdentifier name, Table table,
+        Column[] cols) {
+    }
+
+    public void populateForeignKeyColumn(ValueMapping vm, DBIdentifier name,
+        Table local, Table foreign, Column col, Object target, boolean inverse,
+        int pos, int cols) {
+    }
+
+    public boolean populateNullIndicatorColumns(ValueMapping vm, DBIdentifier name,
+        Table table, Column[] cols) {
+        return false;
+    }
+
+    public DBIdentifier getTableIdentifier(ClassMapping cls, Schema defaultSchema) {
+        return DBIdentifier.newTable(getTableName(cls, defaultSchema));
+    }
+
+    public DBIdentifier getTableIdentifier(FieldMapping fm, Schema defaultSchema) {
+        return DBIdentifier.newTable(getTableName(fm, defaultSchema));
+    }
+
+    public DBIdentifier getPrimaryKeyIdentifier(ClassMapping cm, Table table) {
+        return DBIdentifier.NULL;
+    }
 }



Mime
View raw message