openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrba...@apache.org
Subject svn commit: r899784 [9/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/sql/InformixDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/InformixDictionary.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/InformixDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/InformixDictionary.java Fri Jan 15 19:38:18 2010
@@ -29,6 +29,7 @@
 import java.util.Collection;
 import java.util.Set;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
@@ -154,6 +155,7 @@
         trimSchemaName = true;
     }
 
+    @Override
     public void connectedConfiguration(Connection conn)
         throws SQLException {
         super.connectedConfiguration(conn);
@@ -185,6 +187,7 @@
         }
     }
 
+    @Override
     public Column[] getColumns(DatabaseMetaData meta, String catalog,
         String schemaName, String tableName, String columnName, Connection conn)
         throws SQLException {
@@ -198,30 +201,34 @@
         return cols;
     }
 
+    @Override
     public Column newColumn(ResultSet colMeta)
         throws SQLException {
         Column col = super.newColumn(colMeta);
         if (swapSchemaAndCatalog)
-            col.setSchemaName(colMeta.getString("TABLE_CAT"));
+            col.setSchemaIdentifier(fromDBName(colMeta.getString("TABLE_CAT"), DBIdentifierType.CATALOG));
         return col;
     }
 
+    @Override
     public PrimaryKey newPrimaryKey(ResultSet pkMeta)
         throws SQLException {
         PrimaryKey pk = super.newPrimaryKey(pkMeta);
         if (swapSchemaAndCatalog)
-            pk.setSchemaName(pkMeta.getString("TABLE_CAT"));
+            pk.setSchemaIdentifier(fromDBName(pkMeta.getString("TABLE_CAT"), DBIdentifierType.CATALOG));
         return pk;
     }
 
+    @Override
     public Index newIndex(ResultSet idxMeta)
         throws SQLException {
         Index idx = super.newIndex(idxMeta);
         if (swapSchemaAndCatalog)
-            idx.setSchemaName(idxMeta.getString("TABLE_CAT"));
+            idx.setSchemaIdentifier(fromDBName(idxMeta.getString("TABLE_CAT"), DBIdentifierType.CATALOG));
         return idx;
     }
 
+    @Override
     public void setBoolean(PreparedStatement stmnt, int idx, boolean val,
         Column col)
         throws SQLException {
@@ -230,12 +237,14 @@
         stmnt.setString(idx, val ? "t" : "f");
     }
 
+    @Override
     public String[] getCreateTableSQL(Table table) {
         String[] create = super.getCreateTableSQL(table);
         create[0] = create[0] + " LOCK MODE ROW";
         return create;
     }
 
+    @Override
     public String[] getAddPrimaryKeySQL(PrimaryKey pk) {
         String pksql = getPrimaryKeyConstraintSQL(pk);
         if (pksql == null)
@@ -244,6 +253,7 @@
             + getFullName(pk.getTable(), false) + " ADD CONSTRAINT " + pksql };
     }
 
+    @Override
     public String[] getAddForeignKeySQL(ForeignKey fk) {
         String fksql = getForeignKeyConstraintSQL(fk);
         if (fksql == null)
@@ -252,12 +262,14 @@
             + getFullName(fk.getTable(), false) + " ADD CONSTRAINT " + fksql };
     }
 
+    @Override
     public boolean supportsRandomAccessResultSet(Select sel,
         boolean forUpdate) {
         return !forUpdate && !sel.isLob()
             && super.supportsRandomAccessResultSet(sel, forUpdate);
     }
 
+    @Override
     public Connection decorate(Connection conn)
         throws SQLException {
         conn = super.decorate(conn);
@@ -303,12 +315,14 @@
         return conn;
     }
 
+    @Override
     public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find,
         FilterValue start) {
         throw new UnsupportedException(_loc.get("function-not-supported",
                 getClass(), "LOCATE"));
     }
 
+    @Override
     public boolean needsToCreateIndex(Index idx, Table table) {
        // Informix will automatically create a unique index for the 
        // primary key, so don't create another index again
@@ -325,6 +339,7 @@
     /**
      * Return DB specific schemaCase 
      */
+    @Override
     public String getSchemaCase(){
         return schemaCase;
     }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/IngresDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/IngresDictionary.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/IngresDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/IngresDictionary.java Fri Jan 15 19:38:18 2010
@@ -23,6 +23,7 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
 import org.apache.openjpa.jdbc.schema.Sequence;
 
@@ -210,16 +211,21 @@
      */
     @Override
     protected String getSequencesSQL(String schemaName, String sequenceName) {
+        return getSequencesSQL(DBIdentifier.newSchema(schemaName), DBIdentifier.newSequence(sequenceName));
+    }
+
+    @Override
+    protected String getSequencesSQL(DBIdentifier schemaName, DBIdentifier sequenceName) {
         StringBuilder buf = new StringBuilder();
         buf.append(sequenceSQL);
-        if (schemaName != null || sequenceName != null)
+        if (!DBIdentifier.isNull(schemaName) || !DBIdentifier.isNull(sequenceName))
             buf.append(" WHERE ");
-        if (schemaName != null) {
+        if (!DBIdentifier.isNull(schemaName)) {
             buf.append(sequenceSchemaSQL);
             if (sequenceName != null)
                 buf.append(" AND ");
         }
-        if (sequenceName != null)
+        if (!DBIdentifier.isNull(sequenceName))
             buf.append(sequenceNameSQL);
         return buf.toString();
     }
@@ -232,7 +238,7 @@
     @Override
     protected Sequence newSequence(ResultSet sequenceMeta) throws SQLException {
         Sequence seq = super.newSequence(sequenceMeta);
-        seq.setName(seq.getName().trim());
+        seq.setIdentifier(DBIdentifier.trim(seq.getIdentifier()));
         return seq;
     }
     
@@ -257,6 +263,7 @@
      *            start at the beginning
      */
 
+    @Override
     public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find,
         FilterValue start) {
         buf.append("(POSITION((");
@@ -284,6 +291,7 @@
      *  org.apache.openjpa.jdbc.kernel.exps.FilterValue, 
      *  org.apache.openjpa.jdbc.kernel.exps.FilterValue)
      */
+    @Override
     public void substring(SQLBuffer buf, FilterValue str, FilterValue start,
         FilterValue end) {
         buf.append(substringFunctionName).append("(");

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/InterbaseDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/InterbaseDictionary.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/InterbaseDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/InterbaseDictionary.java Fri Jan 15 19:38:18 2010
@@ -20,9 +20,11 @@
 
 import java.sql.Types;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.Index;
+import org.apache.openjpa.lib.identifier.IdentifierUtil;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.util.StoreException;
 
@@ -65,16 +67,33 @@
         stringLengthFunction = null;
     }
 
+    @Override
     protected String getTableNameForMetadata(String tableName) {
-        return (tableName == null) ? "%"
-            : super.getTableNameForMetadata(tableName);
+        return getTableNameForMetadata(DBIdentifier.newTable(tableName));
     }
 
+    @Override
+    protected String getTableNameForMetadata(DBIdentifier tableName) {
+        if (DBIdentifier.isNull(tableName)) {
+            return IdentifierUtil.PERCENT;
+        }
+        return super.getTableNameForMetadata(tableName);
+    }
+
+    @Override
     protected String getColumnNameForMetadata(String columnName) {
-        return (columnName == null) ? "%"
-            : super.getColumnNameForMetadata(columnName);
+        return getColumnNameForMetadata(DBIdentifier.newColumn(columnName));
+    }
+
+    @Override
+    protected String getColumnNameForMetadata(DBIdentifier columnName) {
+        if (DBIdentifier.isNull(columnName)) {
+            return IdentifierUtil.PERCENT;
+        }
+        return super.getColumnNameForMetadata(columnName);
     }
 
+    @Override
     protected String appendSize(Column col, String typeName) {
         if (col.isPrimaryKey() && col.getType() == Types.VARCHAR) {
             // reduce size of varchar primary key cols proportional to the
@@ -98,21 +117,24 @@
         return super.appendSize(col, typeName);
     }
 
+    @Override
     public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find,
         FilterValue start) {
         throw new StoreException(_loc.get("indexof-not-supported", platform));
     }
 
+    @Override
     public void substring(SQLBuffer buf, FilterValue str, FilterValue start,
         FilterValue end) {
         throw new StoreException(_loc.get("substring-not-supported",
             platform));
     }
 
+    @Override
     public String[] getDropColumnSQL(Column column) {
         // Interbase uses "ALTER TABLE DROP <COLUMN_NAME>" rather than the
         // usual "ALTER TABLE DROP COLUMN <COLUMN_NAME>"
         return new String[]{ "ALTER TABLE "
-            + getFullName(column.getTable(), false) + " DROP " + column };
+            + getFullName(column.getTable(), false) + " DROP " + getColumnDBName(column) };
     }
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/JDataStoreDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/JDataStoreDictionary.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/JDataStoreDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/JDataStoreDictionary.java Fri Jan 15 19:38:18 2010
@@ -67,6 +67,7 @@
         searchStringEscape = "";
     }
 
+    @Override
     public void substring(SQLBuffer buf, FilterValue str, FilterValue start,
         FilterValue end) {
         buf.append("SUBSTRING(");
@@ -85,6 +86,7 @@
         buf.append(")))");
     }
 
+    @Override
     public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find,
         FilterValue start) {
         buf.append("(POSITION(");
@@ -102,6 +104,7 @@
         buf.append(")");
     }
 
+    @Override
     public OpenJPAException newStoreException(String msg, SQLException[] causes,
         Object failed) {
         OpenJPAException ke = super.newStoreException(msg, causes, failed);

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java Fri Jan 15 19:38:18 2010
@@ -30,6 +30,7 @@
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
@@ -47,6 +48,8 @@
 
     public static final String SELECT_HINT = "openjpa.hint.MySQLSelectHint";
 
+    public static final String DELIMITER_BACK_TICK = "`";
+    
     /**
      * The MySQL table type to use when creating tables; defaults to innodb.
      */
@@ -144,11 +147,13 @@
         typeModifierSet.addAll(Arrays.asList(new String[] { "UNSIGNED",
             "ZEROFILL" }));
 
-        delimiter = "`";
+        setLeadingDelimiter(DELIMITER_BACK_TICK);
+        setTrailingDelimiter(DELIMITER_BACK_TICK);
         
         fixedSizeTypeNameSet.remove("NUMERIC");
     }
 
+    @Override
     public void connectedConfiguration(Connection conn) throws SQLException {
         super.connectedConfiguration(conn);
 
@@ -184,6 +189,7 @@
             driverDeserializesBlobs = true;
     }
 
+    @Override
     public Connection decorate(Connection conn)  throws SQLException {
         conn = super.decorate(conn);
         String driver = conf.getConnectionDriverName();
@@ -222,6 +228,7 @@
         return new int[]{maj, min};
     }
 
+    @Override
     public String[] getCreateTableSQL(Table table) {
         String[] sql = super.getCreateTableSQL(table);
         if (!StringUtils.isEmpty(tableType))
@@ -229,6 +236,7 @@
         return sql;
     }
 
+    @Override
     public String[] getDropIndexSQL(Index index) {
         return new String[]{ "DROP INDEX " + getFullName(index) + " ON "
             + getFullName(index.getTable(), false) };
@@ -239,7 +247,7 @@
      */
     @Override
     public String[] getDropPrimaryKeySQL(PrimaryKey pk) {
-        if (pk.getName() == null)
+        if (DBIdentifier.isNull(pk.getIdentifier()))
             return new String[0];
         return new String[]{ "ALTER TABLE "
             + getFullName(pk.getTable(), false)
@@ -252,19 +260,20 @@
      */
     @Override
     public String[] getDropForeignKeySQL(ForeignKey fk, Connection conn) {
-        if (fk.getName() == null) {
-            String fkName = fk.loadNameFromDB(this,conn);
+        if (DBIdentifier.isNull(fk.getIdentifier())) {
+            DBIdentifier fkName = fk.loadIdentifierFromDB(this,conn);
             String[] retVal = (fkName == null) ?  new String[0] :
                 new String[]{ "ALTER TABLE "
                 + getFullName(fk.getTable(), false)
-                + " DROP FOREIGN KEY " + fkName };
+                + " DROP FOREIGN KEY " + toDBName(fkName) };
             return retVal;   
         }
         return new String[]{ "ALTER TABLE "
             + getFullName(fk.getTable(), false)
-            + " DROP FOREIGN KEY " + fk.getName() };
+            + " DROP FOREIGN KEY " + toDBName(fk.getIdentifier()) };
     }
 
+    @Override
     public String[] getAddPrimaryKeySQL(PrimaryKey pk) {
         String[] sql = super.getAddPrimaryKeySQL(pk);
 
@@ -274,8 +283,8 @@
         String[] ret = new String[cols.length + sql.length];
         for (int i = 0; i < cols.length; i++) {
             ret[i] = "ALTER TABLE " + getFullName(cols[i].getTable(), false)
-                + " CHANGE " + cols[i].getName()
-                + " " + cols[i].getName() // name twice
+                + " CHANGE " + toDBName(cols[i].getIdentifier())
+                + " " + toDBName(cols[i].getIdentifier()) // name twice
                 + " " + getTypeName(cols[i]) + " NOT NULL";
         }
 
@@ -283,6 +292,7 @@
         return ret;
     }
     
+    @Override
     public String[] getDeleteTableContentsSQL(Table[] tables,Connection conn) {
         // mysql >= 4 supports more-optimal delete syntax
         if (!optimizeMultiTableDeletes)
@@ -291,7 +301,7 @@
             StringBuilder buf = new StringBuilder(tables.length * 8);
             buf.append("DELETE FROM ");
             for (int i = 0; i < tables.length; i++) {
-                buf.append(tables[i].getFullName());
+                buf.append(toDBName(tables[i].getFullIdentifier()));
                 if (i < tables.length - 1)
                     buf.append(", ");
             }
@@ -299,6 +309,7 @@
         }
     }
 
+    @Override
     protected void appendSelectRange(SQLBuffer buf, long start, long end,
         boolean subselect) {
         buf.append(" LIMIT ").appendValue(start).append(", ");
@@ -308,6 +319,7 @@
             buf.appendValue(end - start);
     }
 
+    @Override
     protected Column newColumn(ResultSet colMeta)
         throws SQLException {
         Column col = super.newColumn(colMeta);
@@ -316,6 +328,7 @@
         return col;
     }
 
+    @Override
     public Object getBlobObject(ResultSet rs, int column, JDBCStore store)
         throws SQLException {
         // if the user has set a get-blob strategy explicitly or the driver
@@ -328,6 +341,7 @@
         return rs.getObject(column);
     }
 
+    @Override
     public int getPreferredType(int type) {
         if (type == Types.CLOB && !useClobs)
             return Types.LONGVARCHAR;
@@ -344,6 +358,7 @@
      * @param lhsxml indicates whether the left operand maps to XML
      * @param rhsxml indicates whether the right operand maps to XML
      */
+    @Override
     public void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs,
         FilterValue rhs, boolean lhsxml, boolean rhsxml) {
         super.appendXmlComparison(buf, op, lhs, rhs, lhsxml, rhsxml);
@@ -372,6 +387,7 @@
         buf.append("')");
     }
     
+    @Override
     public int getBatchFetchSize(int batchFetchSize) {
         return Integer.MIN_VALUE;
     }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java Fri Jan 15 19:38:18 2010
@@ -40,6 +40,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
@@ -195,12 +196,14 @@
         requiresSearchStringEscapeForLike = false;
     }
 
+    @Override
     public void endConfiguration() {
         super.endConfiguration();
         if (useTriggersForAutoAssign)
             supportsAutoAssign = true;
     }
 
+    @Override
     public void connectedConfiguration(Connection conn)
         throws SQLException {
         super.connectedConfiguration(conn);
@@ -292,6 +295,7 @@
         }
     }
 
+    @Override
     public boolean supportsLocking(Select sel) {
         if (!super.supportsLocking(sel))
             return false;
@@ -299,6 +303,7 @@
             sel.getEndIndex(), sel.isDistinct(), sel.getOrdering());
     }
 
+    @Override
     protected SQLBuffer getSelects(Select sel, boolean distinctIdentifiers,
         boolean forUpdate) {
         // if range doesn't require a subselect can use super
@@ -337,6 +342,7 @@
         return selectSQL;
     }
 
+    @Override
     public boolean canOuterJoin(int syntax, ForeignKey fk) {
         if (!super.canOuterJoin(syntax, fk))
             return false;
@@ -349,6 +355,7 @@
         return true;
     }
 
+    @Override
     public SQLBuffer toNativeJoin(Join join) {
         if (join.getType() != Join.TYPE_OUTER)
             return toTraditionalJoin(join);
@@ -386,6 +393,7 @@
         return buf;
     }
 
+    @Override
     protected SQLBuffer toSelect(SQLBuffer select, JDBCFetchConfiguration fetch,
         SQLBuffer tables, SQLBuffer where, SQLBuffer group,
         SQLBuffer having, SQLBuffer order,
@@ -395,6 +403,7 @@
             distinct, forUpdate, start, end, sel);
     }
 
+    @Override
     protected SQLBuffer toSelect(SQLBuffer select, JDBCFetchConfiguration fetch,
         SQLBuffer tables, SQLBuffer where, SQLBuffer group,
         SQLBuffer having, SQLBuffer order,
@@ -478,7 +487,7 @@
         // special handling to configure them correctly; see:
         // http://www.oracle.com/technology/sample_code/tech/java/
         // sqlj_jdbc/files/9i_jdbc/NCHARsupport4UnicodeSample/Readme.html
-        String typeName = (col == null) ? null : col.getTypeName();
+        String typeName = (col == null) ? null : col.getTypeIdentifier().getName();
         if (useSetFormOfUseForUnicode && typeName != null &&
             (typeName.toLowerCase().startsWith("nvarchar") ||
                 typeName.toLowerCase().startsWith("nchar") ||
@@ -534,20 +543,21 @@
         super.setString(stmnt, idx, val, col);
     }
 
+    @Override
     public void setNull(PreparedStatement stmnt, int idx, int colType,
         Column col)
         throws SQLException {
         if ((colType == Types.CLOB || colType == Types.BLOB) && col.isNotNull())
-            throw new UserException(_loc.get("null-blob-in-not-nullable", col
-                .getFullName()));
+            throw new UserException(_loc.get("null-blob-in-not-nullable", toDBName(col
+                .getFullDBIdentifier())));
         if (colType == Types.BLOB && _driverBehavior == BEHAVE_ORACLE)
             stmnt.setBlob(idx, getEmptyBlob());
         else if (colType == Types.CLOB && _driverBehavior == BEHAVE_ORACLE
             && !col.isXML())
             stmnt.setClob(idx, getEmptyClob());
         else if ((colType == Types.STRUCT || colType == Types.OTHER)
-            && col != null && col.getTypeName() != null)
-            stmnt.setNull(idx, Types.STRUCT, col.getTypeName());
+            && col != null && !DBIdentifier.isNull(col.getTypeIdentifier()))
+            stmnt.setNull(idx, Types.STRUCT, col.getTypeIdentifier().getName());
             // some versions of the Oracle JDBC driver will fail if calling
             // setNull with DATE; see bug #1171
         else if (colType == Types.DATE)
@@ -559,6 +569,7 @@
             super.setNull(stmnt, idx, colType, col);
     }
 
+    @Override
     public String getClobString(ResultSet rs, int column)
         throws SQLException {
         if (_driverBehavior != BEHAVE_ORACLE)
@@ -585,6 +596,7 @@
         return clob.getSubString(1, (int) clob.length());
     }
 
+    @Override
     public Timestamp getTimestamp(ResultSet rs, int column, Calendar cal)
         throws SQLException {
         if (cal == null) {
@@ -606,6 +618,7 @@
         return ts;
     }
 
+    @Override
     public Object getObject(ResultSet rs, int column, Map map)
         throws SQLException {
         // recent oracle drivers return oracle-specific types for timestamps
@@ -642,32 +655,54 @@
     public Column[] getColumns(DatabaseMetaData meta, String catalog,
         String schemaName, String tableName, String columnName, Connection conn)
         throws SQLException {
+        return getColumns(meta, 
+            DBIdentifier.newCatalog(catalog), 
+            DBIdentifier.newSchema(schemaName), 
+            DBIdentifier.newTable(tableName), 
+            DBIdentifier.newColumn(columnName),conn);
+    }
+
+    public Column[] getColumns(DatabaseMetaData meta, DBIdentifier catalog,
+        DBIdentifier schemaName, DBIdentifier tableName, DBIdentifier columnName, Connection conn)
+        throws SQLException {
         Column[] cols = super.getColumns(meta, catalog, schemaName, tableName,
             columnName, conn);
 
         for (int i = 0; cols != null && i < cols.length; i++) {
-            if (cols[i].getTypeName() == null)
+            String typeName = cols[i].getTypeIdentifier().getName();
+            if (typeName == null)
                 continue;
-            if (cols[i].getTypeName().toUpperCase().startsWith("TIMESTAMP"))
+            if (typeName.toUpperCase().startsWith("TIMESTAMP"))
                 cols[i].setType(Types.TIMESTAMP);
-            else if ("BLOB".equalsIgnoreCase(cols[i].getTypeName()))
+            else if ("BLOB".equalsIgnoreCase(typeName))
                 cols[i].setType(Types.BLOB);
-            else if ("CLOB".equalsIgnoreCase(cols[i].getTypeName())
-                || "NCLOB".equalsIgnoreCase(cols[i].getTypeName()))
+            else if ("CLOB".equalsIgnoreCase(typeName)
+                || "NCLOB".equalsIgnoreCase(typeName))
                 cols[i].setType(Types.CLOB);
-            else if ("FLOAT".equalsIgnoreCase(cols[i].getTypeName()))
+            else if ("FLOAT".equalsIgnoreCase(typeName))
                 cols[i].setType(Types.FLOAT);
-            else if ("NVARCHAR".equalsIgnoreCase(cols[i].getTypeName()))
+            else if ("NVARCHAR".equalsIgnoreCase(typeName))
                 cols[i].setType(Types.VARCHAR);
-            else if ("NCHAR".equalsIgnoreCase(cols[i].getTypeName()))
+            else if ("NCHAR".equalsIgnoreCase(typeName))
                 cols[i].setType(Types.CHAR);
         }
         return cols;
     }
 
+    @Override
     public PrimaryKey[] getPrimaryKeys(DatabaseMetaData meta,
         String catalog, String schemaName, String tableName, Connection conn)
         throws SQLException {
+        return getPrimaryKeys(meta,
+            DBIdentifier.newCatalog(catalog), 
+            DBIdentifier.newSchema(schemaName), 
+            DBIdentifier.newTable(tableName), conn);
+    }
+
+    @Override
+    public PrimaryKey[] getPrimaryKeys(DatabaseMetaData meta,
+        DBIdentifier catalog, DBIdentifier schemaName, DBIdentifier tableName, Connection conn)
+        throws SQLException {
         StringBuilder buf = new StringBuilder();
         buf.append("SELECT t0.OWNER AS TABLE_SCHEM, ").
             append("t0.TABLE_NAME AS TABLE_NAME, ").
@@ -677,19 +712,19 @@
             append("WHERE t0.OWNER = t1.OWNER ").
             append("AND t0.CONSTRAINT_NAME = t1.CONSTRAINT_NAME ").
             append("AND t1.CONSTRAINT_TYPE = 'P'");
-        if (schemaName != null)
+        if (!DBIdentifier.isNull(schemaName))
             buf.append(" AND t0.OWNER = ?");
-        if (tableName != null)
+        if (!DBIdentifier.isNull(tableName))
             buf.append(" AND t0.TABLE_NAME = ?");
 
         PreparedStatement stmnt = conn.prepareStatement(buf.toString());
         ResultSet rs = null;
         try {
             int idx = 1;
-            if (schemaName != null)
-                setString(stmnt, idx++, schemaName.toUpperCase(), null);
-            if (tableName != null)
-                setString(stmnt, idx++, tableName.toUpperCase(), null);
+            if (!DBIdentifier.isNull(schemaName))
+                setString(stmnt, idx++, convertSchemaCase(schemaName), null);
+            if (!DBIdentifier.isNull(tableName))
+                setString(stmnt, idx++, convertSchemaCase(tableName), null);
             setTimeouts(stmnt, conf, false);
             rs = stmnt.executeQuery();
             List pkList = new ArrayList();
@@ -710,10 +745,22 @@
         }
     }
 
+    @Override
     public Index[] getIndexInfo(DatabaseMetaData meta, String catalog,
         String schemaName, String tableName, boolean unique, boolean approx,
         Connection conn)
         throws SQLException {
+        return getIndexInfo(meta,
+            DBIdentifier.newCatalog(catalog), 
+            DBIdentifier.newSchema(schemaName), 
+            DBIdentifier.newTable(tableName), unique, approx, conn);
+    }
+
+    @Override
+    public Index[] getIndexInfo(DatabaseMetaData meta, DBIdentifier catalog,
+        DBIdentifier schemaName, DBIdentifier tableName, boolean unique, boolean approx,
+        Connection conn)
+        throws SQLException {
         StringBuilder buf = new StringBuilder();
         buf.append("SELECT t0.INDEX_OWNER AS TABLE_SCHEM, ").
             append("t0.TABLE_NAME AS TABLE_NAME, ").
@@ -724,19 +771,19 @@
             append("FROM ALL_IND_COLUMNS t0, ALL_INDEXES t1 ").
             append("WHERE t0.INDEX_OWNER = t1.OWNER ").
             append("AND t0.INDEX_NAME = t1.INDEX_NAME");
-        if (schemaName != null)
+        if (!DBIdentifier.isNull(schemaName))
             buf.append(" AND t0.TABLE_OWNER = ?");
-        if (tableName != null)
+        if (!DBIdentifier.isNull(tableName))
             buf.append(" AND t0.TABLE_NAME = ?");
 
         PreparedStatement stmnt = conn.prepareStatement(buf.toString());
         ResultSet rs = null;
         try {
             int idx = 1;
-            if (schemaName != null)
-                setString(stmnt, idx++, schemaName.toUpperCase(), null);
-            if (tableName != null)
-                setString(stmnt, idx++, tableName.toUpperCase(), null);
+            if (!DBIdentifier.isNull(schemaName))
+                setString(stmnt, idx++, convertSchemaCase(schemaName), null);
+            if (!DBIdentifier.isNull(tableName))
+                setString(stmnt, idx++, convertSchemaCase(tableName), null);
 
             setTimeouts(stmnt, conf, false);
             rs = stmnt.executeQuery();
@@ -757,9 +804,20 @@
         }
     }
 
+    @Override
     public ForeignKey[] getImportedKeys(DatabaseMetaData meta, String catalog,
         String schemaName, String tableName, Connection conn, boolean partialKeys)
         throws SQLException {
+        return getImportedKeys(meta,
+            DBIdentifier.newCatalog(catalog), 
+            DBIdentifier.newSchema(schemaName), 
+            DBIdentifier.newTable(tableName), conn, partialKeys);
+    }
+    
+    @Override
+    public ForeignKey[] getImportedKeys(DatabaseMetaData meta, DBIdentifier catalog,
+        DBIdentifier schemaName, DBIdentifier tableName, Connection conn, boolean partialKeys)
+        throws SQLException {
         StringBuilder delAction = new StringBuilder("DECODE(t1.DELETE_RULE").
             append(", 'NO ACTION', ").append(meta.importedKeyNoAction).
             append(", 'RESTRICT', ").append(meta.importedKeyRestrict).
@@ -791,9 +849,9 @@
             append("AND t1.R_OWNER = t2.OWNER ").
             append("AND t1.R_CONSTRAINT_NAME = t2.CONSTRAINT_NAME ").
             append("AND t0.POSITION = t2.POSITION");
-        if (schemaName != null)
+        if (!DBIdentifier.isNull(schemaName))
             buf.append(" AND t0.OWNER = ?");
-        if (tableName != null)
+        if (!DBIdentifier.isNull(tableName))
             buf.append(" AND t0.TABLE_NAME = ?");
         buf.append(" ORDER BY t2.OWNER, t2.TABLE_NAME, t0.POSITION");
 
@@ -801,10 +859,10 @@
         ResultSet rs = null;
         try {
             int idx = 1;
-            if (schemaName != null)
-                setString(stmnt, idx++, schemaName.toUpperCase(), null);
-            if (tableName != null)
-                setString(stmnt, idx++, tableName.toUpperCase(), null);
+            if (!DBIdentifier.isNull(schemaName))
+                setString(stmnt, idx++, convertSchemaCase(schemaName), null);
+            if (!DBIdentifier.isNull(tableName))
+                setString(stmnt, idx++, convertSchemaCase(tableName), null);
             setTimeouts(stmnt, conf, false);
             rs = stmnt.executeQuery();
             List<ForeignKey> fkList = new ArrayList<ForeignKey>();            
@@ -836,6 +894,7 @@
         }
     }
 
+    @Override
     public String[] getCreateTableSQL(Table table) {
         // only override if we are simulating auto-incremenet with triggers
         String[] create = super.getCreateTableSQL(table);
@@ -867,9 +926,9 @@
             // create the trigger that will insert new values into
             // the table whenever a row is created
             seqs.add("CREATE OR REPLACE TRIGGER " + trig
-                + " BEFORE INSERT ON " + table.getName()
+                + " BEFORE INSERT ON " + toDBName(table.getIdentifier())
                 + " FOR EACH ROW BEGIN SELECT " + seq + ".nextval INTO "
-                + ":new." + cols[i].getName() + " FROM DUAL; "
+                + ":new." + toDBName(cols[i].getIdentifier()) + " FROM DUAL; "
                 + "END " + trig + ";");
         }
         if (seqs == null)
@@ -883,6 +942,7 @@
         return sql;
     }
 
+    @Override
     public String[] getCreateSequenceSQL(Sequence seq) {
         String[] sql = super.getCreateSequenceSQL(seq);
         if (seq.getAllocate() > 1)
@@ -900,35 +960,49 @@
         return getJDBCType(metaTypeCode, lob || xml, precis, scale);        
     }
 
-
+    @Override
     protected String getSequencesSQL(String schemaName, String sequenceName) {
+        return getSequencesSQL(DBIdentifier.newSchema(schemaName), DBIdentifier.newSequence(sequenceName));
+    }
+
+    @Override
+    protected String getSequencesSQL(DBIdentifier schemaName, DBIdentifier sequenceName) {
         StringBuilder buf = new StringBuilder();
         buf.append("SELECT SEQUENCE_OWNER AS SEQUENCE_SCHEMA, ").
             append("SEQUENCE_NAME FROM ALL_SEQUENCES");
-        if (schemaName != null || sequenceName != null)
+        if (!DBIdentifier.isNull(schemaName) || !DBIdentifier.isNull(sequenceName))
             buf.append(" WHERE ");
-        if (schemaName != null) {
+        if (!DBIdentifier.isNull(schemaName)) {
             buf.append("SEQUENCE_OWNER = ?");
-            if (sequenceName != null)
+            if (!DBIdentifier.isNull(sequenceName))
                 buf.append(" AND ");
         }
-        if (sequenceName != null)
+        if (!DBIdentifier.isNull(sequenceName))
             buf.append("SEQUENCE_NAME = ?");
         return buf.toString();
     }
 
     public boolean isSystemSequence(String name, String schema,
         boolean targetSchema) {
+        return isSystemSequence(DBIdentifier.newSequence(name),
+            DBIdentifier.newSchema(schema), targetSchema);
+    }
+
+    @Override
+    public boolean isSystemSequence(DBIdentifier name, DBIdentifier schema,
+        boolean targetSchema) {
         if (super.isSystemSequence(name, schema, targetSchema))
             return true;
 
         // filter out generated sequences used for auto-assign
+        String strName = DBIdentifier.isNull(name) ? "" : name.getName();
         return (autoAssignSequenceName != null
-            && name.equalsIgnoreCase(autoAssignSequenceName))
+            && strName.equalsIgnoreCase(autoAssignSequenceName))
             || (autoAssignSequenceName == null
-            && name.toUpperCase().startsWith("ST_"));
+            && strName.toUpperCase().startsWith("ST_"));
     }
 
+    @Override
     public Object getGeneratedKey(Column col, Connection conn)
         throws SQLException {
         if (!useTriggersForAutoAssign)
@@ -971,17 +1045,19 @@
      */
     protected String getOpenJPA3GeneratedKeySequenceName(Column col) {
         Table table = col.getTable();
-        return makeNameValid("SEQ_" + table.getName(), table.getSchema().
-            getSchemaGroup(), maxTableNameLength, NAME_ANY);
+        DBIdentifier sName = DBIdentifier.preCombine(table.getIdentifier(), "SEQ");
+        return toDBName(getNamingUtil().makeIdentifierValid(sName, table.getSchema().
+            getSchemaGroup(), maxTableNameLength, true));
     }
 
     /**
      * Returns a OpenJPA 3-compatible name for an auto-assign trigger.
      */
     protected String getOpenJPA3GeneratedKeyTriggerName(Column col) {
-        Table table = col.getTable();
-        return makeNameValid("TRIG_" + table.getName(), table.getSchema().
-            getSchemaGroup(), maxTableNameLength, NAME_ANY);
+        Table table = col.getTable();        
+        DBIdentifier sName = DBIdentifier.preCombine(table.getIdentifier(), "TRIG");
+        return toDBName(getNamingUtil().makeIdentifierValid(sName, table.getSchema().
+            getSchemaGroup(), maxTableNameLength, true));
     }
 
     /**
@@ -990,6 +1066,7 @@
      * vendor-specific class; for example Weblogic wraps oracle thin driver
      * lobs in its own interfaces with the same methods.
      */
+    @Override
     public void putBytes(Blob blob, byte[] data)
         throws SQLException {
         if (blob == null)
@@ -1011,6 +1088,7 @@
      * vendor-specific class; for example Weblogic wraps oracle thin driver
      * lobs in its own interfaces with the same methods.
      */
+    @Override
     public void putString(Clob clob, String data)
         throws SQLException {
         if (_putString == null) {
@@ -1030,6 +1108,7 @@
      * vendor-specific class; for example Weblogic wraps oracle thin driver
      * lobs in its own interfaces with the same methods.
      */
+    @Override
     public void putChars(Clob clob, char[] data)
         throws SQLException {
         if (_putChars == null) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PointbaseDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PointbaseDictionary.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PointbaseDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PointbaseDictionary.java Fri Jan 15 19:38:18 2010
@@ -23,6 +23,8 @@
 import java.sql.SQLException;
 import java.sql.Types;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.Index;
@@ -72,21 +74,32 @@
         }
     }
 
+    @Override
     public Column[] getColumns(DatabaseMetaData meta, String catalog,
         String schemaName, String tableName, String columnName, Connection conn)
         throws SQLException {
+        return getColumns(meta, DBIdentifier.newCatalog(catalog), DBIdentifier.newSchema(schemaName),
+            DBIdentifier.newTable(tableName), DBIdentifier.newColumn(columnName), conn);
+    }
+
+    @Override
+    public Column[] getColumns(DatabaseMetaData meta, DBIdentifier catalog,
+        DBIdentifier schemaName, DBIdentifier tableName, DBIdentifier columnName, Connection conn)
+        throws SQLException {
         Column[] cols = super.getColumns(meta, catalog, schemaName, tableName,
             columnName, conn);
 
         // pointbase reports the type for a CLOB field as VARCHAR: override it
         for (int i = 0; cols != null && i < cols.length; i++)
-            if (cols[i].getTypeName().toUpperCase().startsWith("CLOB"))
+            if (cols[i].getTypeIdentifier().getName().toUpperCase().startsWith("CLOB"))
                 cols[i].setType(Types.CLOB);
         return cols;
     }
 
+    @Override
     public String getFullName(Index index) {
-        return getFullName(index.getTable(), false) + "." + index.getName();
+        return toDBName(getNamingUtil().append(DBIdentifierType.INDEX, 
+            getFullIdentifier(index.getTable(), false), index.getIdentifier()));
     }
 
     public void substring(SQLBuffer buf, FilterValue str, FilterValue start,

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java Fri Jan 15 19:38:18 2010
@@ -38,6 +38,7 @@
 import java.util.Date;
 import java.util.Map;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
@@ -209,6 +210,7 @@
         }));
     }
 
+    @Override
     public Date getDate(ResultSet rs, int column)
         throws SQLException {
         try {
@@ -234,6 +236,7 @@
         }
     }
 
+    @Override
     public byte getByte(ResultSet rs, int column)
         throws SQLException {
         // postgres does not perform automatic conversions, so attempting to
@@ -246,6 +249,7 @@
         }
     }
 
+    @Override
     public short getShort(ResultSet rs, int column)
         throws SQLException {
         // postgres does not perform automatic conversions, so attempting to
@@ -258,6 +262,7 @@
         }
     }
 
+    @Override
     public int getInt(ResultSet rs, int column)
         throws SQLException {
         // postgres does not perform automatic conversions, so attempting to
@@ -270,6 +275,7 @@
         }
     }
 
+    @Override
     public long getLong(ResultSet rs, int column)
         throws SQLException {
         // postgres does not perform automatic conversions, so attempting to
@@ -282,6 +288,7 @@
         }
     }
 
+    @Override
     public void setBoolean(PreparedStatement stmnt, int idx, boolean val,
         Column col)
         throws SQLException {
@@ -293,6 +300,7 @@
     /**
      * Handle XML and bytea/oid columns in a PostgreSQL way.
      */
+    @Override
     public void setNull(PreparedStatement stmnt, int idx, int colType,
         Column col)
         throws SQLException {
@@ -307,6 +315,7 @@
         stmnt.setNull(idx, colType);
     }
 
+    @Override
     protected void appendSelectRange(SQLBuffer buf, long start, long end,
         boolean subselect) {
         if (end != Long.MAX_VALUE)
@@ -315,6 +324,7 @@
             buf.append(" OFFSET ").appendValue(start);
     }
 
+    @Override
     public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find,
         FilterValue start) {
         buf.append("(POSITION(");
@@ -332,6 +342,7 @@
         buf.append(")");
     }
 
+    @Override
     public String[] getCreateSequenceSQL(Sequence seq) {
         String[] sql = super.getCreateSequenceSQL(seq);
         if (seq.getAllocate() > 1)
@@ -339,17 +350,22 @@
         return sql;
     }
 
+    @Override
     protected boolean supportsDeferredUniqueConstraints() {
         // Postgres only supports deferred foreign key constraints.
         return false;
     }
 
     protected String getSequencesSQL(String schemaName, String sequenceName) {
-        if (schemaName == null && sequenceName == null)
+        return getSequencesSQL(DBIdentifier.newSchema(schemaName), DBIdentifier.newSequence(sequenceName));
+    }
+
+    protected String getSequencesSQL(DBIdentifier schemaName, DBIdentifier sequenceName) {
+        if (DBIdentifier.isNull(schemaName) && DBIdentifier.isNull(sequenceName))
             return allSequencesSQL;
-        else if (schemaName == null)
+        else if (DBIdentifier.isNull(schemaName))
             return namedSequencesFromAllSchemasSQL;
-        else if (sequenceName == null)
+        else if (DBIdentifier.isNull(sequenceName))
             return allSequencesFromOneSchemaSQL;
         else
             return namedSequenceFromOneSchemaSQL;
@@ -357,27 +373,44 @@
 
     public boolean isSystemSequence(String name, String schema,
         boolean targetSchema) {
+        return isSystemSequence(DBIdentifier.newTable(name), DBIdentifier.newSchema(schema), targetSchema);
+    }
+
+    public boolean isSystemSequence(DBIdentifier name, DBIdentifier schema,
+        boolean targetSchema) {
         if (super.isSystemSequence(name, schema, targetSchema))
             return true;
 
         // filter out generated sequences used for bigserial cols, which are
         // of the form <table>_<col>_seq
-        int idx = name.indexOf('_');
-        return idx != -1 && idx != name.length() - 4
-            && name.toUpperCase().endsWith("_SEQ");
+        String strName = DBIdentifier.isNull(name) ? null : name.getName();
+        int idx = strName.indexOf('_');
+        return idx != -1 && idx != strName.length() - 4
+            && strName.toUpperCase().endsWith("_SEQ");
     }
 
     public boolean isSystemTable(String name, String schema,
         boolean targetSchema) {
+        return isSystemTable(DBIdentifier.newTable(name), DBIdentifier.newSchema(schema), targetSchema);
+    }
+
+    public boolean isSystemTable(DBIdentifier name, DBIdentifier schema,
+        boolean targetSchema) {
         // names starting with "pg_" are reserved for Postgresql internal use
+        String strName = DBIdentifier.isNull(name) ? null : name.getName();
         return super.isSystemTable(name, schema, targetSchema)
-            || (name != null && name.toLowerCase().startsWith("pg_"));
+            || (strName != null && strName.toLowerCase().startsWith("pg_"));
     }
 
     public boolean isSystemIndex(String name, Table table) {
+        return isSystemIndex(DBIdentifier.newIndex(name), table);
+    }
+
+    public boolean isSystemIndex(DBIdentifier name, Table table) {
         // names starting with "pg_" are reserved for Postgresql internal use
+        String strName = DBIdentifier.isNull(name) ? null : name.getName();
         return super.isSystemIndex(name, table)
-            || (name != null && name.toLowerCase().startsWith("pg_"));
+            || (strName != null && strName.toLowerCase().startsWith("pg_"));
     }
 
     public Connection decorate(Connection conn)

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java Fri Jan 15 19:38:18 2010
@@ -342,7 +342,7 @@
             		super.setObject(col, val, metaType, overrideDefault);
             	} else if (!isDefaultValue(val)) {
             		throw new InvalidStateException(_loc.get("diff-values",
-            				new Object[]{ col.getFullName(),
+            				new Object[]{ col.getFullDBIdentifier().getName(),
                             (prev == null) ? null : prev.getClass(), prev,
                             (val == null) ? null : val.getClass(), val })).
             				setFatal(true);

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java Fri Jan 15 19:38:18 2010
@@ -38,6 +38,7 @@
 import java.util.Locale;
 import java.util.Map;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
 import org.apache.openjpa.jdbc.schema.Column;
@@ -505,8 +506,8 @@
         throws SQLException {
         try {
           String s1 = obj.toString();
-          s1 = _dict.stripDelimiters(s1);
-          return getResultSet().findColumn(s1);
+          DBIdentifier sName = DBIdentifier.newColumn(obj.toString());
+          return getResultSet().findColumn(_dict.convertSchemaCase(sName));
         } catch (SQLException se) {
             return 0;
         }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java Fri Jan 15 19:38:18 2010
@@ -758,7 +758,7 @@
 
             if (hasVal)
                 buf.append(", ");
-            buf.append(_cols[i]);
+            buf.append(dict.getColumnDBName(_cols[i]));
             if (_types[i] == RAW)
                 buf.append(" = ").append(_vals[i]);
             else
@@ -788,7 +788,7 @@
                 buf.append(", ");
                 vals.append(", ");
             }
-            buf.append(_cols[i]);
+            buf.append(dict.getColumnDBName(_cols[i]));
             if (_types[i] == RAW)
                 vals.append(_vals[i]);
             else
@@ -827,16 +827,16 @@
 
             // Get platform specific version column name
             if (_cols[i].getVersionStrategy() != null)
-               buf.append(dict.getVersionColumn(_cols[i], _cols[i]
-                   .getTableName())).append(" = ?");
+               buf.append(dict.toDBName(dict.getVersionColumn(_cols[i], _cols[i]
+                   .getTableIdentifier()))).append(" = ?");
             // sqlserver seems to have problems using null parameters in the
             // where clause
             else if (_vals[getWhereIndex(_cols[i])] == NULL)
-                buf.append(_cols[i]).append(" IS NULL");
+                buf.append(dict.getColumnDBName(_cols[i])).append(" IS NULL");
             else if (_types[i] == RAW)
-                buf.append(_cols[i]).append(" = ").append(_vals[i]);
+                buf.append(dict.getColumnDBName(_cols[i])).append(" = ").append(_vals[i]);
             else
-                buf.append(_cols[i]).append(" = ?");
+                buf.append(dict.getColumnDBName(_cols[i])).append(" = ?");
             hasWhere = true;
         }
     }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java Fri Jan 15 19:38:18 2010
@@ -30,6 +30,7 @@
 import java.util.List;
 
 import org.apache.commons.lang.ObjectUtils;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
 import org.apache.openjpa.jdbc.kernel.exps.Val;
 import org.apache.openjpa.jdbc.schema.Column;
@@ -182,6 +183,11 @@
             }
         }
     }
+    
+    public SQLBuffer append(DBIdentifier name) {
+        _sql.append(_dict.toDBName(name));
+        return this;
+    }
 
     public SQLBuffer append(Table table) {
         _sql.append(_dict.getFullName(table, false));
@@ -194,7 +200,7 @@
     }
 
     public SQLBuffer append(Column col) {
-        _sql.append(col.getName());
+        _sql.append(_dict.getColumnDBName(col));
         return this;
     }
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLErrorCodeReader.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLErrorCodeReader.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLErrorCodeReader.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLErrorCodeReader.java Fri Jan 15 19:38:18 2010
@@ -41,7 +41,7 @@
 import org.w3c.dom.NodeList;
 
 /**
- * Parses XML content of SQL Error State codes to populate errro codes for
+ * Parses XML content of SQL Error State codes to populate error codes for
  * a given Database Dictionary.
  * 
  * @author Pinaki Poddar

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java Fri Jan 15 19:38:18 2010
@@ -27,6 +27,7 @@
 import java.sql.Types;
 import java.util.Set;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
 import org.apache.openjpa.jdbc.schema.Column;
@@ -35,6 +36,7 @@
 import org.apache.openjpa.meta.JavaTypes;
 import org.apache.openjpa.util.StoreException;
 
+
 /**
  * Dictionary for Microsoft SQL Server.
  */
@@ -139,12 +141,23 @@
     public Column[] getColumns(DatabaseMetaData meta, String catalog,
         String schemaName, String tableName, String columnName, Connection conn)
         throws SQLException {
+        return getColumns(meta, DBIdentifier.newCatalog(catalog),
+            DBIdentifier.newSchema(schemaName),
+            DBIdentifier.newTable(tableName),
+            DBIdentifier.newColumn(columnName),
+            conn);
+    }
+
+    public Column[] getColumns(DatabaseMetaData meta, DBIdentifier catalog,
+        DBIdentifier schemaName, DBIdentifier tableName, DBIdentifier columnName, Connection conn)
+        throws SQLException {
+
         Column[] cols = super.getColumns(meta, catalog, schemaName, tableName,
             columnName, conn);
 
         // for opta driver, which reports nvarchar as unknown type
         for (int i = 0; cols != null && i < cols.length; i++) {
-            String typeName = cols[i].getTypeName();
+            String typeName = cols[i].getTypeIdentifier().getName();
             if (typeName == null)
                 continue;
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java Fri Jan 15 19:38:18 2010
@@ -688,7 +688,7 @@
      * Return the alias for the given column.
      */
     private String getColumnAlias(Column col, PathJoins pj) {
-        return getColumnAlias(col.getName(), col.getTable(), pj);
+        return getColumnAlias(col.getIdentifier().getName(), col.getTable(), pj);
     }
 
     public String getColumnAlias(String col, Table table) {
@@ -703,7 +703,6 @@
      * Return the alias for the give column
      */
     public String getColumnAlias(Column col, Object path) {
-        String columnName = col.getName();
         Table table = col.getTable();
         String tableAlias = null;
         Iterator itr = getJoinIterator();
@@ -716,19 +715,19 @@
                     tableAlias = join.getAlias2();
                 if (tableAlias != null)
                     return new StringBuilder(tableAlias).append(".").
-                        append(columnName).toString();
+                        append(_dict.getNamingUtil().toDBName(col.getIdentifier())).toString();
             }
         }
         throw new InternalException("Can not resolve alias for field: " +
-            path.toString() + " mapped to column: " + columnName +
-            " table: "+table.getName());
+            path.toString() + " mapped to column: " + col.getIdentifier().getName() +
+            " table: "+table.getIdentifier().getName());
     }
 
     /**
      * Return the alias for the given column.
      */
     private String getColumnAlias(String col, Table table, PathJoins pj) {
-        return getTableAlias(table, pj).append(col).toString();
+        return getTableAlias(table, pj).append(_dict.getNamingUtil().toDBName(col)).toString();
     }
     
     private StringBuilder getTableAlias(Table table, PathJoins pj) {
@@ -1987,7 +1986,7 @@
             return -1;
 
         Integer i = null;
-        Object key = table.getFullName();
+        Object key = table.getFullIdentifier().getName();
         if (pj != null && pj.path() != null)
             key = new Key(pj.path().toString(), key);
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java Fri Jan 15 19:38:18 2010
@@ -29,6 +29,7 @@
 import java.util.Arrays;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
 import org.apache.openjpa.jdbc.schema.Index;
@@ -164,6 +165,7 @@
         supportsCascadeUpdateAction = false;
     }
 
+    @Override
     public int getJDBCType(int metaTypeCode, boolean lob) {
         switch (metaTypeCode) {
             // the default mapping for BYTE is a TINYINT, but Sybase's TINYINT
@@ -176,6 +178,7 @@
         }
     }
 
+    @Override
     public void setBigInteger(PreparedStatement stmnt, int idx, BigInteger val,
         Column col)
         throws SQLException {
@@ -185,11 +188,13 @@
         setObject(stmnt, idx, new BigDecimal(val), Types.BIGINT, col);
     }
 
+    @Override
     public String[] getAddForeignKeySQL(ForeignKey fk) {
         // Sybase has problems with adding foriegn keys via ALTER TABLE command
         return new String[0];
     }
 
+    @Override
     public String[] getCreateTableSQL(Table table) {
         if (!createIdentityColumn)
             return super.getCreateTableSQL(table);
@@ -230,9 +235,10 @@
         return new String[]{ buf.toString() };
     }
 
+    @Override
     protected String getDeclareColumnSQL(Column col, boolean alter) {
         StringBuilder buf = new StringBuilder();
-        buf.append(col).append(" ");
+        buf.append(getColumnDBName(col)).append(" ");
         buf.append(getTypeName(col));
 
         // can't add constraints to a column we're adding after table
@@ -255,13 +261,15 @@
         return buf.toString();
     }
 
+    @Override
     public String[] getDropColumnSQL(Column column) {
         // Sybase uses "ALTER TABLE DROP <COLUMN_NAME>" rather than the
         // usual "ALTER TABLE DROP COLUMN <COLUMN_NAME>"
         return new String[]{ "ALTER TABLE "
-            + getFullName(column.getTable(), false) + " DROP " + column };
+            + getFullName(column.getTable(), false) + " DROP " + getColumnDBName(column) };
     }
 
+    @Override
     public void refSchemaComponents(Table table) {
         // note that we use getColumns() rather than getting the column by name
         // because under some circumstances this method is called under the
@@ -269,10 +277,11 @@
         // that column
         Column[] cols = table.getColumns();
         for (int i = 0; i < cols.length; i++)
-            if (identityColumnName.equalsIgnoreCase(cols[i].getName()))
+            if (identityColumnName.equalsIgnoreCase(cols[i].getIdentifier().getName()))
                 cols[i].ref();
     }
 
+    @Override
     public void endConfiguration() {
         super.endConfiguration();
 
@@ -286,6 +295,7 @@
         }
     }
 
+    @Override
     public Connection decorate(Connection conn)
         throws SQLException {
         conn = super.decorate(conn);
@@ -320,10 +330,10 @@
     protected PrimaryKey newPrimaryKey(ResultSet pkMeta)
         throws SQLException {
         PrimaryKey pk = new PrimaryKey();
-        pk.setSchemaName(pkMeta.getString("table_owner"));
-        pk.setTableName(pkMeta.getString("table_name"));
-        pk.setColumnName(pkMeta.getString("column_name"));
-        pk.setName(pkMeta.getString("index_name"));
+        pk.setSchemaIdentifier(fromDBName(pkMeta.getString("table_owner"), DBIdentifierType.SCHEMA));
+        pk.setTableIdentifier(fromDBName(pkMeta.getString("table_name"), DBIdentifierType.TABLE));
+        pk.setColumnIdentifier(fromDBName(pkMeta.getString("column_name"), DBIdentifierType.COLUMN));
+        pk.setIdentifier(fromDBName(pkMeta.getString("index_name"), DBIdentifierType.CONSTRAINT));
         return pk;
     }
 
@@ -333,10 +343,10 @@
     protected Index newIndex(ResultSet idxMeta)
         throws SQLException {
         Index idx = new Index();
-        idx.setSchemaName(idxMeta.getString("table_owner"));
-        idx.setTableName(idxMeta.getString("table_name"));
-        idx.setColumnName(idxMeta.getString("column_name"));
-        idx.setName(idxMeta.getString("index_name"));
+        idx.setSchemaIdentifier(fromDBName(idxMeta.getString("table_owner"), DBIdentifierType.SCHEMA));
+        idx.setTableIdentifier(fromDBName(idxMeta.getString("table_name"), DBIdentifierType.TABLE));
+        idx.setColumnIdentifier(fromDBName(idxMeta.getString("column_name"), DBIdentifierType.COLUMN));
+        idx.setIdentifier(fromDBName(idxMeta.getString("index_name"), DBIdentifierType.INDEX));
         idx.setUnique(!idxMeta.getBoolean("non_unique"));
         return idx;
     }

Modified: openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties Fri Jan 15 19:38:18 2010
@@ -200,3 +200,7 @@
 connection-unwrap-failed: Unable to get underlying connection from pooled \
 	connection. Java version 6 and a version 4 capable JDBC driver \
 	or data source are minimum requirements to perform this operation.
+cannot-determine-identifier-case: Unable to determine the case to use for delimited \
+    identifiers.  The default value of "preserve" will be used.
+unknown-delim-support: Unable to determine whether delimited identifiers are supported. \
+    The use of delimiters will not be supported.

Added: openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/identifier/TestDBIdentifiers.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/identifier/TestDBIdentifiers.java?rev=899784&view=auto
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/identifier/TestDBIdentifiers.java (added)
+++ openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/identifier/TestDBIdentifiers.java Fri Jan 15 19:38:18 2010
@@ -0,0 +1,275 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.jdbc.sql.identifier;
+
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
+
+import junit.framework.TestCase;
+
+/**
+ * Test operations on DBIdentifier and QualifiedDBIdentifier.
+ *
+ */
+public class TestDBIdentifiers extends TestCase {
+
+    public void testSchemaOps() {
+        // Use a schema name with punctuation.  It will get normalized with
+        // delimiters.
+        QualifiedDBIdentifier p1 = QualifiedDBIdentifier.newPath(DBIdentifier.newSchema("my.schema"));
+        DBIdentifier s1 = DBIdentifier.newSchema("my.schema");
+        assertTrue(QualifiedDBIdentifier.equal(p1, s1));
+        assertEquals("\"my.schema\"", p1.getName());
+        assertEquals("\"my.schema\"", s1.getName());
+        assertEquals(p1.getType(), DBIdentifierType.SCHEMA);
+        assertEquals(s1.getType(), DBIdentifierType.SCHEMA);
+        assertFalse(s1 instanceof QualifiedDBIdentifier);
+
+        QualifiedDBIdentifier p2 = QualifiedDBIdentifier.newPath(DBIdentifier.newSchema("SCHEMA"));
+        DBIdentifier s2 = DBIdentifier.newSchema("SCHEMA2");
+        assertFalse(QualifiedDBIdentifier.equal(p2, s2));
+        assertEquals("SCHEMA", p2.getName());
+        assertEquals("SCHEMA2", s2.getName());
+        assertEquals(p2.getType(), DBIdentifierType.SCHEMA);
+        assertEquals(s2.getType(), DBIdentifierType.SCHEMA);
+        assertTrue(p2 instanceof QualifiedDBIdentifier);
+        assertFalse(s2 instanceof QualifiedDBIdentifier);
+    }
+
+    public void testTableOps() {
+        DBIdentifier name = DBIdentifier.newTable("table");
+        assertEquals("table", name.getName());
+        
+        // Assert name is normalized using delimiters
+        name = DBIdentifier.newTable("my table");
+        assertEquals("\"my table\"", name.getName());
+        // Assert name does not get split into multiple identifiers
+        DBIdentifier[] names = QualifiedDBIdentifier.splitPath(name);
+        assertTableEquals(names, null, "\"my table\"");
+        
+        // Split a delimited schema qualified table name
+        name = DBIdentifier.newTable("\"my.schema\".\"my.table\"");
+        assertEquals("\"my.schema\".\"my.table\"", name.getName());
+        names = QualifiedDBIdentifier.splitPath(name);
+        assertTableEquals(names, "\"my.schema\"", "\"my.table\"");
+        
+        // Split a non-delimited schema qualified table name
+        name = DBIdentifier.newTable("my_schema.my_table");
+        assertEquals("my_schema.my_table", name.getName());
+        names = QualifiedDBIdentifier.splitPath(name);
+        assertTableEquals(names, "my_schema", "my_table");
+
+        // Use Qualified Identifier to create a compound normalized schema and table name
+        DBIdentifier tName = DBIdentifier.newTable("my table");
+        DBIdentifier sName = DBIdentifier.newSchema("my schema");
+        QualifiedDBIdentifier path = QualifiedDBIdentifier.newPath(sName, tName);
+        assertEquals("\"my schema\".\"my table\"", path.getName());
+        assertEquals(tName.getName(), path.getBaseName());
+        assertEquals(sName.getName(), path.getSchemaName().getName());
+        
+        // Use Qualified Identifier to create a compound non-normalized schema and table name
+        tName = DBIdentifier.newTable("my_table");
+        sName = DBIdentifier.newSchema("my_schema");
+        path = QualifiedDBIdentifier.newPath(sName, tName);
+        assertEquals("my_schema.my_table", path.getName());
+        assertEquals(tName.getName(), path.getBaseName());
+        assertEquals(sName.getName(), path.getSchemaName().getName());
+        
+        QualifiedDBIdentifier p1 = QualifiedDBIdentifier.newPath(DBIdentifier.newSchema("schema"), 
+            DBIdentifier.newTable("my table"));
+        QualifiedDBIdentifier p2 = QualifiedDBIdentifier.newPath(DBIdentifier.newSchema("schema"), 
+            DBIdentifier.newTable("\"my table\""));        
+        QualifiedDBIdentifier p3 = QualifiedDBIdentifier.newPath(DBIdentifier.newSchema("schema"), 
+            DBIdentifier.newTable("my_table"));
+        assertTrue(p1.equals(p2));
+        assertFalse(p1.equals(p3));
+        assertFalse(p2.equals(p3));
+        assertFalse(p1.equals(null));
+        assertFalse(p1.equals(DBIdentifier.NULL));
+    }
+    
+    public void testColumnOps() {
+        
+        DBIdentifier c0 = DBIdentifier.newColumn("\"col.1\"");
+        assertEquals("\"col.1\"", c0.getName());
+        assertTrue (c0 instanceof QualifiedDBIdentifier);
+        assertEquals(c0.getType(), DBIdentifierType.COLUMN);
+        
+        // Test 3 part column name with mixed delimiting
+        DBIdentifier c1 = DBIdentifier.newColumn("column 1");
+        DBIdentifier t1 = DBIdentifier.newTable("table");
+        DBIdentifier s1 = DBIdentifier.newSchema("\"my schema\"");
+        
+        DBIdentifier p1 = QualifiedDBIdentifier.newPath(s1, t1, c1);
+        assertEquals("\"my schema\".table.\"column 1\"", p1.getName());
+        
+        DBIdentifier c2 = DBIdentifier.newColumn("\"column_2\"");
+        // Create a new table name without delimiters, but switch on the
+        // delimit flag.  Otherwise, it will get parsed as a multi-part name.
+        DBIdentifier t2 = DBIdentifier.newTable("table.2", true);
+        DBIdentifier p2 = QualifiedDBIdentifier.newPath(t2, c2);
+        assertEquals("\"table.2\".\"column_2\"", p2.getName());
+        
+    }
+    
+    public void testDBIdentifierOps() {
+        
+        // Test truncate
+        DBIdentifier n1 = DBIdentifier.newColumn("abcdefgh");
+        n1 = DBIdentifier.truncate(n1,6);
+        assertEquals("ab", n1.getName());
+
+        // Test truncate with delimiters
+        DBIdentifier n2 = DBIdentifier.newColumn("\"abcd efgh\"");
+        n2 = DBIdentifier.truncate(n2,3);
+        assertEquals("\"abcd e\"", n2.getName());
+
+        // Test append
+        DBIdentifier n3 = DBIdentifier.newColumn("abcdefgh");
+        n3 = DBIdentifier.append(n3,"ijk");
+        assertEquals("abcdefghijk", n3.getName());
+
+        // Test append with the base name delimited
+        DBIdentifier n4 = DBIdentifier.newColumn("\"abcd efgh\"");
+        n4 = DBIdentifier.append(n4, "i k");
+        assertEquals("\"abcd efghi k\"", n4.getName());
+        
+        // Test append with both names delimited
+        DBIdentifier n5 = DBIdentifier.newColumn("\"abcd efgh\"");
+        n5 = DBIdentifier.append(n5, "\"i k\"");
+        assertEquals("\"abcd efghi k\"", n5.getName());
+
+        // Test clone
+        DBIdentifier cn1 = DBIdentifier.newTable("sch.tbl");
+        DBIdentifier cn2 = cn1.clone();
+        assertFalse(cn1 == cn2);
+        assertEquals(cn1.getName(), cn2.getName());
+        assertEquals(cn1, cn2);
+        
+        DBIdentifier tbl = DBIdentifier.newTable("tbl");
+        DBIdentifier sch = DBIdentifier.newSchema("sch");
+        QualifiedDBIdentifier path = QualifiedDBIdentifier.newPath(sch, tbl);
+        QualifiedDBIdentifier path2 = path.clone();
+        assertEquals(tbl.getName(), path.getBaseName());
+        assertEquals(sch, path.getSchemaName());
+        assertEquals(tbl.getName(), path2.getBaseName());
+        assertEquals(sch, path2.getSchemaName());
+        
+        DBIdentifier tbl2 = DBIdentifier.newTable("tbl2");
+        DBIdentifier sch2 = DBIdentifier.newSchema("sch2");
+        DBIdentifier col = DBIdentifier.newColumn("col");
+        QualifiedDBIdentifier cpath = QualifiedDBIdentifier.newPath(sch2, tbl2, col);
+        QualifiedDBIdentifier cpath2 = cpath.clone();
+        assertEquals(col.getName(), cpath2.getBaseName());
+        assertEquals(sch2, cpath2.getSchemaName());
+        assertEquals(tbl2, cpath2.getObjectTableName());
+        
+        // Test delimit operation on create
+        DBIdentifier dName = DBIdentifier.newColumn("\"ITEMNAME\"", true);
+        assertEquals("\"ITEMNAME\"", dName.getName());
+        
+    }
+    
+    public void testPathOps() {
+        
+        // Test equals operator with case insensitive names
+        QualifiedDBIdentifier p1 = QualifiedDBIdentifier.newPath(DBIdentifier.newTable("MyTable"), 
+            DBIdentifier.newColumn("mycol"));
+        QualifiedDBIdentifier p2 = QualifiedDBIdentifier.newPath(DBIdentifier.newTable("MYTABLE"), 
+            DBIdentifier.newColumn("MYCOL"));
+        assertTrue(QualifiedDBIdentifier.equal(p1, p1));
+        
+        // Test equals operator with delimited, case sensitive names
+        QualifiedDBIdentifier p3 = QualifiedDBIdentifier.newPath(DBIdentifier.newTable("\"MyTable\""), 
+            DBIdentifier.newColumn("\"mycol\""));
+        QualifiedDBIdentifier p4 = QualifiedDBIdentifier.newPath(DBIdentifier.newTable("MYTABLE"), 
+            DBIdentifier.newColumn("MYCOL"));
+        QualifiedDBIdentifier p5 = QualifiedDBIdentifier.newPath(DBIdentifier.newTable("\"MyTable\""), 
+            DBIdentifier.newColumn("\"mycol\""));
+        assertFalse(QualifiedDBIdentifier.equal(p3, p4));
+        assertTrue(QualifiedDBIdentifier.equal(p3, p5));
+        
+        // Test setPath method
+        QualifiedDBIdentifier p6 = QualifiedDBIdentifier.newPath(DBIdentifier.newTable("MyTable"), 
+            DBIdentifier.newColumn("mycol"));
+        DBIdentifier n1 = DBIdentifier.newSchema("Schema_1");
+        DBIdentifier n2 = DBIdentifier.newTable("Table_1");
+        DBIdentifier n3 = DBIdentifier.newColumn("Column_1");
+        p6.setPath(n1);
+        assertEquals("Schema_1", n1.getName());
+        assertEquals(n1.getType(), DBIdentifierType.SCHEMA);
+        
+        p6.setPath(n2);
+        assertEquals("Table_1", n2.getName());
+        assertEquals(n2.getType(), DBIdentifierType.TABLE);
+
+        p6.setPath(n3);
+        assertEquals("Column_1", n3.getName());
+        assertEquals(n3.getType(), DBIdentifierType.COLUMN);
+
+        // Test isDelimited method
+        QualifiedDBIdentifier p7 = QualifiedDBIdentifier.newPath(DBIdentifier.newTable("MyTable"), 
+            DBIdentifier.newColumn("mycol"));
+        assertFalse(p7.isDelimited());
+        // All identifiers not delimited
+        QualifiedDBIdentifier p8 = QualifiedDBIdentifier.newPath(DBIdentifier.newTable("My Table"), 
+            DBIdentifier.newColumn("mycol"));
+        assertFalse(p8.isDelimited());
+        // All identifiers delimited by default
+        QualifiedDBIdentifier p9 = QualifiedDBIdentifier.newPath(DBIdentifier.newTable("My Table"), 
+            DBIdentifier.newColumn("my col"));
+        assertTrue(p9.isDelimited());
+
+        // All identifiers specifically delimited
+        QualifiedDBIdentifier p10 = QualifiedDBIdentifier.newPath(DBIdentifier.newTable("\"MyTable\""), 
+            DBIdentifier.newColumn("\"my col\""));
+        assertTrue(p10.isDelimited());
+
+        // All identifiers specifically delimited sch + tbl + col
+        QualifiedDBIdentifier p11 = QualifiedDBIdentifier.newPath(DBIdentifier.newSchema("\"MySchema\""), 
+            DBIdentifier.newTable("\"my tbl\""));
+        assertTrue(p11.isDelimited());
+
+        // Table identifier not delimited
+        QualifiedDBIdentifier p12 = QualifiedDBIdentifier.newPath(DBIdentifier.newSchema("\"MySchema\""), 
+            DBIdentifier.newTable("mytbl"), 
+            DBIdentifier.newColumn("\"my col\""));
+        assertFalse(p12.isDelimited());
+
+    }
+
+    private void assertTableEquals(DBIdentifier[] names, String schema,
+        String table) {
+        assertNotNull(names);
+        assertEquals((schema == null ? 1 : 2), names.length);
+        int idx = 0;
+        if (schema != null) {
+            assertEquals(DBIdentifierType.SCHEMA, names[idx].getType());
+            assertEquals(names[idx].getName(), schema);
+            idx++;
+        } else {
+            assertEquals(DBIdentifierType.TABLE, names[idx].getType());
+            String path = QualifiedDBIdentifier.join(DBIdentifier.newSchema(schema), 
+                DBIdentifier.newTable(table));
+            assertEquals(names[idx].getName(), path);
+        }
+    }
+    
+}

Propchange: openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/identifier/TestDBIdentifiers.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml Fri Jan 15 19:38:18 2010
@@ -94,6 +94,7 @@
                 <include name="**/inheritance/serializable/*.class" />
                 <!--  include files from orm.xml -->
                 <include name="**/xml/*.class" />
+				<exclude name="**/persistence/delimited/identifiers/xml/*.class"/>
                 <exclude name="**/Test*.class" />
             </fileset>
             <config log="DefaultLevel=${openjpa.loglevel}" />
@@ -107,5 +108,15 @@
             </fileset>
             <config log="DefaultLevel=${openjpa.loglevel}" />
         </openjpac>
+		<!-- Enhance delimited identifiers XML-based entities separately -->
+        <openjpac>
+            <config propertiesFile="${project.build.testOutputDirectory}/META-INF/delim_persistence.xml" />
+            <classpath refid="cp" />
+            <fileset dir="${project.build.testOutputDirectory}">
+				<include name="**/persistence/delimited/identifiers/xml/*.class"/>
+				<exclude name="**/persistence/delimited/identifiers/xml/Test*.class"/>
+            </fileset>
+            <config log="DefaultLevel=${openjpa.loglevel}" />
+        </openjpac>
     </target>
 </project>



Mime
View raw message