|
1 | 1 | package org.utplsql.api.testRunner;
|
2 | 2 |
|
| 3 | +import oracle.jdbc.OracleConnection; |
| 4 | +import org.utplsql.api.CustomTypes; |
| 5 | +import org.utplsql.api.TestRunnerOptions; |
3 | 6 | import org.utplsql.api.Version;
|
| 7 | +import org.utplsql.api.db.DynamicParameterList; |
4 | 8 |
|
5 | 9 | import java.sql.CallableStatement;
|
6 | 10 | import java.sql.Connection;
|
7 | 11 | import java.sql.SQLException;
|
8 | 12 |
|
9 | 13 | public class DynamicTestRunnerStatement implements TestRunnerStatement {
|
10 | 14 |
|
11 |
| - private CallableStatement callableStatement; |
12 |
| - private final Connection connection; |
| 15 | + private CallableStatement stmt; |
| 16 | + private final OracleConnection oracleConnection; |
13 | 17 | private final Version utPlSQlVersion;
|
| 18 | + private final TestRunnerOptions options; |
| 19 | + private final DynamicParameterList dynamicParameterList; |
14 | 20 |
|
15 |
| - private DynamicTestRunnerStatement( Version utPlSQlVersion, Connection connection ) { |
| 21 | + private DynamicTestRunnerStatement( Version utPlSQlVersion, OracleConnection connection, TestRunnerOptions options, CallableStatement statement ) throws SQLException { |
16 | 22 | this.utPlSQlVersion = utPlSQlVersion;
|
17 |
| - this.connection = connection; |
| 23 | + this.oracleConnection = connection; |
| 24 | + this.options = options; |
| 25 | + this.stmt = statement; |
| 26 | + |
| 27 | + this.dynamicParameterList = initParameterList(); |
| 28 | + |
| 29 | + prepareStatement(); |
| 30 | + } |
| 31 | + |
| 32 | + private DynamicParameterList initParameterList() throws SQLException { |
| 33 | + /* |
| 34 | + "BEGIN " + |
| 35 | + "ut_runner.run(" + |
| 36 | + "a_paths => ?, " + |
| 37 | + "a_reporters => ?, " + |
| 38 | + "a_color_console => " + colorConsoleStr + ", " + |
| 39 | + "a_coverage_schemes => ?, " + |
| 40 | + "a_source_file_mappings => ?, " + |
| 41 | + "a_test_file_mappings => ?, " + |
| 42 | + "a_include_objects => ?, " + |
| 43 | + "a_exclude_objects => ?, " + |
| 44 | + "a_fail_on_errors => " + failOnErrors + ", " + |
| 45 | + "a_client_character_set => ?, " + |
| 46 | + "a_random_test_order => " + randomExecutionOrder + ", " + |
| 47 | + "a_random_test_order_seed => ?, "+ |
| 48 | + "a_tags => ?"+ |
| 49 | + "); " + |
| 50 | + "END;"; |
| 51 | + */ |
| 52 | + return DynamicParameterList.builder() |
| 53 | + .addIfNotEmpty("a_paths", options.pathList.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection) |
| 54 | + .build(); |
| 55 | + } |
| 56 | + |
| 57 | + private void prepareStatement() throws SQLException { |
| 58 | + if ( stmt == null ) |
| 59 | + oracleConnection.prepareCall(dynamicParameterList.getSql()); |
| 60 | + |
| 61 | + dynamicParameterList.setParamsStartWithIndex(stmt, 1); |
18 | 62 | }
|
19 | 63 |
|
20 | 64 | @Override
|
21 | 65 | public void execute() throws SQLException {
|
| 66 | + |
22 | 67 | // Implement
|
23 | 68 | }
|
24 | 69 |
|
| 70 | + @Override |
| 71 | + public String getSql() { |
| 72 | + return dynamicParameterList.getSql(); |
| 73 | + } |
| 74 | + |
25 | 75 | @Override
|
26 | 76 | public void close() throws SQLException {
|
27 |
| - if (callableStatement != null) { |
28 |
| - callableStatement.close(); |
| 77 | + if (stmt != null) { |
| 78 | + stmt.close(); |
29 | 79 | }
|
30 | 80 | }
|
31 | 81 |
|
32 |
| - public static DynamicTestRunnerStatement forVersion(Version version, Connection connection) { |
33 |
| - return new DynamicTestRunnerStatement(version, connection); |
| 82 | + public static DynamicTestRunnerStatement forVersion(Version version, OracleConnection connection, TestRunnerOptions options, CallableStatement statement ) throws SQLException { |
| 83 | + return new DynamicTestRunnerStatement(version, connection, options, statement); |
34 | 84 | }
|
35 | 85 | }
|
0 commit comments