empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject empire-db git commit: EMPIREDB-265 correctly escape object names for DDL DROP statements
Date Mon, 23 Oct 2017 09:25:47 GMT
Repository: empire-db
Updated Branches:
  refs/heads/master 13c6dad6b -> 65f5aa094


EMPIREDB-265
correctly escape object names for DDL DROP statements


Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/65f5aa09
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/65f5aa09
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/65f5aa09

Branch: refs/heads/master
Commit: 65f5aa094e410ccd8ec699785b40960130a5a4d7
Parents: 13c6dad
Author: Rainer Döbele <doebele@apache.org>
Authored: Mon Oct 23 11:25:43 2017 +0200
Committer: Rainer Döbele <doebele@apache.org>
Committed: Mon Oct 23 11:25:43 2017 +0200

----------------------------------------------------------------------
 .../org/apache/empire/db/DBDDLGenerator.java    | 25 +++++++++++++-------
 .../empire/db/oracle/OracleDDLGenerator.java    |  2 +-
 2 files changed, 17 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/empire-db/blob/65f5aa09/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java b/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
index 81d6343..26ba970 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
@@ -18,6 +18,7 @@
  */
 package org.apache.empire.db;
 
+import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.DataType;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.MiscellaneousErrorException;
@@ -211,6 +212,7 @@ public abstract class DBDDLGenerator<T extends DBDatabaseDriver>
         if (dbo==null || dbo.getDatabase().getDriver()!=driver)
             throw new InvalidArgumentException("dbo", dbo);
         // Check Type of object
+        String schema = dbo.getDatabase().getSchema();
         if (dbo instanceof DBDatabase)
         { // Database
             switch (type)
@@ -219,7 +221,7 @@ public abstract class DBDDLGenerator<T extends DBDatabaseDriver>
                     createDatabase((DBDatabase) dbo, script);
                     return;
                 case DROP:
-                    dropObject(((DBDatabase) dbo).getSchema(), databaseObjectName, script);
+                    dropObject(null, schema, databaseObjectName, script);
                     return;
                 default:
                     throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName()
+ "." + type);
@@ -233,7 +235,7 @@ public abstract class DBDDLGenerator<T extends DBDatabaseDriver>
                     createTable((DBTable) dbo, script);
                     return;
                 case DROP:
-                    dropObject(((DBTable) dbo).getFullName(), "TABLE", script);
+                    dropObject(schema, ((DBTable) dbo).getName(), "TABLE", script);
                     return;
                 default:
                     throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName()
+ "." + type);
@@ -247,10 +249,10 @@ public abstract class DBDDLGenerator<T extends DBDatabaseDriver>
                     createView((DBView) dbo, script);
                     return;
                 case DROP:
-                    dropObject(((DBView) dbo).getFullName(), "VIEW", script);
+                    dropObject(schema, ((DBView) dbo).getName(), "VIEW", script);
                     return;
                 case ALTER:
-                    dropObject(((DBView) dbo).getFullName(), "VIEW", script);
+                    dropObject(schema, ((DBView) dbo).getName(), "VIEW", script);
                     createView((DBView) dbo, script);
                     return;
                 default:
@@ -265,7 +267,7 @@ public abstract class DBDDLGenerator<T extends DBDatabaseDriver>
                     createRelation((DBRelation) dbo, script);
                     return;
                 case DROP:
-                    dropObject(((DBRelation) dbo).getFullName(), "CONSTRAINT", script);
+                    dropObject(schema, ((DBRelation) dbo).getName(), "CONSTRAINT", script);
                     return;
                 default:
                     throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName()
+ "." + type);
@@ -279,7 +281,7 @@ public abstract class DBDDLGenerator<T extends DBDatabaseDriver>
                     createIndex(((DBIndex) dbo).getTable(), (DBIndex) dbo, script);
                     return;
                 case DROP:
-                    dropObject(((DBIndex) dbo).getFullName(), "INDEX", script);
+                    dropObject(schema, ((DBIndex) dbo).getName(), "INDEX", script);
                     return;
                 default:
                     throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName()
+ "." + type);
@@ -332,7 +334,7 @@ public abstract class DBDDLGenerator<T extends DBDatabaseDriver>
      */
     protected void dropDatabase(DBDatabase db, DBSQLScript script)
     {
-        dropObject(db.getSchema(), "DATABASE", script);
+        dropObject(null, db.getSchema(), "DATABASE", script);
     }
     
     /**
@@ -566,15 +568,20 @@ public abstract class DBDDLGenerator<T extends DBDatabaseDriver>
      * @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)
+    protected void dropObject(String schema, String name, String objType, DBSQLScript script)
     {
-        if (name == null || name.length() == 0)
+        if (StringUtils.isEmpty(name))
             throw new InvalidArgumentException("name", name);
         // Create Drop Statement
         StringBuilder sql = new StringBuilder();
         sql.append("DROP ");
         sql.append(objType);
         sql.append(" ");
+        if (StringUtils.isNotEmpty(schema))
+        {   // append schema
+            sql.append(schema);
+            sql.append(".");
+        }
         appendElementName(sql, name);
         script.addStmt(sql);
     }

http://git-wip-us.apache.org/repos/asf/empire-db/blob/65f5aa09/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java b/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
index ff683ae..4b39da5 100644
--- a/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
+++ b/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
@@ -111,7 +111,7 @@ public class OracleDDLGenerator extends DBDDLGenerator<DBDatabaseDriverOracle>
     @Override
     protected void dropDatabase(DBDatabase db, DBSQLScript script)
     {
-        dropObject(db.getSchema(), "USER", script);
+        dropObject(null, db.getSchema(), "USER", script);
     }
     
     /**


Mime
View raw message