|
1 | 1 | package org.utplsql.api.outputBuffer;
|
2 | 2 |
|
3 | 3 | import oracle.jdbc.OracleConnection;
|
| 4 | +import oracle.jdbc.OracleTypes; |
4 | 5 | import org.utplsql.api.Version;
|
5 | 6 | import org.utplsql.api.exception.InvalidVersionException;
|
6 | 7 | import org.utplsql.api.reporter.Reporter;
|
7 | 8 |
|
| 9 | +import java.sql.CallableStatement; |
8 | 10 | import java.sql.Connection;
|
9 |
| -import java.sql.PreparedStatement; |
10 |
| -import java.sql.ResultSet; |
11 | 11 | import java.sql.SQLException;
|
12 | 12 |
|
13 | 13 | public class OutputBufferProvider {
|
@@ -42,26 +42,29 @@ public static OutputBuffer getCompatibleOutputBuffer(Version databaseVersion, Re
|
42 | 42 |
|
43 | 43 | private static boolean hasOutput( Reporter reporter, OracleConnection oraConn ) throws SQLException {
|
44 | 44 |
|
45 |
| - String sql = "select is_output_reporter " + |
46 |
| - " from table(ut_runner.get_reporters_list)" + |
47 |
| - " where ? = substr(reporter_object_name, length(reporter_object_name)-?+1)"; |
48 |
| - try ( PreparedStatement stmt = oraConn.prepareStatement(sql)) { |
| 45 | + String sql = |
| 46 | + "declare " + |
| 47 | + " l_result boolean;" + |
| 48 | + "begin " + |
| 49 | + " begin " + |
| 50 | + " execute immediate '" + |
| 51 | + " begin " + |
| 52 | + " :x :=' || DBMS_ASSERT.SQL_OBJECT_NAME( ? ) || '() is of (ut_output_reporter_base);" + |
| 53 | + " end;'" + |
| 54 | + " using out l_result;" + |
| 55 | + " exception when others then null;" + |
| 56 | + " end;" + |
| 57 | + " ? := case l_result when true then 1 else 0 end;" + |
| 58 | + "end;"; |
| 59 | + |
| 60 | + try ( CallableStatement stmt = oraConn.prepareCall(<
BA40
span class=pl-s1>sql)) { |
49 | 61 | stmt.setQueryTimeout(3);
|
50 | 62 | stmt.setString(1, reporter.getTypeName());
|
51 |
| - stmt.setInt(2, reporter.getTypeName().length()); |
52 |
| - |
53 |
| - try ( ResultSet rs = stmt.executeQuery() ) { |
54 |
| - if ( rs.next() ) { |
55 |
| - String isReporterResult = rs.getString(1); |
| 63 | + stmt.registerOutParameter(2, OracleTypes.INTEGER); |
56 | 64 |
|
57 |
| - if ( isReporterResult == null ) |
58 |
| - throw new IllegalArgumentException("The given type " + reporter.getTypeName() + " is not a valid Reporter!"); |
59 |
| - else |
60 |
| - return isReporterResult.equalsIgnoreCase("Y"); |
61 |
| - } |
62 |
| - else |
63 |
| - throw new SQLException("Could not check Reporter validity"); |
64 |
| - } |
| 65 | + stmt.execute(); |
| 66 | + int result = stmt.getInt(2); |
| 67 | + return result == 1; |
65 | 68 | }
|
66 | 69 | }
|
67 | 70 |
|
|
0 commit comments