-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOutputBufferProvider.java
More file actions
70 lines (59 loc) · 2.58 KB
/
OutputBufferProvider.java
File metadata and controls
70 lines (59 loc) · 2.58 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
package org.utplsql.api.outputBuffer;
import oracle.jdbc.OracleConnection;
import org.utplsql.api.Version;
import org.utplsql.api.exception.InvalidVersionException;
import org.utplsql.api.reporter.Reporter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class OutputBufferProvider {
/** Returns an OutputBuffer compatible with the given databaseVersion
* If we are at 3.1.0 or greater, returns an OutputBuffer based upon the information whether the Reporter has Output or not
*
* @param databaseVersion
* @param reporter
* @param conn
* @return
* @throws SQLException
*/
public static OutputBuffer getCompatibleOutputBuffer(Version databaseVersion, Reporter reporter, Connection conn ) throws SQLException {
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
try {
if (databaseVersion.isGreaterOrEqualThan(new Version("3.1.0"))) {
if ( hasOutput(reporter, oraConn) ) {
return new DefaultOutputBuffer(reporter);
}
else {
return new NonOutputBuffer(reporter);
}
}
}
catch ( InvalidVersionException ignored ) { }
// If we couldn't find an appropriate OutputBuffer, return the Pre310-Compatibility-Buffer
return new CompatibilityOutputBufferPre310(reporter);
}
private static boolean hasOutput( Reporter reporter, OracleConnection oraConn ) throws SQLException {
String sql = "select is_output_reporter " +
" from table(ut_runner.get_reporters_list)" +
" where ? = substr(reporter_object_name, length(reporter_object_name)-?+1)";
try ( PreparedStatement stmt = oraConn.prepareStatement(sql)) {
stmt.setQueryTimeout(3);
stmt.setString(1, reporter.getTypeName());
stmt.setInt(2, reporter.getTypeName().length());
try ( ResultSet rs = stmt.executeQuery() ) {
if ( rs.next() ) {
String isReporterResult = rs.getString(1);
if ( isReporterResult == null )
throw new IllegalArgumentException("The given type " + reporter.getTypeName() + " is not a valid Reporter!");
else
return isReporterResult.equalsIgnoreCase("Y");
}
else
throw new SQLException("Could not check Reporter validity");
}
}
}
private OutputBufferProvider() {
}
}