Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4fbda90

Browse files
author
Samuel Nitsche
committed
Introduced DatabaseNotComptabileException
Also added some tests for getting Framework version and fixed error in getting it
1 parent 9e7fdd2 commit 4fbda90

4 files changed

Lines changed: 36 additions & 9 deletions

File tree

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.utplsql.api;
22

33
import oracle.jdbc.OracleTypes;
4+
import org.utplsql.api.exception.DatabaseNotCompatibleException;
45

56
import java.sql.*;
67

@@ -94,20 +95,25 @@ public static boolean versionCompatibilityCheck(Connection conn)
9495
}
9596

9697

97-
/** Checks if actual API-version is compatible with utPLSQL database version and throws a RuntimeException if not
98-
* Throws a RuntimeException if version compatibility can not be checked.
98+
/** Checks if actual API-version is compatible with utPLSQL database version and throws a DatabaseNotCompatibleException if not
99+
* Throws a DatabaseNotCompatibleException if version compatibility can not be checked.
99100
*
100101
* @param conn Active db connection
101102
*/
102-
public static void failOnVersionCompatibilityCheckFailed( Connection conn )
103+
public static void failOnVersionCompatibilityCheckFailed( Connection conn ) throws DatabaseNotCompatibleException
103104
{
104105
try {
105106
if (!versionCompatibilityCheck(conn))
106-
throw new RuntimeException("API-Version " + UTPLSQL_COMPATIBILITY_VERSION + " not compatible with database. Aborting.");
107+
{
108+
// Try to find out Framework Version
109+
Version v = DBHelper.getDatabaseFrameworkVersion(conn);
110+
111+
throw new DatabaseNotCompatibleException( v.getVersionString() );
112+
}
107113
}
108114
catch ( SQLException e )
109115
{
110-
throw new RuntimeException("Compatibility-check failed with error. Aborting.", e);
116+
throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting.", UTPLSQL_COMPATIBILITY_VERSION, "Unknown", e);
111117
}
112118
}
113119

@@ -120,9 +126,9 @@ public static void failOnVersionCompatibilityCheckFailed( Connection conn )
120126
public static Version getDatabaseFrameworkVersion( Connection conn )
121127
throws SQLException {
122128
Version result = new Version("");
123-
try (Statement stmt = conn.prepareStatement("select ut_runner.version() from dual"))
129+
try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual"))
124130
{
125-
ResultSet rs = stmt.getResultSet();
131+
ResultSet rs = stmt.executeQuery();
126132

127133
if ( rs.next() )
128134
result = new Version(rs.getString(1));

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utplsql.api;
22

3+
import org.utplsql.api.exception.DatabaseNotCompatibleException;
34
import org.utplsql.api.exception.SomeTestsFailedException;
45
import org.utplsql.api.reporter.DocumentationReporter;
56
import org.utplsql.api.reporter.Reporter;
@@ -84,7 +85,7 @@ public TestRunner failOnErrors(boolean failOnErrors) {
8485
return this;
8586
}
8687

87-
public void run(Connection conn) throws SomeTestsFailedException, SQLException {
88+
public void run(Connection conn) throws SomeTestsFailedException, SQLException, DatabaseNotCompatibleException {
8889

8990
// First of all check version compatibility
9091
DBHelper.failOnVersionCompatibilityCheckFailed(conn);

src/main/java/org/utplsql/api/exception/DatabaseNotCompatibleException.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import org.utplsql.api.DBHelper;
44

5+
import java.sql.SQLException;
6+
57
/** Custom exception to indicate API is not compatible with database framework
68
*
79
* @author pesse
810
*
911
*/
10-
public class DatabaseNotCompatibleException extends Exception {
12+
public class DatabaseNotCompatibleException extends SQLException {
1113

1214
private String clientVersion;
1315
private String databaseVersion;
@@ -35,6 +37,11 @@ public DatabaseNotCompatibleException( String databaseVersion, Throwable cause )
3537
this(DBHelper.UTPLSQL_COMPATIBILITY_VERSION, databaseVersion, cause );
3638
}
3739

40+
public DatabaseNotCompatibleException( String databaseVersion )
41+
{
42+
this(DBHelper.UTPLSQL_COMPATIBILITY_VERSION, databaseVersion, null );
43+
}
44+
3845
public String getClientVersion() {
3946
return clientVersion;
4047
}

src/test/java/org/utplsql/api/DBHelperTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,17 @@ public void incompatibleVersion() {
3434
}
3535
}
3636

37+
@Test
38+
public void getFrameworkVersion()
39+
{
40+
try {
41+
Version v = DBHelper.getDatabaseFrameworkVersion(db.newConnection());
42+
Assert.assertEquals(true, v.isValid());
43+
} catch (SQLException e)
44+
{
45+
e.printStackTrace();
46+
Assert.fail();
47+
}
48+
}
49+
3750
}

0 commit comments

Comments
 (0)