-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFileMapper.java
More file actions
99 lines (78 loc) · 3.69 KB
/
FileMapper.java
File metadata and controls
99 lines (78 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package org.utplsql.api;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleTypes;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public final class FileMapper {
private FileMapper() {}
/**
* Call the database api to build the custom file mappings.
*/
public static Array buildFileMappingArray(
Connection conn, FileMapperOptions mapperOptions) throws SQLException {
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
Map typeMap = conn.getTypeMap();
typeMap.put(CustomTypes.UT_FILE_MAPPING, FileMapping.class);
typeMap.put(CustomTypes.UT_KEY_VALUE_PAIR, KeyValuePair.class);
conn.setTypeMap(typeMap);
CallableStatement callableStatement = conn.prepareCall(
"BEGIN " +
"? := ut_file_mapper.build_file_mappings(" +
"a_object_owner => ?, " +
"a_file_paths => ?, " +
"a_file_to_object_type_mapping => ?, " +
"a_regex_pattern => ?, " +
"a_object_owner_subexpression => ?, " +
"a_object_name_subexpression => ?, " +
"a_object_type_subexpression => ?); " +
"END;");
int paramIdx = 0;
callableStatement.registerOutParameter(++paramIdx, OracleTypes.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
if (mapperOptions.getObjectOwner() == null) {
callableStatement.setNull(++paramIdx, Types.VARCHAR);
} else {
callableStatement.setString(++paramIdx, mapperOptions.getObjectOwner());
}
callableStatement.setArray(
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, mapperOptions.getFilePaths().toArray()));
if (mapperOptions.getTypeMappings() == null) {
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_KEY_VALUE_PAIRS);
} else {
callableStatement.setArray(
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_KEY_VALUE_PAIRS, mapperOptions.getTypeMappings().toArray()));
}
if (mapperOptions.getRegexPattern() == null) {
callableStatement.setNull(++paramIdx, Types.VARCHAR);
} else {
callableStatement.setString(++paramIdx, mapperOptions.getRegexPattern());
}
if (mapperOptions.getOwnerSubExpression() == null) {
callableStatement.setNull(++paramIdx, Types.INTEGER);
} else {
callableStatement.setInt(++paramIdx, mapperOptions.getOwnerSubExpression());
}
if (mapperOptions.getNameSubExpression() == null) {
callableStatement.setNull(++paramIdx, Types.INTEGER);
} else {
callableStatement.setInt(++paramIdx, mapperOptions.getNameSubExpression());
}
if (mapperOptions.getTypeSubExpression() == null) {
callableStatement.setNull(++paramIdx, Types.INTEGER);
} else {
callableStatement.setInt(++paramIdx, mapperOptions.getTypeSubExpression());
}
callableStatement.execute();
return callableStatement.getArray(1);
}
public static List<FileMapping> buildFileMappingList(
Connection conn, FileMapperOptions mapperOptions) throws SQLException {
java.sql.Array fileMappings = buildFileMappingArray(conn, mapperOptions);
List<FileMapping> mappingList = new ArrayList<>();
for (Object obj : (Object[]) fileMappings.getArray()) {
mappingList.add((FileMapping) obj);
}
return mappingList;
}
}