empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1180631 [1/2] - in /incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire: data/ db/ db/derby/ db/expr/compare/ db/expr/join/ db/h2/ db/hsql/ db/mysql/ db/oracle/ db/postgresql/ db/sqlserver/
Date Sun, 09 Oct 2011 15:36:15 GMT
Author: doebele
Date: Sun Oct  9 15:36:13 2011
New Revision: 1180631

URL: http://svn.apache.org/viewvc?rev=1180631&view=rev
Log:
EMPIREDB-103
part 1: New base class DBDDLGenerator and implmentations for HSql, SqlServer and Oracle.
Other driver will follow

Added:
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java   (with props)
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/MSSqlDDLGenerator.java   (with props)
Modified:
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/DataType.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCmdType.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpr.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBExistsExpr.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/join/DBJoinExprEx.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDataDictionnary.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleRowNumExpr.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/DataType.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/DataType.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/DataType.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/DataType.java Sun Oct  9 15:36:13 2011
@@ -61,9 +61,9 @@ public enum DataType
     CHAR, //         = 6;
     
     /**
-     * Double precision floating point value
+     * floating point value
      */
-    DOUBLE, //       = 7;
+    FLOAT, //        = 7;
     
     /**
      * Decimal numeric value (size indicates scale and precision)

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCmdType.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCmdType.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCmdType.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCmdType.java Sun Oct  9 15:36:13 2011
@@ -27,5 +27,5 @@ public enum DBCmdType
 {
     CREATE, //  = 0;
     DROP,   //  = 1;
-    ALTER, //   = 2;
+    ALTER,  //  = 2;
 }

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java Sun Oct  9 15:36:13 2011
@@ -30,6 +30,8 @@ import org.apache.empire.db.expr.order.D
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.NotSupportedException;
 import org.apache.empire.exceptions.ObjectNotValidException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 
 
@@ -43,6 +45,7 @@ import org.w3c.dom.Element;
 public abstract class DBCommandExpr extends DBExpr
 {
     private final static long serialVersionUID = 1L;
+    private static final Logger log = LoggerFactory.getLogger(DBCommandExpr.class);
 
     // Internal Classes
     protected static class DBCmdQuery extends DBRowSet

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java Sun Oct  9 15:36:13 2011
@@ -34,11 +34,24 @@ public abstract class DBDDLGenerator<T e
     
     protected T driver;
     
+    protected String DATATYPE_INT_SMALL  = "SMALLINT";  // Integer with small size (usually 16-bit)
+    protected String DATATYPE_INTEGER    = "INTEGER";   // Integer with default size (usually 32-bit) 
+    protected String DATATYPE_INT_BIG    = "BIGINT";    // Integer with long size (usually 64-bit)
+    protected String DATATYPE_CHAR       = "CHAR";      // Fixed length characters (unicode)
+    protected String DATATYPE_VARCHAR    = "VARCHAR";   // variable length characters (unicode)      
+    protected String DATATYPE_DATE       = "DATE";
+    protected String DATATYPE_TIMESTAMP  = "TIMESTAMP";
+    protected String DATATYPE_BOOLEAN    = "BOOLEAN";
+    protected String DATATYPE_DECIMAL    = "DECIMAL";
+    protected String DATATYPE_FLOAT      = "FLOAT";     // floating point number (double precision 8 bytes)
+    protected String DATATYPE_CLOB       = "CLOB";
+    protected String DATATYPE_BLOB       = "BLOB";
+    protected String DATATYPE_UNIQUEID   = "CHAR(36)";  // Globally Unique Identifier
+    
     protected DBDDLGenerator(T driver)
     {
         this.driver = driver;
     }
-    
 
     // Add statements
     protected void addCreateTableStmt(DBTable table, StringBuilder sql, DBSQLScript script)
@@ -70,80 +83,92 @@ public abstract class DBDDLGenerator<T e
     
     /**
      * appends the data type of a column
-     * @param c
+     * @param type
      * @param size
      * @param sql
+     * @returns true if further column attributes may be added or false otherwise
      */
-    protected void appendColumnDataType(DataType c, double size, StringBuilder sql)
+    protected boolean appendColumnDataType(DataType type, double size, DBTableColumn c, StringBuilder sql)
     {
-        switch (c)
+        switch (type)
         {
             case INTEGER:
-                sql.append("INTEGER");
-                break;
             case AUTOINC:
-                sql.append("INTEGER");
-                break;
-            case TEXT:
-            { // Check fixed or variable length
-                int len = Math.abs((int)size);
-                if (len == 0)
-                    len = 100;
-                sql.append("VARCHAR(");
-                sql.append(String.valueOf(len));
-                sql.append(")");
+            {   int bytes = Math.abs((int)size);
+                if (bytes>0 && bytes<3)
+                    sql.append(DATATYPE_INT_SMALL);
+                else if (bytes>4)
+                    sql.append(DATATYPE_INT_BIG);
+                else // Default
+                    sql.append(DATATYPE_INTEGER);  // Default integer length
             }
                 break;
+            case TEXT:
             case CHAR:
-            { // Check fixed or variable length
+            {   // Char or Varchar
+                sql.append((type==DataType.CHAR) ? DATATYPE_CHAR : DATATYPE_VARCHAR);
+                // get length (sign may be used for specifying (unicode>0) or bytes (non-unicode<0)) 
                 int len = Math.abs((int)size);
                 if (len == 0)
-                    len = 1;
-                sql.append("CHAR(");
-                sql.append(String.valueOf(size));
+                    len = (type==DataType.CHAR) ? 1 : 100;
+                sql.append("(");
+                sql.append(String.valueOf(len));
                 sql.append(")");
             }
                 break;
             case DATE:
-                sql.append("DATE");
+                sql.append(DATATYPE_DATE);
                 break;
             case DATETIME:
-                sql.append("DATETIME");
+                sql.append(DATATYPE_TIMESTAMP);
                 break;
             case BOOL:
-                sql.append("BOOLEAN");
+                sql.append(DATATYPE_BOOLEAN);
                 break;
-            case DOUBLE:
-                sql.append("DOUBLE");
+            case FLOAT:
+            {   sql.append(DATATYPE_FLOAT);
+                // append precision (if specified)
+                int prec = Math.abs((int)size);
+                if (prec>0) {
+                    sql.append("(");
+                    sql.append(String.valueOf(prec));
+                    sql.append(")");
+                }
                 break;
+            }    
             case DECIMAL:
-            {
-                sql.append("NUMBER(");
-                int prec = (int) size;
+            {   sql.append(DATATYPE_DECIMAL);
+                int prec  = (int) size;
                 int scale = (int) ((size - prec) * 10 + 0.5);
-                // sql.append((prec+scale).ToString());sql.append(",");
-                sql.append(String.valueOf(prec));
-                sql.append(",");
-                sql.append(String.valueOf(scale));
-                sql.append(")");
+                if (prec>0) {
+                    // append precision and scale
+                    sql.append("(");
+                    sql.append(String.valueOf(prec));
+                    sql.append(",");
+                    sql.append(String.valueOf(scale));
+                    sql.append(")");
+                }
             }
                 break;
             case CLOB:
-                sql.append("CLOB");
+                sql.append(DATATYPE_CLOB);
                 break;
             case BLOB:
-                sql.append("BLOB");
-                if (size > 0)
+                sql.append(DATATYPE_BLOB);
+                if (size > 0) {
                     sql.append(" (" + ((long)size) + ") ");
+                }    
                 break;
             case UNIQUEID:
                 // emulate using java.util.UUID
-                sql.append("CHAR(36)");
+                sql.append(DATATYPE_UNIQUEID);
                 break;
             default:
                 // Error: Unable to append column of type UNKNOWN
                 throw new MiscellaneousErrorException("Error: Unable to append column of type UNKNOWN");
         }
+        // done. Add more attributes (like e.g. NULLABLE or NOT NULL)
+        return true;
     }
     
     /**
@@ -158,7 +183,8 @@ public abstract class DBDDLGenerator<T e
         c.addSQL(sql, DBExpr.CTX_NAME);
         sql.append(" ");
         // Unknown data type
-        appendColumnDataType(c.getDataType(), c.getSize(), sql);
+        if (!appendColumnDataType(c.getDataType(), c.getSize(), c, sql))
+            return;
         // Default Value
         if (driver.isDDLColumnDefaults() && !c.isAutoGenerated() && c.getDefaultValue()!=null)
         {   sql.append(" DEFAULT ");
@@ -214,6 +240,10 @@ public abstract class DBDDLGenerator<T e
                 case DROP:
                     dropObject(((DBView) dbo).getName(), "VIEW", script);
                     return;
+                case ALTER:
+                    dropObject(((DBView) dbo).getName(), "VIEW", script);
+                    createView((DBView) dbo, script);
+                    return;
                 default:
                     throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
             }
@@ -244,9 +274,10 @@ public abstract class DBDDLGenerator<T e
     }
 
     /**
-     * Returns true if the database has been created successfully.
-     * 
-     * @return true if the database has been created successfully
+     * Appends the DDL-Script for creating the given database to an SQL-Script<br/>
+     * This includes the generation of all tables, views and relations.
+     * @param db the database to create
+     * @param script the sql script to which to append the dll command(s)
      */
     protected void createDatabase(DBDatabase db, DBSQLScript script)
     {
@@ -275,10 +306,21 @@ public abstract class DBDDLGenerator<T e
             }
         }
     }
+
+    /**
+     * Appends the DDL-Script for dropping a database to the given script object 
+     * @param db the database to drop
+     * @param script the sql script to which to append the dll command(s)
+     */
+    protected void dropDatabase(DBDatabase db, DBSQLScript script)
+    {
+        dropObject(db.getSchema(), "DATABASE", script);
+    }
     
     /**
-     * Returns true if the table has been created successfully.
-     * @return true if the table has been created successfully
+     * Appends the DDL-Script for creating the given table to an SQL-Script 
+     * @param t the table to create
+     * @param script the sql script to which to append the dll command(s)
      */
     protected void createTable(DBTable t, DBSQLScript script)
     {
@@ -355,8 +397,9 @@ public abstract class DBDDLGenerator<T e
     }
 
     /**
-     * Creates a sql string for creating a relation and appends it to the supplied buffer
-     * @return true if the relation has been created successfully
+     * Appends the DDL-Script for creating the given foreign-key relation to an SQL-Script 
+     * @param r the relation to create
+     * @param script the sql script to which to append the dll command(s)
      */
     protected void createRelation(DBRelation r, DBSQLScript script)
     {
@@ -400,11 +443,10 @@ public abstract class DBDDLGenerator<T e
     }
 
     /**
-     * Creates an alter table dll statement for adding, modifying or dropping a column.
+     * Appends the DDL-Script for altering a table to an SQL-Script 
      * @param col the column which to add, modify or drop
-     * @param type the type of operation to perform
-     * @param script to which to append the sql statement to
-     * @return true if the statement was successfully appended to the buffer
+     * @param type the type of operation to perform (CREATE | MODIFY | DROP)
+     * @param script the sql script to which to append the dll command(s)
      */
     protected void alterTable(DBTableColumn col, DBCmdType type, DBSQLScript script)
     {
@@ -431,9 +473,9 @@ public abstract class DBDDLGenerator<T e
     }
     
     /**
-     * Returns true if the view has been created successfully.
-     * 
-     * @return true if the view has been created successfully
+     * Appends the DDL-Script for creating the given view to an SQL-Script 
+     * @param v the view to create
+     * @param script the sql script to which to append the dll command(s)
      */
     protected void createView(DBView v, DBSQLScript script)
     {
@@ -449,7 +491,7 @@ public abstract class DBDDLGenerator<T e
 
         // Build String
         StringBuilder sql = new StringBuilder();
-        sql.append( "CREATE OR REPLACE VIEW ");
+        sql.append( "CREATE VIEW ");
         v.addSQL(sql, DBExpr.CTX_FULLNAME);
         sql.append( " (" );
         boolean addSeparator = false;
@@ -469,9 +511,10 @@ public abstract class DBDDLGenerator<T e
     }
     
     /**
-     * Returns true if the object has been dropped successfully.
-     * 
-     * @return true if the object has been dropped successfully
+     * Appends the DDL-Script for dropping a database object to an SQL-Script 
+     * @param name the name of the object to delete
+     * @param objType the type of object to delete (TABLE, COLUMN, VIEW, RELATION, etc)
+     * @param script the sql script to which to append the dll command(s)
      */
     protected void dropObject(String name, String objType, DBSQLScript script)
     {

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java Sun Oct  9 15:36:13 2011
@@ -52,6 +52,7 @@ import org.slf4j.LoggerFactory;
 public abstract class DBDatabaseDriver implements Serializable
 {
     private final static long serialVersionUID = 1L;
+    private static final Logger log = LoggerFactory.getLogger(DBDatabaseDriver.class);
   
     // sql-phrases
     public static final int SQL_NULL_VALUE       = 1;   // Oracle: null
@@ -106,9 +107,6 @@ public abstract class DBDatabaseDriver i
     public static final int SQL_FUNC_DECODE_SEP  = 151; // Oracle: ","             SQL: " "
     public static final int SQL_FUNC_DECODE_PART = 152; // Oracle: "{0}, {1}"      SQL: "when {0} then {1}"
     public static final int SQL_FUNC_DECODE_ELSE = 153; // Oracle: "{0}"           SQL: "else {0}"
-
-    // Logger
-    protected static final Logger log = LoggerFactory.getLogger(DBDatabaseDriver.class);
     
     // Flag whether or not to set column defaults when crating DDL statements
     protected boolean ddlColumnDefaults = false;
@@ -720,10 +718,10 @@ public abstract class DBDatabaseDriver i
      * Gets a SQL command for creating, modifying or deleting objects in the database (tables, columns, constraints, etc.)
      * 
      * @param type the command type 
-     * @param dbo the databse object
+     * @param dbo the database object
      * @param script the script to complete
      * 
-     * @return true on succes 
+     * @return true on success 
      */
     public void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
     {

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpr.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpr.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpr.java Sun Oct  9 15:36:13 2011
@@ -37,6 +37,7 @@ import java.util.Set;
 public abstract class DBExpr extends DBObject
 {
     private final static long serialVersionUID = 1L;
+    private static final Logger log = LoggerFactory.getLogger(DBExpr.class);
   
     // SQL Context Flags
     public static final long CTX_DEFAULT       = 7;  // Default: FullyQualified + Value
@@ -48,9 +49,6 @@ public abstract class DBExpr extends DBO
     public static final long CTX_ALIAS         = 8;  // Rename expression
     public static final long CTX_NOPARENTHESES = 16; // No Parentheses
     
-    
-    protected static final Logger log = LoggerFactory.getLogger(DBExpr.class);
-    
     /**
      * Used to build the SQL command. SQL for this expression must be appended to StringBuilder.
      * 
@@ -137,7 +135,7 @@ public abstract class DBExpr extends DBO
                 return Date.class;
             case CHAR:
                 return Character.class;
-            case DOUBLE:
+            case FLOAT:
                 return Double.class;
             case DECIMAL:
                 return java.math.BigDecimal.class;

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java Sun Oct  9 15:36:13 2011
@@ -47,7 +47,7 @@ public abstract class DBRecordData exten
     private final static long serialVersionUID = 1L;
   
     // Logger
-    protected static final Logger log = LoggerFactory.getLogger(DBRecordData.class);
+    private static final Logger log = LoggerFactory.getLogger(DBRecordData.class);
     
     // Field Info
     public abstract int     getFieldCount();

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java Sun Oct  9 15:36:13 2011
@@ -41,9 +41,20 @@ public class DBSQLScript implements Iter
     private static final String DEFAULT_COMMAND_SEPARATOR = ";\r\n\r\n";
 
     // Properties
-    protected String COMMAND_SEPARATOR = DEFAULT_COMMAND_SEPARATOR; 
+    protected String commandSeparator = DEFAULT_COMMAND_SEPARATOR; 
+
     protected ArrayList<String> sqlCmdList = new ArrayList<String>();
     
+    public DBSQLScript()
+    {
+        // nothing
+    }
+    
+    public DBSQLScript(String commandSeparator)
+    {
+        this.commandSeparator = commandSeparator;
+    }
+    
     /**
      * Adds a statement to the script.
      * @param sql the statement
@@ -151,7 +162,7 @@ public class DBSQLScript implements Iter
         for(String stmt : sqlCmdList)
         {
             script.append(stmt);
-            script.append(COMMAND_SEPARATOR);
+            script.append(commandSeparator);
         }
         return script.toString();
     }

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java Sun Oct  9 15:36:13 2011
@@ -31,6 +31,8 @@ import org.apache.empire.db.exceptions.F
 import org.apache.empire.db.exceptions.FieldValueTooLongException;
 import org.apache.empire.exceptions.PropertyReadOnlyException;
 import org.apache.empire.xml.XMLUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 
 
@@ -43,7 +45,8 @@ import org.w3c.dom.Element;
 public class DBTableColumn extends DBColumn
 {
     private final static long serialVersionUID = 1L;
-
+    private static final Logger log = LoggerFactory.getLogger(DBTableColumn.class);
+    
     // Column Information
     protected DataType  type;
     protected double    size;
@@ -289,7 +292,7 @@ public class DBTableColumn extends DBCol
                 break;
 
             case DECIMAL:
-            case DOUBLE:
+            case FLOAT:
                 if (value!=null && (value instanceof java.lang.Number)==false)
                 {   try
                     {   // Convert to String and check

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java Sun Oct  9 15:36:13 2011
@@ -42,6 +42,8 @@ import org.apache.empire.db.DBView;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.NotImplementedException;
 import org.apache.empire.exceptions.NotSupportedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -52,7 +54,8 @@ import org.apache.empire.exceptions.NotS
 public class DBDatabaseDriverDerby extends DBDatabaseDriver
 {
 	private final static long serialVersionUID = 1L;
-  
+    private static final Logger log = LoggerFactory.getLogger(DBDatabaseDriverDerby.class);
+
     /**
      * Defines the Derby command type.
      */ 
@@ -251,7 +254,7 @@ public class DBDatabaseDriverDerby exten
            case BOOL:      return "CAST(? AS UNSIGNED)";
            case INTEGER:   return "CAST(? AS SIGNED)";
            case DECIMAL:   return "CAST(? AS DECIMAL)";
-           case DOUBLE:    return "CAST(? AS DECIMAL)";
+           case FLOAT:    return "CAST(? AS DECIMAL)";
            case DATE:      return "CAST(? AS DATE)";
            case DATETIME:  return "CAST(? AS TIMESTAMP)";
            // Convert to text
@@ -562,7 +565,7 @@ public class DBDatabaseDriverDerby exten
 //                else
                 sql.append("SMALLINT");
                 break;
-            case DOUBLE:
+            case FLOAT:
                 sql.append("DOUBLE");
                 break;
             case DECIMAL:

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBExistsExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBExistsExpr.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBExistsExpr.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBExistsExpr.java Sun Oct  9 15:36:13 2011
@@ -18,12 +18,14 @@
  */
 package org.apache.empire.db.expr.compare;
 
+import java.util.Set;
+
 import org.apache.empire.db.DBColumn;
 import org.apache.empire.db.DBCommand;
 import org.apache.empire.db.DBCommandExpr;
 import org.apache.empire.db.DBDatabase;
-
-import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -35,6 +37,7 @@ import java.util.Set;
 public class DBExistsExpr extends DBCompareExpr
 {
     private final static long serialVersionUID = 1L;
+    private static final Logger log = LoggerFactory.getLogger(DBExistsExpr.class);
   
     public final DBCommandExpr cmd;
     public final DBCompareExpr compareExpr;

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/join/DBJoinExprEx.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/join/DBJoinExprEx.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/join/DBJoinExprEx.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/join/DBJoinExprEx.java Sun Oct  9 15:36:13 2011
@@ -24,6 +24,8 @@ import org.apache.empire.db.DBRowSet;
 import org.apache.empire.db.expr.compare.DBCompareAndOrExpr;
 import org.apache.empire.db.expr.compare.DBCompareColExpr;
 import org.apache.empire.db.expr.compare.DBCompareExpr;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This class is used for building a join expression of an SQL statement.
@@ -36,6 +38,8 @@ import org.apache.empire.db.expr.compare
 public class DBJoinExprEx extends DBJoinExpr
 {
     private final static long serialVersionUID = 1L;
+    private static final Logger log = LoggerFactory.getLogger(DBJoinExprEx.class);
+    
     private final DBCompareExpr cmp;
     
     private static DBColumnExpr findFirstColumn(DBCompareExpr expr)

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java Sun Oct  9 15:36:13 2011
@@ -42,6 +42,8 @@ import org.apache.empire.db.DBView;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.NotImplementedException;
 import org.apache.empire.exceptions.NotSupportedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -51,8 +53,8 @@ import org.apache.empire.exceptions.NotS
  */
 public class DBDatabaseDriverH2 extends DBDatabaseDriver
 {
-
-  private final static long serialVersionUID = 1L;
+    private final static long serialVersionUID = 1L;
+    private static final Logger log = LoggerFactory.getLogger(DBDatabaseDriverH2.class);
 
     /**
      * Defines the H2 command type.
@@ -254,7 +256,7 @@ public class DBDatabaseDriverH2 extends 
            case BOOL:      return "CAST(? AS UNSIGNED)";
            case INTEGER:   return "CAST(? AS SIGNED)";
            case DECIMAL:   return "CAST(? AS DECIMAL)";
-           case DOUBLE:    return "CAST(? AS DECIMAL)";
+           case FLOAT:    return "CAST(? AS DECIMAL)";
            case DATE:      return "CAST(? AS DATE)";
            case DATETIME:  return "CAST(? AS DATETIME)";
            // Convert to text
@@ -557,7 +559,7 @@ public class DBDatabaseDriverH2 extends 
             case BOOL:
                 sql.append("BIT");
                 break;
-            case DOUBLE:
+            case FLOAT:
                 sql.append("DOUBLE");
                 break;
             case DECIMAL:

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java Sun Oct  9 15:36:13 2011
@@ -20,27 +20,18 @@ package org.apache.empire.db.hsql;
 
 import java.sql.Connection;
 import java.util.GregorianCalendar;
-import java.util.Iterator;
 
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBCmdType;
-import org.apache.empire.db.DBColumn;
 import org.apache.empire.db.DBCommand;
-import org.apache.empire.db.DBCommandExpr;
+import org.apache.empire.db.DBDDLGenerator;
 import org.apache.empire.db.DBDatabase;
 import org.apache.empire.db.DBDatabaseDriver;
 import org.apache.empire.db.DBDriverFeature;
-import org.apache.empire.db.DBExpr;
-import org.apache.empire.db.DBIndex;
 import org.apache.empire.db.DBObject;
-import org.apache.empire.db.DBRelation;
 import org.apache.empire.db.DBSQLScript;
-import org.apache.empire.db.DBTable;
-import org.apache.empire.db.DBTableColumn;
-import org.apache.empire.db.DBView;
-import org.apache.empire.exceptions.InvalidArgumentException;
-import org.apache.empire.exceptions.NotImplementedException;
-import org.apache.empire.exceptions.NotSupportedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -51,7 +42,8 @@ import org.apache.empire.exceptions.NotS
  */
 public class DBDatabaseDriverHSql extends DBDatabaseDriver
 {
-  private final static long serialVersionUID = 1L;
+    private final static long serialVersionUID = 1L;
+    private static final Logger log = LoggerFactory.getLogger(DBDatabaseDriverHSql.class);
   
     /**
      * Defines the HSQLDB command type.
@@ -69,6 +61,8 @@ public class DBDatabaseDriverHSql extend
 	        super(db);
 	    }
 	}
+    
+    private DBDDLGenerator<?> ddlGenerator = null; // lazy creation
 	
     /**
      * Constructor for the HSQLDB database driver.
@@ -95,7 +89,7 @@ public class DBDatabaseDriverHSql extend
 
     /**
      * Returns whether or not a particular feature is supported by this driver
-     * @param type type of requrested feature. @see DBDriverFeature
+     * @param type type of requested feature. @see DBDriverFeature
      * @return true if the features is supported or false otherwise
      */
     @Override
@@ -218,7 +212,7 @@ public class DBDatabaseDriverHSql extend
             {
                 return "convert(?, DECIMAL)";
             }
-            case DOUBLE:
+            case FLOAT:
             {
                 return "convert(?, DOUBLE)";
             }
@@ -252,83 +246,6 @@ public class DBDatabaseDriverHSql extend
     }
 
     /**
-     * @see DBDatabaseDriver#getDDLScript(DBCmdType, DBObject, DBSQLScript)  
-     */
-    @Override
-    public void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
-    {
-        // The Object's database must be attached to this driver
-        if (dbo==null || dbo.getDatabase().getDriver()!=this)
-            throw new InvalidArgumentException("dbo", dbo);
-        // Check Type of object
-        if (dbo instanceof DBDatabase)
-        { // Database
-            switch (type)
-            {
-                case CREATE:
-                    createDatabase((DBDatabase) dbo, script);
-                    return;
-                case DROP:
-                    dropObject(((DBDatabase) dbo).getSchema(), "DATABASE", script);
-                    return;
-                default:
-                    throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
-            }
-        } 
-        else if (dbo instanceof DBTable)
-        { // Table
-            switch (type)
-            {
-                case CREATE:
-                    createTable((DBTable) dbo, script);
-                    return;
-                case DROP:
-                    dropObject(((DBTable) dbo).getName(), "TABLE", script);
-                    return;
-                default:
-                    throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
-            }
-        } 
-        else if (dbo instanceof DBView)
-        { // View
-            switch (type)
-            {
-                case CREATE:
-                    createView((DBView) dbo, script);
-                    return;
-                case DROP:
-                    dropObject(((DBView) dbo).getName(), "VIEW", script);
-                    return;
-                default:
-                    throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
-            }
-        } 
-        else if (dbo instanceof DBRelation)
-        { // Relation
-            switch (type)
-            {
-                case CREATE:
-                    alterRelation((DBRelation) dbo, type, script);
-                    return;
-                case DROP:
-                    alterRelation((DBRelation) dbo, type, script);
-                    return;
-                default:
-                    throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
-            }
-        } 
-        else if (dbo instanceof DBTableColumn)
-        { // Table Column
-            alterTable((DBTableColumn) dbo, type, script);
-            return;
-        } 
-        else
-        { // dll generation not supported for this type
-            throw new NotSupportedException(this, "getDDLScript() for "+dbo.getClass().getName());
-        }
-    }
-
-    /**
      * Overridden. Returns a timestamp that is used for record updates created by the database server.
      * 
      * @return the current date and time of the database server.
@@ -341,390 +258,17 @@ public class DBDatabaseDriverHSql extend
     	return new java.sql.Timestamp(cal.getTimeInMillis());
     }
 
-    /*
-     * return the sql for creating a Database
-     */
-    protected void createDatabase(DBDatabase db, DBSQLScript script)
-    {
-        // Create all Sequences
-        Iterator<DBTable> seqtabs = db.getTables().iterator();
-        while (seqtabs.hasNext())
-        {
-            DBTable table = seqtabs.next();
-            Iterator<DBColumn> cols = table.getColumns().iterator();
-            while (cols.hasNext())
-            {
-                DBTableColumn c = (DBTableColumn) cols.next();
-                if (c.getDataType() == DataType.AUTOINC)
-                {
-                    createSequence(db, c, script);
-                }
-            }
-        }
-        // Create all Tables
-        Iterator<DBTable> tables = db.getTables().iterator();
-        while (tables.hasNext())
-        {
-            createTable(tables.next(), script);
-        }
-        // Create Relations
-        Iterator<DBRelation> relations = db.getRelations().iterator();
-        while (relations.hasNext())
-        {
-            alterRelation(relations.next(), DBCmdType.CREATE, script);
-        }
-        // Create Views
-        Iterator<DBView> views = db.getViews().iterator();
-        while (views.hasNext())
-        {
-            createView(views.next(), script);
-        }
-    }
-
-    /**
-     * Returns true if the sequence has been created successfully.
-     * 
-     * @return true if the sequence has been created successfully
-     */
-    protected void createSequence(DBDatabase db, DBTableColumn c, DBSQLScript script)
-    {
-        Object defValue = c.getDefaultValue();
-        String seqName = (defValue != null) ? defValue.toString() : c.toString();
-        // createSQL
-        StringBuilder sql = new StringBuilder();
-        sql.append("-- creating sequence for column ");
-        sql.append(c.toString());
-        sql.append(" --\r\n");
-        sql.append("CREATE SEQUENCE ");
-        db.appendQualifiedName(sql, seqName, detectQuoteName(seqName));
-        sql.append(" START WITH 1");
-        // executeDLL
-        script.addStmt(sql);
-    }
-    
     /**
-     * Returns true if the table has been created successfully.
-     * 
-     * @return true if the table has been created successfully
+     * @see DBDatabaseDriver#getDDLScript(DBCmdType, DBObject, DBSQLScript)  
      */
-    protected void createTable(DBTable t, DBSQLScript script)
+    @Override
+    public void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
     {
-        StringBuilder sql = new StringBuilder();
-        sql.append("-- creating table ");
-        sql.append(t.getName());
-        sql.append(" --\r\n");
-        sql.append("CREATE TABLE ");
-        t.addSQL(sql, DBExpr.CTX_FULLNAME);
-        sql.append(" (");
-        boolean addSeparator = false;
-        Iterator<DBColumn> columns = t.getColumns().iterator();
-        while (columns.hasNext())
-        {
-            DBTableColumn c = (DBTableColumn) columns.next();
-            sql.append((addSeparator) ? ",\r\n   " : "\r\n   ");
-            if (appendColumnDesc(c, sql)==false)
-                continue; // Ignore and continue;
-            addSeparator = true;
-        }
-        // Primary Key
-        DBIndex pk = t.getPrimaryKey();
-        if (pk != null)
-        { // add the primary key
-            sql.append(",\r\n CONSTRAINT ");
-            appendElementName(sql, pk.getName());
-            sql.append(" PRIMARY KEY (");
-            addSeparator = false;
-            // columns
-            DBColumn[] keyColumns = pk.getColumns();
-            for (int i = 0; i < keyColumns.length; i++)
-            {
-                sql.append((addSeparator) ? ", " : "");
-                keyColumns[i].addSQL(sql, DBExpr.CTX_NAME);
-                addSeparator = true;
-            }
-            sql.append(")");
-        }
-        sql.append(")");
-        // Create the table
-        script.addStmt(sql);
-        // Create other Indexes (except primary key)
-        Iterator<DBIndex> indexes = t.getIndexes().iterator();
-        while (indexes.hasNext())
-        {
-            DBIndex idx = indexes.next();
-            if (idx == pk || idx.getType() == DBIndex.PRIMARYKEY)
-                continue;
-
-            // Cretae Index
-            sql.setLength(0);
-            sql.append((idx.getType() == DBIndex.UNIQUE) ? "CREATE UNIQUE INDEX " : "CREATE INDEX ");
-            appendElementName(sql, idx.getName());
-            sql.append(" ON ");
-            t.addSQL(sql, DBExpr.CTX_FULLNAME);
-            sql.append(" (");
-            addSeparator = false;
-
-            // columns
-            DBColumn[] idxColumns = idx.getColumns();
-            for (int i = 0; i < idxColumns.length; i++)
-            {
-                sql.append((addSeparator) ? ", " : "");
-                idxColumns[i].addSQL(sql, DBExpr.CTX_NAME);
-                addSeparator = true;
-            }
-            sql.append(")");
-            // Create Index
-            script.addStmt(sql);
-        }
+        if (ddlGenerator==null)
+            ddlGenerator = new HSqlDDLGenerator(this);
+        // forward request
+        ddlGenerator.getDDLScript(type, dbo, script); 
     }
     
-    /**
-     * Appends a table column definition to a ddl statement
-     * @param c the column which description to append
-     * @param sql the sql builder object
-     * @return true if the column was successfully appended or false otherwise
-     */
-    protected boolean appendColumnDesc(DBTableColumn c, StringBuilder sql)
-    {
-        // Append name
-        c.addSQL(sql, DBExpr.CTX_NAME);
-        sql.append(" ");
-        switch (c.getDataType())
-        {
-            case INTEGER:
-                sql.append("BIGINT");
-                break;
-            case AUTOINC:
-                sql.append("BIGINT");
-                break;
-            case TEXT:
-            { // Check fixed or variable length
-                int size = Math.abs((int) c.getSize());
-                if (size == 0)
-                    size = 100;
-                sql.append("VARCHAR(");
-                sql.append(String.valueOf(size));
-                sql.append(")");
-            }
-                break;
-            case CHAR:
-            { // Check fixed or variable length
-                int size = Math.abs((int) c.getSize());
-                if (size == 0)
-                    size = 1;
-                sql.append("CHAR(");
-                sql.append(String.valueOf(size));
-                sql.append(")");
-            }
-                break;
-            case DATE:
-                sql.append("DATE");
-                break;
-            case DATETIME:
-                sql.append("DATETIME");
-                break;
-            case BOOL:
-                sql.append("BOOLEAN");
-                break;
-            case DOUBLE:
-                // http://hsqldb.org/doc/guide/ch02.html
-                // FLOAT, DOUBLE and REAL are saved as java doubles
-                sql.append("FLOAT");
-                break;
-            case DECIMAL:
-            {
-                sql.append("DECIMAL(");
-                int prec = (int) c.getSize();
-                int scale = (int) ((c.getSize() - prec) * 10 + 0.5);
-                // sql.append((prec+scale).ToString());sql.append(",");
-                sql.append(String.valueOf(prec));
-                sql.append(",");
-                sql.append(String.valueOf(scale));
-                sql.append(")");
-            }
-                break;
-            case CLOB:
-                sql.append("LONGVARCHAR");
-                break;
-            case BLOB:
-                sql.append("LONGVARBINARY");
-                break;
-            case UNIQUEID:
-                // emulate using java.util.UUID
-                sql.append("CHAR(36)");
-                break;
-            case UNKNOWN:
-                log.warn("Cannot append column of Data-Type 'UNKNOWN'");
-                return false;
-        }
-        // Default Value
-        if (isDDLColumnDefaults() && !c.isAutoGenerated() && c.getDefaultValue()!=null)
-        {   sql.append(" DEFAULT ");
-            sql.append(getValueString(c.getDefaultValue(), c.getDataType()));
-        }
-        // Nullable
-        if (c.isRequired() ||  c.isAutoGenerated())
-            sql.append(" NOT NULL");
-        // Done
-        return true;
-    }
-
-    /**
-     * Returns true if the relation has been altered successfully.
-     * 
-     * @return true if the relation has been altered successfully
-     */
-    protected void alterRelation(DBRelation r, DBCmdType type, DBSQLScript script)
-    {
-        switch(type)
-        {
-            case CREATE:
-            {
-                DBTable sourceTable = (DBTable) r.getReferences()[0].getSourceColumn().getRowSet();
-                DBTable targetTable = (DBTable) r.getReferences()[0].getTargetColumn().getRowSet();
-
-                StringBuilder sql = new StringBuilder();
-                sql.append("-- creating foreign key constraint ");
-                sql.append(r.getName());
-                sql.append(" --\r\n");
-                sql.append("ALTER TABLE ");
-                sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
-                sql.append(" ADD CONSTRAINT ");
-                appendElementName(sql, r.getName());
-                sql.append(" FOREIGN KEY (");
-                // Source Names
-                boolean addSeparator = false;
-                DBRelation.DBReference[] refs = r.getReferences();
-                for (int i = 0; i < refs.length; i++)
-                {
-                    sql.append((addSeparator) ? ", " : "");
-                    refs[i].getSourceColumn().addSQL(sql, DBExpr.CTX_NAME);
-                    addSeparator = true;
-                }
-                // References
-                sql.append(") REFERENCES ");
-                targetTable.addSQL(sql, DBExpr.CTX_FULLNAME);
-                sql.append(" (");
-                // Target Names
-                addSeparator = false;
-                for (int i = 0; i < refs.length; i++)
-                {
-                    sql.append((addSeparator) ? ", " : "");
-                    refs[i].getTargetColumn().addSQL(sql, DBExpr.CTX_NAME);
-                    addSeparator = true;
-                }
-                // done
-                sql.append(")");
-                script.addStmt(sql.toString());
-                break;
-            }
-            case DROP:
-            {
-                DBTable sourceTable = (DBTable) r.getReferences()[0].getSourceColumn().getRowSet();
-                StringBuilder sql = new StringBuilder();
-                sql.append("-- dropping constraint ");
-                sql.append(r.getName());
-                sql.append(" --\r\n");
-                sql.append("ALTER TABLE ");
-                sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
-                sql.append(" DROP CONSTRAINT ");
-                appendElementName(sql, r.getName());
-                // done
-                script.addStmt(sql.toString());
-                break;
-            }
-            default:
-                throw new NotImplementedException(this, "Type not supported (" + type + ")");
-        }
-
-    }
-
-    /**
-     * Creates an alter table dll statement for adding, modifying or dropping a column.
-     * @param col the column which to add, modify or drop
-     * @param type the type of operation to perform
-     * @param script to which to append the sql statement to
-     * @return true if the statement was successfully appended to the buffer
-     */
-    protected void alterTable(DBTableColumn col, DBCmdType type, DBSQLScript script)
-    {
-        StringBuilder sql = new StringBuilder();
-        sql.append("ALTER TABLE ");
-        col.getRowSet().addSQL(sql, DBExpr.CTX_FULLNAME);
-        switch(type)
-        {
-            case CREATE:
-                sql.append(" ADD ");
-                appendColumnDesc(col, sql);
-                break;
-            case ALTER:
-                sql.append(" ALTER COLUMN ");
-                appendColumnDesc(col, sql);
-                break;
-            case DROP:
-                sql.append(" DROP COLUMN ");
-                sql.append(col.getName());
-                break;
-        }
-        // done
-        script.addStmt(sql.toString());
-    }
-
-    /**
-     * Returns true if the view has been created successfully.
-     * 
-     * @return true if the view has been created successfully
-     */
-    protected void createView(DBView v, DBSQLScript script)
-    {
-        // Create the Command
-        DBCommandExpr cmd = v.createCommand();
-        if (cmd==null)
-        {   // Check whether Error information is available
-            log.error("No command has been supplied for view " + v.getName());
-            throw new NotImplementedException(this, v.getName() + ".createCommand");
-        }
-        // Make sure there is no OrderBy
-        cmd.clearOrderBy();
-
-        // Build String
-        StringBuilder sql = new StringBuilder();
-        sql.append( "CREATE VIEW ");
-        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;
-        }
-        sql.append(")\r\nAS\r\n");
-        cmd.addSQL( sql, DBExpr.CTX_DEFAULT);
-        // done
-        script.addStmt(sql.toString());
-    }
-
-    /**
-     * Returns true if the object has been dropped successfully.
-     * 
-     * @return true if the object has been dropped successfully
-     */
-    protected void dropObject(String name, String objType, DBSQLScript script)
-    {
-        if (name == null || name.length() == 0)
-            throw new InvalidArgumentException("name", name);
-        // Create Drop Statement
-        StringBuilder sql = new StringBuilder();
-        sql.append("DROP ");
-        sql.append(objType);
-        sql.append(" ");
-        appendElementName(sql, name);
-        // Done
-        script.addStmt(sql);
-    }    
 }
 

Added: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java?rev=1180631&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java (added)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java Sun Oct  9 15:36:13 2011
@@ -0,0 +1,93 @@
+/*
+ * ESTEAM Software GmbH, 09.10.2011
+ */
+package org.apache.empire.db.hsql;
+
+import java.util.Iterator;
+
+import org.apache.empire.data.DataType;
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBDDLGenerator;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBSQLScript;
+import org.apache.empire.db.DBTable;
+import org.apache.empire.db.DBTableColumn;
+
+public class HSqlDDLGenerator extends DBDDLGenerator<DBDatabaseDriverHSql>
+{
+    public HSqlDDLGenerator(DBDatabaseDriverHSql driver)
+    {
+        super(driver);
+        // set Oracle specific data types
+        initDataTypes();
+    }
+
+    /**
+     * sets Oracle specific data types
+     * @param driver
+     */
+    private void initDataTypes()
+    {   // Override data types
+        DATATYPE_CLOB       = "LONGVARCHAR";
+        DATATYPE_BLOB       = "LONGVARBINARY";
+    }
+
+    /*
+    @Override
+    protected boolean appendColumnDataType(DataType type, double size, DBTableColumn c, StringBuilder sql)
+    {
+        switch (type)
+        {
+            default:
+                // use default
+                return super.appendColumnDataType(type, size, c, sql);
+        }
+        return true;
+    }
+    */
+ 
+    @Override
+    protected void createDatabase(DBDatabase db, DBSQLScript script)
+    {
+        // Create all Sequences
+        Iterator<DBTable> seqtabs = db.getTables().iterator();
+        while (seqtabs.hasNext())
+        {
+            DBTable table = seqtabs.next();
+            Iterator<DBColumn> cols = table.getColumns().iterator();
+            while (cols.hasNext())
+            {
+                DBTableColumn c = (DBTableColumn) cols.next();
+                if (c.getDataType() == DataType.AUTOINC)
+                {
+                    createSequence(db, c, script);
+                }
+            }
+        }
+        // default processing
+        super.createDatabase(db, script);
+    }
+
+    /**
+     * Appends the DDL-Script for creating the a sequence to an SQL-Script<br/>
+     * @param db the database to create
+     * @param c the column for which to create the sequence
+     * @param script the sql script to which to append the dll command(s)
+     */
+    protected void createSequence(DBDatabase db, DBTableColumn c, DBSQLScript script)
+    {
+        Object defValue = c.getDefaultValue();
+        String seqName = (defValue != null) ? defValue.toString() : c.toString();
+        // createSQL
+        StringBuilder sql = new StringBuilder();
+        sql.append("-- creating sequence for column ");
+        sql.append(c.toString());
+        sql.append(" --\r\n");
+        sql.append("CREATE SEQUENCE ");
+        db.appendQualifiedName(sql, seqName, detectQuoteName(seqName));
+        sql.append(" START WITH 1");
+        // executeDLL
+        script.addStmt(sql);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java
------------------------------------------------------------------------------
    eol-style = native

Propchange: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java Sun Oct  9 15:36:13 2011
@@ -46,6 +46,8 @@ import org.apache.empire.exceptions.Inva
 import org.apache.empire.exceptions.InvalidPropertyException;
 import org.apache.empire.exceptions.NotImplementedException;
 import org.apache.empire.exceptions.NotSupportedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -56,6 +58,7 @@ import org.apache.empire.exceptions.NotS
 public class DBDatabaseDriverMySQL extends DBDatabaseDriver
 {
     private static final long serialVersionUID = 1L;
+    private static final Logger log = LoggerFactory.getLogger(DBDatabaseDriverMySQL.class);
 
     /**
      * Defines the MySQL command type.
@@ -391,7 +394,7 @@ public class DBDatabaseDriverMySQL exten
            case BOOL:      return "CAST(? AS UNSIGNED)";
            case INTEGER:   return "CAST(? AS SIGNED)";
            case DECIMAL:   return "CAST(? AS DECIMAL)";
-           case DOUBLE:    return "CAST(? AS DECIMAL)";
+           case FLOAT:    return "CAST(? AS DECIMAL)";
            case DATE:      return "CAST(? AS DATE)";
            case DATETIME:  return "CAST(? AS DATETIME)";
            // Convert to text
@@ -706,7 +709,7 @@ public class DBDatabaseDriverMySQL exten
             case BOOL:
                 sql.append("BIT");
                 break;
-            case DOUBLE:
+            case FLOAT:
                 sql.append("DOUBLE");
                 break;
             case DECIMAL:

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java Sun Oct  9 15:36:13 2011
@@ -22,29 +22,24 @@ import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Iterator;
 
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBCmdType;
 import org.apache.empire.db.DBColumn;
 import org.apache.empire.db.DBCommand;
-import org.apache.empire.db.DBCommandExpr;
+import org.apache.empire.db.DBDDLGenerator;
 import org.apache.empire.db.DBDatabase;
 import org.apache.empire.db.DBDatabaseDriver;
 import org.apache.empire.db.DBDriverFeature;
-import org.apache.empire.db.DBExpr;
-import org.apache.empire.db.DBIndex;
 import org.apache.empire.db.DBObject;
 import org.apache.empire.db.DBReader;
-import org.apache.empire.db.DBRelation;
 import org.apache.empire.db.DBSQLScript;
 import org.apache.empire.db.DBTable;
-import org.apache.empire.db.DBTableColumn;
 import org.apache.empire.db.DBView;
 import org.apache.empire.db.exceptions.InternalSQLException;
 import org.apache.empire.exceptions.InvalidArgumentException;
-import org.apache.empire.exceptions.NotImplementedException;
-import org.apache.empire.exceptions.NotSupportedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -54,7 +49,7 @@ import org.apache.empire.exceptions.NotS
 public class DBDatabaseDriverOracle extends DBDatabaseDriver
 {
     private static final long serialVersionUID = 1L;
-
+    private static final Logger log = LoggerFactory.getLogger(DBDatabaseDriverOracle.class);
 
     // Implementation of boolean types
     public enum BooleanType
@@ -66,6 +61,8 @@ public class DBDatabaseDriverOracle exte
     private boolean oracle8Compatibilty = false;
 
     private BooleanType booleanType = BooleanType.NUMBER;
+    
+    private DBDDLGenerator<?> ddlGenerator = null; // lazy creation
 
     /**
      * Constructor for the Oracle database driver.<br>
@@ -226,7 +223,7 @@ public class DBDatabaseDriverOracle exte
                 return "to_char(?)";
             // Convert to number
             case INTEGER:
-            case DOUBLE:
+            case FLOAT:
             case DECIMAL:
                 if (format != null)
                 { // Convert using a format string
@@ -313,84 +310,7 @@ public class DBDatabaseDriverOracle exte
         // Done
         return val;
     }
-
-    /**
-     * @see DBDatabaseDriver#getDDLScript(DBCmdType, DBObject, DBSQLScript)  
-     */
-    @Override
-    public void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
-    {
-        // The Object's database must be attached to this driver
-        if (dbo==null || dbo.getDatabase().getDriver()!=this)
-            throw new InvalidArgumentException("dbo", dbo);
-        // Check Type of object
-        if (dbo instanceof DBDatabase)
-        { // Database
-            switch (type)
-            {
-                case CREATE:
-                    createDatabase((DBDatabase) dbo, script);
-                    return;
-                case DROP:
-                    dropObject(((DBDatabase) dbo).getSchema(), "USER", script);
-                    return;
-                default:
-                    throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
-            }
-        } 
-        else if (dbo instanceof DBTable)
-        { // Table
-            switch (type)
-            {
-                case CREATE:
-                    createTable((DBTable) dbo, script);
-                    return;
-                case DROP:
-                    dropObject(((DBTable) dbo).getName(), "TABLE", script);
-                    return;
-                default:
-                    throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
-            }
-        } 
-        else if (dbo instanceof DBView)
-        { // View
-            switch (type)
-            {
-                case CREATE:
-                    createView((DBView) dbo, script);
-                    return;
-                case DROP:
-                    dropObject(((DBView) dbo).getName(), "VIEW", script);
-                    return;
-                default:
-                    throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
-            }
-        } 
-        else if (dbo instanceof DBRelation)
-        { // Relation
-            switch (type)
-            {
-                case CREATE:
-                    createRelation((DBRelation) dbo, script);
-                    return;
-                case DROP:
-                    dropObject(((DBRelation) dbo).getName(), "CONSTRAINT", script);
-                    return;
-                default:
-                    throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
-            }
-        } 
-        else if (dbo instanceof DBTableColumn)
-        { // Table Column
-            alterTable((DBTableColumn) dbo, type, script);
-            return;
-        } 
-        else
-        { // dll generation not supported for this type
-            throw new NotSupportedException(this, "getDDLScript() for "+dbo.getClass().getName());
-        }
-    }
-
+    
     /**
      * Overridden. Returns a timestamp that is used for record updates created by the database server.
      * 
@@ -425,413 +345,16 @@ public class DBDatabaseDriverOracle exte
     }
 
     /**
-     * Returns true if the database has been created successfully.
-     * 
-     * @return true if the database has been created successfully
-     */
-    protected void createDatabase(DBDatabase db, DBSQLScript script)
-    {
-        // Create all Sequences
-        Iterator<DBTable> seqtabs = db.getTables().iterator();
-        while (seqtabs.hasNext())
-        {
-            DBTable table = seqtabs.next();
-            Iterator<DBColumn> cols = table.getColumns().iterator();
-            while (cols.hasNext())
-            {
-                DBTableColumn c = (DBTableColumn) cols.next();
-                if (c.getDataType() == DataType.AUTOINC)
-                {
-                    createSequence(db, c, script);
-                }
-            }
-        }
-        // Create all Tables
-        Iterator<DBTable> tables = db.getTables().iterator();
-        while (tables.hasNext())
-        {
-            createTable(tables.next(), script);
-        }
-        // Create Relations
-        Iterator<DBRelation> relations = db.getRelations().iterator();
-        while (relations.hasNext())
-        {
-            createRelation(relations.next(), script);
-        }
-        // Create Views
-        Iterator<DBView> views = db.getViews().iterator();
-        while (views.hasNext())
-        {
-            try {
-                createView(views.next(), script);
-            } catch(NotImplementedException e) {
-                // View command not implemented
-                log.warn("Error creating the view {0}. This view will be ignored.");
-                continue;
-            }
-        }
-    }
-
-    /**
-     * Returns true if the sequence has been created successfully.
-     * 
-     * @return true if the sequence has been created successfully
-     */
-    protected void createSequence(DBDatabase db, DBTableColumn c, DBSQLScript script)
-    {
-        Object defValue = c.getDefaultValue();
-        String seqName = (defValue != null) ? defValue.toString() : c.toString();
-        // createSQL
-        StringBuilder sql = new StringBuilder();
-        sql.append("-- creating sequence for column ");
-        sql.append(c.getFullName());
-        sql.append(" --\r\n");
-        sql.append("CREATE SEQUENCE ");
-        db.appendQualifiedName(sql, seqName, detectQuoteName(seqName));
-        sql.append(" INCREMENT BY 1 START WITH 1 MINVALUE 0 NOCYCLE NOCACHE NOORDER");
-        // executeDLL
-        script.addStmt(sql);
-    }
-    
-    /**
-     * Returns true if the table has been created successfully.
-     * @return true if the table has been created successfully
-     */
-    protected void createTable(DBTable t, DBSQLScript script)
-    {
-        StringBuilder sql = new StringBuilder();
-        sql.append("-- creating table ");
-        sql.append(t.getName());
-        sql.append(" --\r\n");
-        sql.append("CREATE TABLE ");
-        t.addSQL(sql, DBExpr.CTX_FULLNAME);
-        sql.append(" (");
-        boolean addSeparator = false;
-        Iterator<DBColumn> columns = t.getColumns().iterator();
-        while (columns.hasNext())
-        {
-            DBTableColumn c = (DBTableColumn) columns.next();
-            sql.append((addSeparator) ? ",\r\n   " : "\r\n   ");
-            if (appendColumnDesc(c, sql)==false)
-                continue; // Ignore and continue;
-            addSeparator = true;
-        }
-        // Primary Key
-        DBIndex pk = t.getPrimaryKey();
-        if (pk != null)
-        { // add the primary key
-            sql.append(",\r\n CONSTRAINT ");
-            appendElementName(sql, pk.getName());
-            sql.append(" PRIMARY KEY (");
-            addSeparator = false;
-            // columns
-            DBColumn[] keyColumns = pk.getColumns();
-            for (int i = 0; i < keyColumns.length; i++)
-            {
-                sql.append((addSeparator) ? ", " : "");
-                keyColumns[i].addSQL(sql, DBExpr.CTX_NAME);
-                addSeparator = true;
-            }
-            sql.append(")");
-        }
-        sql.append(")");
-        // Create the table
-        DBDatabase db = t.getDatabase();
-        script.addStmt(sql);
-        // Create other Indexes (except primary key)
-        Iterator<DBIndex> indexes = t.getIndexes().iterator();
-        while (indexes.hasNext())
-        {
-            DBIndex idx = indexes.next();
-            if (idx == pk || idx.getType() == DBIndex.PRIMARYKEY)
-                continue;
-
-            // Cretae Index
-            sql.setLength(0);
-            sql.append((idx.getType() == DBIndex.UNIQUE) ? "CREATE UNIQUE INDEX " : "CREATE INDEX ");
-            appendElementName(sql, idx.getName());
-            sql.append(" ON ");
-            t.addSQL(sql, DBExpr.CTX_FULLNAME);
-            sql.append(" (");
-            addSeparator = false;
-
-            // columns
-            DBColumn[] idxColumns = idx.getColumns();
-            for (int i = 0; i < idxColumns.length; i++)
-            {
-                sql.append((addSeparator) ? ", " : "");
-                idxColumns[i].addSQL(sql, DBExpr.CTX_NAME);
-                sql.append("");
-                addSeparator = true;
-            }
-            sql.append(")");
-            // Create Index
-            script.addStmt(sql);
-        }
-        // add Comments
-        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, com, script);
-        }
-    }
-    
-    /**
-     * Appends a table column definition to a ddl statement
-     * @param c the column which description to append
-     * @param sql the sql builder object
-     * @return true if the column was successfully appended or false otherwise
-     */
-    protected boolean appendColumnDesc(DBTableColumn c, StringBuilder sql)
-    {
-        // Append name
-        c.addSQL(sql, DBExpr.CTX_NAME);
-        sql.append(" ");
-        switch (c.getDataType())
-        {
-            case INTEGER:
-                sql.append("INTEGER");
-                break;
-            case AUTOINC:
-                sql.append("INTEGER");
-                break;
-            case TEXT:
-            { // Check fixed or variable length
-                int size = Math.abs((int) c.getSize());
-                if (size == 0)
-                    size = 100;
-                sql.append("VARCHAR2(");
-                sql.append(String.valueOf(size));
-                sql.append(" char)");
-            }
-                break;
-            case CHAR:
-            { // Check fixed or variable length
-                int size = Math.abs((int) c.getSize());
-                if (size == 0)
-                    size = 1;
-                sql.append("CHAR(");
-                sql.append(String.valueOf(size));
-                sql.append(")");
-            }
-                break;
-            case DATE:
-                sql.append("DATE");
-                break;
-            case DATETIME:
-                sql.append("DATE");
-                break;
-            case BOOL:
-                if ( booleanType==BooleanType.CHAR )
-                     sql.append("CHAR(1)");
-                else sql.append("NUMBER(1,0)");
-                break;
-            case DOUBLE:
-                sql.append("FLOAT(80)");
-                break;
-            case DECIMAL:
-            {
-                sql.append("NUMBER(");
-                int prec = (int) c.getSize();
-                int scale = (int) ((c.getSize() - prec) * 10 + 0.5);
-                // sql.append((prec+scale).ToString());sql.append(",");
-                sql.append(String.valueOf(prec));
-                sql.append(",");
-                sql.append(String.valueOf(scale));
-                sql.append(")");
-            }
-                break;
-            case CLOB:
-                sql.append("CLOB");
-                break;
-            case BLOB:
-                sql.append("BLOB");
-                if (c.getSize() > 0)
-                    sql.append(" (" + (long) c.getSize() + ") ");
-                break;
-            case UNIQUEID:
-                // emulate using java.util.UUID
-                sql.append("CHAR(36)");
-                break;
-            case UNKNOWN:
-                log.warn("Cannot append column of Data-Type 'UNKNOWN'");
-                return false;
-        }
-        // Default Value
-        if (isDDLColumnDefaults() && !c.isAutoGenerated() && c.getDefaultValue()!=null)
-        {   sql.append(" DEFAULT ");
-            sql.append(getValueString(c.getDefaultValue(), c.getDataType()));
-        }
-        // Nullable
-        if (c.isRequired() ||  c.isAutoGenerated())
-            sql.append(" NOT NULL");
-        // Done
-        return true;
-    }
-
-    /**
-     * Create a sql string for creating a relation and appends it to the supplied buffer
-     * @return true if the relation has been created successfully
-     */
-    protected void createRelation(DBRelation r, DBSQLScript script)
-    {
-        DBTable sourceTable = (DBTable) r.getReferences()[0].getSourceColumn().getRowSet();
-        DBTable targetTable = (DBTable) r.getReferences()[0].getTargetColumn().getRowSet();
-
-        StringBuilder sql = new StringBuilder();
-        sql.append("-- creating foreign key constraint ");
-        sql.append(r.getName());
-        sql.append(" --\r\n");
-        sql.append("ALTER TABLE ");
-        sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
-        sql.append(" ADD CONSTRAINT ");
-        appendElementName(sql, r.getName());
-        sql.append(" FOREIGN KEY (");
-        // Source Names
-        boolean addSeparator = false;
-        DBRelation.DBReference[] refs = r.getReferences();
-        for (int i = 0; i < refs.length; i++)
-        {
-            sql.append((addSeparator) ? ", " : "");
-            refs[i].getSourceColumn().addSQL(sql, DBExpr.CTX_NAME);
-            addSeparator = true;
-        }
-        // References
-        sql.append(") REFERENCES ");
-        targetTable.addSQL(sql, DBExpr.CTX_FULLNAME);
-        sql.append(" (");
-        // Target Names
-        addSeparator = false;
-        for (int i = 0; i < refs.length; i++)
-        {
-            sql.append((addSeparator) ? ", " : "");
-            refs[i].getTargetColumn().addSQL(sql, DBExpr.CTX_NAME);
-            addSeparator = true;
-        }
-        // done
-        sql.append(")");
-        // done
-        script.addStmt(sql);
-    }
-
-    /**
-     * Creates an alter table dll statement for adding, modifiying or droping a column.
-     * @param col the column which to add, modify or drop
-     * @param type the type of operation to perform
-     * @param script to which to append the sql statement to
-     * @return true if the statement was successfully appended to the buffer
-     */
-    protected void alterTable(DBTableColumn col, DBCmdType type, DBSQLScript script)
-    {
-        StringBuilder sql = new StringBuilder();
-        sql.append("ALTER TABLE ");
-        col.getRowSet().addSQL(sql, DBExpr.CTX_FULLNAME);
-        switch(type)
-        {
-            case CREATE:
-                sql.append(" ADD ");
-                appendColumnDesc(col, sql);
-                break;
-            case ALTER:
-                sql.append(" MODIFY ");
-                appendColumnDesc(col, sql);
-                break;
-            case DROP:
-                sql.append(" DROP COLUMN ");
-                sql.append(col.getName());
-                break;
-        }
-        // done
-        script.addStmt(sql);
-    }
-    
-    /**
-     * Returns true if the view has been created successfully.
-     * 
-     * @return true if the view has been created successfully
-     */
-    protected void createView(DBView v, DBSQLScript script)
-    {
-        // Create the Command
-        DBCommandExpr cmd = v.createCommand();
-        if (cmd==null)
-        {   // Check whether Error information is available
-            log.error("No command has been supplied for view " + v.getName());
-            throw new NotImplementedException(this, v.getName() + ".createCommand");
-        }
-        // Make sure there is no OrderBy
-        cmd.clearOrderBy();
-
-        // Build String
-        StringBuilder sql = new StringBuilder();
-        sql.append( "CREATE OR REPLACE VIEW ");
-        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;
-        }
-        sql.append(")\r\nAS\r\n");
-        cmd.addSQL( sql, DBExpr.CTX_DEFAULT);
-        // done
-        script.addStmt(sql.toString());
-    }
-
-    /**
-     * Returns true if the comment has been created successfully.
-     * 
-     * @return true if the comment has been created successfully
-     */
-    protected void createComment(DBDatabase db, String type, DBExpr expr, String comment, DBSQLScript script)
-    {
-        if (comment==null || comment.length()==0)
-            return; // Nothing to do
-        StringBuilder sql = new StringBuilder();
-        sql.append("COMMENT ON ");
-        sql.append(type);
-        sql.append(" ");
-        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("'");
-        // Create Index
-        script.addStmt(sql);
-    }
-    
-    /**
-     * Returns true if the object has been dropped successfully.
-     * 
-     * @return true if the object has been dropped successfully
+     * @see DBDatabaseDriver#getDDLScript(DBCmdType, DBObject, DBSQLScript)  
      */
-    protected void dropObject(String name, String objType, DBSQLScript script)
+    @Override
+    public void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
     {
-        if (name == null || name.length() == 0)
-            throw new InvalidArgumentException("name", name);
-        // Create Drop Statement
-        StringBuilder sql = new StringBuilder();
-        sql.append("DROP ");
-        sql.append(objType);
-        sql.append(" ");
-        appendElementName(sql, name);
-        script.addStmt(sql);
+        if (ddlGenerator==null)
+            ddlGenerator = new OracleDDLGenerator(this);
+        // forward request
+        ddlGenerator.getDDLScript(type, dbo, script); 
     }
-
     
     /**
      * Checks whether the database definition matches the real database structure.

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java Sun Oct  9 15:36:13 2011
@@ -35,21 +35,42 @@ public class OracleDDLGenerator extends 
     public OracleDDLGenerator(DBDatabaseDriverOracle driver)
     {
         super(driver);
+        // set Oracle specific data types
+        initDataTypes(driver);
+    }
+
+    /**
+     * sets Oracle specific data types
+     * @param driver
+     */
+    private void initDataTypes(DBDatabaseDriverOracle driver)
+    {   // Override data types
+        DATATYPE_INT_SMALL  = "NUMBER(5)";
+        DATATYPE_INT_BIG    = "NUMBER(38)";
+        DATATYPE_VARCHAR    = "VARCHAR2";
+        DATATYPE_DECIMAL    = "NUMBER";
+        if ( driver.getBooleanType() == BooleanType.CHAR )
+             DATATYPE_BOOLEAN = "CHAR(1)";
+        else DATATYPE_BOOLEAN = "NUMBER(1,0)";
     }
 
     @Override
-    protected void appendColumnDataType(DataType c, double size, StringBuilder sql)
+    protected boolean appendColumnDataType(DataType type, double size, DBTableColumn c, StringBuilder sql)
     {
-        switch (c)
+        switch (type)
         {
             case TEXT:
-            { // Check fixed or variable length
+            case CHAR:
+            {   // Char or Varchar
+                sql.append((type==DataType.CHAR) ? DATATYPE_CHAR : DATATYPE_VARCHAR);
+                // get length
                 int len = Math.abs((int)size);
                 if (len == 0)
-                    len = 100;
-                sql.append("VARCHAR2(");
+                    len = (type==DataType.CHAR) ? 1 : 100;
+                sql.append("(");
                 sql.append(String.valueOf(len));
-                sql.append(" char)");
+                // Check sign for char (unicode) or bytes (non-unicode) 
+                sql.append((size>0) ? " CHAR)" : " BYTE)");
             }
                 break;
             case BOOL:
@@ -57,14 +78,12 @@ public class OracleDDLGenerator extends 
                      sql.append("CHAR(1)");
                 else sql.append("NUMBER(1,0)");
                 break;
-            case DOUBLE:
-                sql.append("FLOAT(80)");
-                break;
                 
             default:
                 // use default
-                super.appendColumnDataType(c, size, sql);
+                return super.appendColumnDataType(type, size, c, sql);
         }
+        return true;
     }
  
     @Override
@@ -88,6 +107,12 @@ public class OracleDDLGenerator extends 
         // Tables and the rest
         super.createDatabase(db, script);
     }
+
+    @Override
+    protected void dropDatabase(DBDatabase db, DBSQLScript script)
+    {
+        dropObject(db.getSchema(), "USER", script);
+    }
     
     /**
      * Returns true if the sequence has been created successfully.

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDataDictionnary.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDataDictionnary.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDataDictionnary.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDataDictionnary.java Sun Oct  9 15:36:13 2011
@@ -101,7 +101,7 @@ public class OracleDataDictionnary {
         dataTypeMapping = new HashMap<String, DataType[]>();
         dataTypeMapping.put("VARCHAR2", new DataType[] { DataType.TEXT });
         dataTypeMapping.put("CHAR",     new DataType[] { DataType.CHAR, DataType.BOOL });
-        dataTypeMapping.put("NUMBER",   new DataType[] { DataType.DECIMAL, DataType.DOUBLE, 
+        dataTypeMapping.put("NUMBER",   new DataType[] { DataType.DECIMAL, DataType.FLOAT, 
                                                          DataType.INTEGER, DataType.AUTOINC, DataType.BOOL });
         dataTypeMapping.put("DATE",     new DataType[] { DataType.DATE, DataType.DATETIME });
         dataTypeMapping.put("CLOB",     new DataType[] { DataType.CLOB });

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleRowNumExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleRowNumExpr.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleRowNumExpr.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleRowNumExpr.java Sun Oct  9 15:36:13 2011
@@ -26,6 +26,8 @@ import org.apache.empire.db.DBColumn;
 import org.apache.empire.db.DBColumnExpr;
 import org.apache.empire.db.DBDatabase;
 import org.apache.empire.xml.XMLUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 
 
@@ -35,6 +37,8 @@ import org.w3c.dom.Element;
 public class OracleRowNumExpr extends DBColumnExpr
 {
     private final static long serialVersionUID = 1L;
+    private static final Logger log = LoggerFactory.getLogger(OracleRowNumExpr.class);
+    
     public final DBDatabase   db;
 
     /**

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java?rev=1180631&r1=1180630&r2=1180631&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java Sun Oct  9 15:36:13 2011
@@ -401,7 +401,7 @@ public class DBDatabaseDriverPostgreSQL 
             case BOOL:     return "CAST(? AS BOOL)";
             case INTEGER:  return "CAST(? AS INTEGER)";
             case DECIMAL:  return "CAST(? AS DECIMAL)";
-            case DOUBLE:   return "CAST(? AS DOUBLE PRECISION)";
+            case FLOAT:   return "CAST(? AS DOUBLE PRECISION)";
             case DATE:     return "CAST(? AS DATE)";
             case DATETIME: return "CAST(? AS TIMESTAMP)";
                 // Convert to text
@@ -761,7 +761,7 @@ public class DBDatabaseDriverPostgreSQL 
             case BOOL:
                 sql.append("BOOLEAN");
                 break;
-            case DOUBLE:
+            case FLOAT:
                 sql.append("DOUBLE PRECISION");
                 break;
             case DECIMAL:



Mime
View raw message