geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [geode] branch feature/GEODE-3781 updated: added prepareStatementCache
Date Wed, 25 Oct 2017 21:34:56 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/feature/GEODE-3781 by this push:
     new efcbd7d  added prepareStatementCache
efcbd7d is described below

commit efcbd7d54712adc377f6557d9ca7740741ac3a59
Author: Darrel Schneider <dschneider@pivotal.io>
AuthorDate: Wed Oct 25 14:34:39 2017 -0700

    added prepareStatementCache
---
 .../apache/geode/connectors/jdbc/JDBCManager.java  | 25 ++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
index 67fdc1f..c115b57 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
@@ -24,6 +24,8 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import org.apache.geode.cache.Operation;
 import org.apache.geode.cache.Region;
@@ -76,7 +78,7 @@ public class JDBCManager {
     String tableName = getTableName(region);
     List<ColumnValue> columnList = getColumnToValueList(tableName, key, value, operation);
     String query = getQueryString(tableName, columnList, operation);
-    Statement statement = getQueryStatement(columnList, query);
+    PreparedStatement statement = getQueryStatement(columnList, query);
     try {
       statement.execute(query);
     } catch (SQLException e) {
@@ -126,13 +128,24 @@ public class JDBCManager {
     columnValues.append(")");
     return columnNames.append(columnValues).toString();
   }
-
-  private Statement getQueryStatement(List<ColumnValue> columnList, String query) {
-
-    // TODO Auto-generated method stub
-    return null;
+  
+  private Connection getConnection() {
+    return null; // NYI
   }
 
+  private final ConcurrentMap<String, PreparedStatement> preparedStatementCache = new
ConcurrentHashMap<>();
+  
+  private PreparedStatement getQueryStatement(List<ColumnValue> columnList, String
query) {
+    return preparedStatementCache.computeIfAbsent(query, k -> {
+      Connection con = getConnection();
+      try {
+        return con.prepareStatement(k);
+      } catch (SQLException e) {
+        throw new IllegalStateException("TODO handle exception", e);
+      }
+    });
+  }
+  
   private List<ColumnValue> getColumnToValueList(String tableName, Object key, PdxInstance
value,
       Operation operation) {
     Set<String> keyColumnNames = getKeyColumnNames(tableName);

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <commits@geode.apache.org>'].

Mime
View raw message