Skip to content

Commit d2830e2

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents ce64da5 + af3ba95 commit d2830e2

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

examples/embedded_in_dat/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Example using IloOplCallJava
1+
# Example using IloOplCallJava in .dat files
22

33
This sample is basically the same as [ilo_opl_call_java](../ilo_opl_call_java).
44

lib/jdbc-custom-data-source.jar

177 Bytes
Binary file not shown.

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ public OutputParameters(boolean autodrop,
5454
private String _url = null;
5555
private String _user = null;
5656
private String _password = null;
57+
58+
/** Resolve <code>s</code> using environment variables.
59+
* If <code>s</code> starts with "$" and is the name of an existing
60+
* environment variable then return the value of that variable, otherwise
61+
* return <code>s</code>.
62+
* @param s The string to resolve.
63+
* @return The value of environment variable <code>s</code> if such a
64+
* variable exists, <code>s</code> otherwise.
65+
*/
66+
private static String resolveString(String s) {
67+
if ( s == null || s.length() < 2 || s.charAt(0) != '$' )
68+
return s;
69+
final String value = System.getenv(s.substring(1));
70+
if ( value != null )
71+
return value;
72+
return s;
73+
}
5774

5875
/**
5976
* Creates a new JDBC configuration.
@@ -70,17 +87,17 @@ public void setUrl(String url) {
7087
}
7188

7289
public String getUser() {
73-
return _user;
90+
return resolveString(_user);
7491
}
75-
92+
7693
public void setUser(String user) {
7794
_user = user;
7895
}
7996

8097
public String getPassword() {
81-
return _password;
98+
return resolveString(_password);
8299
}
83-
100+
84101
public void setPassword(String password) {
85102
_password = password;
86103
}

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,19 @@ String getInsertQuery(IloTupleSchema schema, String table) {
112112
return query;
113113
}
114114

115-
void updateValues(IloTuple tuple, IloTupleSchema schema,
116-
IloOplTupleSchemaDefinition tupleSchemaDef, PreparedStatement stmt) throws SQLException {
117-
for (int i = 0; i < schema.getSize(); i++) {
118-
int index = i+1; // index in PreparedStatement
119-
Type columnType = tupleSchemaDef.getComponent(i).getElementDefinitionType();
120-
if (columnType == Type.INTEGER)
121-
stmt.setInt(index, tuple.getIntValue(i));
122-
else if (columnType == Type.FLOAT)
123-
stmt.setDouble(index, tuple.getNumValue(i));
124-
else if (columnType == Type.STRING)
125-
stmt.setString(index, tuple.getStringValue(i));
126-
}
115+
void updateValues(IloTuple tuple, IloTupleSchema schema,
116+
IloOplTupleSchemaDefinition tupleSchemaDef, PreparedStatement stmt) throws SQLException {
117+
for (int i = 0; i < schema.getSize(); i++) {
118+
int index = i + 1; // index in PreparedStatement
119+
Type columnType = tupleSchemaDef.getComponent(i).getElementDefinitionType();
120+
if (columnType == Type.INTEGER)
121+
stmt.setInt(index, tuple.getIntValue(i));
122+
else if (columnType == Type.FLOAT)
123+
stmt.setDouble(index, tuple.getNumValue(i));
124+
else if (columnType == Type.STRING)
125+
stmt.setString(index, tuple.getStringValue(i));
127126
}
127+
}
128128

129129
static final String DROP_QUERY = "DROP TABLE %";
130130

@@ -173,6 +173,9 @@ void customWrite(String name, OutputParameters op) {
173173
try {
174174
IloOplElementDefinition tupleDef = _def.getElementDefinition(schema.getName());
175175
IloOplTupleSchemaDefinition tupleSchemaDef = tupleDef.asTupleSchema();
176+
final Type[] columnType = new Type[schema.getSize()];
177+
for (int i = 0; i < columnType.length; ++i)
178+
columnType[i] = tupleSchemaDef.getComponent(i).getElementDefinitionType();
176179

177180
String psql = null;
178181
if (op.outputTable != null && op.insertStatement == null) {
@@ -222,4 +225,4 @@ void customWrite(String name, OutputParameters op) {
222225
}
223226
}
224227
}
225-
}
228+
}

0 commit comments

Comments
 (0)