Skip to content

Commit

Permalink
ADBDEV-3096: Add function to split value
Browse files Browse the repository at this point in the history
  • Loading branch information
RomaZe committed Oct 11, 2022
1 parent 45090ee commit 208e91c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

public class OracleParallelSessionParamFactory {
public OracleParallelSessionParam create(String property, String value, String delimiter) {
validateValue(property, value, delimiter);
String[] values = splitValue(property, value, delimiter);

HashMap<String, String> map = getParallelSessionParam(value.split(delimiter));
HashMap<String, String> map = getParallelSessionParam(values);
String clause = map.get("clause").toUpperCase();
String statementType = map.get("statement_type").toUpperCase();
String degreeOfParallelism = map.get("degree_of_parallelism");
Expand All @@ -21,19 +21,22 @@ public OracleParallelSessionParam create(String property, String value, String d
return param;
}

private void validateValue(String property, String value, String delimiter) {
if (StringUtils.isBlank(value)) {
throw new IllegalArgumentException(String.format(
"The parameter '%s' is empty in jdbc-site.xml", property)
);
}
private String[] splitValue(String property, String value, String delimiter) {
validateValue(property, value);
String[] values = value.split(delimiter);
if (values.length < 2 || values.length > 3) {
throw new IllegalArgumentException(String.format(
"The parameter '%s' in jdbc-site.xml has to contain at least 2 but not more then 3 values delimited by %s",
property, delimiter)
);
}
return values;
}

private void validateValue(String property, String value) {
if (StringUtils.isBlank(value)) {
throw new IllegalArgumentException(String.format("The parameter '%s' is blank in jdbc-site.xml", property));
}
}

private HashMap<String, String> getParallelSessionParam(String[] values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void createWithBlankValue() {
String value = " ";
Exception exception = assertThrows(IllegalArgumentException.class,
() -> oracleParallelSessionParamFactory.create(property, value, delimiter));
String expectedMessage = "The parameter 'jdbc.session.property.alter_session_parallel.1' is empty in jdbc-site.xml";
String expectedMessage = "The parameter 'jdbc.session.property.alter_session_parallel.1' is blank in jdbc-site.xml";
String actualMessage = exception.getMessage();
assertEquals(expectedMessage, actualMessage);
}
Expand Down

0 comments on commit 208e91c

Please sign in to comment.