Skip to content

Commit a1113b8

Browse files
author
Samuel Nitsche
committed
Simple approach towards checking version compability
not sufficient though, we want to have a more specific check with fallback-mechanisms for some features
1 parent 5d725d5 commit a1113b8

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

src/main/java/org/utplsql/api/DBHelper.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,20 @@ public static boolean versionCompatibilityCheck(Connection conn)
9696
return versionCompatibilityCheck(conn, UTPLSQL_VERSION);
9797
}
9898

99+
/** Checks if actual API-version is compatible with utPLSQL database version and throws a RuntimeException if not
100+
* Throws a RuntimeException if version compatibility can not be checked.
101+
*
102+
* @param conn
103+
*/
104+
public static void failOnVersionCompatibilityCheckFailed( Connection conn )
105+
{
106+
try {
107+
if (!versionCompatibilityCheck(conn))
108+
throw new RuntimeException("API-Version " + UTPLSQL_VERSION + " not compatible with database. Aborting.");
109+
}
110+
catch ( SQLException e )
111+
{
112+
throw new RuntimeException("Compatibility-check failed with error. Aborting.", e);
113+
}
114+
}
99115
}

src/main/java/org/utplsql/api/TestRunner.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public TestRunner failOnErrors(boolean failOnErrors) {
8585
}
8686

8787
public void run(Connection conn) throws SomeTestsFailedException, SQLException {
88+
89+
// First of all check version compatibility
90+
DBHelper.failOnVersionCompatibilityCheckFailed(conn);
91+
8892
for (Reporter r : this.reporterList)
8993
validateReporter(conn, r);
9094

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.utplsql.api.exception;
2+
3+
import org.utplsql.api.DBHelper;
4+
5+
/** Custom exception to indicate API is not compatible with database framework
6+
*
7+
* @author pesse
8+
*
9+
*/
10+
public class DatabaseNotCompatibleException extends Exception {
11+
12+
private String clientVersion;
13+
private String databaseVersion;
14+
15+
public DatabaseNotCompatibleException( String message, String clientVersion, String databaseVersion, Throwable cause )
16+
{
17+
super(message, cause);
18+
19+
this.clientVersion = clientVersion;
20+
this.databaseVersion = databaseVersion;
21+
}
22+
23+
public DatabaseNotCompatibleException( String clientVersion, String databaseVersion, Throwable cause )
24+
{
25+
this("utPLSQL API (" + String.valueOf(clientVersion) + ") not compatible with database (" + String.valueOf(databaseVersion) + ")", clientVersion, databaseVersion, cause);
26+
}
27+
28+
public DatabaseNotCompatibleException( String clientVersion, String databaseVersion )
29+
{
30+
this(clientVersion, databaseVersion, null);
31+
}
32+
33+
public DatabaseNotCompatibleException( String databaseVersion, Throwable cause )
34+
{
35+
this(DBHelper.UTPLSQL_VERSION, databaseVersion, cause );
36+
}
37+
38+
public String getClientVersion() {
39+
return clientVersion;
40+
}
41+
42+
public String getDatabaseVersion()
43+
{
44+
return databaseVersion;
45+
}
46+
}

0 commit comments

Comments
 (0)