This is an automated email from the ASF dual-hosted git repository.

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ffa6a28 EMPIREDB-431 DBView: allow directly adding columns from 
another view
0ffa6a28 is described below

commit 0ffa6a28b619a4fc556933a2cb8e08204df57bc5
Author: Rainer Döbele <[email protected]>
AuthorDate: Mon Nov 25 11:16:35 2024 +0100

    EMPIREDB-431
    DBView: allow directly adding columns from another view
---
 .../src/main/java/org/apache/empire/db/DBView.java | 25 ++++++++++++++++------
 .../empire/dbms/oracle/OracleDDLGenerator.java     | 11 ++++++++++
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/empire-db/src/main/java/org/apache/empire/db/DBView.java 
b/empire-db/src/main/java/org/apache/empire/db/DBView.java
index f4c25e88..9f8b63f7 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBView.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBView.java
@@ -79,7 +79,7 @@ public abstract class DBView extends DBRowSet implements 
Cloneable
                 setAttribute(Column.COLATTR_ENUMTYPE, enumType);
             // Add to view
             if (view != null)
-                view.addColumn(this);
+                view.addViewColumn(this);
         }
 
         /**
@@ -101,7 +101,7 @@ public abstract class DBView extends DBRowSet implements 
Cloneable
                 setAttribute(Column.COLATTR_ENUMTYPE, enumType);
             // Add to view
             if (view != null)
-                view.addColumn(this);
+                view.addViewColumn(this);
         }
         
         public DBColumnExpr getSourceColumnExpr()
@@ -452,7 +452,7 @@ public abstract class DBView extends DBRowSet implements 
Cloneable
      * 
      * @param col a view column object
      */
-    protected void addColumn(DBViewColumn col)
+    protected void addViewColumn(DBViewColumn col)
     { // find column by name
         if (col == null || col.getRowSet() != this)
             throw new InvalidArgumentException("col", col);
@@ -500,18 +500,29 @@ public abstract class DBView extends DBRowSet implements 
Cloneable
     }
 
     /**
-     * Adds a column to the view based on an existing column in another table 
or view.
+     * Adds a column to the view based on an existing column in another table.
      * 
-     * @param sourceColumn existing column in another table or view  
+     * @param sourceColumn existing column in another table  
      * @return the view column object
      */
     protected final DBViewColumn addColumn(DBTableColumn sourceColumn)
     {   // find column by name
-        return new DBViewColumn(this, sourceColumn.getName(), sourceColumn, 
0.0d);
+        return new DBViewColumn(this, sourceColumn.getName(), sourceColumn, 
sourceColumn.getSize());
     }
 
     /**
-     * This function searchs for equal columns given by the specified 
DBColumnExpr object.
+     * Adds a column to the view based on an existing column in another view.
+     * 
+     * @param sourceColumn existing column in another view  
+     * @return the view column object
+     */
+    protected final DBViewColumn addColumn(DBViewColumn sourceColumn)
+    {   // find column by name
+        return new DBViewColumn(this, sourceColumn.getName(), sourceColumn, 
sourceColumn.getSize());
+    }
+
+    /**
+     * This function searches for equal columns given by the specified 
DBColumnExpr object.
      * 
      * @param expr the DBColumnExpr object
      * @return the located column (only DBViewColumn objects)
diff --git 
a/empire-db/src/main/java/org/apache/empire/dbms/oracle/OracleDDLGenerator.java 
b/empire-db/src/main/java/org/apache/empire/dbms/oracle/OracleDDLGenerator.java
index 800dc18e..f7b5706d 100644
--- 
a/empire-db/src/main/java/org/apache/empire/dbms/oracle/OracleDDLGenerator.java
+++ 
b/empire-db/src/main/java/org/apache/empire/dbms/oracle/OracleDDLGenerator.java
@@ -18,6 +18,7 @@
  */
 package org.apache.empire.dbms.oracle;
 
+import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBColumn;
 import org.apache.empire.db.DBDDLGenerator;
@@ -28,6 +29,7 @@ import org.apache.empire.db.DBSQLBuilder;
 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.dbms.oracle.DBMSHandlerOracle.BooleanType;
 
 public class OracleDDLGenerator extends DBDDLGenerator<DBMSHandlerOracle>
@@ -166,6 +168,15 @@ public class OracleDDLGenerator extends 
DBDDLGenerator<DBMSHandlerOracle>
                 createComment(db, "COLUMN", c, com, script);
         }
     }
+    
+    @Override
+    protected void addCreateViewStmt(DBView v, DBSQLBuilder sql, DBSQLScript 
script)
+    {
+        // log.info("Adding create statmement for view {}.", v.getName());
+        String stmt = sql.toString();
+        stmt = StringUtils.replace(stmt, "CREATE VIEW", "CREATE OR REPLACE 
VIEW");
+        script.addStmt(stmt);
+    }
 
     protected void createComment(DBDatabase db, String type, DBExpr expr, 
String comment, DBSQLScript script)
     {

Reply via email to