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

Skip to content

Commit f566ffe

Browse files
committed
Improve exception handling
Try to narrow down some edge cases during getting database version. Some refactoring, too
1 parent c007ca9 commit f566ffe

5 files changed

Lines changed: 20 additions & 8 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.utplsql</groupId>
66
<artifactId>java-api</artifactId>
7-
<version>3.1.1-SNAPSHOT</version>
7+
<version>3.1.1.1-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>utPLSQL-java-api</name>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
55

66
import java.sql.*;
7+
import java.util.Objects;
78

89
/**
910
* Database utility functions.
@@ -49,7 +50,7 @@ public static String getCurrentSchema(Connection conn) throws SQLException {
4950
* @throws SQLException any database error
5051
*/
5152
public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLException {
52-
assert conn != null;
53+
Objects.requireNonNull(conn);
5354
Version result = new Version("");
5455
try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual"))
5556
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ private JavaApiVersionInfo() { }
1111

1212
private static final String BUILD_NO = "123";
1313
private static final String MAVEN_PROJECT_NAME = "utPLSQL-java-api";
14-
private static final String MAVEN_PROJECT_VERSION = "3.1.1-SNAPSHOT";
14+
private static final String MAVEN_PROJECT_VERSION = "3.1.1";
1515

1616
public static String getVersion() {
1717
return MAVEN_PROJECT_VERSION + "." + BUILD_NO;

src/main/java/org/utplsql/api/compatibility/CompatibilityProxy.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.sql.Connection;
1515
import java.sql.SQLException;
1616
import java.sql.Types;
17+
import java.util.Objects;
1718

1819
/** Class to check compatibility with database framework and also to give several specific implementations depending
1920
* on the version of the connected framework.
@@ -23,7 +24,7 @@
2324
*/
2425
public class CompatibilityProxy {
2526

26-
public static final String UTPLSQL_API_VERSION = "3.1.0";
27+
private static final String UTPLSQL_API_VERSION = "3.1.1";
2728
public static final String UTPLSQL_COMPATIBILITY_VERSION = "3";
2829

2930
private Version databaseVersion;
@@ -51,12 +52,19 @@ public CompatibilityProxy( Connection conn, boolean skipCompatibilityCheck ) thr
5152
private void doCompatibilityCheckWithDatabase( Connection conn ) throws SQLException
5253
{
5354
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);
5462

5563
if (OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(databaseVersion)) {
5664
try {
5765
compatible = versionCompatibilityCheck(conn, UTPLSQL_COMPATIBILITY_VERSION, null);
5866
} 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);
6068
}
6169
} else
6270
compatible = versionCompatibilityCheckPre303(UTPLSQL_COMPATIBILITY_VERSION);
@@ -105,9 +113,13 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
105113
*/
106114
private boolean versionCompatibilityCheckPre303(String requested )
107115
{
108-
Version requesteVersion = new Version(requested);
116+
Version requestedVersion = new Version(requested);
109117

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())) )
111123
return true;
112124
else
113125
return false;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public void skipCompatibilityCheck() throws SQLException {
2222
CompatibilityProxy proxy = new CompatibilityProxy(getConnection(), true);
2323
proxy.failOnNotCompatible();
2424
assertEquals(true, proxy.isCompatible());
25-
assertEquals(CompatibilityProxy.UTPLSQL_API_VERSION, proxy.getDatabaseVersion().toString());
2625

2726
}
2827
}

0 commit comments

Comments
 (0)