-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOutputBufferProvider.java
More file actions
64 lines (54 loc) · 2.36 KB
/
OutputBufferProvider.java
File metadata and controls
64 lines (54 loc) · 2.36 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
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 (new Version("3.0.4.1610").isGreaterOrEqualThan(databaseVersion)) {
if ( hasOutput(reporter, oraConn) ) {
return new DefaultOutputBuffer(reporter);
}
else {
return new NonOutputBuffer(reporter);
}
}
}
catch ( InvalidVersionException e ) { }
// 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 {
try ( PreparedStatement stmt = oraConn.prepareStatement("select ut_runner.is_output_reporter(?) from dual")) {
stmt.setString(1, reporter.getTypeName());
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 if (isReporterResult.equalsIgnoreCase("Y") )
return true;
else
return false;
}
else
throw new SQLException("Could not check Reporter validity");
}
}
}
}