-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#29) extracted statement composition and parameter management from j…
…dbc statements
- Loading branch information
Showing
12 changed files
with
162 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
driver/src/main/java/com/consol/citrus/db/driver/statement/StatementComposer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.consol.citrus.db.driver.statement; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
class StatementComposer { | ||
|
||
String composeStatement(final String statement, final StatementParameters parameters) { | ||
return statement + " - (" + | ||
parameters.getParametersAsMap() | ||
.values() | ||
.stream() | ||
.map(param -> param != null ? param.toString() : "null") | ||
.collect(Collectors.joining(",")) + ")"; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
driver/src/main/java/com/consol/citrus/db/driver/statement/StatementParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.consol.citrus.db.driver.statement; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import static java.util.stream.Collectors.toMap; | ||
|
||
public class StatementParameters { | ||
|
||
private Map<String, Object> namedParameters = new HashMap<>(); | ||
private Map<Integer, Object> indexedParameters = new HashMap<>(); | ||
|
||
StatementParameters(final StatementParameters statementParameters) { | ||
this.namedParameters = new HashMap<>(statementParameters.getParametersAsMap()); | ||
|
||
final List<Object> originalIndexParameters = statementParameters.getParametersAsList(); | ||
this.indexedParameters = IntStream | ||
.range(0, originalIndexParameters.size()) | ||
.boxed() | ||
.collect(toMap(Function.identity(), originalIndexParameters::get)); | ||
} | ||
|
||
StatementParameters() { | ||
} | ||
|
||
public Object get(final int index) { | ||
return indexedParameters.get(index); | ||
} | ||
|
||
public Object get(final String namedParameter) { | ||
return namedParameters.get(namedParameter); | ||
} | ||
|
||
void setParameter(final String parameterName, final Object value) { | ||
namedParameters.put(parameterName, value); | ||
} | ||
|
||
void setParameter(final int parameterIndex, final Object value) { | ||
indexedParameters.put(parameterIndex-1, value); | ||
} | ||
|
||
Map<String, Object> getParametersAsMap(){ | ||
return namedParameters; | ||
} | ||
|
||
List<Object> getParametersAsList() { | ||
return new ArrayList<>(indexedParameters.values()); | ||
} | ||
|
||
void clear() { | ||
namedParameters.clear(); | ||
indexedParameters.clear(); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof StatementParameters)) return false; | ||
final StatementParameters that = (StatementParameters) o; | ||
return Objects.equals(namedParameters, that.namedParameters); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(namedParameters); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "StatementParameters{" + | ||
"parameters=" + namedParameters + | ||
'}'; | ||
} | ||
|
||
public int size() { | ||
return namedParameters.size() + indexedParameters.size(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.