Skip to content

Commit 74daeb6

Browse files
authored
Merge pull request #96 from utPLSQL/feature/testRunnerStatement_as_dynamic_paramList
TestRunnerStatement with dynamic Parameter-list
2 parents 34e7d43 + 97be74d commit 74daeb6

16 files changed

+646
-397
lines changed

Diff for: .travis.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@ env:
2929
- UTPLSQL_VERSION="v3.1.3"
3030
- UTPLSQL_VERSION="v3.1.6"
3131
- UTPLSQL_VERSION="v3.1.7"
32+
- UTPLSQL_VERSION="v3.1.8"
3233
- UTPLSQL_VERSION="develop"
3334
UTPLSQL_FILE="utPLSQL"
3435

3536
matrix:
3637
include:
37-
- env: UTPLSQL_VERSION="v3.1.7"
38+
- env: UTPLSQL_VERSION="v3.1.8"
3839
jdk: openjdk9
39-
- env: UTPLSQL_VERSION="v3.1.7"
40+
- env: UTPLSQL_VERSION="v3.1.8"
4041
jdk: openjdk10
41-
- env: UTPLSQL_VERSION="v3.1.7"
42+
- env: UTPLSQL_VERSION="v3.1.8"
4243
jdk: openjdk11
43-
- env: UTPLSQL_VERSION="v3.1.7"
44+
- env: UTPLSQL_VERSION="v3.1.8"
4445
jdk: openjdk12
45-
- env: UTPLSQL_VERSION="v3.1.7"
46+
- env: UTPLSQL_VERSION="v3.1.8"
4647
jdk: openjdk13
4748

4849
before_cache:

Diff for: .travis/maven_cfg.sh

-14
This file was deleted.

Diff for: src/main/java/org/utplsql/api/Version.java

+36-17
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ public class Version implements Comparable<Version> {
2424
public final static Version V3_0_2 = new Version("3.0.2", 3, 0, 2, null, true);
2525
public final static Version V3_0_3 = new Version("3.0.3", 3, 0, 3, null, true);
2626
public final static Version V3_0_4 = new Version("3.0.4", 3, 0, 4, null, true);
27-
public final static Version V3_1_0 = new Version("3.1.0", 3, 1, 0, null, true);
28-
public final static Version V3_1_1 = new Version("3.1.1", 3, 1, 1, null, true);
29-
public final static Version V3_1_2 = new Version("3.1.2", 3, 1, 2, null, true);
30-
public final static Version V3_1_3 = new Version("3.1.3", 3, 1, 3, null, true);
31-
public final static Version V3_1_4 = new Version("3.1.4", 3, 1, 4, null, true);
32-
public final static Version V3_1_5 = new Version("3.1.5", 3, 1, 5, null, true);
33-
public final static Version V3_1_6 = new Version("3.1.6", 3, 1, 6, null, true);
34-
public final static Version V3_1_7 = new Version("3.1.7", 3, 1, 7, null, true);
27+
public final static Version V3_1_0 = new Version("3.1.0", 3, 1, 0, 1847, true);
28+
public final static Version V3_1_1 = new Version("3.1.1", 3, 1, 1, 1865, true);
29+
public final static Version V3_1_2 = new Version("3.1.2", 3, 1, 2, 2130, true);
30+
public final static Version V3_1_3 = new Version("3.1.3", 3, 1, 3, 2398, true);
31+
public final static Version V3_1_4 = new Version("3.1.4", 3, 1, 4, 2223, true);
32+
public final static Version V3_1_5 = new Version("3.1.5", 3, 1, 5, 2707, true);
33+
public final static Version V3_1_6 = new Version("3.1.6", 3, 1, 6, 2729, true);
34+
public final static Version V3_1_7 = new Version("3.1.7", 3, 1, 7, 3085, true);
35+
public final static Version V3_1_8 = new Version("3.1.8", 3, 1, 8, 3188, true);
3536
private final static Map<String, Version> knownVersions =
36-
Stream.of(V3_0_0, V3_0_1, V3_0_2, V3_0_3, V3_0_4, V3_1_0, V3_1_1, V3_1_2, V3_1_3, V3_1_4, V3_1_5, V3_1_6, V3_1_7)
37+
Stream.of(V3_0_0, V3_0_1, V3_0_2, V3_0_3, V3_0_4, V3_1_0, V3_1_1, V3_1_2, V3_1_3, V3_1_4, V3_1_5, V3_1_6, V3_1_7, V3_1_8)
3738
.collect(toMap(Version::toString, Function.identity()));
38-
public final static Version LATEST = V3_1_7;
39+
public final static Version LATEST = V3_1_8;
3940

4041
private final String origString;
4142
private final Integer major;
@@ -167,10 +168,14 @@ public String getNormalizedString() {
167168
}
168169

169170
private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2) {
171+
return compareToWithNulls(i1, i2, false);
172+
}
173+
174+
private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2, boolean nullMeansEqual) {
170175
if (i1 == null && i2 == null) {
171176
return 0;
172177
} else if (i1 == null) {
173-
return -1;
178+
return nullMeansEqual ? 0 : -1;
174179
} else if (i2 == null) {
175180
return 1;
176181
} else {
@@ -180,26 +185,30 @@ private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2) {
180185

181186
@Override
182187
public int compareTo(Version o) {
188+
return compareTo(o, false);
189+
}
190+
191+
public int compareTo(Version o, boolean nullMeansEqual) {
183192
int curResult;
184193

185194
if (isValid() && o.isValid()) {
186195

187-
curResult = compareToWithNulls(getMajor(), o.getMajor());
196+
curResult = compareToWithNulls(getMajor(), o.getMajor(), nullMeansEqual);
188197
if (curResult != 0) {
189198
return curResult;
190199
}
191200

192-
curResult = compareToWithNulls(getMinor(), o.getMinor());
201+
curResult = compareToWithNulls(getMinor(), o.getMinor(), nullMeansEqual);
193202
if (curResult != 0) {
194203
return curResult;
195204
}
196205

197-
curResult = compareToWithNulls(getBugfix(), o.getBugfix());
206+
curResult = compareToWithNulls(getBugfix(), o.getBugfix(), nullMeansEqual);
198207
if (curResult != 0) {
199208
return curResult;
200209
}
201210

202-
curResult = compareToWithNulls(getBuild(), o.getBuild());
211+
curResult = compareToWithNulls(getBuild(), o.getBuild(), nullMeansEqual);
203212
if (curResult != 0) {
204213
return curResult;
205214
}
@@ -220,6 +229,7 @@ private void versionsAreValid(Version v) throws InvalidVersionException {
220229

221230
/**
222231
* Compares this version to a given version and returns true if this version is greater or equal than the given one
232+
* If one of the version parts of the base version is null, this level is assumed equal no matter the comparing level's version part
223233
* Throws an InvalidVersionException if either this or the given version are invalid
224234
*
225235
* @param v Version to compare with
@@ -230,7 +240,7 @@ public boolean isGreaterOrEqualThan(Version v) throws InvalidVersionException {
230240

231241
versionsAreValid(v);
232242

233-
return compareTo(v) >= 0;
243+
return compareTo(v, true) >= 0;
234244
}
235245

236246

@@ -240,11 +250,20 @@ public boolean isGreaterThan(Version v) throws InvalidVersionException {
240250
return compareTo(v) > 0;
241251
}
242252

253+
/**
254+
* Compares this version to a given version and returns true if this version is less or equal than the given one
255+
* If one of the version parts of the base version is null, this level is assumed equal no matter the comparing level's version part
256+
* Throws an InvalidVersionException if either this or the given version are invalid
257+
*
258+
* @param v Version to compare with
259+
* @return
260+
* @throws InvalidVersionException
261+
*/
243262
public boolean isLessOrEqualThan(Version v) throws InvalidVersionException {
244263

245264
versionsAreValid(v);
246265

247-
return compareTo(v) <= 0;
266+
return compareTo(v, true) <= 0;
248267
}
249268

250269
public boolean isLessThan(Version v) throws InvalidVersionException {

Diff for: src/main/java/org/utplsql/api/db/DynamicParameterList.java

+42-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public class DynamicParameterList {
2020

2121
interface DynamicParameter {
2222
void setParam( CallableStatement statement, int index ) throws SQLException;
23+
24+
default String getSql( String key ) {
25+
return key + " => ?";
26+
}
2327
}
2428

2529
private DynamicParameterList(LinkedHashMap<String, DynamicParameter> params) {
@@ -33,8 +37,8 @@ private DynamicParameterList(LinkedHashMap<String, DynamicParameter> params) {
3337
* @return comma-separated list of parameter identifiers
3438
*/
3539
public String getSql() {
36-
return params.keySet().stream()
37-
.map(e -> e + " => ?")
40+
return params.entrySet().stream()
41+
.map(e -> e.getValue().getSql(e.getKey()))
3842
.collect(Collectors.joining(", "));
3943
}
4044

@@ -115,6 +119,18 @@ public DynamicParameterListBuilder addIfNotEmpty(String identifier, Object[] val
115119
return this;
116120
}
117121

122+
public DynamicParameterListBuilder add(String identifier, Boolean value) {
123+
params.put(identifier, new DynamicBoolParameter(value));
124+
return this;
125+
}
126+
127+
public DynamicParameterListBuilder addIfNotEmpty(String identifier, Boolean value) {
128+
if ( value != null ) {
129+
add(identifier, value);
130+
}
131+
return this;
132+
}
133+
118134
public DynamicParameterList build() {
119135
return new DynamicParameterList(params);
120136
}
@@ -155,6 +171,28 @@ public void setParam(CallableStatement statement, int index) throws SQLException
155171
}
156172
}
157173

174+
private static class DynamicBoolParameter implements DynamicParameter {
175+
private final Boolean value;
176+
177+
DynamicBoolParameter( Boolean value ) {
178+
this.value = value;
179+
}
180+
181+
@Override
182+
public void setParam(CallableStatement statement, int index) throws SQLException {
183+
if ( value == null ) {
184+
statement.setNull(index, Types.BOOLEAN);
185+
} else {
186+
statement.setInt(index, (value)?1:0);
187+
}
188+
}
189+
190+
@Override
191+
public String getSql(String key) {
192+
return key + " => (case ? when 1 then true else false end)";
193+
}
194+
}
195+
158196
private static class DynamicArrayParameter implements DynamicParameter {
159197
private final Object[] value;
160198
private final String customTypeName;
@@ -172,7 +210,8 @@ public void setParam(CallableStatement statement, int index) throws SQLException
172210
statement.setNull(index, Types.ARRAY, customTypeName);
173211
} else {
174212
statement.setArray(
175-
index, oraConnection.createOracleArray(customTypeName, value)
213+
index,
214+
oraConnection.createOracleArray(customTypeName, value)
176215
);
177216
}
178217
}

Diff for: src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java

-101
This file was deleted.

0 commit comments

Comments
 (0)