Skip to content

Feature/improve exception handling #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ env:
- UTPLSQL_VERSION="v3.0.2"
- UTPLSQL_VERSION="v3.0.3"
- UTPLSQL_VERSION="v3.0.4"
- UTPLSQL_VERSION="v3.1.0"
- UTPLSQL_VERSION="v3.1.1"
- UTPLSQL_VERSION="v3.1.2"
- UTPLSQL_VERSION="develop"
UTPLSQL_FILE="utPLSQL"

Expand Down
6 changes: 0 additions & 6 deletions .travis/install_utplsql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ else
curl -L -O "https://github.com/utPLSQL/utPLSQL/releases/download/$UTPLSQL_VERSION/$UTPLSQL_FILE.tar.gz"
fi

# Download develop branch of utPLSQL.
#UTPLSQL_VERSION="develop"
#UTPLSQL_FILE="utPLSQL"
#git clone -b develop --single-branch https://github.com/utPLSQL/utPLSQL.git
# tar -czf $UTPLSQL_FILE.tar.gz $UTPLSQL_FILE && rm -rf $UTPLSQL_FILE

# Create a temporary install script.
cat > install.sh.tmp <<EOF
tar -xzf ${UTPLSQL_FILE}.tar.gz && rm ${UTPLSQL_FILE}.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.utplsql</groupId>
<artifactId>java-api</artifactId>
<version>3.1.1-SNAPSHOT</version>
<version>3.1.1.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>utPLSQL-java-api</name>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/utplsql/api/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.utplsql.api.exception.UtPLSQLNotInstalledException;

import java.sql.*;
import java.util.Objects;

/**
* Database utility functions.
Expand Down Expand Up @@ -49,7 +50,7 @@ public static String getCurrentSchema(Connection conn) throws SQLException {
* @throws SQLException any database error
*/
public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLException {
assert conn != null;
Objects.requireNonNull(conn);
Version result = new Version("");
try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual"))
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/utplsql/api/JavaApiVersionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private JavaApiVersionInfo() { }

private static final String BUILD_NO = "123";
private static final String MAVEN_PROJECT_NAME = "utPLSQL-java-api";
private static final String MAVEN_PROJECT_VERSION = "3.1.1-SNAPSHOT";
private static final String MAVEN_PROJECT_VERSION = "3.1.1";

public static String getVersion() {
return MAVEN_PROJECT_VERSION + "." + BUILD_NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Objects;

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

public static final String UTPLSQL_API_VERSION = "3.1.0";
private static final String UTPLSQL_API_VERSION = "3.1.1";
public static final String UTPLSQL_COMPATIBILITY_VERSION = "3";

private Version databaseVersion;
Expand Down Expand Up @@ -51,12 +52,19 @@ public CompatibilityProxy( Connection conn, boolean skipCompatibilityCheck ) thr
private void doCompatibilityCheckWithDatabase( Connection conn ) throws SQLException
{
databaseVersion = DBHelper.getDatabaseFrameworkVersion(conn);
Version clientVersion = new Version(UTPLSQL_COMPATIBILITY_VERSION);

if ( databaseVersion == null )
throw new DatabaseNotCompatibleException("Could not get database version", clientVersion, null, null);

if ( databaseVersion.getMajor() == null )
throw new DatabaseNotCompatibleException("Illegal database version: " + databaseVersion.toString(), clientVersion, databaseVersion, null);

if (OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(databaseVersion)) {
try {
compatible = versionCompatibilityCheck(conn, UTPLSQL_COMPATIBILITY_VERSION, null);
} catch (SQLException e) {
throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), new Version(UTPLSQL_COMPATIBILITY_VERSION), new Version("Unknown"), e);
throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), clientVersion, new Version("Unknown"), e);
}
} else
compatible = versionCompatibilityCheckPre303(UTPLSQL_COMPATIBILITY_VERSION);
Expand Down Expand Up @@ -105,9 +113,13 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
*/
private boolean versionCompatibilityCheckPre303(String requested )
{
Version requesteVersion = new Version(requested);
Version requestedVersion = new Version(requested);

if (databaseVersion.getMajor().equals(requesteVersion.getMajor()) && (requesteVersion.getMinor() == null || requesteVersion.getMinor().equals(databaseVersion.getMinor())) )
Objects.requireNonNull(databaseVersion.getMajor(), "Illegal database Version: " + databaseVersion.toString());
if (
databaseVersion.getMajor().equals(requestedVersion.getMajor())
&& (requestedVersion.getMinor() == null
|| requestedVersion.getMinor().equals(databaseVersion.getMinor())) )
return true;
else
return false;
Expand Down
1 change: 0 additions & 1 deletion src/test/java/org/utplsql/api/CompatibilityIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public void skipCompatibilityCheck() throws SQLException {
CompatibilityProxy proxy = new CompatibilityProxy(getConnection(), true);
proxy.failOnNotCompatible();
assertEquals(true, proxy.isCompatible());
assertEquals(CompatibilityProxy.UTPLSQL_API_VERSION, proxy.getDatabaseVersion().toString());

}
}
5 changes: 3 additions & 2 deletions src/test/java/org/utplsql/api/DBHelperIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

import java.sql.SQLException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class DBHelperIT extends AbstractDatabaseTest {

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

@Test
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/utplsql/api/VersionObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public void versionPatternRecognitionFull() {
assertEquals("3.1.3.1234", v.getNormalizedString());
}

@Test
public void versionPatternRecognitionDevelop() {
Version v = new Version("v3.1.3.2140-develop");

assertEquals(3, (long)v.getMajor());
assertEquals(1, (long)v.getMinor());
assertEquals(3, (long)v.getBugfix());
assertEquals(2140, (long)v.getBuild());
assertTrue(v.isValid());
assertEquals("3.1.3.2140", v.getNormalizedString());
}

@Test
public void versionPatternRecognitionPartial() {
Version v = new Version("3.1.etc");
Expand Down