← 返回首页
Refactoring and changing DatabaseNotCompatibleException · utPLSQL/utPLSQL-java-api@ec81b5b · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Commit ec81b5b

Browse files
authored andcommitted
Refactoring and changing DatabaseNotCompatibleException
- TestRunnerStatement-Implementations are now hidden from public - DatabaseNotCompatibleException now uses Version-objects instead of strings - Version now contains a getNormalizedVersion()-method and it's toString()-method returns the original version string
1 parent 6b4d2af commit ec81b5b

10 files changed

Lines changed: 60 additions & 37 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ public static void failOnVersionCompatibilityCheckFailed( Connection conn ) thro
108108
// Try to find out Framework Version
109109
Version v = DBHelper.getDatabaseFrameworkVersion(conn);
110110

111-
throw new DatabaseNotCompatibleException( v.getVersionString() );
111+
throw new DatabaseNotCompatibleException( v );
112112
}
113113
}
114114
catch ( SQLException e )
115115
{
116-
throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), UTPLSQL_COMPATIBILITY_VERSION, "Unknown", e);
116+
throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), new Version(UTPLSQL_COMPATIBILITY_VERSION), new Version("Unknown"), e);
117117
}
118118
}
119119

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.utplsql.api.exception.SomeTestsFailedException;
77
import org.utplsql.api.reporter.DocumentationReporter;
88
import org.utplsql.api.reporter.Reporter;
9-
import org.utplsql.api.testRunner.AbstractTestRunnerStatement;
109
import org.utplsql.api.testRunner.TestRunnerStatement;
1110

1211
import java.sql.CallableStatement;

‎src/main/java/org/utplsql/api/Version.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ private void parseVersionString()
4848
}
4949
}
5050

51-
public String getOrigString() {
51+
@Override
52+
public String toString() {
5253
return origString;
5354
}
5455

@@ -76,7 +77,7 @@ public boolean isValid() {
7677
*
7778
* @return
7879
*/
79-
public String getVersionString()
80+
public String getNormalizedString()
8081
{
8182
if ( isValid() ) {
8283
StringBuilder sb = new StringBuilder();

‎src/main/java/org/utplsql/api/compatibility/CompatibilityProvider.java‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
import org.utplsql.api.DBHelper;
44
import org.utplsql.api.TestRunnerOptions;
5-
import org.utplsql.api.Version;
6-
import org.utplsql.api.testRunner.AbstractTestRunnerStatement;
7-
import org.utplsql.api.testRunner.Pre303TestRunnerStatement;
8-
import org.utplsql.api.testRunner.ActualTestRunnerStatement;
9-
import org.utplsql.api.testRunner.TestRunnerStatement;
5+
import org.utplsql.api.testRunner.*;
106

117
import java.sql.Connection;
128
import java.sql.SQLException;
@@ -22,15 +18,6 @@ public class CompatibilityProvider {
2218

2319
public static TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException
2420
{
25-
Version version = DBHelper.getDatabaseFrameworkVersion(conn);
26-
27-
AbstractTestRunnerStatement stmt = null;
28-
29-
if ( version.getMajor() == 3 && version.getMinor() == 0 && version.getBugfix() <= 2 )
30-
stmt = new Pre303TestRunnerStatement(options, conn);
31-
else
32-
stmt = new ActualTestRunnerStatement(options, conn);
33-
34-
return stmt;
21+
return TestRunnerStatementProvider.getCompatibleTestRunnerStatement(DBHelper.getDatabaseFrameworkVersion(conn), options, conn);
3522
}
3623
}

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

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

33
import org.utplsql.api.DBHelper;
4+
import org.utplsql.api.Version;
45

56
import java.sql.SQLException;
67

@@ -11,42 +12,42 @@
1112
*/
1213
public class DatabaseNotCompatibleException extends SQLException {
1314

14-
private String clientVersion;
15-
private String databaseVersion;
15+
private Version clientVersion;
16+
private Version databaseVersion;
1617

17-
public DatabaseNotCompatibleException( String message, String clientVersion, String databaseVersion, Throwable cause )
18+
public DatabaseNotCompatibleException( String message, Version clientVersion, Version databaseVersion, Throwable cause )
1819
{
1920
super(message, cause);
2021

2122
this.clientVersion = clientVersion;
2223
this.databaseVersion = databaseVersion;
2324
}
2425

25-
public DatabaseNotCompatibleException( String clientVersion, String databaseVersion, Throwable cause )
26+
public DatabaseNotCompatibleException( Version clientVersion, Version databaseVersion, Throwable cause )
2627
{
2728
this("utPLSQL API (" + String.valueOf(clientVersion) + ") not compatible with database (" + String.valueOf(databaseVersion) + ")", clientVersion, databaseVersion, cause);
2829
}
2930

30-
public DatabaseNotCompatibleException( String clientVersion, String databaseVersion )
31+
public DatabaseNotCompatibleException( Version clientVersion, Version databaseVersion )
3132
{
3233
this(clientVersion, databaseVersion, null);
3334
}
3435

35-
public DatabaseNotCompatibleException( String databaseVersion, Throwable cause )
36+
public DatabaseNotCompatibleException( Version databaseVersion, Throwable cause )
3637
{
37-
this(DBHelper.UTPLSQL_COMPATIBILITY_VERSION, databaseVersion, cause );
38+
this(new Version(DBHelper.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, cause );
3839
}
3940

40-
public DatabaseNotCompatibleException( String databaseVersion )
41+
public DatabaseNotCompatibleException( Version databaseVersion )
4142
{
42-
this(DBHelper.UTPLSQL_COMPATIBILITY_VERSION, databaseVersion, null );
43+
this(new Version(DBHelper.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, null );
4344
}
4445

45-
public String getClientVersion() {
46+
public Version getClientVersion() {
4647
return clientVersion;
4748
}
4849

49-
public String getDatabaseVersion()
50+
public Version getDatabaseVersion()
5051
{
5152
return databaseVersion;
5253
}

‎src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @author pesse
1717
*/
18-
public abstract class AbstractTestRunnerStatement implements TestRunnerStatement {
18+
abstract class AbstractTestRunnerStatement implements TestRunnerStatement {
1919

2020
protected TestRunnerOptions options;
2121
protected Connection conn;

‎src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @author pesse
1212
*/
13-
public class ActualTestRunnerStatement extends AbstractTestRunnerStatement {
13+
class ActualTestRunnerStatement extends AbstractTestRunnerStatement {
1414

1515
public ActualTestRunnerStatement(TestRunnerOptions options, Connection connection ) throws SQLException {
1616
super( options, connection);

‎src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @author pesse
1212
*/
13-
public class Pre303TestRunnerStatement extends AbstractTestRunnerStatement {
13+
class Pre303TestRunnerStatement extends AbstractTestRunnerStatement {
1414

1515
public Pre303TestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException {
1616
super(options, conn);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.utplsql.api.testRunner;
2+
3+
import org.utplsql.api.DBHelper;
4+
import org.utplsql.api.TestRunnerOptions;
5+
import org.utplsql.api.Version;
6+
7+
import java.sql.Connection;
8+
import java.sql.SQLException;
9+
10+
/** Provides different implementations of TestRunnerStatement based on the version of the database framework
11+
*
12+
* @author pesse
13+
*/
14+
public class TestRunnerStatementProvider {
15+
16+
/** Returns the TestRunnerStatement-implementation compatible with the given databaseVersion.
17+
*
18+
* @param databaseVersion Version of the database framework
19+
* @param options TestRunnerOptions to be used
20+
* @param conn Active Connection
21+
* @return TestRunnerStatment compatible with the database framework
22+
* @throws SQLException
23+
*/
24+
public static TestRunnerStatement getCompatibleTestRunnerStatement(Version databaseVersion, TestRunnerOptions options, Connection conn ) throws SQLException
25+
{
26+
AbstractTestRunnerStatement stmt = null;
27+
28+
if ( databaseVersion.getMajor() == 3 && databaseVersion.getMinor() == 0 && databaseVersion.getBugfix() <= 2 )
29+
stmt = new Pre303TestRunnerStatement(options, conn);
30+
else
31+
stmt = new ActualTestRunnerStatement(options, conn);
32+
33+
return stmt;
34+
}
35+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void versionPatternRecognitionFull() {
1414
Assert.assertEquals(3, (long)v.getBugfix());
1515
Assert.assertEquals(1234, (long)v.getBuild());
1616
Assert.assertEquals(true, v.isValid());
17-
Assert.assertEquals("3.1.3.1234", v.getVersionString());
17+
Assert.assertEquals("3.1.3.1234", v.getNormalizedString());
1818
}
1919

2020
@Test
@@ -26,7 +26,7 @@ public void versionPatternRecognitionPartial() {
2626
Assert.assertNull(v.getBugfix());
2727
Assert.assertNull(v.getBuild());
2828
Assert.assertEquals(true, v.isValid());
29-
Assert.assertEquals("3.1", v.getVersionString());
29+
Assert.assertEquals("3.1", v.getNormalizedString());
3030
}
3131

3232
@Test
@@ -38,6 +38,6 @@ public void versionPatternRecognitionInvalid() {
3838
Assert.assertNull(v.getBugfix());
3939
Assert.assertNull(v.getBuild());
4040
Assert.assertEquals(false, v.isValid());
41-
Assert.assertEquals("invalid", v.getVersionString());
41+
Assert.assertEquals("invalid", v.getNormalizedString());
4242
}
4343
}

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.