IGNITE-3791 Wrapped table name, keyspace name and column name in all generated 
DDL/DML statements. - Fixes #1062.

Signed-off-by: Alexey Kuznetsov <akuznet...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3db0a3de
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3db0a3de
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3db0a3de

Branch: refs/heads/ignite-3199-1
Commit: 3db0a3dea7503524aea8595434a0d43236c9cbb3
Parents: 8b8b02e
Author: Igor <irud...@gmail.com>
Authored: Thu Sep 15 09:41:22 2016 +0700
Committer: Alexey Kuznetsov <akuznet...@apache.org>
Committed: Thu Sep 15 09:41:22 2016 +0700

----------------------------------------------------------------------
 .../persistence/KeyPersistenceSettings.java     |  6 ++---
 .../KeyValuePersistenceSettings.java            |  4 +--
 .../persistence/PersistenceController.java      | 26 ++++++++++----------
 .../persistence/PersistenceSettings.java        |  4 +--
 .../store/cassandra/persistence/PojoField.java  |  2 +-
 .../cassandra/persistence/PojoValueField.java   |  6 ++---
 .../store/cassandra/utils/DDLGenerator.java     | 10 ++++++++
 7 files changed, 34 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3db0a3de/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/KeyPersistenceSettings.java
----------------------------------------------------------------------
diff --git 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/KeyPersistenceSettings.java
 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/KeyPersistenceSettings.java
index 393dbe4..5732b4e 100644
--- 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/KeyPersistenceSettings.java
+++ 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/KeyPersistenceSettings.java
@@ -104,7 +104,7 @@ public class KeyPersistenceSettings extends 
PersistenceSettings {
             if (partKey.length() != 0)
                 partKey.append(", ");
 
-            partKey.append(column);
+            partKey.append("\"").append(column).append("\"");
         }
 
         StringBuilder clusterKey = new StringBuilder();
@@ -115,7 +115,7 @@ public class KeyPersistenceSettings extends 
PersistenceSettings {
                 if (clusterKey.length() != 0)
                     clusterKey.append(", ");
 
-                clusterKey.append(column);
+                clusterKey.append("\"").append(column).append("\"");
             }
         }
 
@@ -143,7 +143,7 @@ public class KeyPersistenceSettings extends 
PersistenceSettings {
 
             boolean asc = PojoKeyField.SortOrder.ASC.equals(sortOrder);
 
-            builder.append(field.getColumn()).append(" ").append(asc ? "asc" : 
"desc");
+            builder.append("\"").append(field.getColumn()).append("\" 
").append(asc ? "asc" : "desc");
         }
 
         return builder.length() == 0 ? null : "clustering order by (" + 
builder.toString() + ")";

http://git-wip-us.apache.org/repos/asf/ignite/blob/3db0a3de/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/KeyValuePersistenceSettings.java
----------------------------------------------------------------------
diff --git 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/KeyValuePersistenceSettings.java
 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/KeyValuePersistenceSettings.java
index 2c43ed4..f4de066 100644
--- 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/KeyValuePersistenceSettings.java
+++ 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/KeyValuePersistenceSettings.java
@@ -249,7 +249,7 @@ public class KeyValuePersistenceSettings implements 
Serializable {
      */
     public String getKeyspaceDDLStatement() {
         StringBuilder builder = new StringBuilder();
-        builder.append("create keyspace if not exists ").append(keyspace);
+        builder.append("create keyspace if not exists 
\"").append(keyspace).append("\"");
 
         if (keyspaceOptions != null) {
             if (!keyspaceOptions.trim().toLowerCase().startsWith("with"))
@@ -285,7 +285,7 @@ public class KeyValuePersistenceSettings implements 
Serializable {
 
         StringBuilder builder = new StringBuilder();
 
-        builder.append("create table if not exists 
").append(keyspace).append(".").append(tbl);
+        builder.append("create table if not exists 
\"").append(keyspace).append("\".\"").append(tbl).append("\"");
         
builder.append("\n(\n").append(colsDDL).append(",\n").append(primaryKeyDDL).append("\n)");
 
         if (!optionsDDL.isEmpty())

http://git-wip-us.apache.org/repos/asf/ignite/blob/3db0a3de/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PersistenceController.java
----------------------------------------------------------------------
diff --git 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PersistenceController.java
 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PersistenceController.java
index e734ca3..9a1699b 100644
--- 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PersistenceController.java
+++ 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PersistenceController.java
@@ -107,11 +107,11 @@ public class PersistenceController {
                 questionsList.append(",");
             }
 
-            colsList.append(column);
+            colsList.append("\"").append(column).append("\"");
             questionsList.append("?");
         }
 
-        writeStatement = "insert into " + persistenceSettings.getKeyspace() + 
"." + persistenceSettings.getTable() + " (" +
+        writeStatement = "insert into \"" + persistenceSettings.getKeyspace() 
+ "\".\"" + persistenceSettings.getTable() + "\" (" +
             colsList.toString() + ") values (" + questionsList.toString() + 
")";
 
         if (persistenceSettings.getTTL() != null)
@@ -139,14 +139,14 @@ public class PersistenceController {
             if (statement.length() != 0)
                 statement.append(" and ");
 
-            statement.append(column).append("=?");
+            statement.append("\"").append(column).append("\"=?");
         }
 
         statement.append(";");
 
-        delStatement = "delete from " +
-            persistenceSettings.getKeyspace() + "." +
-            persistenceSettings.getTable() + " where " +
+        delStatement = "delete from \"" +
+            persistenceSettings.getKeyspace() + "\".\"" +
+            persistenceSettings.getTable() + "\" where " +
             statement.toString();
 
         return delStatement;
@@ -173,7 +173,7 @@ public class PersistenceController {
             if (i > 0)
                 hdrWithKeyFields.append(", ");
 
-            hdrWithKeyFields.append(keyCols.get(i));
+            hdrWithKeyFields.append("\"").append(keyCols.get(i)).append("\"");
         }
 
         StringBuilder hdr = new StringBuilder("select ");
@@ -184,22 +184,22 @@ public class PersistenceController {
 
             hdrWithKeyFields.append(",");
 
-            hdr.append(valCols.get(i));
-            hdrWithKeyFields.append(valCols.get(i));
+            hdr.append("\"").append(valCols.get(i)).append("\"");
+            hdrWithKeyFields.append("\"").append(valCols.get(i)).append("\"");
         }
 
         StringBuilder statement = new StringBuilder();
 
-        statement.append(" from ");
+        statement.append(" from \"");
         statement.append(persistenceSettings.getKeyspace());
-        statement.append(".").append(persistenceSettings.getTable());
-        statement.append(" where ");
+        statement.append("\".\"").append(persistenceSettings.getTable());
+        statement.append("\" where ");
 
         for (int i = 0; i < keyCols.size(); i++) {
             if (i > 0)
                 statement.append(" and ");
 
-            statement.append(keyCols.get(i)).append("=?");
+            statement.append("\"").append(keyCols.get(i)).append("\"=?");
         }
 
         statement.append(";");

http://git-wip-us.apache.org/repos/asf/ignite/blob/3db0a3de/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PersistenceSettings.java
----------------------------------------------------------------------
diff --git 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PersistenceSettings.java
 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PersistenceSettings.java
index 20d790a..1e858a3 100644
--- 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PersistenceSettings.java
+++ 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PersistenceSettings.java
@@ -219,10 +219,10 @@ public abstract class PersistenceSettings implements 
Serializable {
      */
     public String getTableColumnsDDL() {
         if (PersistenceStrategy.BLOB.equals(stgy))
-            return "  " + col + " " + DataType.Name.BLOB.toString();
+            return "  \"" + col + "\" " + DataType.Name.BLOB.toString();
 
         if (PersistenceStrategy.PRIMITIVE.equals(stgy))
-            return "  " + col + " " + 
PropertyMappingHelper.getCassandraType(javaCls);
+            return "  \"" + col + "\" " + 
PropertyMappingHelper.getCassandraType(javaCls);
 
         StringBuilder builder = new StringBuilder();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/3db0a3de/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PojoField.java
----------------------------------------------------------------------
diff --git 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PojoField.java
 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PojoField.java
index af569fd..402aa9a 100644
--- 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PojoField.java
+++ 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PojoField.java
@@ -205,7 +205,7 @@ public abstract class PojoField implements Serializable {
 
         this.javaCls = desc.getReadMethod().getDeclaringClass();
         this.desc = desc;
-        this.colDDL = col + " " + cassandraType.toString();
+        this.colDDL = "\"" + col + "\" " + cassandraType.toString();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/3db0a3de/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PojoValueField.java
----------------------------------------------------------------------
diff --git 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PojoValueField.java
 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PojoValueField.java
index c29f1db..c3512c3 100644
--- 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PojoValueField.java
+++ 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/persistence/PojoValueField.java
@@ -125,11 +125,11 @@ public class PojoValueField extends PojoField {
         StringBuilder builder = new StringBuilder();
 
         if (idxCls != null)
-            builder.append("create custom index if not exists on 
").append(keyspace).append(".").append(tbl);
+            builder.append("create custom index if not exists on 
\"").append(keyspace).append("\".\"").append(tbl).append("\"");
         else
-            builder.append("create index if not exists on 
").append(keyspace).append(".").append(tbl);
+            builder.append("create index if not exists on 
\"").append(keyspace).append("\".\"").append(tbl).append("\"");
 
-        builder.append(" (").append(getColumn()).append(")");
+        builder.append(" (\"").append(getColumn()).append("\")");
 
         if (idxCls != null)
             builder.append(" using '").append(idxCls).append("'");

http://git-wip-us.apache.org/repos/asf/ignite/blob/3db0a3de/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/utils/DDLGenerator.java
----------------------------------------------------------------------
diff --git 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/utils/DDLGenerator.java
 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/utils/DDLGenerator.java
index 4f40478..19e21f0 100644
--- 
a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/utils/DDLGenerator.java
+++ 
b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/utils/DDLGenerator.java
@@ -18,6 +18,8 @@
 package org.apache.ignite.cache.store.cassandra.utils;
 
 import java.io.File;
+import java.util.List;
+
 import 
org.apache.ignite.cache.store.cassandra.persistence.KeyValuePersistenceSettings;
 
 /**
@@ -52,6 +54,14 @@ public class DDLGenerator {
                 System.out.println();
                 System.out.println(settings.getTableDDLStatement());
                 System.out.println();
+
+                List<String> statements = settings.getIndexDDLStatements();
+                if (statements != null && !statements.isEmpty()) {
+                    for (String st : statements) {
+                        System.out.println(st);
+                        System.out.println();
+                    }
+                }
             }
             catch (Throwable e) {
                 
System.out.println("-------------------------------------------------------------");

Reply via email to