This is an automated email from the ASF dual-hosted git repository. agingade 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 77f119d Extracted ColumnValue class. 77f119d is described below commit 77f119d0271ffb5f6fb875d7fa3986dc40c083a0 Author: Anil <aging...@pivotal.io> AuthorDate: Thu Oct 26 17:06:59 2017 -0700 Extracted ColumnValue class. --- .../apache/geode/connectors/jdbc/ColumnValue.java | 39 +++++++++ .../apache/geode/connectors/jdbc/JDBCManager.java | 94 +++++++++------------- 2 files changed, 75 insertions(+), 58 deletions(-) diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/ColumnValue.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/ColumnValue.java new file mode 100644 index 0000000..de422d5 --- /dev/null +++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/ColumnValue.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.connectors.jdbc; + +public class ColumnValue { + final private boolean isKey; + final private String columnName; + final private Object value; + + public ColumnValue(boolean isKey, String columnName, Object value) { + this.isKey = isKey; + this.columnName = columnName; + this.value = value; + } + + public boolean isKey() { + return this.isKey; + } + + public String getColumnName() { + return this.columnName; + } + + public Object getValue() { + return this.value; + } +} 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 1b98da6..0ec643b 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 @@ -37,35 +37,12 @@ public class JDBCManager { private Connection conn; + private final ConcurrentMap<String, String> tableToPrimaryKeyMap = new ConcurrentHashMap<>(); + JDBCManager(JDBCConfiguration config) { this.config = config; } - public class ColumnValue { - - final private boolean isKey; - final private String columnName; - final private Object value; - - public ColumnValue(boolean isKey, String columnName, Object value) { - this.isKey = isKey; - this.columnName = columnName; - this.value = value; - } - - public boolean isKey() { - return this.isKey; - } - - public String getColumnName() { - return this.columnName; - } - - public Object getValue() { - return this.value; - } - } - public void write(Region region, Operation operation, Object key, PdxInstance value) { String tableName = getTableName(region); List<ColumnValue> columnList = getColumnToValueList(tableName, key, value, operation); @@ -265,44 +242,45 @@ public class JDBCManager { return fieldName; } - private final ConcurrentMap<String, String> tableToPrimaryKeyMap = new ConcurrentHashMap<>(); - private String getKeyColumnName(String tableName) { return tableToPrimaryKeyMap.computeIfAbsent(tableName, k -> { - // TODO: check config for key column - Connection con = getConnection(); - try { - DatabaseMetaData metaData = con.getMetaData(); - ResultSet tablesRS = metaData.getTables(null, null, "%", null); - String realTableName = null; - while (tablesRS.next()) { - String name = tablesRS.getString("TABLE_NAME"); - if (name.equalsIgnoreCase(k)) { - if (realTableName != null) { - throw new IllegalStateException("Duplicate tables that match region name"); - } - realTableName = name; + return computeKeyColumnName(k); + }); + } + + private String computeKeyColumnName(String k) { + // TODO: check config for key column + Connection con = getConnection(); + try { + DatabaseMetaData metaData = con.getMetaData(); + ResultSet tablesRS = metaData.getTables(null, null, "%", null); + String realTableName = null; + while (tablesRS.next()) { + String name = tablesRS.getString("TABLE_NAME"); + if (name.equalsIgnoreCase(k)) { + if (realTableName != null) { + throw new IllegalStateException("Duplicate tables that match region name"); } + realTableName = name; } - if (realTableName == null) { - throw new IllegalStateException("no table was found that matches " + k); - } - ResultSet primaryKeys = metaData.getPrimaryKeys(null, null, realTableName); - if (!primaryKeys.next()) { - throw new IllegalStateException( - "The table " + k + " does not have a primary key column."); - } - String key = primaryKeys.getString("COLUMN_NAME"); - if (primaryKeys.next()) { - throw new IllegalStateException( - "The table " + k + " has more than one primary key column."); - } - return key; - } catch (SQLException e) { - handleSQLException(e); - return null; // never reached } - }); + if (realTableName == null) { + throw new IllegalStateException("no table was found that matches " + k); + } + ResultSet primaryKeys = metaData.getPrimaryKeys(null, null, realTableName); + if (!primaryKeys.next()) { + throw new IllegalStateException("The table " + k + " does not have a primary key column."); + } + String key = primaryKeys.getString("COLUMN_NAME"); + if (primaryKeys.next()) { + throw new IllegalStateException( + "The table " + k + " has more than one primary key column."); + } + return key; + } catch (SQLException e) { + handleSQLException(e); + return null; // never reached + } } private void handleSQLException(SQLException e) { -- To stop receiving notification emails like this one, please contact ['"commits@geode.apache.org" <commits@geode.apache.org>'].