@@ -20,15 +20,11 @@ private DBHelper() {}
|
20 | 20 | * @throws SQLException any database error
|
21 | 21 | */
|
22 | 22 | public static String newSysGuid(Connection conn) throws SQLException {
|
23 |
| -CallableStatement callableStatement = null; |
24 |
| -try { |
25 |
| -callableStatement = conn.prepareCall("BEGIN ? := sys_guid(); END;"); |
| 23 | +assert conn != null; |
| 24 | +try (CallableStatement callableStatement = conn.prepareCall("BEGIN ? := sys_guid(); END;")) { |
26 | 25 | callableStatement.registerOutParameter(1, OracleTypes.RAW);
|
27 | 26 | callableStatement.executeUpdate();
|
28 | 27 | return callableStatement.getString(1);
|
29 |
| -} finally { |
30 |
| -if (callableStatement != null) |
31 |
| -callableStatement.close(); |
32 | 28 | }
|
33 | 29 | }
|
34 | 30 |
|
@@ -39,26 +35,22 @@ public static String newSysGuid(Connection conn) throws SQLException {
|
39 | 35 | * @throws SQLException any database error
|
40 | 36 | */
|
41 | 37 | public static String getCurrentSchema(Connection conn) throws SQLException {
|
42 |
| -CallableStatement callableStatement = null; |
43 |
| -try { |
44 |
| -callableStatement = conn.prepareCall("BEGIN ? := sys_context('userenv', 'current_schema'); END;"); |
| 38 | +assert conn != null; |
| 39 | +try (CallableStatement callableStatement = conn.prepareCall("BEGIN ? := sys_context('userenv', 'current_schema'); END;")) { |
45 | 40 | callableStatement.registerOutParameter(1, Types.VARCHAR);
|
46 | 41 | callableStatement.executeUpdate();
|
47 | 42 | return callableStatement.getString(1);
|
48 |
| -} finally { |
49 |
| -if (callableStatement != null) |
50 |
| -callableStatement.close(); |
51 | 43 | }
|
52 | 44 | }
|
53 | 45 |
|
54 | 46 | /** Returns the Frameworks version string of the given connection
|
55 | 47 | *
|
56 | 48 | * @param conn Active db connection
|
57 |
| -* @return |
58 |
| -* @throws SQLException |
| 49 | +* @return Version-string of the utPLSQL framework |
| 50 | +* @throws SQLException any database error |
59 | 51 | */
|
60 |
| -public static Version getDatabaseFrameworkVersion( Connection conn ) |
61 |
| -throws SQLException { |
| 52 | +public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLException { |
| 53 | +assert conn != null; |
62 | 54 | Version result = new Version("");
|
63 | 55 | try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual"))
|
64 | 56 | {
|
@@ -78,11 +70,32 @@ public static Version getDatabaseFrameworkVersion( Connection conn )
|
78 | 70 | return result;
|
79 | 71 | }
|
80 | 72 |
|
| 73 | +/** Returns the Oracle database Version from a given connection object |
| 74 | +* |
| 75 | +* @param conn Connection-Object |
| 76 | +* @return Returns version-string of the Oracle Database product component |
| 77 | +* @throws SQLException any database error |
| 78 | +*/ |
| 79 | +public static String getOracleDatabaseVersion( Connection conn ) throws SQLException { |
| 80 | +assert conn != null; |
| 81 | +String result = null; |
| 82 | +try (PreparedStatement stmt = conn.prepareStatement("select version from product_component_version where product like 'Oracle Database%'")) |
| 83 | +{ |
| 84 | +ResultSet rs = stmt.executeQuery(); |
| 85 | + |
| 86 | +if ( rs.next() ) |
| 87 | +result = rs.getString(1); |
| 88 | +} |
| 89 | + |
| 90 | +return result; |
| 91 | +} |
| 92 | + |
81 | 93 | /**
|
82 | 94 | * Enable the dbms_output buffer with unlimited size.
|
83 | 95 | * @param conn the connection
|
84 | 96 | */
|
85 | 97 | public static void enableDBMSOutput(Connection conn) {
|
| 98 | +assert conn != null; |
86 | 99 | try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.enable(NULL); END;")) {
|
87 | 100 | call.execute();
|
88 | 101 | } catch (SQLException e) {
|
@@ -95,6 +108,7 @@ public static void enableDBMSOutput(Connection conn) {
|
95 | 108 | * @param conn the connection
|
96 | 109 | */
|
97 | 110 | public static void disableDBMSOutput(Connection conn) {
|
| 111 | +assert conn != null; |
98 | 112 | try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.disable(); END;")) {
|
99 | 113 | call.execute();
|
100 | 114 | } catch (SQLException e) {
|
|
0 commit comments