9
9
import org .utplsql .api .FileMapperOptions ;
10
10
import org .utplsql .api .FileMapping ;
11
11
import org .utplsql .api .KeyValuePair ;
12
+ import org .utplsql .api .db .DynamicParameterList ;
13
+ import org .utplsql .api .db .DynamicParameterListBuilder ;
12
14
13
15
import java .sql .*;
14
- import java .util .ArrayList ;
15
- import java .util .List ;
16
- import java .util .Map ;
16
+ import java .util .*;
17
17
18
18
final class FileMapper {
19
19
@@ -34,66 +34,38 @@ private static Array buildFileMappingArray(
34
34
typeMap .put (CustomTypes .UT_KEY_VALUE_PAIR , KeyValuePair .class );
35
35
conn .setTypeMap (typeMap );
36
36
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
-
58
37
logger .debug ("Building fileMappingArray" );
59
- Object [] filePathsArray = mapperOptions .getFilePaths ().toArray ();
38
+ final Object [] filePathsArray = mapperOptions .getFilePaths ().toArray ();
60
39
for ( Object elem : filePathsArray ) {
61
40
logger .debug ("Path: " + elem );
62
41
}
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 ();
72
45
}
73
46
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 ();
79
57
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;" );
85
64
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 );
91
67
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 );
97
69
98
70
callableStatement .execute ();
99
71
return callableStatement .getArray (1 );
0 commit comments