-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDefaultDatabaseInformation.java
More file actions
72 lines (58 loc) · 2.44 KB
/
DefaultDatabaseInformation.java
File metadata and controls
72 lines (58 loc) · 2.44 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
71
72
package org.utplsql.api.db;
import org.utplsql.api.Version;
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
import javax.annotation.Nullable;
import java.sql.*;
public class DefaultDatabaseInformation implements DatabaseInformation {
@Override
public Version getUtPlsqlFrameworkVersion(Connection conn) throws SQLException {
Version result = Version.create("");
try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual")) {
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
result = Version.create(rs.getString(1));
}
rs.close();
} catch (SQLException e) {
if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) {
throw new UtPLSQLNotInstalledException(e);
} else {
throw e;
}
}
return result;
}
@Override
public String getOracleVersion(Connection conn) throws SQLException {
String result = null;
try (PreparedStatement stmt = conn.prepareStatement("select version from product_component_version where product like 'Oracle Database%'")) {
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
result = rs.getString(1);
}
}
return result;
}
@Override
public String getCurrentSchema(Connection conn) throws SQLException {
try (CallableStatement callableStatement = conn.prepareCall("BEGIN ? := sys_context('userenv', 'current_schema'); END;")) {
callableStatement.registerOutParameter(1, Types.VARCHAR);
callableStatement.executeUpdate();
return callableStatement.getString(1);
}
}
@Override
public int frameworkCompatibilityCheck(Connection conn, String requested, @Nullable String current) throws SQLException {
try (CallableStatement callableStatement = conn.prepareCall("BEGIN ? := ut_runner.version_compatibility_check(?, ?); END;")) {
callableStatement.registerOutParameter(1, Types.SMALLINT);
callableStatement.setString(2, requested);
if (current == null) {
callableStatement.setNull(3, Types.VARCHAR);
} else {
callableStatement.setString(3, current);
}
callableStatement.executeUpdate();
return callableStatement.getInt(1);
}
}
}