You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2017/10/31 00:36:46 UTC
[geode] branch feature/GEODE-3781 updated: added user and password
properties
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 37158a5 added user and password properties
37158a5 is described below
commit 37158a58b96abedaf2c4c33492f8cf2fa96a0715
Author: Darrel Schneider <ds...@pivotal.io>
AuthorDate: Mon Oct 30 17:36:30 2017 -0700
added user and password properties
---
.../geode/connectors/jdbc/JDBCConfiguration.java | 15 +++++++--
.../apache/geode/connectors/jdbc/JDBCManager.java | 12 ++++---
.../connectors/jdbc/JDBCConfigurationUnitTest.java | 37 ++++++++++++++++++++++
.../connectors/jdbc/JDBCManagerUnitTestTest.java | 11 ++++---
4 files changed, 64 insertions(+), 11 deletions(-)
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCConfiguration.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCConfiguration.java
index d96b9e8..e7a59bb 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCConfiguration.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCConfiguration.java
@@ -39,14 +39,17 @@ public class JDBCConfiguration {
Collections.unmodifiableList(Arrays.asList(DRIVER, URL));
private final String driver;
-
- private String url;
+ private final String url;
+ private final String user;
+ private final String password;
JDBCConfiguration(Properties configProps) {
validateKnownProperties(configProps);
validateRequiredProperties(configProps);
this.driver = configProps.getProperty(DRIVER);
this.url = configProps.getProperty(URL);
+ this.user = configProps.getProperty(USER);
+ this.password = configProps.getProperty(PASSWORD);
}
private void validateKnownProperties(Properties configProps) {
@@ -74,4 +77,12 @@ public class JDBCConfiguration {
return this.url;
}
+ public String getUser() {
+ return this.user;
+ }
+
+ public String getPassword() {
+ return this.password;
+ }
+
}
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 991dd47..6d6ca77 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
@@ -174,7 +174,7 @@ public class JDBCManager {
return columnNames.append(columnValues).toString();
}
- Connection getConnection() {
+ Connection getConnection(String user, String password) {
Connection result = this.conn;
try {
if (result != null && !result.isClosed()) {
@@ -194,7 +194,8 @@ public class JDBCManager {
}
}
try {
- result = createConnection(this.config.getURL());
+ result =
+ createConnection(this.config.getURL(), this.config.getUser(), this.config.getPassword());
} catch (SQLException e) {
// TODO: consider a different exception
throw new IllegalStateException("Could not connect to " + this.config.getURL(), e);
@@ -203,7 +204,8 @@ public class JDBCManager {
return result;
}
- protected Connection createConnection(String url) throws SQLException {
+ protected Connection createConnection(String url, String user, String password)
+ throws SQLException {
return DriverManager.getConnection(url);
}
@@ -253,7 +255,7 @@ public class JDBCManager {
return getPreparedStatementCache().computeIfAbsent(key, k -> {
String query = getQueryString(tableName, columnList, operation);
System.out.println("query=" + query);
- Connection con = getConnection();
+ Connection con = getConnection(null, null);
try {
return con.prepareStatement(query);
} catch (SQLException e) {
@@ -308,7 +310,7 @@ public class JDBCManager {
String computeKeyColumnName(String tableName) {
// TODO: check config for key column
- Connection con = getConnection();
+ Connection con = getConnection(null, null);
try {
DatabaseMetaData metaData = con.getMetaData();
ResultSet tablesRS = metaData.getTables(null, null, "%", null);
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCConfigurationUnitTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCConfigurationUnitTest.java
index c994e98..1d32948 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCConfigurationUnitTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCConfigurationUnitTest.java
@@ -74,4 +74,41 @@ public class JDBCConfigurationUnitTest {
assertThat(config.getURL()).isEqualTo("myUrl");
}
+ @Test
+ public void testDefaultUser() {
+ Properties props = new Properties();
+ props.setProperty("url", "");
+ props.setProperty("driver", "");
+ JDBCConfiguration config = new JDBCConfiguration(props);
+ assertThat(config.getUser()).isEqualTo(null);
+ }
+
+ @Test
+ public void testDefaultPassword() {
+ Properties props = new Properties();
+ props.setProperty("url", "");
+ props.setProperty("driver", "");
+ JDBCConfiguration config = new JDBCConfiguration(props);
+ assertThat(config.getPassword()).isEqualTo(null);
+ }
+
+ @Test
+ public void testUser() {
+ Properties props = new Properties();
+ props.setProperty("url", "");
+ props.setProperty("driver", "");
+ props.setProperty("user", "myUser");
+ JDBCConfiguration config = new JDBCConfiguration(props);
+ assertThat(config.getUser()).isEqualTo("myUser");
+ }
+
+ @Test
+ public void testPassword() {
+ Properties props = new Properties();
+ props.setProperty("url", "");
+ props.setProperty("driver", "");
+ props.setProperty("password", "myPassword");
+ JDBCConfiguration config = new JDBCConfiguration(props);
+ assertThat(config.getPassword()).isEqualTo("myPassword");
+ }
}
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCManagerUnitTestTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCManagerUnitTestTest.java
index 0f3b101..31aed63 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCManagerUnitTestTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCManagerUnitTestTest.java
@@ -60,7 +60,8 @@ public class JDBCManagerUnitTestTest {
}
@Override
- protected Connection createConnection(String url) throws SQLException {
+ protected Connection createConnection(String url, String user, String password)
+ throws SQLException {
ResultSet rsKeys = mock(ResultSet.class);
when(rsKeys.next()).thenReturn(true, false);
when(rsKeys.getString("COLUMN_NAME")).thenReturn(ID_COLUMN_NAME);
@@ -99,7 +100,8 @@ public class JDBCManagerUnitTestTest {
}
@Override
- protected Connection createConnection(String url) throws SQLException {
+ protected Connection createConnection(String url, String user, String password)
+ throws SQLException {
ResultSet rsKeys = mock(ResultSet.class);
when(rsKeys.next()).thenReturn(true, false);
when(rsKeys.getString("COLUMN_NAME")).thenReturn(ID_COLUMN_NAME);
@@ -138,7 +140,8 @@ public class JDBCManagerUnitTestTest {
}
@Override
- protected Connection createConnection(String url) throws SQLException {
+ protected Connection createConnection(String url, String user, String password)
+ throws SQLException {
if (primaryKeyResults == null) {
primaryKeyResults = mock(ResultSet.class);
when(primaryKeyResults.next()).thenReturn(true, false);
@@ -326,7 +329,7 @@ public class JDBCManagerUnitTestTest {
@Test
public void verifyMissingDriverClass() {
createManager("non existent driver", "fakeURL");
- catchException(this.mgr).getConnection();
+ catchException(this.mgr).getConnection(null, null);
assertThat((Exception) caughtException()).isInstanceOf(IllegalStateException.class);
assertThat(caughtException().getMessage())
.isEqualTo("Driver class \"non existent driver\" not found");
--
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].