-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAbstractTestRunnerStatement.java
More file actions
102 lines (79 loc) · 3.63 KB
/
AbstractTestRunnerStatement.java
File metadata and controls
102 lines (79 loc) · 3.63 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
100
101
102
package org.utplsql.api.testRunner;
import oracle.jdbc.OracleConnection;
import org.utplsql.api.CustomTypes;
import org.utplsql.api.FileMapper;
import org.utplsql.api.FileMapping;
import org.utplsql.api.TestRunnerOptions;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
/**
* Abstract class which creates a callable statement for running tests
* The SQL to be used has to be implemented for there are differences between the Framework-versions
*
* @author pesse
*/
abstract class AbstractTestRunnerStatement implements TestRunnerStatement {
protected final TestRunnerOptions options;
protected final CallableStatement callableStatement;
private final Connection conn;
public AbstractTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException {
this.options = options;
this.conn = conn;
callableStatement = conn.prepareCall(getSql());
createStatement();
}
protected abstract String getSql();
protected int createStatement() throws SQLException {
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
int paramIdx = 0;
callableStatement.setArray(
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.pathList.toArray()));
callableStatement.setArray(
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_REPORTERS, options.reporterList.toArray()));
if (options.coverageSchemes.isEmpty()) {
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
} else {
callableStatement.setArray(
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.coverageSchemes.toArray()));
}
if (options.sourceMappingOptions == null) {
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
} else {
List<FileMapping> sourceMappings = FileMapper.buildFileMappingList(conn, options.sourceMappingOptions);
callableStatement.setArray(
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings.toArray()));
}
if (options.testMappingOptions == null) {
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
} else {
List<FileMapping> sourceMappings = FileMapper.buildFileMappingList(conn, options.testMappingOptions);
callableStatement.setArray(
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings.toArray()));
}
if (options.includeObjects.isEmpty()) {
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
} else {
callableStatement.setArray(
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.includeObjects.toArray()));
}
if (options.excludeObjects.isEmpty()) {
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
} else {
callableStatement.setArray(
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.excludeObjects.toArray()));
}
return paramIdx;
}
public void execute() throws SQLException {
callableStatement.execute();
}
@Override
public void close() throws SQLException {
if (callableStatement != null) {
callableStatement.close();
}
}
}