Skip to content

Commit b22774b

Browse files
author
Daniel Junglas
committed
Add functions to set username and password.
Also allow specifying these as environment variables so that they don't have to be in the .dat in plain text.
1 parent 39343e9 commit b22774b

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/jdbc-custom-data-source.jar

2.52 KB
Binary file not shown.

src/main/java/com/ibm/opl/customdatasource/JdbcConfiguration.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ public class JdbcConfiguration {
3030
private String _url = null;
3131
private String _user = null;
3232
private String _password = null;
33+
34+
/** Resolve <code>s</code> using environment variables.
35+
* If <code>s</code> starts with "$" and is the name of an existing
36+
* environment variable then return the value of that variable, otherwise
37+
* return <code>s</code>.
38+
* @param s The string to resolve.
39+
* @return The value of environment variable <code>s</code> if such a
40+
* variable exists, <code>s</code> otherwise.
41+
*/
42+
private static String resolveString(String s) {
43+
if ( s == null || s.length() < 2 || s.charAt(0) != '$' )
44+
return s;
45+
final String value = System.getenv(s.substring(1));
46+
if ( value != null )
47+
return value;
48+
return s;
49+
}
3350

3451
/**
3552
* Creates a new JDBC configuration.
@@ -46,11 +63,19 @@ public void setUrl(String url) {
4663
}
4764

4865
public String getUser() {
49-
return _user;
66+
return resolveString(_user);
67+
}
68+
69+
public void setUser(String user) {
70+
_user = user;
5071
}
5172

5273
public String getPassword() {
53-
return _password;
74+
return resolveString(_password);
75+
}
76+
77+
public void setPassword(String password) {
78+
_password = password;
5479
}
5580

5681
public Properties getReadQueries() {

0 commit comments

Comments
 (0)