geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [geode] 01/02: only one handleSqlException method is now used instead of multiple copies now calls close when done with the ResultSet obtained from metadata connectionManager is now final on SqlHandler
Date Fri, 29 Dec 2017 22:30:52 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 8169022515416328b5d900c3005b038179c2ffed
Author: Darrel Schneider <dschneider@pivotal.io>
AuthorDate: Fri Dec 29 09:20:42 2017 -0800

    only one handleSqlException method is now used instead of multiple copies
    now calls close when done with the ResultSet obtained from metadata
    connectionManager is now final on SqlHandler
---
 .../jdbc/internal/ConnectionManager.java           | 30 ++++++----------------
 .../geode/connectors/jdbc/internal/SqlHandler.java |  4 +--
 2 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionManager.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionManager.java
index f8e9c44..052f860 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionManager.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/ConnectionManager.java
@@ -42,22 +42,14 @@ class ConnectionManager {
     return configService.getMappingForRegion(regionName);
   }
 
-  private JdbcDataSource createDataSource(ConnectionConfiguration config) {
-    return dataSourceMap.computeIfAbsent(config.getName(), k -> {
-      return buildJdbcDataSource(config);
-    });
-  }
-
   JdbcDataSource buildJdbcDataSource(ConnectionConfiguration config) {
     return new JdbcDataSourceBuilder(config).create();
   }
 
   private JdbcDataSource getDataSource(ConnectionConfiguration config) {
-    JdbcDataSource dataSource = dataSourceMap.get(config.getName());
-    if (dataSource != null) {
-      return dataSource;
-    }
-    return createDataSource(config);
+    return dataSourceMap.computeIfAbsent(config.getName(), k -> {
+      return buildJdbcDataSource(config);
+    });
   }
 
   Connection getConnection(ConnectionConfiguration config) {
@@ -111,17 +103,15 @@ class ConnectionManager {
   }
 
   private String computeKeyColumnName(ConnectionConfiguration connectionConfig, String tableName)
{
-    // TODO: check config for key column
     String key = null;
     try (Connection connection = getConnection(connectionConfig)) {
       DatabaseMetaData metaData = connection.getMetaData();
-      ResultSet tables = metaData.getTables(null, null, "%", null);
-
-      String realTableName = getTableNameFromMetaData(tableName, tables);
-      key = getPrimaryKeyColumnNameFromMetaData(realTableName, metaData);
-
+      try (ResultSet tables = metaData.getTables(null, null, "%", null)) {
+        String realTableName = getTableNameFromMetaData(tableName, tables);
+        key = getPrimaryKeyColumnNameFromMetaData(realTableName, metaData);
+      }
     } catch (SQLException e) {
-      handleSQLException(e);
+      SqlHandler.handleSQLException(e);
     }
     return key;
   }
@@ -159,10 +149,6 @@ class ConnectionManager {
     return key;
   }
 
-  private void handleSQLException(SQLException e) {
-    throw new IllegalStateException("JDBC connector detected unexpected SQLException", e);
-  }
-
   private void close(JdbcDataSource dataSource) {
     if (dataSource != null) {
       try {
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 06ec40c..1bcd5c0 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
@@ -31,7 +31,7 @@ import org.apache.geode.pdx.internal.PdxInstanceImpl;
 
 @Experimental
 public class SqlHandler {
-  private ConnectionManager manager;
+  private final ConnectionManager manager;
 
   public SqlHandler(ConnectionManager manager) {
     this.manager = manager;
@@ -220,7 +220,7 @@ public class SqlHandler {
     }
   }
 
-  private void handleSQLException(SQLException e) {
+  static void handleSQLException(SQLException e) {
     throw new IllegalStateException("JDBC connector detected unexpected SQLException", e);
   }
 }

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

Mime
View raw message