|
14 | 14 | import java.sql.Connection;
|
15 | 15 | import java.sql.SQLException;
|
16 | 16 | import java.sql.Types;
|
| 17 | +import java.util.Objects; |
17 | 18 |
|
18 | 19 | /** Class to check compatibility with database framework and also to give several specific implementations depending
|
19 | 20 | * on the version of the connected framework.
|
|
23 | 24 | */
|
24 | 25 | public class CompatibilityProxy {
|
25 | 26 |
|
26 |
| - public static final String UTPLSQL_API_VERSION = "3.1.0"; |
| 27 | + private static final String UTPLSQL_API_VERSION = "3.1.1"; |
27 | 28 | public static final String UTPLSQL_COMPATIBILITY_VERSION = "3";
|
28 | 29 |
|
29 | 30 | private Version databaseVersion;
|
@@ -51,12 +52,19 @@ public CompatibilityProxy( Connection conn, boolean skipCompatibilityCheck ) thr
|
51 | 52 | private void doCompatibilityCheckWithDatabase( Connection conn ) throws SQLException
|
52 | 53 | {
|
53 | 54 | databaseVersion = DBHelper.getDatabaseFrameworkVersion(conn);
|
| 55 | + Version clientVersion = new Version(UTPLSQL_COMPATIBILITY_VERSION); |
| 56 | + |
| 57 | + if ( databaseVersion == null ) |
| 58 | + throw new DatabaseNotCompatibleException("Could not get database version", clientVersion, null, null); |
| 59 | + |
| 60 | + if ( databaseVersion.getMajor() == null ) |
| 61 | + throw new DatabaseNotCompatibleException("Illegal database version: " + databaseVersion.toString(), clientVersion, databaseVersion, null); |
54 | 62 |
|
55 | 63 | if (OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(databaseVersion)) {
|
56 | 64 | try {
|
57 | 65 | compatible = versionCompatibilityCheck(conn, UTPLSQL_COMPATIBILITY_VERSION, null);
|
58 | 66 | } catch (SQLException e) {
|
59 |
| - throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), new Version(UTPLSQL_COMPATIBILITY_VERSION), new Version("Unknown"), e); |
| 67 | + throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), clientVersion, new Version("Unknown"), e); |
60 | 68 | }
|
61 | 69 | } else
|
62 | 70 | compatible = versionCompatibilityCheckPre303(UTPLSQL_COMPATIBILITY_VERSION);
|
@@ -105,9 +113,13 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
|
105 | 113 | */
|
106 | 114 | private boolean versionCompatibilityCheckPre303(String requested )
|
107 | 115 | {
|
108 |
| - Version requesteVersion = new Version(requested); |
| 116 | + Version requestedVersion = new Version(requested); |
109 | 117 |
|
110 |
| - if (databaseVersion.getMajor().equals(requesteVersion.getMajor()) && (requesteVersion.getMinor() == null || requesteVersion.getMinor().equals(databaseVersion.getMinor())) ) |
| 118 | + Objects.requireNonNull(databaseVersion.getMajor(), "Illegal database Version: " + databaseVersion.toString()); |
| 119 | + if ( |
| 120 | + databaseVersion.getMajor().equals(requestedVersion.getMajor()) |
| 121 | + && (requestedVersion.getMinor() == null |
| 122 | + || requestedVersion.getMinor().equals(databaseVersion.getMinor())) ) |
111 | 123 | return true;
|
112 | 124 | else
|
113 | 125 | return false;
|
|
0 commit comments