geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [geode] 01/02: changed getTableName to getQuotedTablePath
Date Wed, 09 Jan 2019 22:43:55 GMT
This is an automated email from the ASF dual-hosted git repository.

dschneider pushed a commit to branch feature/GEODE-6225
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 3be1bf7a5c88c038c291aacc511b95af408cd46c
Author: Darrel Schneider <dschneider@pivotal.io>
AuthorDate: Wed Jan 9 12:19:16 2019 -0800

    changed getTableName to getQuotedTablePath
---
 .../geode/connectors/jdbc/internal/SqlHandler.java |  2 +-
 .../jdbc/internal/SqlStatementFactory.java         | 16 +++----
 .../connectors/jdbc/internal/TableMetaData.java    |  8 ++--
 .../jdbc/internal/TableMetaDataView.java           |  7 ++-
 .../connectors/jdbc/internal/SqlHandlerTest.java   |  2 +-
 .../jdbc/internal/SqlStatementFactoryTest.java     | 56 +++++++++++++---------
 .../jdbc/internal/TableMetaDataManagerTest.java    | 22 +++++++--
 7 files changed, 73 insertions(+), 40 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlHandler.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlHandler.java
index b6d12d5..ec1fdbf 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlHandler.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlHandler.java
@@ -225,7 +225,7 @@ public class SqlHandler {
       Operation operation) {
     SqlStatementFactory statementFactory =
         new SqlStatementFactory(tableMetaData.getIdentifierQuoteString());
-    String tableName = tableMetaData.getTableName();
+    String tableName = tableMetaData.getQuotedTablePath();
     if (operation.isCreate()) {
       return statementFactory.createInsertSqlString(tableName, entryColumnData);
     } else if (operation.isUpdate()) {
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlStatementFactory.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlStatementFactory.java
index 7807942..7d85ced 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlStatementFactory.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlStatementFactory.java
@@ -24,14 +24,14 @@ class SqlStatementFactory {
     this.quote = identifierQuoteString;
   }
 
-  String createSelectQueryString(String tableName, EntryColumnData entryColumnData) {
+  String createSelectQueryString(String quotedTablePath, EntryColumnData entryColumnData)
{
     return addKeyColumnsToQuery(entryColumnData,
-        new StringBuilder("SELECT * FROM ").append(quote).append(tableName).append(quote));
+        new StringBuilder("SELECT * FROM ").append(quotedTablePath));
   }
 
-  String createDestroySqlString(String tableName, EntryColumnData entryColumnData) {
+  String createDestroySqlString(String quotedTablePath, EntryColumnData entryColumnData)
{
     return addKeyColumnsToQuery(entryColumnData,
-        new StringBuilder("DELETE FROM ").append(quote).append(tableName).append(quote));
+        new StringBuilder("DELETE FROM ").append(quotedTablePath));
   }
 
   private String addKeyColumnsToQuery(EntryColumnData entryColumnData, StringBuilder queryBuilder)
{
@@ -48,9 +48,9 @@ class SqlStatementFactory {
     return queryBuilder.toString();
   }
 
-  String createUpdateSqlString(String tableName, EntryColumnData entryColumnData) {
+  String createUpdateSqlString(String quotedTablePath, EntryColumnData entryColumnData) {
     StringBuilder query = new StringBuilder("UPDATE ")
-        .append(quote).append(tableName).append(quote)
+        .append(quotedTablePath)
         .append(" SET ");
     int idx = 0;
     for (ColumnData column : entryColumnData.getEntryValueColumnData()) {
@@ -64,9 +64,9 @@ class SqlStatementFactory {
     return addKeyColumnsToQuery(entryColumnData, query);
   }
 
-  String createInsertSqlString(String tableName, EntryColumnData entryColumnData) {
+  String createInsertSqlString(String quotedTablePath, EntryColumnData entryColumnData) {
     StringBuilder columnNames = new StringBuilder("INSERT INTO ")
-        .append(quote).append(tableName).append(quote)
+        .append(quotedTablePath)
         .append(" (");
     StringBuilder columnValues = new StringBuilder(" VALUES (");
     addColumnDataToSqlString(entryColumnData, columnNames, columnValues);
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/TableMetaData.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/TableMetaData.java
index 5020e12..affd8a6 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/TableMetaData.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/TableMetaData.java
@@ -22,22 +22,22 @@ import java.util.Set;
 
 public class TableMetaData implements TableMetaDataView {
 
-  private final String tableName;
+  private final String quotedTablePath;
   private final List<String> keyColumnNames;
   private final Map<String, Integer> columnNameToTypeMap;
   private final String identifierQuoteString;
 
   public TableMetaData(String tableName, List<String> keyColumnNames, String quoteString,
       Map<String, Integer> dataTypes) {
-    this.tableName = tableName;
+    this.quotedTablePath = quoteString + tableName + quoteString;
     this.keyColumnNames = keyColumnNames;
     this.columnNameToTypeMap = dataTypes;
     this.identifierQuoteString = quoteString;
   }
 
   @Override
-  public String getTableName() {
-    return tableName;
+  public String getQuotedTablePath() {
+    return quotedTablePath;
   }
 
   @Override
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/TableMetaDataView.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/TableMetaDataView.java
index 3c18dd4..e897dea 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/TableMetaDataView.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/TableMetaDataView.java
@@ -21,7 +21,12 @@ import java.util.List;
 import java.util.Set;
 
 public interface TableMetaDataView {
-  String getTableName();
+  /**
+   * The path will include the catalog and schema if needed.
+   *
+   * @return the fully qualified, quoted, table path
+   */
+  String getQuotedTablePath();
 
   List<String> getKeyColumnNames();
 
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlHandlerTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlHandlerTest.java
index fc8c861..a9303ad 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlHandlerTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlHandlerTest.java
@@ -90,7 +90,7 @@ public class SqlHandlerTest {
     when(region.getRegionService()).thenReturn(cache);
     tableMetaDataManager = mock(TableMetaDataManager.class);
     tableMetaDataView = mock(TableMetaDataView.class);
-    when(tableMetaDataView.getTableName()).thenReturn(TABLE_NAME);
+    when(tableMetaDataView.getQuotedTablePath()).thenReturn(TABLE_NAME);
     when(tableMetaDataView.getKeyColumnNames()).thenReturn(Arrays.asList(KEY_COLUMN));
     final String IDS = "ids";
     when(tableMetaDataManager.getTableMetaDataView(any(), any()))
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlStatementFactoryTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlStatementFactoryTest.java
index 0a13981..22d8853 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlStatementFactoryTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlStatementFactoryTest.java
@@ -25,7 +25,8 @@ import org.junit.Test;
 
 public class SqlStatementFactoryTest {
 
-  private static final String TABLE_NAME = "testTable";
+  private static final String QUOTE = "@@";
+  private static final String QUOTED_TABLE_PATH = QUOTE + "testTable" + QUOTE;
   private static final String KEY_COLUMN_1_NAME = "keyColumn1";
   private static final String KEY_COLUMN_2_NAME = "keyColumn2";
   private static final String VALUE_COLUMN_1_NAME = "valueColumn1";
@@ -34,7 +35,11 @@ public class SqlStatementFactoryTest {
   private final List<ColumnData> valueColumnData = new ArrayList<>();
 
   private EntryColumnData entryColumnData;
-  private SqlStatementFactory factory = new SqlStatementFactory("");
+  private SqlStatementFactory factory = new SqlStatementFactory(QUOTE);
+
+  private String quoted(String id) {
+    return QUOTE + id + QUOTE;
+  }
 
   @Before
   public void setup() {
@@ -47,9 +52,10 @@ public class SqlStatementFactoryTest {
   @Test
   public void getSelectQueryString() throws Exception {
     String expectedStatement =
-        String.format("SELECT * FROM %s WHERE %s = ?", TABLE_NAME, KEY_COLUMN_1_NAME);
+        String.format("SELECT * FROM %s WHERE %s = ?", QUOTED_TABLE_PATH,
+            quoted(KEY_COLUMN_1_NAME));
 
-    String statement = factory.createSelectQueryString(TABLE_NAME, entryColumnData);
+    String statement = factory.createSelectQueryString(QUOTED_TABLE_PATH, entryColumnData);
 
     assertThat(statement).isEqualTo(expectedStatement);
   }
@@ -57,9 +63,9 @@ public class SqlStatementFactoryTest {
   @Test
   public void getDestroySqlString() throws Exception {
     String expectedStatement =
-        String.format("DELETE FROM %s WHERE %s = ?", TABLE_NAME, KEY_COLUMN_1_NAME);
+        String.format("DELETE FROM %s WHERE %s = ?", QUOTED_TABLE_PATH, quoted(KEY_COLUMN_1_NAME));
 
-    String statement = factory.createDestroySqlString(TABLE_NAME, entryColumnData);
+    String statement = factory.createDestroySqlString(QUOTED_TABLE_PATH, entryColumnData);
 
     assertThat(statement).isEqualTo(expectedStatement);
   }
@@ -67,9 +73,10 @@ public class SqlStatementFactoryTest {
   @Test
   public void getUpdateSqlString() throws Exception {
     String expectedStatement = String.format("UPDATE %s SET %s = ?, %s = ? WHERE %s = ?",
-        TABLE_NAME, VALUE_COLUMN_1_NAME, VALUE_COLUMN_2_NAME, KEY_COLUMN_1_NAME);
+        QUOTED_TABLE_PATH, quoted(VALUE_COLUMN_1_NAME), quoted(VALUE_COLUMN_2_NAME),
+        quoted(KEY_COLUMN_1_NAME));
 
-    String statement = factory.createUpdateSqlString(TABLE_NAME, entryColumnData);
+    String statement = factory.createUpdateSqlString(QUOTED_TABLE_PATH, entryColumnData);
 
     assertThat(statement).isEqualTo(expectedStatement);
   }
@@ -77,9 +84,10 @@ public class SqlStatementFactoryTest {
   @Test
   public void getInsertSqlString() throws Exception {
     String expectedStatement = String.format("INSERT INTO %s (%s,%s,%s) VALUES (?,?,?)",
-        TABLE_NAME, VALUE_COLUMN_1_NAME, VALUE_COLUMN_2_NAME, KEY_COLUMN_1_NAME);
+        QUOTED_TABLE_PATH, quoted(VALUE_COLUMN_1_NAME), quoted(VALUE_COLUMN_2_NAME),
+        quoted(KEY_COLUMN_1_NAME));
 
-    String statement = factory.createInsertSqlString(TABLE_NAME, entryColumnData);
+    String statement = factory.createInsertSqlString(QUOTED_TABLE_PATH, entryColumnData);
 
     assertThat(statement).isEqualTo(expectedStatement);
   }
@@ -89,9 +97,9 @@ public class SqlStatementFactoryTest {
     valueColumnData.clear();
     keyColumnData.clear();
 
-    String statement = factory.createInsertSqlString(TABLE_NAME, entryColumnData);
+    String statement = factory.createInsertSqlString(QUOTED_TABLE_PATH, entryColumnData);
 
-    String expectedStatement = String.format("INSERT INTO %s () VALUES ()", TABLE_NAME);
+    String expectedStatement = String.format("INSERT INTO %s () VALUES ()", QUOTED_TABLE_PATH);
     assertThat(statement).isEqualTo(expectedStatement);
   }
 
@@ -99,10 +107,11 @@ public class SqlStatementFactoryTest {
   public void getInsertSqlStringGivenMultipleKeys() throws Exception {
     keyColumnData.add(new ColumnData(KEY_COLUMN_2_NAME, null, 0));
 
-    String statement = factory.createInsertSqlString(TABLE_NAME, entryColumnData);
+    String statement = factory.createInsertSqlString(QUOTED_TABLE_PATH, entryColumnData);
 
     String expectedStatement = String.format("INSERT INTO %s (%s,%s,%s,%s) VALUES (?,?,?,?)",
-        TABLE_NAME, VALUE_COLUMN_1_NAME, VALUE_COLUMN_2_NAME, KEY_COLUMN_1_NAME, KEY_COLUMN_2_NAME);
+        QUOTED_TABLE_PATH, quoted(VALUE_COLUMN_1_NAME), quoted(VALUE_COLUMN_2_NAME),
+        quoted(KEY_COLUMN_1_NAME), quoted(KEY_COLUMN_2_NAME));
     assertThat(statement).isEqualTo(expectedStatement);
   }
 
@@ -110,10 +119,11 @@ public class SqlStatementFactoryTest {
   public void getUpdateSqlStringGivenMultipleKeys() throws Exception {
     keyColumnData.add(new ColumnData(KEY_COLUMN_2_NAME, null, 0));
 
-    String statement = factory.createUpdateSqlString(TABLE_NAME, entryColumnData);
+    String statement = factory.createUpdateSqlString(QUOTED_TABLE_PATH, entryColumnData);
 
     String expectedStatement = String.format("UPDATE %s SET %s = ?, %s = ? WHERE %s = ? AND
%s = ?",
-        TABLE_NAME, VALUE_COLUMN_1_NAME, VALUE_COLUMN_2_NAME, KEY_COLUMN_1_NAME, KEY_COLUMN_2_NAME);
+        QUOTED_TABLE_PATH, quoted(VALUE_COLUMN_1_NAME), quoted(VALUE_COLUMN_2_NAME),
+        quoted(KEY_COLUMN_1_NAME), quoted(KEY_COLUMN_2_NAME));
     assertThat(statement).isEqualTo(expectedStatement);
   }
 
@@ -121,11 +131,12 @@ public class SqlStatementFactoryTest {
   public void getSelectQueryStringGivenMultipleKeys() throws Exception {
     keyColumnData.add(new ColumnData(KEY_COLUMN_2_NAME, null, 0));
 
-    String statement = factory.createSelectQueryString(TABLE_NAME, entryColumnData);
+    String statement = factory.createSelectQueryString(QUOTED_TABLE_PATH, entryColumnData);
 
     String expectedStatement =
-        String.format("SELECT * FROM %s WHERE %s = ? AND %s = ?", TABLE_NAME, KEY_COLUMN_1_NAME,
-            KEY_COLUMN_2_NAME);
+        String.format("SELECT * FROM %s WHERE %s = ? AND %s = ?", QUOTED_TABLE_PATH,
+            quoted(KEY_COLUMN_1_NAME),
+            quoted(KEY_COLUMN_2_NAME));
     assertThat(statement).isEqualTo(expectedStatement);
   }
 
@@ -133,11 +144,12 @@ public class SqlStatementFactoryTest {
   public void getDestroySqlStringGivenMultipleKeys() throws Exception {
     keyColumnData.add(new ColumnData(KEY_COLUMN_2_NAME, null, 0));
 
-    String statement = factory.createDestroySqlString(TABLE_NAME, entryColumnData);
+    String statement = factory.createDestroySqlString(QUOTED_TABLE_PATH, entryColumnData);
 
     String expectedStatement =
-        String.format("DELETE FROM %s WHERE %s = ? AND %s = ?", TABLE_NAME, KEY_COLUMN_1_NAME,
-            KEY_COLUMN_2_NAME);
+        String.format("DELETE FROM %s WHERE %s = ? AND %s = ?", QUOTED_TABLE_PATH,
+            quoted(KEY_COLUMN_1_NAME),
+            quoted(KEY_COLUMN_2_NAME));
     assertThat(statement).isEqualTo(expectedStatement);
   }
 
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/TableMetaDataManagerTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/TableMetaDataManagerTest.java
index c5c3520..081c2a7 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/TableMetaDataManagerTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/TableMetaDataManagerTest.java
@@ -264,7 +264,23 @@ public class TableMetaDataManagerTest {
     TableMetaDataView data =
         tableMetaDataManager.getTableMetaDataView(connection, regionMapping);
 
-    assertThat(data.getTableName()).isEqualTo(TABLE_NAME);
+    assertThat(data.getQuotedTablePath()).isEqualTo(TABLE_NAME);
+  }
+
+  @Test
+  public void returnsQuotedTableNameWhenMetaDataHasQuoteId() throws Exception {
+    setupPrimaryKeysMetaData();
+    when(primaryKeysResultSet.next()).thenReturn(true).thenReturn(false);
+    when(tablesResultSet.next()).thenReturn(true).thenReturn(true).thenReturn(false);
+    when(tablesResultSet.getString("TABLE_NAME")).thenReturn(TABLE_NAME.toUpperCase())
+        .thenReturn(TABLE_NAME);
+    String QUOTE = "@@";
+    when(this.databaseMetaData.getIdentifierQuoteString()).thenReturn(QUOTE);
+
+    TableMetaDataView data =
+        tableMetaDataManager.getTableMetaDataView(connection, regionMapping);
+
+    assertThat(data.getQuotedTablePath()).isEqualTo(QUOTE + TABLE_NAME + QUOTE);
   }
 
   @Test
@@ -279,7 +295,7 @@ public class TableMetaDataManagerTest {
     TableMetaDataView data =
         tableMetaDataManager.getTableMetaDataView(connection, regionMapping);
 
-    assertThat(data.getTableName()).isEqualTo(TABLE_NAME.toUpperCase());
+    assertThat(data.getQuotedTablePath()).isEqualTo(TABLE_NAME.toUpperCase());
   }
 
   @Test
@@ -411,7 +427,7 @@ public class TableMetaDataManagerTest {
     TableMetaDataView data =
         tableMetaDataManager.getTableMetaDataView(connection, regionMapping);
 
-    assertThat(data.getTableName()).isEqualTo(TABLE_NAME);
+    assertThat(data.getQuotedTablePath()).isEqualTo(TABLE_NAME);
   }
 
   private void setupPrimaryKeysMetaData() throws SQLException {


Mime
View raw message