|
12 | 12 | */
|
13 | 13 | public final class DBHelper {
|
14 | 14 |
|
| 15 | + public static final String UTPLSQL_COMPATIBILITY_VERSION = "3.0.3"; |
| 16 | + |
15 | 17 | private DBHelper() {}
|
16 | 18 |
|
17 | 19 | /**
|
@@ -52,4 +54,70 @@ public static String getCurrentSchema(Connection conn) throws SQLException {
|
52 | 54 | }
|
53 | 55 | }
|
54 | 56 |
|
| 57 | + /** |
| 58 | + * Check the utPLSQL version compatibility. |
| 59 | + * @param conn the connection |
| 60 | + * @return true if the requested utPLSQL version is compatible with the one installed on database |
| 61 | + * @throws SQLException any database error |
| 62 | + */ |
| 63 | + public static boolean versionCompatibilityCheck(Connection conn, String requested, String current) |
| 64 | + throws SQLException { |
| 65 | + CallableStatement callableStatement = null; |
| 66 | + try { |
| 67 | + callableStatement = conn.prepareCall("BEGIN ? := ut_runner.version_compatibility_check(?, ?); END;"); |
| 68 | + callableStatement.registerOutParameter(1, Types.SMALLINT); |
| 69 | + callableStatement.setString(2, requested); |
| 70 | + |
| 71 | + if (current == null) |
| 72 | + callableStatement.setNull(3, Types.VARCHAR); |
| 73 | + else |
| 74 | + callableStatement.setString(3, current); |
| 75 | + |
| 76 | + callableStatement.executeUpdate(); |
| 77 | + return callableStatement.getInt(1) == 1; |
| 78 | + } catch (SQLException e) { |
| 79 | + if (e.getErrorCode() == 6550) |
| 80 | + return false; |
| 81 | + else |
| 82 | + throw e; |
| 83 | + } finally { |
| 84 | + if (callableStatement != null) |
| 85 | + callableStatement.close(); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + public static boolean versionCompatibilityCheck(Connection conn, String requested) |
| 90 | + throws SQLException { |
| 91 | + return versionCompatibilityCheck(conn, requested, null); |
| 92 | + } |
| 93 | + |
| 94 | + public static boolean versionCompatibilityCheck(Connection conn) |
| 95 | + throws SQLException { |
| 96 | + return versionCompatibilityCheck(conn, UTPLSQL_COMPATIBILITY_VERSION); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Enable the dbms_output buffer with unlimited size. |
| 101 | + * @param conn the connection |
| 102 | + */ |
| 103 | + public static void enableDBMSOutput(Connection conn) { |
| 104 | + try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.enable(NULL); END;")) { |
| 105 | + call.execute(); |
| 106 | + } catch (SQLException e) { |
| 107 | + System.out.println("Failed to enable dbms_output."); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Disable the dbms_output buffer. |
| 113 | + * @param conn the connection |
| 114 | + */ |
| 115 | + public static void disableDBMSOutput(Connection conn) { |
| 116 | + try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.disable(); END;")) { |
| 117 | + call.execute(); |
| 118 | + } catch (SQLException e) { |
| 119 | + System.out.println("Failed to disable dbms_output."); |
| 120 | + } |
| 121 | + } |
| 122 | + |
55 | 123 | }
|
0 commit comments