8000 Now let's use that sweet new DynamicParameterListBuilder · utPLSQL/utPLSQL-java-api@9cd9937 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9cd9937

Browse files
committed
Now let's use that sweet new DynamicParameterListBuilder
1 parent c01e8c2 commit 9cd9937

File tree

1 file changed

+26
-54
lines changed

1 file changed

+26
-54
lines changed

src/main/java/org/utplsql/api/testRunner/FileMapper.java

Lines changed: 26 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import org.utplsql.api.FileMapperOptions;
1010
import org.utplsql.api.FileMapping;
1111
import org.utplsql.api.KeyValuePair;
12+
import org.utplsql.api.db.DynamicParameterList;
13+
import org.utplsql.api.db.DynamicParameterListBuilder;
1214

1315
import java.sql.*;
14-
import java.util.ArrayList;
15-
import java.util.List;
16-
import java.util.Map;
16+
import java.util.*;
1717

1818
final class FileMapper {
1919

@@ -34,66 +34,38 @@ private static Array buildFileMappingArray(
3434
typeMap.put(CustomTypes.UT_KEY_VALUE_PAIR, KeyValuePair.class);
3535
conn.setTypeMap(typeMap);
3636

37-
CallableStatement callableStatement = conn.prepareCall(
38-
"BEGIN " +
39-
"? := ut_file_mapper.build_file_mappings(" +
40-
"a_object_owner => ?, " +
41-
"a_file_paths => ?, " +
42-
"a_file_to_object_type_mapping => ?, " +
43-
"a_regex_pattern => ?, " +
44-
"a_object_owner_subexpression => ?, " +
45-
"a_object_name_subexpression => ?, " +
46-
"a_object_type_subexpression => ?); " +
47-
"END;");
48-
49-
int paramIdx = 0;
50-
callableStatement.registerOutParameter(++paramIdx, OracleTypes.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
51-
52-
if (mapperOptions.getObjectOwner() == null) {
53-
callableStatement.setNull(++paramIdx, Types.VARCHAR);
54-
} else {
55-
callableStatement.setString(++paramIdx, mapperOptions.getObjectOwner());
56-
}
57-
5837
logger.debug("Building fileMappingArray");
59-
Object[] filePathsArray = mapperOptions.getFilePaths().toArray();
38+
final Object[] filePathsArray = mapperOptions.getFilePaths().toArray();
6039
for ( Object elem : filePathsArray ) {
6140
logger.debug("Path: " + elem);
6241
}
63-
64-
callableStatement.setArray(
65-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, filePathsArray));
66-
67-
if (mapperOptions.getTypeMappings() == null || mapperOptions.getTypeMappings().size() == 0) {
68-
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_KEY_VALUE_PAIRS);
69-
} else {
70-
callableStatement.setArray(
71-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_KEY_VALUE_PAIRS, mapperOptions.getTypeMappings().toArray()));
42+
Object[] typeMapArray = null;
43+
if ( mapperOptions.getTypeMappings() != null ) {
44+
typeMapArray = mapperOptions.getTypeMappings().toArray();
7245
}
7346

74-
if (mapperOptions.getRegexPattern() == null) {
75-
callableStatement.setNull(++paramIdx, Types.VARCHAR);
76-
} else {
77-
callableStatement.setString(++paramIdx, mapperOptions.getRegexPattern());
78-
}
47+
DynamicParameterList parameterList = DynamicParameterListBuilder.create()
48+
.add("a_file_paths", filePathsArray, CustomTypes.UT_VARCHAR2_LIST, oraConn)
49+
.onlyAddIfNotEmpty()
50+
.add("a_object_owner", mapperOptions.getObjectOwner())
51+
.add("a_file_to_object_type_mapping", typeMapArray, CustomTypes.UT_KEY_VALUE_PAIRS, oraConn)
52+
.add("a_regex_pattern", mapperOptions.getRegexPattern())
53+
.add("a_object_owner_subexpression", mapperOptions.getOwnerSubExpression())
54+
.add("a_object_name_subexpression", mapperOptions.getNameSubExpression())
55+
.add("a_object_type_subexpression", mapperOptions.getTypeSubExpression())
56+
.build();
7957

80-
if (mapperOptions.getOwnerSubExpression() == null) {
81-
callableStatement.setNull(++paramIdx, Types.INTEGER);
82-
} else {
83-
callableStatement.setInt(++paramIdx, mapperOptions.getOwnerSubExpression());
84-
}
58+
CallableStatement callableStatement = conn.prepareCall(
59+
"BEGIN " +
60+
"? := ut_file_mapper.build_file_mappings(" +
61+
parameterList.getSql() +
62+
"); " +
63+
"END;");
8564

86-
if (mapperOptions.getNameSubExpression() == null) {
87-
callableStatement.setNull(++paramIdx, Types.INTEGER);
88-
} else {
89-
callableStatement.setInt(++paramIdx, mapperOptions.getNameSubExpression());
90-
}
65+
int paramIdx = 0;
66+
callableStatement.registerOutParameter(++paramIdx, OracleTypes.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
9167

92-
if (mapperOptions.getTypeSubExpression() == null) {
93-
callableStatement.setNull(++paramIdx, Types.INTEGER);
94-
} else {
95-
callableStatement.setInt(++paramIdx, mapperOptions.getTypeSubExpression());
96-
}
68+
parameterList.setParamsStartWithIndex(callableStatement, ++paramIdx);
9769

9870
callableStatement.execute();
9971
return callableStatement.getArray(1);

0 commit comments

Comments
 (0)
0