Author: tomdz
Date: Sun Jul 23 22:41:30 2006
New Revision: 424910

URL: http://svn.apache.org/viewvc?rev=424910&view=rev
Log:
Added script mode to the SQL generation to allow platforms to create different 
SQL depending on whether it will be executed directly via JDBC or output to a 
file
Added Oracle support for SQL script generation which uses a forward slash to 
delimit PL/SQL code

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java
    
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
    
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java
    
db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
    
db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java
URL: 
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java?rev=424910&r1=424909&r2=424910&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java Sun Jul 23 
22:41:30 2006
@@ -113,6 +113,24 @@
     // runtime properties
 
     /**
+     * Determines whether script mode is on. This means that the generated SQL 
is not
+     * intended to be sent directly to the database but rather to be saved in 
a SQL
+     * script file. Per default, script mode is off.
+     * 
+     * @return <code>true</code> if script mode is on
+     */
+    public boolean isScriptModeOn();
+
+    /**
+     * Specifies whether script mode is on. This means that the generated SQL 
is not
+     * intended to be sent directly to the database but rather to be saved in 
a SQL
+     * script file.
+     * 
+     * @param scriptModeOn <code>true</code> if script mode is on
+     */
+    public void setScriptModeOn(boolean scriptModeOn);
+
+    /**
      * Determines whether delimited identifiers are used or normal SQL92 
identifiers
      * (which may only contain alphanumerical characters and the underscore, 
must start
      * with a letter and cannot be a reserved keyword).

Modified: 
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
URL: 
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java?rev=424910&r1=424909&r2=424910&view=diff
==============================================================================
--- 
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java 
(original)
+++ 
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java 
Sun Jul 23 22:41:30 2006
@@ -78,12 +78,14 @@
     private SqlBuilder _builder;
     /** The model reader for this platform. */
     private JdbcModelReader _modelReader;
+    /** Whether script mode is on. */
+    private boolean _scriptModeOn;
     /** Whether SQL comments are generated or not. */
     private boolean _sqlCommentsOn = true;
     /** Whether delimited identifiers are used or not. */
-    private boolean _delimitedIdentifierModeOn = false;
+    private boolean _delimitedIdentifierModeOn;
     /** Whether read foreign keys shall be sorted alphabetically. */
-    private boolean _foreignKeysSorted = false;
+    private boolean _foreignKeysSorted;
 
     /**
      * [EMAIL PROTECTED]
@@ -131,6 +133,22 @@
     public PlatformInfo getPlatformInfo()
     {
         return _info;
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     */
+    public boolean isScriptModeOn()
+    {
+        return _scriptModeOn;
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     */
+    public void setScriptModeOn(boolean scriptModeOn)
+    {
+        _scriptModeOn = scriptModeOn;
     }
 
     /**

Modified: 
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java
URL: 
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java?rev=424910&r1=424909&r2=424910&view=diff
==============================================================================
--- 
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java
 (original)
+++ 
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java
 Sun Jul 23 22:41:30 2006
@@ -149,28 +149,53 @@
         String columnName  = getColumnName(column);
         String triggerName = getConstraintName("trg", table, column.getName(), 
null);
 
-        // note that the BEGIN ... SELECT ... END; is all in one line and does
-        // not contain a semicolon except for the END-one
-        // this way, the tokenizer will not split the statement before the END
-        print("CREATE OR REPLACE TRIGGER ");
-        printIdentifier(triggerName);
-        print(" BEFORE INSERT ON ");
-        printIdentifier(getTableName(table));
-        print(" FOR EACH ROW WHEN (new.");
-        printIdentifier(columnName);
-        println(" IS NULL)");
-        print("BEGIN SELECT ");
-        printIdentifier(getConstraintName("seq", table, column.getName(), 
null));
-        print(".nextval INTO :new.");
-        printIdentifier(columnName);
-        print(" FROM dual");
-        print(getPlatformInfo().getSqlCommandDelimiter());
-        print(" END");
-        // It is important that there is a semicolon at the end of the 
statement (or more
-        // precisely, at the end of the PL/SQL block), and thus we put two 
semicolons here
-        // because the tokenizer will remove the one at the end
-        print(getPlatformInfo().getSqlCommandDelimiter());
-        printEndOfStatement();
+        if (getPlatform().isScriptModeOn())
+        {
+            // For the script, we output a more nicely formatted version
+            print("CREATE OR REPLACE TRIGGER ");
+            printlnIdentifier(triggerName);
+            print("BEFORE INSERT ON ");
+            printlnIdentifier(getTableName(table));
+            print("FOR EACH ROW WHEN (new.");
+            printIdentifier(columnName);
+            println(" IS NULL)");
+            println("BEGIN");
+            print("  SELECT ");
+            printIdentifier(getConstraintName("seq", table, column.getName(), 
null));
+            print(".nextval INTO :new.");
+            printIdentifier(columnName);
+            print(" FROM dual");
+            println(getPlatformInfo().getSqlCommandDelimiter());
+            print("END");
+            println(getPlatformInfo().getSqlCommandDelimiter());
+            println("/");
+            println();
+        }
+        else
+        {
+            // note that the BEGIN ... SELECT ... END; is all in one line and 
does
+            // not contain a semicolon except for the END-one
+            // this way, the tokenizer will not split the statement before the 
END
+            print("CREATE OR REPLACE TRIGGER ");
+            printIdentifier(triggerName);
+            print(" BEFORE INSERT ON ");
+            printIdentifier(getTableName(table));
+            print(" FOR EACH ROW WHEN (new.");
+            printIdentifier(columnName);
+            println(" IS NULL)");
+            print("BEGIN SELECT ");
+            printIdentifier(getConstraintName("seq", table, column.getName(), 
null));
+            print(".nextval INTO :new.");
+            printIdentifier(columnName);
+            print(" FROM dual");
+            print(getPlatformInfo().getSqlCommandDelimiter());
+            print(" END");
+            // It is important that there is a semicolon at the end of the 
statement (or more
+            // precisely, at the end of the PL/SQL block), and thus we put two 
semicolons here
+            // because the tokenizer will remove the one at the end
+            print(getPlatformInfo().getSqlCommandDelimiter());
+            printEndOfStatement();
+        }
     }
 
     /**

Modified: 
db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
URL: 
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java?rev=424910&r1=424909&r2=424910&view=diff
==============================================================================
--- 
db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
 (original)
+++ 
db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
 Sun Jul 23 22:41:30 2006
@@ -115,6 +115,7 @@
         {
             FileWriter writer = new FileWriter(_outputFile);
 
+            platform.setScriptModeOn(true);
             if (platform.getPlatformInfo().isSqlCommentsSupported())
             {
                 // we're generating SQL comments if possible

Modified: 
db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java
URL: 
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java?rev=424910&r1=424909&r2=424910&view=diff
==============================================================================
--- 
db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java
 (original)
+++ 
db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java
 Sun Jul 23 22:41:30 2006
@@ -90,6 +90,7 @@
         boolean            isCaseSensitive = 
platform.isDelimitedIdentifierModeOn();
         CreationParameters params          = getFilteredParameters(model, 
platform.getName(), isCaseSensitive);
 
+        platform.setScriptModeOn(false);
         // we're disabling the comment generation because we're writing 
directly to the database
         platform.setSqlCommentsOn(false);
         try


Reply via email to