You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by jr...@apache.org on 2010/01/15 20:38:26 UTC

svn commit: r899784 [6/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...

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java Fri Jan 15 19:38:18 2010
@@ -34,8 +34,11 @@
 import java.util.Set;
 import javax.sql.DataSource;
 
-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.identifier.DBIdentifier.DBIdentifierType;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
@@ -65,7 +68,7 @@
     private boolean _openjpaTables = true;
     private SchemaGroup _group = null;
 
-    private List _listeners = null;
+    private List<Listener> _listeners = null;
     private int _schemaObjects = 0;
 
     /**
@@ -85,7 +88,20 @@
         _dict = conf.getDBDictionaryInstance();
 
         // create a table of allowed schema and tables to reflect on
-        _allowed = parseSchemasList(conf.getSchemasList());
+        String[] schemaArray = conf.getSchemasList();
+        DBIdentifier[] names = new DBIdentifier[schemaArray == null ? 0 : schemaArray.length];
+        for (int i = 0; i < names.length; i++) {
+            String[] splitName = Normalizer.splitName(schemaArray[i]);
+            if (splitName == null || splitName.length == 0) {
+                continue;
+            }
+            if (splitName.length == 1) {
+                names[i] = DBIdentifier.newSchema(schemaArray[i]);
+            } else {
+                names[i] = QualifiedDBIdentifier.newTable(schemaArray[i]);
+            }
+        }
+        _allowed = parseSchemasList(names);
     }
 
     /**
@@ -95,34 +111,25 @@
      * null if no args are given. If no tables are given for a particular
      * schema, maps the schema name to null.
      */
-    private static Object[][] parseSchemasList(String[] args) {
+    private static Object[][] parseSchemasList(DBIdentifier[] args) {
         if (args == null || args.length == 0)
             return null;
 
-        Map schemas = new HashMap();
-        String schema, table;
-        int dotIdx;
-        Collection tables;
+        Map<DBIdentifier, Collection<DBIdentifier>> schemas = new HashMap<DBIdentifier, Collection<DBIdentifier>>();
+        DBIdentifier schema = DBIdentifier.NULL, table = DBIdentifier.NULL;
+        Collection<DBIdentifier> tables = null;
         for (int i = 0; i < args.length; i++) {
-            dotIdx = args[i].indexOf('.');
-            if (dotIdx == -1) {
-                schema = args[i];
-                table = null;
-            } else if (dotIdx == 0) {
-                schema = null;
-                table = args[i].substring(1);
-            } else {
-                schema = args[i].substring(0, dotIdx);
-                table = args[i].substring(dotIdx + 1);
-            }
+            QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(args[i]);
+            schema = path.getSchemaName();
+            table = path.getIdentifier();
 
             // if just a schema name, map schema to null
-            if (table == null && !schemas.containsKey(schema))
+            if (DBIdentifier.isNull(table) && !schemas.containsKey(schema))
                 schemas.put(schema, null);
-            else if (table != null) {
-                tables = (Collection) schemas.get(schema);
+            else if (!DBIdentifier.isNull(table)) {
+                tables = schemas.get(schema);
                 if (tables == null) {
-                    tables = new LinkedList();
+                    tables = new LinkedList<DBIdentifier>();
                     schemas.put(schema, tables);
                 }
                 tables.add(table);
@@ -130,15 +137,16 @@
         }
 
         Object[][] parsed = new Object[schemas.size()][2];
-        Map.Entry entry;
+        Map.Entry<DBIdentifier, Collection<DBIdentifier>> entry;
         int idx = 0;
-        for (Iterator itr = schemas.entrySet().iterator(); itr.hasNext();) {
-            entry = (Map.Entry) itr.next();
-            tables = (Collection) entry.getValue();
+        for (Iterator<Map.Entry<DBIdentifier, Collection<DBIdentifier>>> itr = schemas.entrySet().iterator(); 
+            itr.hasNext();) {
+            entry = itr.next();
+            tables = entry.getValue();
 
             parsed[idx][0] = entry.getKey();
             if (tables != null)
-                parsed[idx][1] = tables.toArray(new String[tables.size()]);
+                parsed[idx][1] = tables.toArray(new DBIdentifier[tables.size()]);
             idx++;
         }
         return parsed;
@@ -240,16 +248,24 @@
     public void generateSchemas()
         throws SQLException {
         fireGenerationEvent(_loc.get("generating-schemas"));
-        generateSchemas(null);
+        generateSchemas((DBIdentifier[])null);
     }
 
     /**
+     * @deprecated
+     */
+    public void generateSchemas(String[] schemasAndTables)
+        throws SQLException {        
+        generateSchemas(DBIdentifier.toArray(schemasAndTables, DBIdentifierType.TABLE));
+    }
+    
+    /**
      * Generate the schemas and/or tables named in the given strings.
      * This method calls {@link #generateIndexes},
      * {@link #generatePrimaryKeys}, and {@link #generateForeignKeys}
      * automatically.
      */
-    public void generateSchemas(String[] schemasAndTables)
+    public void generateSchemas(DBIdentifier[] schemasAndTables)
         throws SQLException {
         fireGenerationEvent(_loc.get("generating-schemas"));
 
@@ -260,10 +276,10 @@
             schemaMap = parseSchemasList(schemasAndTables);
 
         if (schemaMap == null) {
-            generateSchema(null, null);
+            generateSchema(DBIdentifier.NULL, (DBIdentifier[])null);
 
             // estimate the number of schema objects we will need to visit
-            // in order to estimate progresss total for any listeners
+            // in order to estimate progress total for any listeners
             int numTables = getTables(null).size();
             _schemaObjects += numTables
                 + (_pks ? numTables : 0)
@@ -271,28 +287,28 @@
                 + (_fks ? numTables : 0);
 
             if (_pks)
-                generatePrimaryKeys(null, null);
+                generatePrimaryKeys(DBIdentifier.NULL, null);
             if (_indexes)
-                generateIndexes(null, null);
+                generateIndexes(DBIdentifier.NULL, null);
             if (_fks)
-                generateForeignKeys(null, null);
+                generateForeignKeys(DBIdentifier.NULL, null);
             return;
         }
 
         // generate all schemas and tables
         for (int i = 0; i < schemaMap.length; i++)
-            generateSchema((String) schemaMap[i][0],
-                (String[]) schemaMap[i][1]);
+            generateSchema((DBIdentifier) schemaMap[i][0],
+                (DBIdentifier[]) schemaMap[i][1]);
 
         // generate pks, indexes, fks
-        String schemaName;
-        String[] tableNames;
+        DBIdentifier schemaName = DBIdentifier.NULL;
+        DBIdentifier[] tableNames;
         for (int i = 0; i < schemaMap.length; i++) {
-            schemaName = (String) schemaMap[i][0];
-            tableNames = (String[]) schemaMap[i][1];
+            schemaName = (DBIdentifier) schemaMap[i][0];
+            tableNames = (DBIdentifier[]) schemaMap[i][1];
 
             // estimate the number of schema objects we will need to visit
-            // in order to estimate progresss total for any listeners
+            // in order to estimate progress total for any listeners
             int numTables = (tableNames != null) ? tableNames.length
                 : getTables(schemaName).size();
             _schemaObjects += numTables
@@ -310,6 +326,17 @@
     }
 
     /**
+     * @param name
+     * @param tableNames
+     * @deprecated
+     */
+    public void generateSchema(String name, String[] tableNames)
+        throws SQLException {
+        generateSchema(DBIdentifier.newSchema(name),
+            DBIdentifier.toArray(tableNames, DBIdentifierType.TABLE));
+    }
+
+    /**
      * Add a fully-constructed {@link Schema} matching the given database
      * schema to the current group. No foreign keys are generated because
      * some keys might span schemas. You must call
@@ -320,7 +347,7 @@
      * @param tableNames a list of tables to generate in the schema, or null
      * to generate all tables
      */
-    public void generateSchema(String name, String[] tableNames)
+    public void generateSchema(DBIdentifier name, DBIdentifier[] tableNames)
         throws SQLException {
         fireGenerationEvent(_loc.get("generating-schema", name));
 
@@ -329,13 +356,13 @@
         DatabaseMetaData meta = conn.getMetaData();
         try {
             if (tableNames == null)
-                generateTables(name, null, conn, meta);
+                generateTables(name, DBIdentifier.NULL, conn, meta);
             else
                 for (int i = 0; i < tableNames.length; i++)
                     generateTables(name, tableNames[i], conn, meta);
 
             if (_seqs)
-                generateSequences(name, null, conn, meta);
+                generateSequences(name, DBIdentifier.NULL, conn, meta);
         } finally {
             // some databases require a commit after metadata to release locks
             try {
@@ -355,9 +382,24 @@
      * only be called after all schemas are generated. The schema name and
      * tables array can be null to indicate that indexes should be generated
      * for all schemas and/or tables.
+     * @deprecated
      */
     public void generatePrimaryKeys(String schemaName, String[] tableNames)
         throws SQLException {
+        generatePrimaryKeys(DBIdentifier.newSchema(schemaName),
+            DBIdentifier.toArray(tableNames, DBIdentifierType.TABLE));
+    }
+
+    
+    /**
+     * Generate primary key information for the given schema. This method
+     * must be called in addition to {@link #generateSchema}. It should
+     * only be called after all schemas are generated. The schema name and
+     * tables array can be null to indicate that indexes should be generated
+     * for all schemas and/or tables.
+     */
+    public void generatePrimaryKeys(DBIdentifier schemaName, DBIdentifier[] tableNames)
+        throws SQLException {
         fireGenerationEvent(_loc.get("generating-all-primaries", schemaName));
 
         Connection conn = _ds.getConnection();
@@ -387,8 +429,22 @@
      * only be called after all schemas are generated. The schema name and
      * tables array can be null to indicate that indexes should be generated
      * for all schemas and/or tables.
+     * @deprecated
+     */
+    public void generateIndexes(String schemaName, String[] tableNames) 
+        throws SQLException {
+        generateIndexes(DBIdentifier.newSchema(schemaName),
+            DBIdentifier.toArray(tableNames, DBIdentifierType.TABLE));
+    }
+
+    /**
+     * Generate index information for the given schema. This method
+     * must be called in addition to {@link #generateSchema}. It should
+     * only be called after all schemas are generated. The schema name and
+     * tables array can be null to indicate that indexes should be generated
+     * for all schemas and/or tables.
      */
-    public void generateIndexes(String schemaName, String[] tableNames)
+    public void generateIndexes(DBIdentifier schemaName, DBIdentifier[] tableNames)
         throws SQLException {
         fireGenerationEvent(_loc.get("generating-all-indexes", schemaName));
 
@@ -419,9 +475,24 @@
      * only be called after all schemas are generated. The schema name and
      * tables array can be null to indicate that indexes should be generated
      * for all schemas and/or tables.
+     * @deprecated
      */
     public void generateForeignKeys(String schemaName, String[] tableNames)
         throws SQLException {
+        generateForeignKeys(DBIdentifier.newSchema(schemaName),
+            DBIdentifier.toArray(tableNames, DBIdentifierType.TABLE));
+    }
+
+    
+    /**
+     * Generate foreign key information for the given schema. This method
+     * must be called in addition to {@link #generateSchema}. It should
+     * only be called after all schemas are generated. The schema name and
+     * tables array can be null to indicate that indexes should be generated
+     * for all schemas and/or tables.
+     */
+    public void generateForeignKeys(DBIdentifier schemaName, DBIdentifier[] tableNames)
+        throws SQLException {
         fireGenerationEvent(_loc.get("generating-all-foreigns", schemaName));
 
         Connection conn = _ds.getConnection();
@@ -446,9 +517,19 @@
     }
 
     /**
-     * Adds all tables matching the given name pattern to the schema.
+     * @deprecated
      */
     public void generateTables(String schemaName, String tableName,
+        Connection conn, DatabaseMetaData meta) 
+        throws SQLException {
+        generateTables(DBIdentifier.newSchema(schemaName),
+            DBIdentifier.newTable(tableName), conn, meta);
+    }
+
+    /**
+     * Adds all tables matching the given name pattern to the schema.
+     */
+    public void generateTables(DBIdentifier schemaName, DBIdentifier tableName,
         Connection conn, DatabaseMetaData meta)
         throws SQLException {
         fireGenerationEvent(_loc.get("generating-columns", schemaName,
@@ -456,43 +537,47 @@
         if (_log.isTraceEnabled())
             _log.trace(_loc.get("gen-tables", schemaName, tableName));
 
-        Column[] cols = _dict.getColumns(meta, conn.getCatalog(), schemaName,
+        Column[] cols = _dict.getColumns(meta, 
+            DBIdentifier.newCatalog(conn.getCatalog()), schemaName,
             tableName, null, conn);
 
         // when we want to get all the columns for all tables, we need to build
         // a list of tables to verify because some databases (e.g., Postgres)
         // will include indexes in the list of columns, and there is no way to
         // distinguish the indexes from proper columns
-        Set tableNames = null;
-        if (tableName == null || "%".equals(tableName)) {
-            Table[] tables = _dict.getTables(meta, conn.getCatalog(),
+        Set<DBIdentifier> tableNames = null;
+        if (DBIdentifier.isNull(tableName) || "%".equals(tableName.getName())) {
+            Table[] tables = _dict.getTables(meta, DBIdentifier.newCatalog(conn.getCatalog()),
                 schemaName, tableName, conn);
-            tableNames = new HashSet();
+            tableNames = new HashSet<DBIdentifier>();
             for (int i = 0; tables != null && i < tables.length; i++) {
-                if (cols == null)
-                    tableNames.add(tables[i].getName());
-                else
-                    tableNames.add(tables[i].getName().toUpperCase());
+                if (cols == null) {
+                    tableNames.add(tables[i].getIdentifier());
+                }
+                else {
+                    DBIdentifier sName = DBIdentifier.toUpper(tables[i].getIdentifier());
+                    tableNames.add(sName);
+                }
             }
         }
 
         // if database can't handle null table name, recurse on each known name
-        if (cols == null && tableName == null) {
-            for (Iterator itr = tableNames.iterator(); itr.hasNext();)
-                generateTables(schemaName, (String) itr.next(), conn, meta);
+        if (cols == null && DBIdentifier.isNull(tableName)) {
+            for (Iterator<DBIdentifier> itr = tableNames.iterator(); itr.hasNext();)
+                generateTables(schemaName, itr.next(), conn, meta);
             return;
         }
 
         SchemaGroup group = getSchemaGroup();
         Schema schema;
         Table table;
-        String tableSchema;
+        DBIdentifier tableSchema = DBIdentifier.NULL;
         for (int i = 0; cols != null && i < cols.length; i++) {
-            if (tableName == null || tableName.equals("%")) {
-                tableName = cols[i].getTableName();
+            if (DBIdentifier.isNull(tableName) || tableName.equals("%")) {
+                tableName = cols[i].getTableIdentifier();
             }
-            if (schemaName == null) {
-                tableSchema = StringUtils.trimToNull(cols[i].getSchemaName());
+            if (DBIdentifier.isNull(schemaName)) {
+                tableSchema = DBIdentifier.trimToNull(cols[i].getSchemaIdentifier());
             }
             else {
                 tableSchema = schemaName;
@@ -500,15 +585,16 @@
             
             // ignore special tables
             if (!_openjpaTables &&
-                (tableName.toUpperCase().startsWith("OPENJPA_")
-                    || tableName.toUpperCase().startsWith("JDO_"))) // legacy
+                (tableName.getName().toUpperCase().startsWith("OPENJPA_")
+                    || tableName.getName().toUpperCase().startsWith("JDO_"))) // legacy
                 continue;
-            if (_dict.isSystemTable(tableName, tableSchema, schemaName != null))
+            if (_dict.isSystemTable(tableName, tableSchema, !DBIdentifier.isNull(schemaName)))
                 continue;
 
             // ignore tables not in list, or not allowed by schemas property
+            
             if (tableNames != null
-                && !tableNames.contains(tableName.toUpperCase()))
+                && !tableNames.contains(DBIdentifier.toUpper(tableName)))
                 continue;
             if (!isAllowedTable(tableSchema, tableName))
                 continue;
@@ -525,9 +611,9 @@
             }
 
             if (_log.isTraceEnabled())
-                _log.trace(_loc.get("gen-column", cols[i].getName(), table));
+                _log.trace(_loc.get("gen-column", cols[i].getIdentifier(), table));
 
-            if (table.getColumn(cols[i].getName(), _dict) == null) {
+            if (table.getColumn(cols[i].getIdentifier()) == null) {
                 table.importColumn(cols[i]);
             }
         }
@@ -536,30 +622,30 @@
     /**
      * Return whether the given table is allowed by the user's schema list.
      */
-    private boolean isAllowedTable(String schema, String table) {
+    private boolean isAllowedTable(DBIdentifier schema, DBIdentifier table) {
         if (_allowed == null)
             return true;
 
         // do case-insensitive comparison on allowed table and schema names
-        String[] tables;
-        String[] anySchemaTables = null;
+        DBIdentifier[] tables;
+        DBIdentifier[] anySchemaTables = null;
         for (int i = 0; i < _allowed.length; i++) {
             if (_allowed[i][0] == null) {
-                anySchemaTables = (String[]) _allowed[i][1];
+                anySchemaTables = (DBIdentifier[]) _allowed[i][1];
                 if (schema == null)
                     break;
                 continue;
             }
-            if (!StringUtils.equalsIgnoreCase(schema, (String) _allowed[i][0]))
+            if (!schema.equals((DBIdentifier) _allowed[i][0]))
                 continue;
 
             if (table == null)
                 return true;
-            tables = (String[]) _allowed[i][1];
+            tables = (DBIdentifier[]) _allowed[i][1];
             if (tables == null)
                 return true;
             for (int j = 0; j < tables.length; j++)
-                if (StringUtils.equalsIgnoreCase(table, tables[j]))
+                if (table.equals(tables[j]))
                     return true;
         }
 
@@ -567,7 +653,7 @@
             if (table == null)
                 return true;
             for (int i = 0; i < anySchemaTables.length; i++)
-                if (StringUtils.equalsIgnoreCase(table, anySchemaTables[i]))
+                if (table.equals(anySchemaTables[i]))
                     return true;
         }
         return false;
@@ -575,10 +661,18 @@
 
     /**
      * Generates table primary keys.
+     * @deprecated
      */
     public void generatePrimaryKeys(String schemaName, String tableName,
         Connection conn, DatabaseMetaData meta)
         throws SQLException {
+        generatePrimaryKeys(DBIdentifier.newSchema(schemaName), DBIdentifier.newTable(tableName),
+            conn, meta);
+    }
+
+    public void generatePrimaryKeys(DBIdentifier schemaName, DBIdentifier tableName,
+        Connection conn, DatabaseMetaData meta)
+        throws SQLException {
         fireGenerationEvent(_loc.get("generating-primary",
             schemaName, tableName));
         if (_log.isTraceEnabled())
@@ -586,55 +680,65 @@
 
         // if looking for a non-existant table, just return
         SchemaGroup group = getSchemaGroup();
-        if (tableName != null && group.findTable(tableName) == null)
+        if (tableName != null && !tableName.isNull() && 
+                group.findTable(QualifiedDBIdentifier.getPath(tableName)) == null)
             return;
 
         // if the database can't use a table name wildcard, recurse on each
         // concrete table in the requested schema(s)
-        PrimaryKey[] pks = _dict.getPrimaryKeys(meta, conn.getCatalog(),
+        PrimaryKey[] pks = _dict.getPrimaryKeys(meta, 
+            DBIdentifier.newCatalog(conn.getCatalog()),
             schemaName, tableName, conn);
         Table table;
         if (pks == null && tableName == null) {
-            Collection tables = getTables(schemaName);
-            for (Iterator itr = tables.iterator(); itr.hasNext();) {
+            Collection<Table> tables = getTables(schemaName);
+            for (Iterator<Table> itr = tables.iterator(); itr.hasNext();) {
                 table = (Table) itr.next();
-                generatePrimaryKeys(table.getSchemaName(),
-                    table.getName(), conn, meta);
+                generatePrimaryKeys(table.getSchemaIdentifier(),
+                    table.getIdentifier(), conn, meta);
             }
             return;
         }
 
         Schema schema;
         PrimaryKey pk;
-        String name;
-        String colName;
+        DBIdentifier name = DBIdentifier.NULL;
+        DBIdentifier colName = DBIdentifier.NULL;
         for (int i = 0; pks != null && i < pks.length; i++) {
-            schemaName = StringUtils.trimToNull(pks[i].getSchemaName());
+            schemaName = DBIdentifier.trimToNull(schemaName);
             schema = group.getSchema(schemaName);
             if (schema == null)
                 continue;
-            table = schema.getTable(pks[i].getTableName());
+            table = schema.getTable(pks[i].getTableIdentifier());
             if (table == null)
                 continue;
 
-            colName = pks[i].getColumnName();
-            name = pks[i].getName();
+            colName = pks[i].getColumnIdentifier();
+            name = pks[i].getIdentifier();
             if (_log.isTraceEnabled())
                 _log.trace(_loc.get("gen-pk", name, table, colName));
 
             pk = table.getPrimaryKey();
             if (pk == null)
                 pk = table.addPrimaryKey(name);
-            pk.addColumn(table.getColumn(colName, _dict));
+            pk.addColumn(table.getColumn(colName));
         }
     }
 
     /**
      * Generates table indexes.
+     * @deprecated
      */
     public void generateIndexes(String schemaName, String tableName,
         Connection conn, DatabaseMetaData meta)
         throws SQLException {
+        generateIndexes(DBIdentifier.newSchema(schemaName), DBIdentifier.newTable(tableName),
+            conn, meta);
+    }
+
+    public void generateIndexes(DBIdentifier schemaName, DBIdentifier tableName,
+        Connection conn, DatabaseMetaData meta)
+        throws SQLException {
         fireGenerationEvent(_loc.get("generating-indexes",
             schemaName, tableName));
         if (_log.isTraceEnabled())
@@ -642,52 +746,52 @@
 
         // if looking for a non-existant table, just return
         SchemaGroup group = getSchemaGroup();
-        if (tableName != null && group.findTable(tableName) == null)
+        if (tableName != null && group.findTable(QualifiedDBIdentifier.getPath(tableName)) == null)
             return;
 
         // if the database can't use a table name wildcard, recurse on each
         // concrete table in the requested schema(s)
-        Index[] idxs = _dict.getIndexInfo(meta, conn.getCatalog(),
+        Index[] idxs = _dict.getIndexInfo(meta, DBIdentifier.newCatalog(conn.getCatalog()),
             schemaName, tableName, false, true, conn);
         Table table;
         if (idxs == null && tableName == null) {
-            Collection tables = getTables(schemaName);
-            for (Iterator itr = tables.iterator(); itr.hasNext();) {
-                table = (Table) itr.next();
-                generateIndexes(table.getSchemaName(),
-                    table.getName(), conn, meta);
+            Collection<Table> tables = getTables(schemaName);
+            for (Iterator<Table> itr = tables.iterator(); itr.hasNext();) {
+                table = itr.next();
+                generateIndexes(table.getSchemaIdentifier(),
+                    table.getIdentifier(), conn, meta);
             }
             return;
         }
 
         Schema schema;
         Index idx;
-        String name;
-        String colName;
-        String pkName;
+        DBIdentifier name = DBIdentifier.NULL;
+        DBIdentifier colName = DBIdentifier.NULL;
+        DBIdentifier pkName = DBIdentifier.NULL;
         for (int i = 0; idxs != null && i < idxs.length; i++) {
-            schemaName = StringUtils.trimToNull(idxs[i].getSchemaName());
+            schemaName = DBIdentifier.trimToNull(idxs[i].getSchemaIdentifier());
             schema = group.getSchema(schemaName);
             if (schema == null)
                 continue;
-            table = schema.getTable(idxs[i].getTableName());
+            table = schema.getTable(idxs[i].getTableIdentifier());
             if (table == null)
                 continue;
 
             if (table.getPrimaryKey() != null)
-                pkName = table.getPrimaryKey().getName();
+                pkName = table.getPrimaryKey().getIdentifier();
             else
                 pkName = null;
 
             // statistics don't have names; skip them
-            name = idxs[i].getName();
-            if (StringUtils.isEmpty(name)
-                || (pkName != null && name.equalsIgnoreCase(pkName))
+            name = idxs[i].getIdentifier();
+            if (DBIdentifier.isEmpty(name)
+                || (pkName != null && name.equals(pkName))
                 || _dict.isSystemIndex(name, table))
                 continue;
 
-            colName = idxs[i].getColumnName();
-            if (table.getColumn(colName, _dict) == null)
+            colName = idxs[i].getColumnIdentifier();
+            if (table.getColumn(colName) == null)
                 continue;
 
             if (_log.isTraceEnabled())
@@ -699,7 +803,7 @@
                 idx = table.addIndex(name);
                 idx.setUnique(idxs[i].isUnique());
             }
-            idx.addColumn(table.getColumn(colName, _dict));
+            idx.addColumn(table.getColumn(colName));
         }
     }
 
@@ -709,6 +813,13 @@
     public void generateForeignKeys(String schemaName, String tableName,
         Connection conn, DatabaseMetaData meta)
         throws SQLException {
+        generateForeignKeys(DBIdentifier.newSchema(schemaName), DBIdentifier.newTable(tableName),
+            conn, meta);
+    }
+
+    public void generateForeignKeys(DBIdentifier schemaName, DBIdentifier tableName,
+        Connection conn, DatabaseMetaData meta)
+        throws SQLException {
         fireGenerationEvent(_loc.get("generating-foreign",
             schemaName, tableName));
         if (_log.isTraceEnabled())
@@ -716,20 +827,20 @@
 
         // if looking for a non-existant table, just return
         SchemaGroup group = getSchemaGroup();
-        if (tableName != null && group.findTable(tableName) == null)
+        if (!DBIdentifier.isNull(tableName) && group.findTable(QualifiedDBIdentifier.getPath(tableName)) == null)
             return;
 
         // if the database can't use a table name wildcard, recurse on each
         // concrete table in the requested schema(s)
-        ForeignKey[] fks = _dict.getImportedKeys(meta, conn.getCatalog(),
+        ForeignKey[] fks = _dict.getImportedKeys(meta, DBIdentifier.newCatalog(conn.getCatalog()),
             schemaName, tableName, conn);
         Table table;
-        if (fks == null && tableName == null) {
-            Collection tables = getTables(schemaName);
-            for (Iterator itr = tables.iterator(); itr.hasNext();) {
-                table = (Table) itr.next();
-                generateForeignKeys(table.getSchemaName(),
-                    table.getName(), conn, meta);
+        if (fks == null && DBIdentifier.isNull(tableName)) {
+            Collection<Table> tables = getTables(schemaName);
+            for (Iterator<Table> itr = tables.iterator(); itr.hasNext();) {
+                table = itr.next();
+                generateForeignKeys(table.getSchemaIdentifier(),
+                    table.getIdentifier(), conn, meta);
             }
             return;
         }
@@ -737,26 +848,26 @@
         Schema schema;
         Table pkTable;
         ForeignKey fk;
-        String name;
-        String pkSchemaName;
-        String pkTableName;
-        String pkColName;
-        String fkColName;
+        DBIdentifier name = DBIdentifier.NULL;
+        DBIdentifier pkSchemaName = DBIdentifier.NULL;
+        DBIdentifier pkTableName = DBIdentifier.NULL;
+        DBIdentifier pkColName = DBIdentifier.NULL;
+        DBIdentifier fkColName = DBIdentifier.NULL;
         int seq;
         boolean seqWas0 = false; // some drivers incorrectly start at 0
-        Collection invalids = null;
+        Collection<ForeignKey> invalids = null;
         for (int i = 0; fks != null && i < fks.length; i++) {
-            schemaName = StringUtils.trimToNull(fks[i].getSchemaName());
+            schemaName = DBIdentifier.trimToNull(fks[i].getSchemaIdentifier());
             schema = group.getSchema(schemaName);
             if (schema == null)
                 continue;
-            table = schema.getTable(fks[i].getTableName());
+            table = schema.getTable(fks[i].getTableIdentifier());
             if (table == null)
                 continue;
 
-            name = fks[i].getName();
-            fkColName = fks[i].getColumnName();
-            pkColName = fks[i].getPrimaryKeyColumnName();
+            name = fks[i].getIdentifier();
+            fkColName = fks[i].getColumnIdentifier();
+            pkColName = fks[i].getPrimaryKeyColumnIdentifier();
             seq = fks[i].getKeySequence();
             if (seq == 0)
                 seqWas0 = true;
@@ -764,18 +875,16 @@
                 seq++;
 
             // find pk table
-            pkSchemaName = fks[i].getPrimaryKeySchemaName();
+            pkSchemaName = fks[i].getPrimaryKeySchemaIdentifier();
             if(_dict.getTrimSchemaName()) {
-                pkSchemaName= StringUtils.trimToNull(pkSchemaName);
+                pkSchemaName= DBIdentifier.trimToNull(pkSchemaName);
             }
-            pkTableName = fks[i].getPrimaryKeyTableName();
+            pkTableName = fks[i].getPrimaryKeyTableIdentifier();
             if (_log.isTraceEnabled())
                 _log.trace(_loc.get("gen-fk", new Object[]{ name, table,
                     fkColName, pkTableName, pkColName, seq + "" }));
 
-            if (!StringUtils.isEmpty(pkSchemaName))
-                pkTableName = pkSchemaName + "." + pkTableName;
-            pkTable = group.findTable(pkTableName);
+            pkTable = group.findTable(QualifiedDBIdentifier.newPath(pkSchemaName, pkTableName));
             if (pkTable == null)
                 throw new SQLException(_loc.get("gen-nofktable",
                     table, pkTableName).getMessage());
@@ -799,18 +908,18 @@
 
             if (invalids == null || !invalids.contains(fk)) {
                 try {
-                    Column fkCol = table.getColumn(fkColName, _dict);
+                    Column fkCol = table.getColumn(fkColName);
                     if (fkCol == null) {
                         throw new IllegalArgumentException(_loc.get(
-                            "no-column", fkColName, table.getName())
+                            "no-column", fkColName, table.getIdentifier())
                             .getMessage());
                     }
-                    fk.join(fkCol, pkTable.getColumn(pkColName, _dict));
+                    fk.join(fkCol, pkTable.getColumn(pkColName));
                 } catch (IllegalArgumentException iae) {
                     if (_log.isWarnEnabled())
                         _log.warn(_loc.get("bad-join", iae.toString()));
                     if (invalids == null)
-                        invalids = new HashSet();
+                        invalids = new HashSet<ForeignKey>();
                     invalids.add(fk);
                 }
             }
@@ -818,8 +927,8 @@
 
         // remove invalid fks
         if (invalids != null) {
-            for (Iterator itr = invalids.iterator(); itr.hasNext();) {
-                fk = (ForeignKey) itr.next();
+            for (Iterator<ForeignKey> itr = invalids.iterator(); itr.hasNext();) {
+                fk = itr.next();
                 fk.getTable().removeForeignKey(fk);
             }
         }
@@ -827,30 +936,39 @@
 
     /**
      * Adds all sequences matching the given name pattern to the schema.
+     * @deprecated
      */
     public void generateSequences(String schemaName, String sequenceName,
         Connection conn, DatabaseMetaData meta)
         throws SQLException {
+        generateSequences(DBIdentifier.newSchema(schemaName), 
+            DBIdentifier.newSequence(sequenceName), conn, meta);
+    }
+    
+    public void generateSequences(DBIdentifier schemaName, DBIdentifier sequenceName,
+        Connection conn, DatabaseMetaData meta)
+        throws SQLException {
         fireGenerationEvent(_loc.get("generating-sequences", schemaName));
         if (_log.isTraceEnabled())
             _log.trace(_loc.get("gen-seqs", schemaName, sequenceName));
 
         // since all the sequences are generated under the default schema
         // therefore, we can use the null schemaname to search
-        Sequence[] seqs = _dict.getSequences(meta, conn.getCatalog(),
-            null, sequenceName, conn);
+        Sequence[] seqs = _dict.getSequences(meta, DBIdentifier.newCatalog(conn.getCatalog()),
+            DBIdentifier.NULL, sequenceName, conn);
 
         SchemaGroup group = getSchemaGroup();
         Schema schema;
-        String sequenceSchema;
+        DBIdentifier sequenceSchema = DBIdentifier.NULL;
         for (int i = 0; seqs != null && i < seqs.length; i++) {
-            sequenceName = seqs[i].getName();
-            sequenceSchema = StringUtils.trimToNull(seqs[i].getSchemaName());
+            sequenceName = seqs[i].getIdentifier();
+            sequenceSchema = DBIdentifier.trimToNull(seqs[i].getSchemaIdentifier());
 
             // ignore special tables
+            String seqUpper = DBIdentifier.toUpper(sequenceName).getName();
             if (!_openjpaTables &&
-                (sequenceName.toUpperCase().startsWith("OPENJPA_")
-                    || sequenceName.toUpperCase().startsWith("JDO_"))) // legacy
+                (seqUpper.startsWith("OPENJPA_")
+                    || seqUpper.startsWith("JDO_"))) // legacy
                 continue;
             if (_dict.isSystemSequence(sequenceName, sequenceSchema,
                 schemaName != null))
@@ -860,26 +978,11 @@
 
             schema = group.getSchema(sequenceSchema);
             if (schema == null) {
-                // TODO: temp until a more global name solution is implemented
-                schema = group.getSchema(_dict.addDelimiters(sequenceSchema));
-//                schema = group.getSchema(_dict.delimitString(sequenceSchema, 
-//                    DBDictionary.DBIdentifiers.SEQUENCE_GEN_SCHEMA));
-            }
-            if (schema == null) {
                 schema = group.addSchema(sequenceSchema);
-                // TODO: temp until a more global solution is implemented
-//                group.addDelimSchemaName(_dict.delimitString(sequenceSchema, 
-//                    DBDictionary.DBIdentifiers.SEQUENCE_GEN_SCHEMA), schema);
-                group.addDelimSchemaName(_dict.addDelimiters(sequenceSchema), schema);
             }
             if (schema.getSequence(sequenceName) == null) {
-                Sequence seq = schema.addSequence(sequenceName);
-                // TODO: temp until a more global solution is implemented
-//                schema.addDelimSequenceName(_dict.delimitString(sequenceName, 
-//                    DBDictionary.DBIdentifiers.SEQUENCE_GEN_SEQ_NAME), seq);
-                schema.addDelimSequenceName(_dict.addDelimiters(sequenceName), seq);
+                schema.addSequence(sequenceName);
             }
-                
         }
     }
 
@@ -895,8 +998,8 @@
             return;
 
         Event e = new Event(schemaObject, _schemaObjects);
-        for (Iterator i = _listeners.iterator(); i.hasNext();) {
-            Listener l = (Listener) i.next();
+        for (Iterator<Listener> i = _listeners.iterator(); i.hasNext();) {
+            Listener l = i.next();
             if (!l.schemaObjectGenerated(e))
                 throw new SQLException(_loc.get("refresh-cancelled")
                     .getMessage());
@@ -910,7 +1013,7 @@
      */
     public void addListener(Listener l) {
         if (_listeners == null)
-            _listeners = new LinkedList();
+            _listeners = new LinkedList<Listener>();
         _listeners.add(l);
     }
 
@@ -928,17 +1031,17 @@
      * Return all tables for the given schema name, or all tables in
      * the schema group if null is given.
      */
-    private Collection getTables(String schemaName) {
+    private Collection<Table> getTables(DBIdentifier schemaName) {
         SchemaGroup group = getSchemaGroup();
-        if (schemaName != null) {
+        if (!DBIdentifier.isNull(schemaName)) {
             Schema schema = group.getSchema(schemaName);
             if (schema == null)
-                return Collections.EMPTY_LIST;
+                return Collections.emptyList();
             return Arrays.asList(schema.getTables());
         }
 
         Schema[] schemas = group.getSchemas();
-        Collection tables = new LinkedList();
+        Collection<Table> tables = new LinkedList<Table>();
         for (int i = 0; i < schemas.length; i++)
             tables.addAll(Arrays.asList(schemas[i].getTables()));
         return tables;
@@ -955,6 +1058,7 @@
     /**
      * An event corresponding to the generation of a schema object.
      */
+    @SuppressWarnings("serial")
     public class Event
         extends EventObject {
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGroup.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGroup.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGroup.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGroup.java Fri Jan 15 19:38:18 2010
@@ -23,17 +23,20 @@
 import java.util.LinkedList;
 import java.util.Map;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier;
+
 /**
  * Represents a grouping of schemas used in a database.
  *
  * @author Abe White
  */
+@SuppressWarnings("serial")
 public class SchemaGroup
     extends NameSet
     implements Cloneable {
 
-    private Map _schemaMap = null;
-    private Map<String, Schema> _delimSchemaMap = null;
+    private Map<DBIdentifier, Schema> _schemaMap = null;
 
     // cache
     private Schema[] _schemas = null;
@@ -50,55 +53,53 @@
 
     /**
      * Return the schema with the given name, or null if none.
+     * @deprecated
      */
     public Schema getSchema(String name) {
         if (_schemaMap == null)
             return null;
-        if (name != null)
-            name = name.toUpperCase();
-        // TODO: temp until a more global solution is implemented
-        Schema schema = (Schema) _schemaMap.get(name);
-        if (schema == null && _delimSchemaMap != null) {
-            schema = _delimSchemaMap.get(name);
-        }
+        return getSchema(DBIdentifier.toUpper(DBIdentifier.newSchema(name)));
+    }
+
+    public Schema getSchema(DBIdentifier name) {
+        if (_schemaMap == null)
+            return null;
+        DBIdentifier sName = DBIdentifier.toUpper(name);
+        Schema schema = (Schema) _schemaMap.get(sName);
         return schema;
-//        return (Schema) _schemaMap.get(name);
     }
 
     /**
      * Add a schema to the group.
      */
     public Schema addSchema() {
-        return addSchema(null);
+        return addSchema(DBIdentifier.NULL);
     }
 
     /**
      * Add a schema to the group.
      */
-    public Schema addSchema(String name) {
+    public Schema addSchema(DBIdentifier name) {
         addName(name, false);
         Schema schema = newSchema(name);
-        if (name != null)
-            name = name.toUpperCase();
+        DBIdentifier sName = DBIdentifier.toUpper(name);
         if (_schemaMap == null)
-            _schemaMap = new HashMap();
-        _schemaMap.put(name, schema);
+            _schemaMap = new HashMap<DBIdentifier, Schema>();
+        _schemaMap.put(sName, schema);
         _schemas = null;
         return schema;
     }
-    
-    // TODO: temp until a more global solution is implemented
-    public void addDelimSchemaName(String name, Schema schema) {
-        addName(name,false);
-        if (name != null)
-            name = name.toUpperCase();
-        if (_delimSchemaMap == null) {
-            _delimSchemaMap = new HashMap<String, Schema>();
-        }
-        _delimSchemaMap.put(name, schema);
-    }
 
     /**
+     * @deprecated
+     * @param name
+     * @return
+     */
+    public Schema addSchema(String name) {
+        return addSchema(DBIdentifier.newSchema(name));
+    }
+    
+    /**
      * Remove the given schema from the group.
      *
      * @return true if the schema was removed, false if not in the group
@@ -107,13 +108,11 @@
         if (schema == null)
             return false;
 
-        String name = schema.getName();
-        if (name != null)
-            name = name.toUpperCase();
+        DBIdentifier name = DBIdentifier.toUpper(schema.getIdentifier());
         Schema rem = (Schema) _schemaMap.get(name);
         if (schema.equals(rem)) {
             _schemaMap.remove(name);
-            removeName(schema.getName());
+            removeName(schema.getIdentifier());
             _schemas = null;
             schema.remove();
             return true;
@@ -128,7 +127,7 @@
         if (schema == null)
             return null;
 
-        Schema copy = addSchema(schema.getName());
+        Schema copy = addSchema(schema.getIdentifier());
         Sequence[] seqs = schema.getSequences();
         for (int i = 0; i < seqs.length; i++)
             copy.importSequence(seqs[i]);
@@ -164,39 +163,50 @@
      * {@link #findTable} may exhibit dynamic behavior in some schema group
      * implementations, this method only returns true if the table has been
      * added to this group or is known to exist in the database.
+     * @deprecated
      */
     public boolean isKnownTable(String name) {
         return findTable(name) != null;
     }
 
+      public boolean isKnownTable(QualifiedDBIdentifier path) {
+          return findTable(path) != null;
+      }
+    
     /**
      * Find the equivalent of the given table in this schema group. The
      * given table that may have come from another schema group.
      */
     public Table findTable(Table table) {
-        return findTable(table.getFullName());
+        return findTable(table.getQualifiedPath());
     }
 
     /**
      * Find the table with the given name in the group, using '.' as the
      * catalog separator. Returns null if no table found.
+     * @deprecated
      */
     public Table findTable(String name) {
         if (name == null)
             return null;
 
-        int dotIdx = name.indexOf('.');
-        if (dotIdx != -1) {
-            String schemaName = name.substring(0, dotIdx);
-            name = name.substring(dotIdx + 1);
-            Schema schema = getSchema(schemaName);
+        return findTable(QualifiedDBIdentifier.getPath(DBIdentifier.newTable(name)));
+    }
+
+    public Table findTable(QualifiedDBIdentifier path) {
+        if (DBIdentifier.isNull(path)) {
+            return null;
+        }
+        if (!DBIdentifier.isNull(path.getSchemaName())) {
+            Schema schema = getSchema(path.getSchemaName());
             if (schema != null)
-                return schema.getTable(name);
+                return schema.getTable(path.getUnqualifiedName());
+            
         } else {
             Schema[] schemas = getSchemas();
             Table tab;
             for (int i = 0; i < schemas.length; i++) {
-                tab = schemas[i].getTable(name);
+                tab = schemas[i].getTable(path.getIdentifier());
                 if (tab != null)
                     return tab;
             }
@@ -207,30 +217,38 @@
     /**
      * Find the table with the given name in the group, using '.' as the catalog
      * separator. Returns null if no table found.
+     * @deprecated
      */
     public Table findTable(Schema inSchema, String name) {
-        return findTable(inSchema, name, null);
+        if (name == null)
+            return null;
+        return findTable(inSchema, DBIdentifier.newTable(name), DBIdentifier.NULL);
+    }
+
+    public Table findTable(Schema inSchema, DBIdentifier name) {
+        if (DBIdentifier.isNull(name))
+            return null;
+        return findTable(inSchema, QualifiedDBIdentifier.getPath(name), DBIdentifier.NULL);
+    }
+
+    public Table findTable(Schema inSchema, DBIdentifier name, DBIdentifier defaultSchemaName) {
+        if (DBIdentifier.isNull(name))
+            return null;
+        return findTable(inSchema, QualifiedDBIdentifier.getPath(name), defaultSchemaName);
     }
     
-    /**
-     * Find the table with the given name in the group, using '.' as the catalog
-     * separator. Returns null if no table found.
-     */
-    public Table findTable(Schema inSchema, String name, String defaultSchemaName) {
-        if (name == null)
+    public Table findTable(Schema inSchema, QualifiedDBIdentifier path, DBIdentifier defaultSchemaName) {
+        if (path == null)
             return null;
 
-        int dotIdx = name.indexOf('.');
-        if (dotIdx != -1) {
-            String schemaName = name.substring(0, dotIdx);
-            name = name.substring(dotIdx + 1);
-            Schema schema = getSchema(schemaName);
+        if (!DBIdentifier.isNull(path.getSchemaName())) {
+            Schema schema = getSchema(path.getSchemaName());
             if (schema != null)
-                return schema.getTable(name);
+                return schema.getTable(path.getIdentifier());
         } else {
             Schema[] schemas = getSchemas();
             for (int i = 0; i < schemas.length; i++) {
-                Table tab = schemas[i].getTable(name);
+                Table tab = schemas[i].getTable(path.getIdentifier());
                 // if a table is found and it has the same schema
                 // as the input schema , it means that the table
                 // exists. However, if the input schema is null,
@@ -239,11 +257,11 @@
                 // We can't handle the case that one entity has schema name
                 // and other entity does not have schema name but both entities
                 // map to the same table.
-                boolean isDefaultSchema = inSchema.getName() == null && 
-                    defaultSchemaName != null && 
-                    defaultSchemaName.equalsIgnoreCase(schemas[i].getName());
-                boolean hasNoDefaultSchema = inSchema.getName() == null && 
-                    defaultSchemaName == null; 
+                boolean isDefaultSchema = DBIdentifier.isNull(inSchema.getIdentifier()) && 
+                    !DBIdentifier.isNull(defaultSchemaName) && 
+                    DBIdentifier.equalsIgnoreCase(defaultSchemaName, schemas[i].getIdentifier());
+                boolean hasNoDefaultSchema = DBIdentifier.isNull(inSchema.getIdentifier()) && 
+                    DBIdentifier.isNull(defaultSchemaName); 
                 
                 if (tab != null &&
                     (schemas[i] == inSchema || isDefaultSchema || hasNoDefaultSchema)) 
@@ -269,39 +287,58 @@
      * {@link #findSequence} may exhibit dynamic behavior in some schema group
      * implementations, this method only returns true if the sequence has been
      * added to this group or is known to exist in the database.
+     * @deprecated
      */
     public boolean isKnownSequence(String name) {
         return findSequence(name) != null;
     }
 
+    public boolean isKnownSequence(DBIdentifier name) {
+        return findSequence(QualifiedDBIdentifier.getPath(name)) != null;
+    }
+
+    public boolean isKnownSequence(QualifiedDBIdentifier path) {
+        return findSequence(path) != null;
+    }
+
     /**
      * Find the equivalent of the given sequence in this schema group. The
      * given sequence that may have come from another schema group.
      */
     public Sequence findSequence(Sequence seq) {
-        return findSequence(seq.getFullName());
+        return findSequence(QualifiedDBIdentifier.getPath(seq.getIdentifier()));
     }
 
     /**
      * Find the sequence with the given name in the group, using '.' as the
      * catalog separator. Returns null if no sequence found.
+     * @deprecated
      */
     public Sequence findSequence(String name) {
         if (name == null)
             return null;
+        return findSequence(DBIdentifier.newSequence(name));
+    }
 
-        int dotIdx = name.indexOf('.');
-        if (dotIdx != -1) {
-            String schemaName = name.substring(0, dotIdx);
-            name = name.substring(dotIdx + 1);
-            Schema schema = getSchema(schemaName);
+    public Sequence findSequence(DBIdentifier name) {
+        if (DBIdentifier.isNull(name))
+            return null;
+        return findSequence(QualifiedDBIdentifier.getPath(name));
+    }
+
+    public Sequence findSequence(QualifiedDBIdentifier path) {
+        if (path == null)
+            return null;
+
+        if (!DBIdentifier.isNull(path.getSchemaName())) {
+            Schema schema = getSchema(path.getSchemaName());
             if (schema != null)
-                return schema.getSequence(name);
+                return schema.getSequence(path.getIdentifier());
         } else {
             Schema[] schemas = getSchemas();
             Sequence seq;
             for (int i = 0; i < schemas.length; i++) {
-                seq = schemas[i].getSequence(name);
+                seq = schemas[i].getSequence(path.getIdentifier());
                 if (seq != null)
                     return seq;
             }
@@ -312,28 +349,32 @@
     /**
      * Find the sequence with the given name in the group, using '.' as the
      * catalog separator. Returns null if no sequence found.
+     * @deprecated
      */
     public Sequence findSequence(Schema inSchema, String name) {
         if (name == null)
             return null;
+        return findSequence(inSchema, QualifiedDBIdentifier.getPath(DBIdentifier.newSequence(name)));
+    }
+
+    
+    public Sequence findSequence(Schema inSchema, QualifiedDBIdentifier path) {
+        if (path == null)
+            return null;
 
-        int dotIdx = name.indexOf('.');
-        if (dotIdx != -1) {
-            String schemaName = name.substring(0, dotIdx);
-            name = name.substring(dotIdx + 1);
-            Schema schema = getSchema(schemaName);
+        if (!DBIdentifier.isNull(path.getSchemaName())) {
+            Schema schema = getSchema(path.getSchemaName());
             if (schema != null)
-                return schema.getSequence(name);
+                return schema.getSequence(path.getIdentifier());
         } else {
             Schema[] schemas = getSchemas();
             Sequence seq;
             for (int i = 0; i < schemas.length; i++) {
-                seq = schemas[i].getSequence(name);
+                seq = schemas[i].getSequence(path.getIdentifier());
                 if ((seq != null) &&
-                        (schemas[i] == inSchema || inSchema.getName() == null))
+                        (schemas[i] == inSchema || DBIdentifier.isNull(inSchema.getIdentifier())))
                     return seq;
             }
-
         }
         return null;
     }
@@ -349,7 +390,7 @@
         Schema[] schemas = getSchemas();
         Table[] tabs;
         ForeignKey[] fks;
-        Collection exports = new LinkedList();
+        Collection<ForeignKey> exports = new LinkedList<ForeignKey>();
         for (int i = 0; i < schemas.length; i++) {
             tabs = schemas[i].getTables();
             for (int j = 0; j < tabs.length; j++) {
@@ -436,65 +477,106 @@
             for (int j = 0; j < tabs.length; j++) {
                 fks = tabs[j].getForeignKeys();
                 for (int k = 0; k < fks.length; k++)
-                    getSchema(schemas[i].getName()).getTable
-                        (tabs[j].getName()).importForeignKey(fks[k]);
+                    getSchema(schemas[i].getIdentifier()).getTable
+                        (tabs[j].getIdentifier()).importForeignKey(fks[k]);
             }
         }
     }
 
     /**
      * Return a new schema with the given name.
+     * @deprecated
      */
     protected Schema newSchema(String name) {
         return new Schema(name, this);
     }
 
+    protected Schema newSchema(DBIdentifier name) {
+        return new Schema(name, this);
+    }
+
     /**
      * Return a new sequence with the given name and owner schema.
+     * @deprecated
      */
     protected Sequence newSequence(String name, Schema schema) {
         return new Sequence(name, schema);
     }
 
+    protected Sequence newSequence(DBIdentifier name, Schema schema) {
+        return new Sequence(name, schema);
+    }
+
     /**
      * Return a new table with the given name and owner schema.
+     * @deprecated
      */
     protected Table newTable(String name, Schema schema) {
         return new Table(name, schema);
     }
 
+    protected Table newTable(DBIdentifier name, Schema schema) {
+        return new Table(name, schema);
+    }
+
     /**
      * Return a new column with the given name and owner table.
+     * @deprecated
      */
     protected Column newColumn(String name, Table table) {
         return new Column(name, table);
     }
 
+    protected Column newColumn(DBIdentifier name, Table table) {
+        return new Column(name, table);
+    }
+
     /**
      * Return a new primary key with the given name and owner table.
+     * @deprecated
      */
     protected PrimaryKey newPrimaryKey(String name, Table table) {
         return new PrimaryKey(name, table);
     }
 
+    protected PrimaryKey newPrimaryKey(DBIdentifier name, Table table) {
+        return new PrimaryKey(name, table);
+    }
+
     /**
      * Return a new index with the given name and owner table.
+     * @deprecated
      */
     protected Index newIndex(String name, Table table) {
         return new Index(name, table);
     }
 
+    protected Index newIndex(DBIdentifier name, Table table) {
+        return new Index(name, table);
+    }
+
     /**
      * Return a new unique constraint with the given name and owner table.
+     * @deprecated
      */
     protected Unique newUnique(String name, Table table) {
         return new Unique(name, table);
     }
 
+    protected Unique newUnique(DBIdentifier name, Table table) {
+        return new Unique(name, table);
+    }
+
     /**
      * Return a new foreign key with the given name and owner table.
+     * @deprecated
      */
     protected ForeignKey newForeignKey(String name, Table table) {
         return new ForeignKey(name, table);
     }
+
+    protected ForeignKey newForeignKey(DBIdentifier name, Table table) {
+        return new ForeignKey(name, table);
+    }
+
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java Fri Jan 15 19:38:18 2010
@@ -39,10 +39,13 @@
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.jdbc.sql.SQLExceptions;
 import org.apache.openjpa.lib.conf.Configurations;
+import org.apache.openjpa.lib.identifier.IdentifierUtil;
 import org.apache.openjpa.lib.log.Log;
+import org.apache.openjpa.lib.meta.MetaDataSerializer;
 import org.apache.openjpa.lib.util.Files;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Options;
@@ -416,7 +419,7 @@
         throws SQLException {
         SchemaGroup group = getSchemaGroup();
         Schema[] schemas = group.getSchemas();
-        Collection tables = new LinkedHashSet();
+        Collection<Table> tables = new LinkedHashSet<Table>();
         for (int i = 0; i < schemas.length; i++) {
             Table[] ts = schemas[i].getTables();
             for (int j = 0; j < ts.length; j++)
@@ -451,14 +454,14 @@
             for (int i = 0; i < schemas.length; i++) {
                 seqs = schemas[i].getSequences();
                 for (int j = 0; j < seqs.length; j++) {
-                    if (db.findSequence(schemas[i], seqs[j].getFullName()) !=
+                    if (db.findSequence(schemas[i], seqs[j].getQualifiedPath()) !=
                             null)
                         continue;
 
                     if (createSequence(seqs[j])) {
-                        schema = db.getSchema(seqs[j].getSchemaName());
+                        schema = db.getSchema(seqs[j].getSchemaIdentifier());
                         if (schema == null)
-                            schema = db.addSchema(seqs[j].getSchemaName());
+                            schema = db.addSchema(seqs[j].getSchemaIdentifier());
                         schema.importSequence(seqs[j]);
                     } else
                         _log.warn(_loc.get("add-seq", seqs[j]));
@@ -471,31 +474,23 @@
         Table dbTable;
         Column[] cols;
         Column col;
-        String delim = _dict.getDelimiter();
-        String defaultSchemaName = _dict.getDefaultSchemaName();
+        DBIdentifier defaultSchemaName = DBIdentifier.newSchema(_dict.getDefaultSchemaName());
         for (int i = 0; i < schemas.length; i++) {
             tabs = schemas[i].getTables();
             for (int j = 0; j < tabs.length; j++) {
                 cols = tabs[j].getColumns();
-                dbTable = db.findTable(schemas[i], tabs[j].getFullName(), defaultSchemaName);
+                dbTable = db.findTable(schemas[i], tabs[j].getQualifiedPath(), defaultSchemaName);
                 for (int k = 0; k < cols.length; k++) {
                     if (dbTable != null) {
-                        String colName = cols[k].getName();
-                        boolean delimCol = false;
-                        if (colName.startsWith(delim) 
-                                && colName.endsWith(delim)) {
-                            colName = colName.substring(1, colName.length()-1);
-                            delimCol = true;
-                        }
-                        col = dbTable.getColumn(colName, _dict);
+                        DBIdentifier colName = cols[k].getIdentifier();
+                        col = dbTable.getColumn(colName);
                         if (col == null) {
                             if (addColumn(cols[k]))
                                 dbTable.importColumn(cols[k]);
                             else
                                 _log.warn(_loc.get("add-col", cols[k],
                                     tabs[j]));
-                        // TODO: Find a way to compare these with delimCol
-                        } else if (!delimCol && !cols[k].equalsColumn(col)) {
+                        } else if (!cols[k].equalsColumn(col)) {
                             _log.warn(_loc.get("bad-col", new Object[]{
                                 col, dbTable, col.getDescription(),
                                 cols[k].getDescription() }));
@@ -512,7 +507,7 @@
                 tabs = schemas[i].getTables();
                 for (int j = 0; j < tabs.length; j++) {
                     pk = tabs[j].getPrimaryKey();
-                    dbTable = db.findTable(schemas[i], tabs[j].getFullName());
+                    dbTable = db.findTable(schemas[i], tabs[j].getQualifiedPath());
                     if (pk != null && !pk.isLogical() && dbTable != null) {
                         if (dbTable.getPrimaryKey() == null
                             && addPrimaryKey(pk))
@@ -528,18 +523,18 @@
         }
 
         // tables
-        Set newTables = new HashSet();
+        Set<Table> newTables = new HashSet<Table>();
         for (int i = 0; i < schemas.length; i++) {
             tabs = schemas[i].getTables();
             for (int j = 0; j < tabs.length; j++) {
-                if (db.findTable(schemas[i], tabs[j].getFullName()) != null)
+                if (db.findTable(schemas[i], tabs[j].getQualifiedPath()) != null)
                     continue;
 
                 if (createTable(tabs[j])) {
                     newTables.add(tabs[j]);
-                    schema = db.getSchema(tabs[j].getSchemaName());
+                    schema = db.getSchema(tabs[j].getSchemaIdentifier());
                     if (schema == null)
-                        schema = db.addSchema(tabs[j].getSchemaName());
+                        schema = db.addSchema(tabs[j].getSchemaIdentifier());
                     schema.importTable(tabs[j]);
                 } else
                     _log.warn(_loc.get("add-table", tabs[j]));
@@ -558,7 +553,7 @@
                     continue;
 
                 idxs = tabs[j].getIndexes();
-                dbTable = db.findTable(schemas[i], tabs[j].getFullName());
+                dbTable = db.findTable(schemas[i], tabs[j].getQualifiedPath());
                 for (int k = 0; k < idxs.length; k++) {
                     if (dbTable != null) {
                         idx = findIndex(dbTable, idxs[k]);
@@ -608,7 +603,7 @@
                     continue;
 
                 fks = tabs[j].getForeignKeys();
-                dbTable = db.findTable(schemas[i],tabs[j].getFullName());
+                dbTable = db.findTable(schemas[i],tabs[j].getQualifiedPath());
                 for (int k = 0; k < fks.length; k++) {
                     if (!fks[k].isLogical() && dbTable != null) {
                         fk = findForeignKey(dbTable, fks[k]);
@@ -715,7 +710,7 @@
         // columns
         Column[] cols;
         Column col;
-        Collection drops = new LinkedList();
+        Collection<Table> drops = new LinkedList<Table>();
         for (int i = 0; i < schemas.length; i++) {
             tabs = schemas[i].getTables();
             for (int j = 0; j < tabs.length; j++) {
@@ -725,7 +720,7 @@
                 reposTable = repos.findTable(tabs[j]);
                 if (reposTable != null) {
                     for (int k = 0; k < cols.length; k++) {
-                        col = reposTable.getColumn(cols[k].getName(), _dict);
+                        col = reposTable.getColumn(cols[k].getIdentifier());
                         if (col == null || !cols[k].equalsColumn(col)) {
                             if (tabs[j].getColumns().length == 1)
                                 drops.add(tabs[j]);
@@ -782,7 +777,7 @@
         // calculate tables to drop; we can only drop tables if we're sure
         // the user listed the entire table definition in the stuff they want
         // dropped; else they might just want to drop a few columns
-        Collection drops = new LinkedList();
+        Collection<Table> drops = new LinkedList<Table>();
         Table[] tabs;
         Table dbTable;
         Column[] dbCols;
@@ -798,7 +793,7 @@
 
                 dbCols = dbTable.getColumns();
                 for (int k = 0; k < dbCols.length; k++)
-                    if (tabs[j].getColumn(dbCols[k].getName(), _dict) == null)
+                    if (tabs[j].getColumn(dbCols[k].getIdentifier()) == null)
                         continue tables;
 
                 drops.add(tabs[j]);
@@ -838,8 +833,8 @@
 
             // also drop imported foreign keys for tables that will be dropped
             Table tab;
-            for (Iterator itr = drops.iterator(); itr.hasNext();) {
-                tab = (Table) itr.next();
+            for (Iterator<Table> itr = drops.iterator(); itr.hasNext();) {
+                tab = itr.next();
                 dbTable = db.findTable(tab);
                 if (dbTable == null)
                     continue;
@@ -870,7 +865,7 @@
                 for (int k = 0; k < cols.length; k++) {
                     col = null;
                     if (dbTable != null)
-                        col = dbTable.getColumn(cols[k].getName(), _dict);
+                        col = dbTable.getColumn(cols[k].getIdentifier());
                     if (dbTable == null || col == null)
                         continue;
 
@@ -890,8 +885,8 @@
      */
     private boolean isDroppable(Table table) {
         return _openjpaTables
-            || (!table.getName().toUpperCase().startsWith("OPENJPA_")
-            && !table.getName().toUpperCase().startsWith("JDO_")); // legacy
+            || (!DBIdentifier.toUpper(table.getIdentifier()).getName().startsWith("OPENJPA_")
+            && !DBIdentifier.toUpper(table.getIdentifier()).getName().startsWith("JDO_")); // legacy
     }
 
     /**
@@ -899,8 +894,8 @@
      */
     private boolean isDroppable(Sequence seq) {
         return _openjpaTables
-            || (!seq.getName().toUpperCase().startsWith("OPENJPA_")
-            && !seq.getName().toUpperCase().startsWith("JDO_")); // legacy
+            || (!DBIdentifier.toUpper(seq.getIdentifier()).getName().startsWith("OPENJPA_")
+            && !DBIdentifier.toUpper(seq.getIdentifier()).getName().startsWith("JDO_")); // legacy
     }
 
     /**
@@ -933,15 +928,15 @@
      * Remove the given collection of tables from the database schema. Orders
      * the removals according to foreign key constraints on the tables.
      */
-    private void dropTables(Collection tables, SchemaGroup change)
+    private void dropTables(Collection<Table> tables, SchemaGroup change)
         throws SQLException {
         if (tables.isEmpty())
             return;
 
         Table table;
         Table changeTable;
-        for (Iterator itr = tables.iterator(); itr.hasNext();) {
-            table = (Table) itr.next();
+        for (Iterator<Table> itr = tables.iterator(); itr.hasNext();) {
+            table = itr.next();
             if (dropTable(table)) {
                 changeTable = change.findTable(table);
                 if (changeTable != null)
@@ -1128,22 +1123,24 @@
                 // group; some may not exist yet, which is OK; we just need
                 // to make sure we can detect the changes to the ones that
                 // do exist
-                Collection tables = new LinkedList();
+                Collection<DBIdentifier> tables = new LinkedList<DBIdentifier>();
                 SchemaGroup group = assertSchemaGroup();
                 Schema[] schemas = group.getSchemas();
                 Table[] tabs;
                 for (int i = 0; i < schemas.length; i++) {
                     tabs = schemas[i].getTables();
                     for (int j = 0; j < tabs.length; j++) {
-                        if (tabs[j].getSchemaName() == null)
-                            tables.add("." + tabs[j].getName());
-                        else
-                            tables.add(tabs[j].getFullName());
+                        if (DBIdentifier.isNull(tabs[j].getSchemaIdentifier())) {
+                            tables.add(tabs[j].getIdentifier());
+                        } else {
+                            DBIdentifier sName = tabs[j].getFullIdentifier();
+                            tables.add(sName);
+                        }
                     }
                 }
                 if (!tables.isEmpty())
-                    gen.generateSchemas((String[]) tables.toArray
-                        (new String[tables.size()]));
+                    gen.generateSchemas((DBIdentifier[]) tables.toArray
+                        (new DBIdentifier[tables.size()]));
             }
             _db = gen.getSchemaGroup();
         }
@@ -1448,7 +1445,7 @@
             log.info(_loc.get("sch-reflect-write"));
             SchemaSerializer ser = new XMLSchemaSerializer(conf);
             ser.addAll(gen.getSchemaGroup());
-            ser.serialize(flags.writer, ser.PRETTY);
+            ser.serialize(flags.writer, MetaDataSerializer.PRETTY);
             return true;
         }
 
@@ -1486,7 +1483,7 @@
             log.info(_loc.get("tool-export-write"));
             SchemaSerializer ser = new XMLSchemaSerializer(conf);
             ser.addAll(schema);
-            ser.serialize(flags.writer, ser.PRETTY);
+            ser.serialize(flags.writer, MetaDataSerializer.PRETTY);
             return true;
         }
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schemas.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schemas.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schemas.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schemas.java Fri Jan 15 19:38:18 2010
@@ -21,7 +21,10 @@
 import java.sql.Types;
 import java.util.Date;
 
+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;
 
 /**
  * Helper class to deal with schemas.
@@ -40,20 +43,24 @@
     /**
      * Return the schema name that should be used for new tables, or null if
      * none.
+     * @deprecated
      */
     public static String getNewTableSchema(JDBCConfiguration conf) {
+        return getNewTableSchemaIdentifier(conf).getName();
+    }
+
+    public static DBIdentifier getNewTableSchemaIdentifier(JDBCConfiguration conf) {
         if (conf.getSchema() != null)
-            return conf.getSchema();
+            return DBIdentifier.newSchema(conf.getSchema());
 
         String[] schemas = conf.getSchemasList();
         if (schemas.length == 0)
-            return null;
-        int dotIdx = schemas[0].lastIndexOf('.');
-        if (dotIdx == 0)
-            return null;
-        if (dotIdx == -1)
-            return schemas[0];
-        return schemas[0].substring(0, dotIdx);
+            return DBIdentifier.NULL;
+        String[] names = Normalizer.splitName(schemas[0]);
+        if (names.length == 0 || StringUtils.isEmpty(names[0])) {
+            return DBIdentifier.NULL;
+        }
+        return DBIdentifier.newSchema(names[0]);
     }
 
     /**
@@ -190,7 +197,7 @@
     /**
      * Return the java type for the given SQL type from {@link Types}.
      */
-    public static Class getJavaType(int type, int size, int decimals) {
+    public static Class<?> getJavaType(int type, int size, int decimals) {
         switch (type) {
             case Types.CHAR:
                 if (size == 1)

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Sequence.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Sequence.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Sequence.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Sequence.java Fri Jan 15 19:38:18 2010
@@ -20,6 +20,10 @@
 
 import java.io.File;
 
+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.lib.identifier.IdentifierUtil;
 import org.apache.openjpa.lib.meta.SourceTracker;
 
 /**
@@ -27,20 +31,21 @@
  *
  * @author Abe White
  */
+@SuppressWarnings("serial")
 public class Sequence
     extends ReferenceCounter
-    implements Comparable, SourceTracker {
+    implements Comparable<Sequence>, SourceTracker {
 
-    private String _name = null;
-    private String _fullName = null;
+    private DBIdentifier _name = DBIdentifier.NULL;
     private Schema _schema = null;
-    private String _schemaName = null;
+    private DBIdentifier _schemaName = DBIdentifier.NULL;
     private int _initial = 1;
     private int _increment = 1;
     private int _cache = 0;
     private int _lineNum = 0;  
     private int _colNum = 0;  
-
+    private QualifiedDBIdentifier _fullPath = null;
+    
     // keep track of source
     private File _source = null;
     private int _srcType = SRC_OTHER;
@@ -56,11 +61,16 @@
      *
      * @param name the sequence name
      * @param schema the sequence schema
+     * @deprecated
      */
     public Sequence(String name, Schema schema) {
-        setName(name);
+        this(DBIdentifier.newSequence(name), schema);
+    }
+
+    public Sequence(DBIdentifier name, Schema schema) {
+        setIdentifier(name);
         if (schema != null)
-            setSchemaName(schema.getName());
+            setSchemaIdentifier(schema.getIdentifier());
         _schema = schema;
     }
 
@@ -69,7 +79,7 @@
      */
     void remove() {
         _schema = null;
-        _fullName = null;
+        _fullPath = null;
     }
 
     /**
@@ -83,51 +93,75 @@
      * The sequence's schema name.
      */
     public String getSchemaName() {
-        return _schemaName;
+        return getSchemaIdentifier().getName();
+    }
+    
+    public DBIdentifier getSchemaIdentifier() {
+        return _schemaName == null ? DBIdentifier.NULL : _schemaName;
     }
 
     /**
      * The sequence's schema name. You can only call this method on sequences
      * whose schema object is not set.
+     * @deprecated
      */
     public void setSchemaName(String name) {
+        setSchemaIdentifier(DBIdentifier.newSchema(name));
+    }
+
+    public void setSchemaIdentifier(DBIdentifier name) {
         if (getSchema() != null)
             throw new IllegalStateException();
         _schemaName = name;
-        _fullName = null;
+        _fullPath = null;
     }
 
     /**
      * Return the name of the sequence.
+     * @deprecated
      */
     public String getName() {
-        return _name;
+        return getIdentifier().getName();
+    }
+
+    public DBIdentifier getIdentifier() {
+        return _name == null ? DBIdentifier.NULL : _name;
     }
 
     /**
      * Set the name of the sequence. This method can only be called on
      * sequences that are not part of a schema.
+     * @deprecated
      */
     public void setName(String name) {
+        setIdentifier(DBIdentifier.newSequence(name));
+    }
+
+    public void setIdentifier(DBIdentifier name) {
         if (getSchema() != null)
             throw new IllegalStateException();
         _name = name;
-        _fullName = null;
+        _fullPath = null;
     }
 
     /**
      * Return the sequence name, including schema, using '.' as the
      * catalog separator.
+     * @deprecated
      */
     public String getFullName() {
-        if (_fullName == null) {
-            Schema schema = getSchema();
-            if (schema == null || schema.getName() == null)
-                _fullName = getName();
-            else
-                _fullName = schema.getName() + "." + getName();
+        return getFullIdentifier().getName();
+    }
+
+    public DBIdentifier getFullIdentifier() {
+        return getQualifiedPath().getIdentifier();
+    }
+
+    public QualifiedDBIdentifier getQualifiedPath() {
+        if (_fullPath  == null) {
+            _fullPath = QualifiedDBIdentifier.newPath(_schemaName, _name );
         }
-        return _fullName;
+        return _fullPath;
     }
 
     /**
@@ -190,23 +224,24 @@
     }
 
     public String getResourceName() {
-        return getFullName();
+        return getFullIdentifier().getName();
     }
 
-    public int compareTo(Object other) {
-        String name = getFullName();
-        String otherName = ((Sequence) other).getFullName();
-        if (name == null && otherName == null)
+    public int compareTo(Sequence other) {
+        DBIdentifier name = getIdentifier();
+        DBIdentifier otherName = other.getIdentifier();
+        if (DBIdentifier.isNull(name) && DBIdentifier.isNull(otherName)) {
             return 0;
-        if (name == null)
+        }
+        if (DBIdentifier.isNull(name))
             return 1;
-        if (otherName == null)
+        if (DBIdentifier.isNull(otherName))
             return -1;
         return name.compareTo(otherName);
     }
 
     public String toString() {
-        return getFullName();
+        return getFullIdentifier().getName();
     }
     
     public int getLineNumber() {
@@ -224,4 +259,5 @@
     public void setColNumber(int colNum) {
         _colNum = colNum;
     }
+
 }