8000 Improve hasOutput check to a real PL/SQL type-check · utPLSQL/utPLSQL-java-api@e567af0 · GitHub
[go: up one dir, main page]

Skip to content

Commit e567af0

Browse files
committed
Improve hasOutput check to a real PL/SQL type-check
Thanks Jacek for the hint! It's also less verbose now.
1 parent a4ee67d commit e567af0

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.utplsql.api.outputBuffer;
22

33
import oracle.jdbc.OracleConnection;
4+
import oracle.jdbc.OracleTypes;
45
import org.utplsql.api.Version;
56
import org.utplsql.api.exception.InvalidVersionException;
67
import org.utplsql.api.reporter.Reporter;
78

9+
import java.sql.CallableStatement;
810
import java.sql.Connection;
9-
import java.sql.PreparedStatement;
10-
import java.sql.ResultSet;
1111
import java.sql.SQLException;
1212

1313
public class OutputBufferProvider {
@@ -42,26 +42,29 @@ public static OutputBuffer getCompatibleOutputBuffer(Version databaseVersion, Re
4242

4343
private static boolean hasOutput( Reporter reporter, OracleConnection oraConn ) throws SQLException {
4444

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)) {
4961
stmt.setQueryTimeout(3);
5062
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);
5664

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;
6568
}
6669
}
6770

0 commit comments

Comments
 (0)
0