empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r690298 - in /incubator/empire-db/trunk/core/Empire-db: ./ src/org/apache/empire/db/ src/org/apache/empire/db/hsql/ src/org/apache/empire/db/mysql/ src/org/apache/empire/db/oracle/ src/org/apache/empire/db/sqlserver/ src/org/apache/empire/xml/
Date Fri, 29 Aug 2008 15:25:36 GMT
Author: doebele
Date: Fri Aug 29 08:25:33 2008
New Revision: 690298

URL: http://svn.apache.org/viewvc?rev=690298&view=rev
Log:
EMPIREDB-6

Modified:
    incubator/empire-db/trunk/core/Empire-db/CHANGELOG.txt
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumn.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumnExpr.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabase.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBTable.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/xml/XMLUtil.java

Modified: incubator/empire-db/trunk/core/Empire-db/CHANGELOG.txt
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/CHANGELOG.txt?rev=690298&r1=690297&r2=690298&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/CHANGELOG.txt (original)
+++ incubator/empire-db/trunk/core/Empire-db/CHANGELOG.txt Fri Aug 29 08:25:33 2008
@@ -2,6 +2,11 @@
 Copyright 2008 The Apache Software Foundation
 
 --------------
+Release 2.0.4:
+--------------
+EMPIREDB-6:	Support for spaces and dashes in table, view and column names added.
+
+--------------
 Release 2.0.3:
 --------------
 EMPIREDB-5: Added missing ASF headers. See JIRA for further information.

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumn.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumn.java?rev=690298&r1=690297&r2=690298&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumn.java (original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumn.java Fri Aug
29 08:25:33 2008
@@ -51,8 +51,6 @@
     protected final String     name;
     protected String           comment;
     
-    protected boolean          useQuotes = false;
-    
     /**
      * Constructs a DBColumn object and set the specified parameters to this object.
      *
@@ -87,15 +85,6 @@
      */
     public abstract boolean isReadOnly();
 
-    /**
-     * @return Returns true if the column will be surrounded by quotes.
-     */
-    public boolean isUseQuotes()
-    {
-        return useQuotes;
-    }
-
-
     public abstract boolean checkValue(Object value);
 
     @Override
@@ -129,19 +118,15 @@
     @Override
     public void addSQL(StringBuilder buf, long context)
     { 
-        // Use alias if no select
-        if ((context & CTX_FULLNAME) != 0 && rowset != null)
-        { // Fully Qualified Name
+        // Append rowset alias
+        if ((context & CTX_FULLNAME) != 0)
+        {   // Fully Qualified Name
             buf.append(rowset.getAlias());
             buf.append(".");
         }
-        // Use Quotes
-        if (useQuotes)
-            buf.append("\"");
-        buf.append(name);
-        // Use Quotes
-        if (useQuotes)
-            buf.append("\"");
+        // Append the name
+        DBDatabaseDriver driver = getDatabaseDriver();
+        driver.appendElementName(buf, name);
     }
 
     /**
@@ -261,14 +246,5 @@
     {
         this.comment = comment;
     }
-
-    /**
-     * If set to TRUE, the column will be surronded by quotation marks in the SQL.
-     * 
-     * @param useQuotes flag to set quotes
-     */
-    public void setUseQuotes(boolean useQuotes)
-    {
-        this.useQuotes = useQuotes;
-    }    
+    
 }
\ No newline at end of file

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumnExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumnExpr.java?rev=690298&r1=690297&r2=690298&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumnExpr.java (original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumnExpr.java Fri
Aug 29 08:25:33 2008
@@ -56,6 +56,16 @@
     protected Attributes  attributes = null;
     protected Options     options = null;
     protected String      beanPropertyName = null;
+    
+    /**
+     * returns the Database driver or null if the Expression is not attached to an open database<BR/>
+     * This function is intended for convenience only.
+     */
+    protected final DBDatabaseDriver getDatabaseDriver()
+    {
+        DBDatabase db = getDatabase();
+        return (db!=null) ? db.getDriver() : null;
+    }
 
     /**
      * Returns the data type of this column expression.

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabase.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabase.java?rev=690298&r1=690297&r2=690298&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabase.java (original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabase.java Fri
Aug 29 08:25:33 2008
@@ -284,15 +284,23 @@
      */
     public void appendQualifiedName(StringBuilder buf, String name)
     {
+        // Check driver
+        if (driver==null)
+        {   // No driver attached!
+            error(Errors.ObjectNotValid, name);
+            buf.append(name);
+            return;
+        }
         // Schema
-        if (schema != null && driver!=null)
+        if (schema != null)
         { // Add Schema
             buf.append(schema);
             buf.append(".");
         }
-        buf.append(name);
+        // Append the name
+        driver.appendElementName(buf, name);
         // Database Link
-        if (linkName!=null && driver!=null)
+        if (linkName!=null)
         { // Add Schema
             buf.append(driver.getSQLPhrase(DBDatabaseDriver.SQL_DATABASE_LINK));
             buf.append(linkName);

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java?rev=690298&r1=690297&r2=690298&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
(original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
Fri Aug 29 08:25:33 2008
@@ -45,14 +45,16 @@
 {
     // sql-phrases
     public static final int SQL_NULL_VALUE       = 1;   // Oracle: null
-    public static final int SQL_RENAME_COLUMN    = 2;   // Oracle: AS
-    public static final int SQL_PARAMETER        = 3;   // Oracle: ?
-    public static final int SQL_CONCAT_EXPR      = 4;   // Oracle: ||
-    public static final int SQL_RENAME_TABLE     = 5;   // Oracle: AS
-    public static final int SQL_DATABASE_LINK    = 6;   // Oracle: @
+    public static final int SQL_PARAMETER        = 2;   // Oracle: ?
+    public static final int SQL_RENAME_TABLE     = 3;   // Oracle: AS
+    public static final int SQL_RENAME_COLUMN    = 4;   // Oracle: AS
+    public static final int SQL_DATABASE_LINK    = 5;   // Oracle: @
+    public static final int SQL_QUOTES_OPEN      = 6;   // Oracle: "; MSSQL: [
+    public static final int SQL_QUOTES_CLOSE     = 7;   // Oracle: "; MSSQL: ]
+    public static final int SQL_CONCAT_EXPR      = 8;   // Oracle: ||
     // data types
-    public static final int SQL_BOOLEAN_TRUE     = 10;  // Oracle: "'Y'"      SQL: "1"
-    public static final int SQL_BOOLEAN_FALSE    = 11;  // Oracle: "'N'"      SQL: "0"
+    public static final int SQL_BOOLEAN_TRUE     = 10;  // Oracle: "'Y'"; MSSQL: "1"
+    public static final int SQL_BOOLEAN_FALSE    = 11;  // Oracle: "'N'"; MSSQL: "0"
     public static final int SQL_CURRENT_DATE     = 20;  // Oracle: "sysdate"
     public static final int SQL_DATE_PATTERN     = 21;  // "yyyy.MM.dd"
     public static final int SQL_DATE_TEMPLATE    = 22;  // Oracle: "TO_DATE('{0}', 'YYYY-MM-DD')"
@@ -81,9 +83,9 @@
     public static final int SQL_FUNC_FLOOR       = 123; // Oracle: floor(?)
     public static final int SQL_FUNC_CEILING     = 124; // Oracle: ceil(?)
     // Date
-    public static final int SQL_FUNC_DAY         = 132; // MS SQL month(?)
-    public static final int SQL_FUNC_MONTH       = 133; // MS SQL month(?)
-    public static final int SQL_FUNC_YEAR        = 134; // MS SQL year (?)
+    public static final int SQL_FUNC_DAY         = 132; // MSSQL: month(?)
+    public static final int SQL_FUNC_MONTH       = 133; // MSSQL: month(?)
+    public static final int SQL_FUNC_YEAR        = 134; // MSSQL: year (?)
     // Aggregation
     public static final int SQL_FUNC_SUM         = 140; // Oracle: sum(?)
     public static final int SQL_FUNC_COUNT       = 141; // Oracle: count(?)
@@ -206,6 +208,37 @@
      * @return true if the features is supported or false otherwise
      */
     public abstract boolean isSupported(DBDriverFeature type);
+
+    /**
+     * Checks wether a table or column name needs to be quoted or not<BR/>
+     * By default names containing a "-", "+" or " " require quoting.<BR/>
+     * Overrides this function to add database specific keywords like "user" or "count" 

+     */
+    protected boolean quoteElementName(String name)
+    {
+        // Check for any of the characters - +  and space
+        return (name.indexOf(' ')>0)
+            || (name.indexOf('-')>0)
+            || (name.indexOf('+')>0); 
+    }
+
+    /**
+     * Appends a table, view or column name to an SQL phrase. 
+     * @param sql the StringBuilder containing the SQL phrase.
+     * @param name the name of the object (table, view or column)
+     */
+    public void appendElementName(StringBuilder sql, String name)
+    {
+        // Check whether to use quotes or not
+        boolean useQuotes = quoteElementName(name);
+        if (useQuotes)
+            sql.append(getSQLPhrase(DBDatabaseDriver.SQL_QUOTES_OPEN));
+        // Append Name
+        sql.append(name);
+        // End Quotes
+        if (useQuotes)
+            sql.append(getSQLPhrase(DBDatabaseDriver.SQL_QUOTES_CLOSE));
+    }
     
     /**
      * Returns an sql phrase template for this database system.<br>

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBTable.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBTable.java?rev=690298&r1=690297&r2=690298&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBTable.java (original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBTable.java Fri Aug
29 08:25:33 2008
@@ -278,15 +278,12 @@
     @Override
     public void addSQL(StringBuilder buf, long context)
     {
-        if ((context & CTX_FULLNAME)!=0 && db!=null)
-        {   // Add Schema
-            db.appendQualifiedName(buf, name);
+        // Append Name
+        if ((context & CTX_NAME|CTX_FULLNAME)!=0)
+        {    // Add Schema
+             db.appendQualifiedName(buf, name);
         }
-        else
-        {   // Simple Name only
-            buf.append(name);
-        }
-        // Tables and Views?
+        // Append Alias
         if ((context & CTX_ALIAS)!=0 && alias!=null)
         {    // append alias
              buf.append(getRenameTablePhrase());

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java?rev=690298&r1=690297&r2=690298&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
(original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
Fri Aug 29 08:25:33 2008
@@ -113,11 +113,13 @@
         {
             // sql-phrases
             case SQL_NULL_VALUE:        return "null";
-            case SQL_RENAME_COLUMN:     return " AS ";
             case SQL_PARAMETER:         return " ? ";
-            case SQL_CONCAT_EXPR:       return "concat(?, {0})"; // " + " leads to problems
if operands are case when statements that return empty string 
             case SQL_RENAME_TABLE:      return " ";
+            case SQL_RENAME_COLUMN:     return " AS ";
             case SQL_DATABASE_LINK:     return "@";
+            case SQL_QUOTES_OPEN:       return "\"";
+            case SQL_QUOTES_CLOSE:      return "\"";
+            case SQL_CONCAT_EXPR:       return "concat(?, {0})"; // " + " leads to problems
if operands are case when statements that return empty string 
             // data types
             case SQL_BOOLEAN_TRUE:      return String.valueOf(Boolean.TRUE);
             case SQL_BOOLEAN_FALSE:     return String.valueOf(Boolean.FALSE);
@@ -395,7 +397,7 @@
         sql.append(t.getName());
         sql.append(" --\r\n");
         sql.append("CREATE TABLE ");
-        sql.append(t.getFullName());
+        t.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append(" (");
         boolean addSeparator = false;
         Iterator<DBColumn> columns = t.getColumns().iterator();
@@ -412,7 +414,7 @@
         if (pk != null)
         { // add the primary key
             sql.append(",\r\n CONSTRAINT ");
-            sql.append(pk.getName());
+            appendElementName(sql, pk.getName());
             sql.append(" PRIMARY KEY (");
             addSeparator = false;
             // columns
@@ -420,7 +422,7 @@
             for (int i = 0; i < keyColumns.length; i++)
             {
                 sql.append((addSeparator) ? ", " : "");
-                sql.append(keyColumns[i].getName());
+                keyColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                 addSeparator = true;
             }
             sql.append(")");
@@ -440,9 +442,9 @@
             // Cretae Index
             sql.setLength(0);
             sql.append((idx.getType() == DBIndex.UNIQUE) ? "CREATE UNIQUE INDEX " : "CREATE
INDEX ");
-            sql.append(idx.getFullName());
+            appendElementName(sql, idx.getName());
             sql.append(" ON ");
-            sql.append(t.getFullName());
+            t.addSQL(sql, DBExpr.CTX_FULLNAME);
             sql.append(" (");
             addSeparator = false;
 
@@ -451,7 +453,7 @@
             for (int i = 0; i < idxColumns.length; i++)
             {
                 sql.append((addSeparator) ? ", " : "");
-                sql.append(idxColumns[i].getName());
+                idxColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                 addSeparator = true;
             }
             sql.append(")");
@@ -471,7 +473,8 @@
      */
     private boolean appendColumnDesc(DBTableColumn c, StringBuilder sql)
     {
-        sql.append(c.getName());
+        // Append name
+        c.addSQL(sql, DBExpr.CTX_NAME);
         sql.append(" ");
         switch (c.getDataType())
         {
@@ -566,9 +569,9 @@
                 sql.append(r.getName());
                 sql.append(" --\r\n");
                 sql.append("ALTER TABLE ");
-                sql.append(sourceTable.getFullName());
+                sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
                 sql.append(" ADD CONSTRAINT ");
-                sql.append(r.getFullName());
+                appendElementName(sql, r.getName());
                 sql.append(" FOREIGN KEY (");
                 // Source Names
                 boolean addSeparator = false;
@@ -576,19 +579,19 @@
                 for (int i = 0; i < refs.length; i++)
                 {
                     sql.append((addSeparator) ? ", " : "");
-                    sql.append(refs[i].getSourceColumn().getName());
+                    refs[i].getSourceColumn().addSQL(sql, DBExpr.CTX_NAME);
                     addSeparator = true;
                 }
                 // References
                 sql.append(") REFERENCES ");
-                sql.append(targetTable.getFullName());
+                targetTable.addSQL(sql, DBExpr.CTX_FULLNAME);
                 sql.append(" (");
                 // Target Names
                 addSeparator = false;
                 for (int i = 0; i < refs.length; i++)
                 {
                     sql.append((addSeparator) ? ", " : "");
-                    sql.append(refs[i].getTargetColumn().getName());
+                    refs[i].getTargetColumn().addSQL(sql, DBExpr.CTX_NAME);
                     addSeparator = true;
                 }
                 // done
@@ -607,9 +610,9 @@
                 sql.append(r.getName());
                 sql.append(" --\r\n");
                 sql.append("ALTER TABLE ");
-                sql.append(sourceTable.getFullName());
+                sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
                 sql.append(" DROP CONSTRAINT ");
-                sql.append(r.getName());
+                appendElementName(sql, r.getName());
                 // done
                 return script.addStmt(sql.toString());
             }
@@ -630,7 +633,7 @@
     {
         StringBuilder sql = new StringBuilder();
         sql.append("ALTER TABLE ");
-        sql.append(col.getRowSet().getName());
+        col.getRowSet().addSQL(sql, DBExpr.CTX_FULLNAME);
         switch(type)
         {
             case CREATE:
@@ -673,13 +676,14 @@
         // Build String
         StringBuilder sql = new StringBuilder();
         sql.append( "CREATE VIEW ");
-        sql.append( v.getName() );
+        v.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append( " (" );
         boolean addSeparator = false;
         for(DBColumn c : v.getColumns())
         {
             if (addSeparator)
                 sql.append(", ");
+            // Add Column name
             c.addSQL(sql, DBExpr.CTX_NAME);
             // next
             addSeparator = true;
@@ -704,7 +708,7 @@
         sql.append("DROP ");
         sql.append(objType);
         sql.append(" ");
-        sql.append(name);
+        appendElementName(sql, name);
         // Done
         return script.addStmt(sql);
     }

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java?rev=690298&r1=690297&r2=690298&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
(original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
Fri Aug 29 08:25:33 2008
@@ -203,11 +203,13 @@
         {
             // sql-phrases
             case SQL_NULL_VALUE:              return "null";
-            case SQL_RENAME_COLUMN:           return " AS ";
             case SQL_PARAMETER:               return " ? ";
-            case SQL_CONCAT_EXPR:             return "concat(?, {0})";
             case SQL_RENAME_TABLE:            return " ";
+            case SQL_RENAME_COLUMN:           return " AS ";
             case SQL_DATABASE_LINK:           return "@";
+            case SQL_QUOTES_OPEN:             return "\"";
+            case SQL_QUOTES_CLOSE:            return "\"";
+            case SQL_CONCAT_EXPR:             return "concat(?, {0})";
             // data types
             case SQL_BOOLEAN_TRUE:            return "1";
             case SQL_BOOLEAN_FALSE:           return "0";
@@ -445,7 +447,7 @@
         sql.append(t.getName());
         sql.append(" --\r\n");
         sql.append("CREATE TABLE ");
-        sql.append(t.getFullName());
+        t.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append(" (");
         boolean addSeparator = false;
         Iterator<DBColumn> columns = t.getColumns().iterator();
@@ -468,7 +470,7 @@
             for (int i = 0; i < keyColumns.length; i++)
             {
                 sql.append((addSeparator) ? ", " : "");
-                sql.append(keyColumns[i].getName());
+                keyColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                 addSeparator = true;
             }
             sql.append(")");
@@ -496,9 +498,9 @@
             // Cretae Index
             sql.setLength(0);
             sql.append((idx.getType() == DBIndex.UNIQUE) ? "CREATE UNIQUE INDEX " : "CREATE
INDEX ");
-            sql.append(idx.getFullName());
+            appendElementName(sql, idx.getName());
             sql.append(" ON ");
-            sql.append(t.getFullName());
+            t.addSQL(sql, DBExpr.CTX_FULLNAME);
             sql.append(" (");
             addSeparator = false;
 
@@ -507,7 +509,7 @@
             for (int i = 0; i < idxColumns.length; i++)
             {
                 sql.append((addSeparator) ? ", " : "");
-                sql.append(idxColumns[i].getName());
+                idxColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                 addSeparator = true;
             }
             sql.append(")");
@@ -527,7 +529,8 @@
      */
     private boolean appendColumnDesc(DBTableColumn c, StringBuilder sql)
     {
-        sql.append(c.getName());
+        // Append name
+        c.addSQL(sql, DBExpr.CTX_NAME);
         sql.append(" ");
         switch (c.getDataType())
         {
@@ -633,9 +636,9 @@
         sql.append(r.getName());
         sql.append(" --\r\n");
         sql.append("ALTER TABLE ");
-        sql.append(sourceTable.getFullName());
+        sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append(" ADD CONSTRAINT ");
-        sql.append(r.getFullName());
+        appendElementName(sql, r.getName());
         sql.append(" FOREIGN KEY (");
         // Source Names
         boolean addSeparator = false;
@@ -643,19 +646,19 @@
         for (int i = 0; i < refs.length; i++)
         {
             sql.append((addSeparator) ? ", " : "");
-            sql.append(refs[i].getSourceColumn().getName());
+            refs[i].getSourceColumn().addSQL(sql, DBExpr.CTX_NAME);
             addSeparator = true;
         }
         // References
         sql.append(") REFERENCES ");
-        sql.append(targetTable.getFullName());
+        targetTable.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append(" (");
         // Target Names
         addSeparator = false;
         for (int i = 0; i < refs.length; i++)
         {
             sql.append((addSeparator) ? ", " : "");
-            sql.append(refs[i].getTargetColumn().getName());
+            refs[i].getTargetColumn().addSQL(sql, DBExpr.CTX_NAME);
             addSeparator = true;
         }
         // done
@@ -677,7 +680,7 @@
     {
         StringBuilder sql = new StringBuilder();
         sql.append("ALTER TABLE ");
-        sql.append(col.getRowSet().getName());
+        col.getRowSet().addSQL(sql, DBExpr.CTX_FULLNAME);
         switch(type)
         {
             case CREATE:
@@ -720,14 +723,15 @@
         // Build String
         StringBuilder sql = new StringBuilder();
         sql.append( "CREATE VIEW ");
-        sql.append( v.getName() );
+        v.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append( " (" );
         boolean addSeparator = false;
         for(DBColumn c : v.getColumns())
         {
             if (addSeparator)
                 sql.append(", ");
-            sql.append(c.getName());
+            // Add Column name
+            c.addSQL(sql, DBExpr.CTX_NAME);
             // next
             addSeparator = true;
         }
@@ -751,7 +755,7 @@
         sql.append("DROP ");
         sql.append(objType);
         sql.append(" ");
-        sql.append(name);
+        appendElementName(sql, name);
         return script.addStmt(sql);
     }
 

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java?rev=690298&r1=690297&r2=690298&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
(original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
Fri Aug 29 08:25:33 2008
@@ -125,11 +125,13 @@
         {
             // sql-phrases
             case SQL_NULL_VALUE:                return "null";
-            case SQL_RENAME_COLUMN:             return " AS ";
             case SQL_PARAMETER:                 return " ? ";
-            case SQL_CONCAT_EXPR:               return " || ";
             case SQL_RENAME_TABLE:              return " ";
+            case SQL_RENAME_COLUMN:             return " AS ";
             case SQL_DATABASE_LINK:             return "@";
+            case SQL_QUOTES_OPEN:               return "\"";
+            case SQL_QUOTES_CLOSE:              return "\"";
+            case SQL_CONCAT_EXPR:               return " || ";
             // data types
             case SQL_BOOLEAN_TRUE:              return (booleanType==BooleanType.CHAR) ?
"'Y'" : "1";
             case SQL_BOOLEAN_FALSE:             return (booleanType==BooleanType.CHAR) ?
"'N'" : "0";
@@ -477,7 +479,7 @@
         sql.append(t.getName());
         sql.append(" --\r\n");
         sql.append("CREATE TABLE ");
-        sql.append(t.getFullName());
+        t.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append(" (");
         boolean addSeparator = false;
         Iterator<DBColumn> columns = t.getColumns().iterator();
@@ -494,7 +496,7 @@
         if (pk != null)
         { // add the primary key
             sql.append(",\r\n CONSTRAINT ");
-            sql.append(pk.getName());
+            appendElementName(sql, pk.getName());
             sql.append(" PRIMARY KEY (");
             addSeparator = false;
             // columns
@@ -502,7 +504,7 @@
             for (int i = 0; i < keyColumns.length; i++)
             {
                 sql.append((addSeparator) ? ", " : "");
-                sql.append(keyColumns[i].getName());
+                keyColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                 addSeparator = true;
             }
             sql.append(")");
@@ -523,9 +525,9 @@
             // Cretae Index
             sql.setLength(0);
             sql.append((idx.getType() == DBIndex.UNIQUE) ? "CREATE UNIQUE INDEX " : "CREATE
INDEX ");
-            sql.append(idx.getFullName());
+            appendElementName(sql, idx.getName());
             sql.append(" ON ");
-            sql.append(t.getFullName());
+            t.addSQL(sql, DBExpr.CTX_FULLNAME);
             sql.append(" (");
             addSeparator = false;
 
@@ -534,7 +536,7 @@
             for (int i = 0; i < idxColumns.length; i++)
             {
                 sql.append((addSeparator) ? ", " : "");
-                sql.append(idxColumns[i].getName());
+                idxColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                 sql.append("");
                 addSeparator = true;
             }
@@ -544,14 +546,14 @@
                 return false;
         }
         // add Comments
-        createComment(db, "TABLE", t.getFullName(), t.getComment(), script);
+        createComment(db, "TABLE", t, t.getComment(), script);
         columns = t.getColumns().iterator();
         while (columns.hasNext())
         {
             DBColumn c = columns.next();
             String com = c.getComment();
             if (com != null)
-                createComment(db, "COLUMN", c.getFullName(), com, script);
+                createComment(db, "COLUMN", c, com, script);
         }
         // done
         return success();
@@ -565,7 +567,8 @@
      */
     private boolean appendColumnDesc(DBTableColumn c, StringBuilder sql)
     {
-        sql.append(c.getName());
+        // Append name
+        c.addSQL(sql, DBExpr.CTX_NAME);
         sql.append(" ");
         switch (c.getDataType())
         {
@@ -659,9 +662,9 @@
         sql.append(r.getName());
         sql.append(" --\r\n");
         sql.append("ALTER TABLE ");
-        sql.append(sourceTable.getFullName());
+        sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append(" ADD CONSTRAINT ");
-        sql.append(r.getFullName());
+        appendElementName(sql, r.getName());
         sql.append(" FOREIGN KEY (");
         // Source Names
         boolean addSeparator = false;
@@ -669,19 +672,19 @@
         for (int i = 0; i < refs.length; i++)
         {
             sql.append((addSeparator) ? ", " : "");
-            sql.append(refs[i].getSourceColumn().getName());
+            refs[i].getSourceColumn().addSQL(sql, DBExpr.CTX_NAME);
             addSeparator = true;
         }
         // References
         sql.append(") REFERENCES ");
-        sql.append(targetTable.getFullName());
+        targetTable.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append(" (");
         // Target Names
         addSeparator = false;
         for (int i = 0; i < refs.length; i++)
         {
             sql.append((addSeparator) ? ", " : "");
-            sql.append(refs[i].getTargetColumn().getName());
+            refs[i].getTargetColumn().addSQL(sql, DBExpr.CTX_NAME);
             addSeparator = true;
         }
         // done
@@ -701,7 +704,7 @@
     {
         StringBuilder sql = new StringBuilder();
         sql.append("ALTER TABLE ");
-        sql.append(col.getRowSet().getName());
+        col.getRowSet().addSQL(sql, DBExpr.CTX_FULLNAME);
         switch(type)
         {
             case CREATE:
@@ -744,14 +747,15 @@
         // Build String
         StringBuilder sql = new StringBuilder();
         sql.append( "CREATE OR REPLACE VIEW ");
-        sql.append( v.getName() );
+        v.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append( " (" );
         boolean addSeparator = false;
         for(DBColumn c : v.getColumns())
         {
             if (addSeparator)
                 sql.append(", ");
-            sql.append(c.getName());
+            // Add Column name
+            c.addSQL(sql, DBExpr.CTX_NAME);
             // next
             addSeparator = true;
         }
@@ -766,7 +770,7 @@
      * 
      * @return true if the comment has been created successfully
      */
-    private boolean createComment(DBDatabase db, String type, String objName, String comment,
DBSQLScript script)
+    private boolean createComment(DBDatabase db, String type, DBExpr expr, String comment,
DBSQLScript script)
     {
         if (comment==null || comment.length()==0)
             return true;
@@ -774,7 +778,13 @@
         sql.append("COMMENT ON ");
         sql.append(type);
         sql.append(" ");
-        sql.append(objName);
+        if (expr instanceof DBColumn)
+        {
+            DBColumn c = (DBColumn)expr;
+            c.getRowSet().addSQL(sql, DBExpr.CTX_NAME);
+            sql.append(".");
+        }
+        expr.addSQL(sql, DBExpr.CTX_NAME);
         sql.append(" IS '");
         sql.append(comment);
         sql.append("'");
@@ -796,7 +806,7 @@
         sql.append("DROP ");
         sql.append(objType);
         sql.append(" ");
-        sql.append(name);
+        appendElementName(sql, name);
         return script.addStmt(sql);
     }
 

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java?rev=690298&r1=690297&r2=690298&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
(original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
Fri Aug 29 08:25:33 2008
@@ -188,11 +188,13 @@
         {
             // sql-phrases
             case SQL_NULL_VALUE:              return "null";
-            case SQL_RENAME_COLUMN:           return " AS ";
             case SQL_PARAMETER:               return " ? ";
-            case SQL_CONCAT_EXPR:             return " + ";
             case SQL_RENAME_TABLE:            return " ";
+            case SQL_RENAME_COLUMN:           return " AS ";
             case SQL_DATABASE_LINK:           return "@";
+            case SQL_QUOTES_OPEN:             return "[";
+            case SQL_QUOTES_CLOSE:            return "]";
+            case SQL_CONCAT_EXPR:             return " + ";
             // data types
             case SQL_BOOLEAN_TRUE:            return "1";
             case SQL_BOOLEAN_FALSE:           return "0";
@@ -422,9 +424,9 @@
         sql.append("-- creating table ");
         sql.append(t.getName());
         sql.append(" --\r\n");
-        sql.append("CREATE TABLE [");
-        sql.append(t.getFullName());
-        sql.append("] (");
+        sql.append("CREATE TABLE ");
+        t.addSQL(sql, DBExpr.CTX_FULLNAME);
+        sql.append(" (");
         boolean addSeparator = false;
         Iterator<DBColumn> columns = t.getColumns().iterator();
         while (columns.hasNext())
@@ -440,7 +442,7 @@
         if (pk != null)
         { // add the primary key
             sql.append(",\r\n CONSTRAINT ");
-            sql.append(pk.getName());
+            appendElementName(sql, pk.getName());
             sql.append(" PRIMARY KEY (");
             addSeparator = false;
             // columns
@@ -448,7 +450,7 @@
             for (int i = 0; i < keyColumns.length; i++)
             {
                 sql.append((addSeparator) ? ", " : "");
-                sql.append(keyColumns[i].getName());
+                keyColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                 addSeparator = true;
             }
             sql.append(")");
@@ -468,9 +470,9 @@
             // Cretae Index
             sql.setLength(0);
             sql.append((idx.getType() == DBIndex.UNIQUE) ? "CREATE UNIQUE INDEX " : "CREATE
INDEX ");
-            sql.append(idx.getFullName());
+            appendElementName(sql, idx.getName());
             sql.append(" ON ");
-            sql.append(t.getFullName());
+            t.addSQL(sql, DBExpr.CTX_FULLNAME);
             sql.append(" (");
             addSeparator = false;
 
@@ -479,7 +481,7 @@
             for (int i = 0; i < idxColumns.length; i++)
             {
                 sql.append((addSeparator) ? ", " : "");
-                sql.append(idxColumns[i].getName());
+                idxColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                 sql.append("");
                 addSeparator = true;
             }
@@ -500,7 +502,8 @@
      */
     private boolean appendColumnDesc(DBTableColumn c, StringBuilder sql)
     {
-        sql.append(c.getName());
+        // Append name
+        c.addSQL(sql, DBExpr.CTX_NAME);
         sql.append(" ");
         switch (c.getDataType())
         {
@@ -593,9 +596,9 @@
         sql.append(r.getName());
         sql.append(" --\r\n");
         sql.append("ALTER TABLE ");
-        sql.append(sourceTable.getFullName());
+        sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append(" ADD CONSTRAINT ");
-        sql.append(r.getFullName());
+        appendElementName(sql, r.getName());
         sql.append(" FOREIGN KEY (");
         // Source Names
         boolean addSeparator = false;
@@ -603,19 +606,19 @@
         for (int i = 0; i < refs.length; i++)
         {
             sql.append((addSeparator) ? ", " : "");
-            sql.append(refs[i].getSourceColumn().getName());
+            refs[i].getSourceColumn().addSQL(sql, DBExpr.CTX_NAME);
             addSeparator = true;
         }
         // References
         sql.append(") REFERENCES ");
-        sql.append(targetTable.getFullName());
+        targetTable.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append(" (");
         // Target Names
         addSeparator = false;
         for (int i = 0; i < refs.length; i++)
         {
             sql.append((addSeparator) ? ", " : "");
-            sql.append(refs[i].getTargetColumn().getName());
+            refs[i].getTargetColumn().addSQL(sql, DBExpr.CTX_NAME);
             addSeparator = true;
         }
         // done
@@ -637,7 +640,7 @@
     {
         StringBuilder sql = new StringBuilder();
         sql.append("ALTER TABLE ");
-        sql.append(col.getRowSet().getName());
+        col.getRowSet().addSQL(sql, DBExpr.CTX_FULLNAME);
         switch(type)
         {
             case CREATE:
@@ -680,14 +683,15 @@
         // Build String
         StringBuilder sql = new StringBuilder();
         sql.append( "CREATE VIEW ");
-        sql.append( v.getName() );
+        v.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append( " (" );
         boolean addSeparator = false;
         for(DBColumn c : v.getColumns())
         {
             if (addSeparator)
                 sql.append(", ");
-            sql.append(c.getName());
+            // Add Column name
+            c.addSQL(sql, DBExpr.CTX_NAME);
             // next
             addSeparator = true;
         }
@@ -711,7 +715,7 @@
         sql.append("DROP ");
         sql.append(objType);
         sql.append(" ");
-        sql.append(name);
+        appendElementName(sql, name);
         return script.addStmt(sql);
     }
 

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/xml/XMLUtil.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/xml/XMLUtil.java?rev=690298&r1=690297&r2=690298&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/xml/XMLUtil.java (original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/xml/XMLUtil.java Fri Aug
29 08:25:33 2008
@@ -366,6 +366,10 @@
     {
         if (parent == null)
             return null; // Fehler
+        // Name must not contain spaces
+        if (name.indexOf(' ')>=0)
+            name = name.replace(' ', '_');
+        // Create Element
         Element child = parent.getOwnerDocument().createElement(name);
         if (value != null)
             setElementText(child, value);



Mime
View raw message