Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDBC: Merge develop to master #90

Merged
merged 32 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
be4f084
check JDBC connection #69
Aug 21, 2018
dc92751
check JDBC connection #69
Aug 21, 2018
0f19fc8
Add getDBMajorVersion only for test
Sep 3, 2018
9b15e42
added checkConnectionTimeOut
Sep 11, 2018
2f6246e
JDBC info.xml updated.
Sep 14, 2018
db14299
JDBC info.xml file updated.
Sep 14, 2018
cb3edb0
Add new parameter jdbcCredentials
Dec 12, 2018
096dad2
Add new parameter jdbcCredentials
Dec 12, 2018
cc6469a
Fix SPLDOC typo in checkConnection parameter #74
Dec 12, 2018
3b39de0
Add new parameter jdbcCredentials
Dec 12, 2018
d80ba34
Add new parameter jdbcCredentials
Dec 13, 2018
fd59a03
info.xml updated parameter jdbcCredentials
anouri Dec 13, 2018
1fd2a3b
JDBC SPLDOC improved #76
anouri Jan 4, 2019
8fe42b4
java.net.ConnectException not catched #57
anouri Jan 7, 2019
5f70c7d
support application configuration
anouri Jan 7, 2019
929500b
exception handling improved.
Jan 15, 2019
0d9d8cb
loop in exception handling fixed
Jan 17, 2019
bbd0f9b
credentials is a string and not a file
Jan 17, 2019
ecbd83f
Document JDBC driver setup. #77
Jan 18, 2019
9f3755d
corrections for #79 #78
Jan 23, 2019
748ca57
merge master to develop
Jan 23, 2019
e2c7969
remove spldocs from develop branch
Jan 23, 2019
b0bdebe
removed lib from develop branch
Jan 23, 2019
5866b73
copy from master to develop
Feb 5, 2019
6c0690c
merge jdbc master branche to develop (#83)
anouri Feb 5, 2019
e19f3fa
release number increased #82
Feb 5, 2019
ba0c78a
check sqlFailureAction before rollback
Feb 5, 2019
bad2c70
Merge branch 'master' into develop
Apr 15, 2019
55499af
Corrections for issues #86 #87 #88
Apr 15, 2019
d4e6902
correction for #88
Apr 15, 2019
7cd4ded
correction for #88
Apr 24, 2019
e413a63
update JDNC info.xml file version 1.5.0
anouri Apr 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.ibm.streamsx.jdbc;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
Expand All @@ -13,6 +14,7 @@
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;
Expand Down Expand Up @@ -161,7 +163,7 @@ public void setJdbcPassword(String jdbcPassword){

//Parameter jdbcProperties
@Parameter(name = "jdbcProperties", optional = true,
description = "This optional parameter specifies the path name of the file that contains the jdbc connection properties: 'user' and 'password'")
description = "This optional parameter specifies the path name of the file that contains the jdbc connection properties: 'user', 'password' and jdbcUrl")
public void setJdbcProperties(String jdbcProperties){
this.jdbcProperties = jdbcProperties;
}
Expand Down Expand Up @@ -335,17 +337,18 @@ public static void checkParametersRuntime(OperatorContextChecker checker) {
public static void checkParameters(OperatorContextChecker checker) {
// If statement is set as parameter, statementAttr can not be set
checker.checkExcludedParameters("statement", "statementAttr");
// If jdbcProperties is set as parameter, jdbcUser and jdbcPassword can not be set
// If jdbcProperties is set as parameter, jdbcUser, jdbcPassword and jdbcUrl can not be set
checker.checkExcludedParameters("jdbcUser", "jdbcProperties");
checker.checkExcludedParameters("jdbcPassword", "jdbcProperties");
checker.checkExcludedParameters("jdbcUrl", "jdbcProperties");

// If credentials is set as parameter, jdbcUser, jdbcPassword and jdbcUrl can not be set.
checker.checkExcludedParameters("jdbcUser", "credentials");
checker.checkExcludedParameters("jdbcPassword", "credentials");
checker.checkExcludedParameters("jdbcUrl", "credentials");
checker.checkExcludedParameters("credentials", "jdbcUrl");

// If credentials is set as parameter, credentials can not be set
// If credentials is set as parameter, jdbcProperties can not be set
checker.checkExcludedParameters("jdbcProperties", "credentials");

// check reconnection related parameters
Expand All @@ -356,8 +359,9 @@ public static void checkParameters(OperatorContextChecker checker) {
OperatorContext context = checker.getOperatorContext();
if ((!context.getParameterNames().contains("credentials"))
&& (!context.getParameterNames().contains("appConfigName"))
&& (!context.getParameterNames().contains("jdbcUrl"))) {
checker.setInvalidContext("The parameter 'jdbcUrl' is not defined. It must be set in one of these parameters: 'jdbcUrl' or 'credentials' or via the credentials parameter in an application configuration.", null);
&& (!context.getParameterNames().contains("jdbcUrl"))
&& (!context.getParameterNames().contains("jdbcProperties"))) {
checker.setInvalidContext("The parameter 'jdbcUrl' is not defined. It must be set in one of these parameters: 'jdbcUrl' or 'credentials' or via the credentials parameter in an application configuration or via properties file.", null);
}

if ((!context.getParameterNames().contains("credentials"))
Expand Down Expand Up @@ -548,9 +552,9 @@ protected void processControlPort(StreamingInput<Tuple> stream, Tuple tuple) thr
LOGGER.log(LogLevel.ERROR, Messages.getString("JDBC_CLASS_NAME_NOT_EXIST"));
}
// if jdbcProperties is relative path, convert to absolute path
if (jdbcProperties != null && !jdbcProperties.trim().isEmpty() && !jdbcProperties.startsWith(File.separator))
if (jdbcProperties != null && !jdbcProperties.trim().isEmpty())
{
jdbcProperties = getOperatorContext().getPE().getApplicationDirectory() + File.separator + jdbcProperties;
getProperties(jdbcProperties);
}

if (credentials != null && !credentials.trim().isEmpty())
Expand All @@ -562,8 +566,6 @@ protected void processControlPort(StreamingInput<Tuple> stream, Tuple tuple) thr
if (jdbcUrl == null || jdbcUrl.trim().isEmpty()){
LOGGER.log(LogLevel.ERROR, Messages.getString("JDBC_URL_NOT_EXIST"));
}

// System.out.println("credentials : " + credentials);

// Roll back the transaction
jdbcClientHelper.rollbackWithClearBatch();
Expand Down Expand Up @@ -681,9 +683,9 @@ private synchronized void setupJDBCConnection() throws Exception{
TRACE.log(TraceLevel.DEBUG, "Create JDBC Connection, jdbcUrl: " + jdbcUrl);
try{
// if jdbcProperties is relative path, convert to absolute path
if (jdbcProperties != null && !jdbcProperties.trim().isEmpty() && !jdbcProperties.startsWith(File.separator))
if (jdbcProperties != null && !jdbcProperties.trim().isEmpty())
{
jdbcProperties = getOperatorContext().getPE().getApplicationDirectory() + File.separator + jdbcProperties;
getProperties(jdbcProperties);
}

if (credentials != null && !credentials.trim().isEmpty()) {
Expand All @@ -707,8 +709,48 @@ private synchronized void setupJDBCConnection() throws Exception{
}
}




// read properties file and set user name, password and jdbcUrl.
public void getProperties(String jdbcProperties) throws IOException {
try {
// if jdbcProperties is relative path, convert to absolute path
if (!jdbcProperties.startsWith(File.separator))
{
jdbcProperties = getOperatorContext().getPE().getApplicationDirectory() + File.separator + jdbcProperties;
}

System.out.println("JDBC Properties file from Operator '" + getOperatorContext().getName() + "' : " + jdbcProperties);

Properties jdbcConnectionProps = new Properties();
FileInputStream fileInput = new FileInputStream(jdbcProperties);
jdbcConnectionProps.load(fileInput);
fileInput.close();
jdbcUser = jdbcConnectionProps.getProperty("user");
if (null == jdbcUser){
LOGGER.log(LogLevel.ERROR, "'user' is not defined in property file: " + jdbcProperties);
throw new Exception(Messages.getString("'jdbcUser' is required to create JDBC connection."));
}
jdbcPassword = jdbcConnectionProps.getProperty("password");
if (null == jdbcPassword){
LOGGER.log(LogLevel.ERROR, "'password' is not defined in property file: " + jdbcProperties);
throw new Exception(Messages.getString("'jdbcPassword' is required to create JDBC connection."));
}
// It supports jdbcUrl and jdbcurl
jdbcUrl = jdbcConnectionProps.getProperty("jdbcUrl");
if (null == jdbcUrl){
jdbcUrl = jdbcConnectionProps.getProperty("jdbcurl");
if (null == jdbcUrl){
LOGGER.log(LogLevel.ERROR, "'jdbcUrl' is not defined in property file: " + jdbcProperties);
throw new Exception(Messages.getString("JDBC_URL_NOT_EXIST"));
}
}

} catch (Exception ex) {
ex.printStackTrace();
}
}


// read credentials and set user name, password and jdbcUrl.
public void getCredentials(String credentials) throws IOException {
String jsonString = credentials;
Expand All @@ -728,11 +770,16 @@ public void getCredentials(String credentials) throws IOException {
}

jdbcUrl = (String)obj.get("jdbcurl");
if (jdbcUrl == null || jdbcUrl.trim().isEmpty()){
jdbcUrl = (String)obj.get("jdbcUrl");
}
// jdbcUrl is required
if (jdbcUrl == null || jdbcUrl.trim().isEmpty()){
LOGGER.log(LogLevel.ERROR, Messages.getString("JDBC_URL_NOT_EXIST"));
throw new Exception(Messages.getString("JDBC_URL_NOT_EXIST"));
}
System.out.println("jdbcUrl from credentials in Operator '" + getOperatorContext().getName() + "' :" + jdbcUrl);

} catch (Exception ex) {
ex.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public class JDBCClientHelper {
// the user's password.
private String jdbcPassword = null;
private boolean sslConnection = false;
// the jdbc properties file.
private String jdbcProperties = null;
// the transaction isolation level at which statement runs.
private String isolationLevel = IJDBCConstants.TRANSACTION_READ_UNCOMMITTED;
// transactions are automatically committed or not.
Expand Down Expand Up @@ -87,7 +85,6 @@ public JDBCClientHelper(String jdbcClassName, String jdbcUrl,
this.jdbcUser = jdbcUser;
this.jdbcPassword = jdbcPassword;
this.sslConnection = sslConnection;
this.jdbcProperties = jdbcProperties;
this.autoCommit = autoCommit;
this.isolationLevel = isolationLevel;
this.reconnectionPolicy = reconnectionPolicy;
Expand All @@ -108,33 +105,16 @@ public synchronized void createConnection() throws Exception, SQLException{
//Load class into memory
Class.forName(jdbcClassName);

// Load jdbc properties
Properties jdbcConnectionProps = new Properties();
if (jdbcProperties != null){
FileInputStream fileInput = new FileInputStream(jdbcProperties);
jdbcConnectionProps.load(fileInput);
fileInput.close();
String user = jdbcConnectionProps.getProperty("user");
if (null == user){
LOGGER.log(LogLevel.ERROR, "'user' is not defined in property file: " + jdbcProperties);
return;
}
String password = jdbcConnectionProps.getProperty("password");
if (null == password){
LOGGER.log(LogLevel.ERROR, "'password' is not defined in property file: " + jdbcProperties);
return;
}

} else {
// pick up user and password if they are parameters
if (jdbcUser != null && jdbcPassword != null) {
jdbcConnectionProps.put("user", jdbcUser);
jdbcConnectionProps.put("password", jdbcPassword);
jdbcConnectionProps.put("avatica_user", jdbcUser);
jdbcConnectionProps.put("avatica_password", jdbcPassword);
}
// pick up user and password if they are parameters
if (jdbcUser != null && jdbcPassword != null) {
jdbcConnectionProps.put("user", jdbcUser);
jdbcConnectionProps.put("password", jdbcPassword);
// properties for phoenix jdbc properties.
jdbcConnectionProps.put("avatica_user", jdbcUser);
jdbcConnectionProps.put("avatica_password", jdbcPassword);
}

}

// add sslConnection to properties
if (sslConnection)
Expand Down Expand Up @@ -257,7 +237,6 @@ public synchronized void resetConnection(String jdbcClassName, String jdbcUrl,
this.jdbcUrl = jdbcUrl;
this.jdbcUser = jdbcUser;
this.jdbcPassword = jdbcPassword;
this.jdbcProperties = jdbcProperties;

// Set JDBC Connection Status as false
connected = false;
Expand Down
7 changes: 6 additions & 1 deletion com.ibm.streamsx.jdbc/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@

* Insert BLOB bug fixed #82

++ What is new in version 1.5.0

* Add **jdbcUrl** to the jdbc properties.
* Support both **jdbcUrl** and **jdbcurl** in credentials and in properties file.

</info:description>
<info:version>1.4.4</info:version>
<info:version>1.5.0</info:version>
<info:requiredProductVersion>4.2.0.0</info:requiredProductVersion>
</info:identity>
<info:dependencies/>
Expand Down