Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TestRunnerStatement with dynamic Parameter-list #96

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

Merged
merged 26 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
de3311c
Add some more unit-tests
pesse Jul 19, 2019
7f52a33
completely filled TestRunnerOptions for testing purposes
pesse Jul 19, 2019
156f2d9
Start exploring possibilities for a dynamic TestRunner-Statement
pesse Jul 19, 2019
a10b8b7
Merge branch 'develop' into feature/testRunnerStatement_as_dynamic_pa…
pesse Jul 22, 2019
166720b
Make getSql public for better testability
pesse Jul 22, 2019
2ce1e79
Test against interface
pesse Jul 22, 2019
6100f3c
Slow approach towards new DynamicTestRunner-Statement
pesse Jul 22, 2019
4f591ef
Add failing test for Boolean support of DynamicParameterList
pesse Jul 22, 2019
4aba265
Some more params of TestRunner handeled
pesse Jul 22, 2019
b3d5779
We can add booleans now
pesse Oct 20, 2019
f2e1e01
Two more parameters in the new DynamicStatement
pesse Oct 20, 2019
5ff0ee2
FileMappings are more complicated to pass around
pesse Oct 20, 2019
a7b8266
Adding TestFileMappings
pesse Oct 21, 2019
e1b7dd3
Implement remaining dynamic parameters
pesse Oct 21, 2019
c0ca8cd
Remove helper comments
pesse Oct 21, 2019
4afca5f
Add version Bugfix-numbers
pesse Oct 21, 2019
32b7d56
Version isGreaterThanOrEqual and isLessOrEqual treat NULL in base ver…
pesse Oct 21, 2019
1b9e0b2
Add tests for all utPLSQL versions
pesse Oct 21, 2019
2a3d9df
Added "end case" part
pesse Oct 21, 2019
19a9037
Replace old TestRunnerStatements with the new DynamicTestRunnerStatement
pesse Oct 21, 2019
1751d68
Switch to OpenJDK 8
pesse Oct 21, 2019
02114ae
Add utPLSQL 3.1.8 version
pesse Oct 21, 2019
6a0723a
Fix Version-String
pesse Oct 22, 2019
3799867
Merge branch 'develop' into feature/testRunnerStatement_as_dynamic_pa…
pesse Oct 22, 2019
6ffa576
Test JDK13 also with version 3.1.8
pesse Oct 22, 2019
97be74d
We don't need Maven CFG anymore
pesse Oct 22, 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
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ env:
- UTPLSQL_VERSION="v3.1.3"
- UTPLSQL_VERSION="v3.1.6"
- UTPLSQL_VERSION="v3.1.7"
- UTPLSQL_VERSION="v3.1.8"
- UTPLSQL_VERSION="develop"
UTPLSQL_FILE="utPLSQL"

matrix:
include:
- env: UTPLSQL_VERSION="v3.1.7"
- env: UTPLSQL_VERSION="v3.1.8"
jdk: openjdk9
- env: UTPLSQL_VERSION="v3.1.7"
- env: UTPLSQL_VERSION="v3.1.8"
jdk: openjdk10
- env: UTPLSQL_VERSION="v3.1.7"
- env: UTPLSQL_VERSION="v3.1.8"
jdk: openjdk11
- env: UTPLSQL_VERSION="v3.1.7"
- env: UTPLSQL_VERSION="v3.1.8"
jdk: openjdk12
- env: UTPLSQL_VERSION="v3.1.7"
- env: UTPLSQL_VERSION="v3.1.8"
jdk: openjdk13

before_cache:
Expand Down
14 changes: 0 additions & 14 deletions .travis/maven_cfg.sh

This file was deleted.

53 changes: 36 additions & 17 deletions src/main/java/org/utplsql/api/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ public class Version implements Comparable<Version> {
public final static Version V3_0_2 = new Version("3.0.2", 3, 0, 2, null, true);
public final static Version V3_0_3 = new Version("3.0.3", 3, 0, 3, null, true);
public final static Version V3_0_4 = new Version("3.0.4", 3, 0, 4, null, true);
public final static Version V3_1_0 = new Version("3.1.0", 3, 1, 0, null, true);
public final static Version V3_1_1 = new Version("3.1.1", 3, 1, 1, null, true);
public final static Version V3_1_2 = new Version("3.1.2", 3, 1, 2, null, true);
public final static Version V3_1_3 = new Version("3.1.3", 3, 1, 3, null, true);
public final static Version V3_1_4 = new Version("3.1.4", 3, 1, 4, null, true);
public final static Version V3_1_5 = new Version("3.1.5", 3, 1, 5, null, true);
public final static Version V3_1_6 = new Version("3.1.6", 3, 1, 6, null, true);
public final static Version V3_1_7 = new Version("3.1.7", 3, 1, 7, null, true);
public final static Version V3_1_0 = new Version("3.1.0", 3, 1, 0, 1847, true);
public final static Version V3_1_1 = new Version("3.1.1", 3, 1, 1, 1865, true);
public final static Version V3_1_2 = new Version("3.1.2", 3, 1, 2, 2130, true);
public final static Version V3_1_3 = new Version("3.1.3", 3, 1, 3, 2398, true);
public final static Version V3_1_4 = new Version("3.1.4", 3, 1, 4, 2223, true);
public final static Version V3_1_5 = new Version("3.1.5", 3, 1, 5, 2707, true);
public final static Version V3_1_6 = new Version("3.1.6", 3, 1, 6, 2729, true);
public final static Version V3_1_7 = new Version("3.1.7", 3, 1, 7, 3085, true);
public final static Version V3_1_8 = new Version("3.1.8", 3, 1, 8, 3188, true);
private final static Map<String, Version> knownVersions =
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)
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)
.collect(toMap(Version::toString, Function.identity()));
public final static Version LATEST = V3_1_7;
public final static Version LATEST = V3_1_8;

private final String origString;
private final Integer major;
Expand Down Expand Up @@ -167,10 +168,14 @@ public String getNormalizedString() {
}

private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2) {
return compareToWithNulls(i1, i2, false);
}

private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2, boolean nullMeansEqual) {
if (i1 == null && i2 == null) {
return 0;
} else if (i1 == null) {
return -1;
return nullMeansEqual ? 0 : -1;
} else if (i2 == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to check nullMeansEqual here so that comparetoWithNulls is symmetric?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't get it...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't i2 be treated same way as i1 so that if i2 is null you check nullMeansEqual

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah.
I thought about this a lot yesterday. The thing is - we are not implementing the normal compareTo method, but we implement something which is only used by isGreaterOrEqualTo and isLessOrEqualTo.
For these 2 cases I think the comparison order is important, because the lazier "equal" depends on the base version to have a null.

Example:
Technically, when comparing 3.1.7 with 3.1.7.3085, 3.1.7 is less and not equal. That's how the comparison was before (null being treated as 0 basically).
But that's not what I want when using isGreaterOrEqualTo - I want this function to be forgiving if I only provide 3.1.7 as base, so any number in the 4th level of the comparison should be treated as being equal.
On the other hand, when I provide a specific base (e.g. 3.1.7.3085), I really expect it to be precise, so I can't treat i2 the same way in that case.

Maybe I should not use parameters here and instead write the isGreaterOrEqualTo function separately so it's more clear we're not implementing a strict compareTo here.

return 1;
} else {
Expand All @@ -180,26 +185,30 @@ private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2) {

@Override
public int compareTo(Version o) {
return compareTo(o, false);
}

public int compareTo(Version o, boolean nullMeansEqual) {
int curResult;

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

curResult = compareToWithNulls(getMajor(), o.getMajor());
curResult = compareToWithNulls(getMajor(), o.getMajor(), nullMeansEqual);
if (curResult != 0) {
return curResult;
}

curResult = compareToWithNulls(getMinor(), o.getMinor());
curResult = compareToWithNulls(getMinor(), o.getMinor(), nullMeansEqual);
if (curResult != 0) {
return curResult;
}

curResult = compareToWithNulls(getBugfix(), o.getBugfix());
curResult = compareToWithNulls(getBugfix(), o.getBugfix(), nullMeansEqual);
if (curResult != 0) {
return curResult;
}

curResult = compareToWithNulls(getBuild(), o.getBuild());
curResult = compareToWithNulls(getBuild(), o.getBuild(), nullMeansEqual);
if (curResult != 0) {
return curResult;
}
Expand All @@ -220,6 +229,7 @@ private void versionsAreValid(Version v) throws InvalidVersionException {

/**
* Compares this version to a given version and returns true if this version is greater or equal than the given one
* 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
* Throws an InvalidVersionException if either this or the given version are invalid
*
* @param v Version to compare with
Expand All @@ -230,7 +240,7 @@ public boolean isGreaterOrEqualThan(Version v) throws InvalidVersionException {

versionsAreValid(v);

return compareTo(v) >= 0;
return compareTo(v, true) >= 0;
}


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

/**
* Compares this version to a given version and returns true if this version is less or equal than the given one
* 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
* Throws an InvalidVersionException if either this or the given version are invalid
*
* @param v Version to compare with
* @return
* @throws InvalidVersionException
*/
public boolean isLessOrEqualThan(Version v) throws InvalidVersionException {

versionsAreValid(v);

return compareTo(v) <= 0;
return compareTo(v, true) <= 0;
}

public boolean isLessThan(Version v) throws InvalidVersionException {
Expand Down
45 changes: 42 additions & 3 deletions src/main/java/org/utplsql/api/db/DynamicParameterList.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class DynamicParameterList {

interface DynamicParameter {
void setParam( CallableStatement statement, int index ) throws SQLException;

default String getSql( String key ) {
return key + " => ?";
}
}

private DynamicParameterList(LinkedHashMap<String, DynamicParameter> params) {
Expand All @@ -33,8 +37,8 @@ private DynamicParameterList(LinkedHashMap<String, DynamicParameter> params) {
* @return comma-separated list of parameter identifiers
*/
public String getSql() {
return params.keySet().stream()
.map(e -> e + " => ?")
return params.entrySet().stream()
.map(e -> e.getValue().getSql(e.getKey()))
.collect(Collectors.joining(", "));
}

Expand Down Expand Up @@ -115,6 +119,18 @@ public DynamicParameterListBuilder addIfNotEmpty(String identifier, Object[] val
return this;
}

public DynamicParameterListBuilder add(String identifier, Boolean value) {
params.put(identifier, new DynamicBoolParameter(value));
return this;
}

public DynamicParameterListBuilder addIfNotEmpty(String identifier, Boolean value) {
if ( value != null ) {
add(identifier, value);
}
return this;
}

public DynamicParameterList build() {
return new DynamicParameterList(params);
}
Expand Down Expand Up @@ -155,6 +171,28 @@ public void setParam(CallableStatement statement, int index) throws SQLException
}
}

private static class DynamicBoolParameter implements DynamicParameter {
private final Boolean value;

DynamicBoolParameter( Boolean value ) {
this.value = value;
}

@Override
public void setParam(CallableStatement statement, int index) throws SQLException {
if ( value == null ) {
statement.setNull(index, Types.BOOLEAN);
} else {
statement.setInt(index, (value)?1:0);
}
}

@Override
public String getSql(String key) {
return key + " => (case ? when 1 then true else false end)";
}
}

private static class DynamicArrayParameter implements DynamicParameter {
private final Object[] value;
private final String customTypeName;
Expand All @@ -172,7 +210,8 @@ public void setParam(CallableStatement statement, int index) throws SQLException
statement.setNull(index, Types.ARRAY, customTypeName);
} else {
statement.setArray(
index, oraConnection.createOracleArray(customTypeName, value)
index,
oraConnection.createOracleArray(customTypeName, value)
);
}
}
Expand Down

This file was deleted.

Loading