Skip to content

Commit 9fd066f

Browse files
authored
Merge pull request #62 from utPLSQL/feature/improve_exception_handling
Feature/improve exception handling
2 parents c007ca9 + 248a9bb commit 9fd066f

File tree

9 files changed

+36
-17
lines changed

9 files changed

+36
-17
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ env:
2727
- UTPLSQL_VERSION="v3.0.2"
2828
- UTPLSQL_VERSION="v3.0.3"
2929
- UTPLSQL_VERSION="v3.0.4"
30-
- UTPLSQL_VERSION="v3.1.0"
3130
- UTPLSQL_VERSION="v3.1.1"
31+
- UTPLSQL_VERSION="v3.1.2"
3232
- UTPLSQL_VERSION="develop"
3333
UTPLSQL_FILE="utPLSQL"
3434

.travis/install_utplsql.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ else
1111
curl -L -O "https://github.com/utPLSQL/utPLSQL/releases/download/$UTPLSQL_VERSION/$UTPLSQL_FILE.tar.gz"
1212
fi
1313

14-
# Download develop branch of utPLSQL.
15-
#UTPLSQL_VERSION="develop"
16-
#UTPLSQL_FILE="utPLSQL"
17-
#git clone -b develop --single-branch https://github.com/utPLSQL/utPLSQL.git
18-
# tar -czf $UTPLSQL_FILE.tar.gz $UTPLSQL_FILE && rm -rf $UTPLSQL_FILE
19-
2014
# Create a temporary install script.
2115
cat > install.sh.tmp <<EOF
2216
tar -xzf ${UTPLSQL_FILE}.tar.gz && rm ${UTPLSQL_FILE}.tar.gz

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
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
import java.sql.SQLException;
66

7-
import static org.junit.jupiter.api.Assertions.assertEquals;
87
import static org.junit.jupiter.api.Assertions.assertNotNull;
8+
import static org.junit.jupiter.api.Assertions.assertTrue;
99

1010
public class DBHelperIT extends AbstractDatabaseTest {
1111

1212
@Test
1313
public void getFrameworkVersion() throws SQLException {
1414
Version v = DBHelper.getDatabaseFrameworkVersion(getConnection());
15-
assertEquals(true, v.isValid());
15+
assertTrue(v.isValid());
16+
System.out.println(v.getNormalizedString() + " - " + v.toString());
1617
}
1718

1819
@Test

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ public void versionPatternRecognitionFull() {
1919
assertEquals("3.1.3.1234", v.getNormalizedString());
2020
}
2121

22+
@Test
23+
public void versionPatternRecognitionDevelop() {
24+
Version v = new Version("v3.1.3.2140-develop");
25+
26+
assertEquals(3, (long)v.getMajor());
27+
assertEquals(1, (long)v.getMinor());
28+
assertEquals(3, (long)v.getBugfix());
29+
assertEquals(2140, (long)v.getBuild());
30+
assertTrue(v.isValid());
31+
assertEquals("3.1.3.2140", v.getNormalizedString());
32+
}
33+
2234
@Test
2335
public void versionPatternRecognitionPartial() {
2436
Version v = new Version("3.1.etc");

0 commit comments

Comments
 (0)