Skip to content

Commit a67ace4

Browse files
pesseSamuel Nitsche
authored andcommitted
Introducing optional features
for better Compatibility tracking
1 parent 4fca40a commit a67ace4

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private void doCompatibilityCheckWithDatabase( Connection conn ) throws SQLExcep
4949
{
5050
databaseVersion = DBHelper.getDatabaseFrameworkVersion(conn);
5151

52-
if (frameworkHasCompatibilityCheck()) {
52+
if (OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(databaseVersion)) {
5353
try {
5454
compatible = versionCompatibilityCheck(conn, UTPLSQL_COMPATIBILITY_VERSION, null);
5555
} catch (SQLException e) {
@@ -115,18 +115,6 @@ private boolean versionCompatibilityCheckPre303( String requested )
115115
return false;
116116
}
117117

118-
/** Checks if framework has the compatibility check, which is since 3.0.3
119-
*
120-
* @return Whether framework is >= 3.0.3 or not
121-
*/
122-
private boolean frameworkHasCompatibilityCheck()
123-
{
124-
if ( databaseVersion.getMajor() >= 3 && databaseVersion.getMinor() >= 0 && databaseVersion.getBugfix() >= 3 ) // Compatibility check is included since 3.0.3
125-
return true;
126-
else
127-
return false;
128-
}
129-
130118
/** Checks if actual API-version is compatible with utPLSQL database version and throws a DatabaseNotCompatibleException if not
131119
* Throws a DatabaseNotCompatibleException if version compatibility can not be checked.
132120
*
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.utplsql.api.compatibility;
2+
3+
import org.utplsql.api.Version;
4+
import org.utplsql.api.exception.InvalidVersionException;
5+
6+
public enum OptionalFeatures {
7+
8+
FAIL_ON_ERROR("3.0.3", null),
9+
FRAMEWORK_COMPATIBILITY_CHECK("3.0.3", null);
10+
11+
private Version minVersion;
12+
private Version maxVersion;
13+
14+
OptionalFeatures( String minVersion, String maxVersion )
15+
{
16+
if ( minVersion != null )
17+
this.minVersion = new Version(minVersion);
18+
if ( maxVersion != null)
19+
this.maxVersion = new Version(maxVersion);
20+
}
21+
22+
public boolean isAvailableFor(Version version ) {
23+
24+
try {
25+
if ((minVersion == null || version.isGreaterOrEqualThan(minVersion)) &&
26+
(maxVersion == null || maxVersion.isGreaterOrEqualThan(version))
27+
)
28+
return true;
29+
else
30+
return false;
31+
} catch ( InvalidVersionException e ) {
32+
return false; // We have no optional features for invalid versions
33+
}
34+
}
35+
}

src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.utplsql.api.DBHelper;
44
import org.utplsql.api.TestRunnerOptions;
55
import org.utplsql.api.Version;
6+
import org.utplsql.api.compatibility.OptionalFeatures;
7+
import org.utplsql.api.exception.InvalidVersionException;
68

79
import java.sql.Connection;
810
import java.sql.SQLException;
@@ -21,13 +23,16 @@ public class TestRunnerStatementProvider {
2123
* @return TestRunnerStatment compatible with the database framework
2224
* @throws SQLException
2325
*/
24-
public static TestRunnerStatement getCompatibleTestRunnerStatement(Version databaseVersion, TestRunnerOptions options, Connection conn ) throws SQLException
25-
{
26+
public static TestRunnerStatement getCompatibleTestRunnerStatement(Version databaseVersion, TestRunnerOptions options, Connection conn ) throws SQLException {
2627
AbstractTestRunnerStatement stmt = null;
2728

28-
if ( databaseVersion.getMajor() == 3 && databaseVersion.getMinor() == 0 && databaseVersion.getBugfix() <= 2 )
29-
stmt = new Pre303TestRunnerStatement(options, conn);
30-
else
29+
try {
30+
if (new Version("3.0.2").isGreaterOrEqualThan(databaseVersion))
31+
stmt = new Pre303TestRunnerStatement(options, conn);
32+
33+
} catch ( InvalidVersionException e ) {}
34+
35+
if ( stmt == null )
3136
stmt = new ActualTestRunnerStatement(options, conn);
3237

3338
return stmt;

0 commit comments

Comments
 (0)