11
11
import org .utplsql .api .testRunner .TestRunnerStatement ;
12
12
import org .utplsql .api .testRunner .TestRunnerStatementProvider ;
13
13
14
+ import javax .annotation .Nullable ;
14
15
import java .sql .Connection ;
15
16
import java .sql .SQLException ;
16
17
import java .util .Objects ;
@@ -26,28 +27,31 @@ public class CompatibilityProxy {
26
27
27
28
public static final String UTPLSQL_COMPATIBILITY_VERSION = "3" ;
28
29
private final DatabaseInformation databaseInformation ;
29
- private Version databaseVersion ;
30
+ private Version utPlsqlVersion ;
31
+ private Version realDbPlsqlVersion ;
30
32
private boolean compatible = false ;
31
33
32
34
public CompatibilityProxy (Connection conn ) throws SQLException {
33
- this (conn , false , null );
35
+ this (conn , null , null );
34
36
}
35
37
36
- public CompatibilityProxy (Connection conn , DatabaseInformation databaseInformation ) throws SQLException {
37
- this (conn , false , databaseInformation );
38
+ public CompatibilityProxy (Connection conn , @ Nullable DatabaseInformation databaseInformation ) throws SQLException {
39
+ this (conn , null , databaseInformation );
38
40
}
39
41
40
- public CompatibilityProxy (Connection conn , boolean skipCompatibilityCheck ) throws SQLException {
41
- this (conn , skipCompatibilityCheck , null );
42
+ public CompatibilityProxy (Connection conn , @ Nullable Version assumedUtPlsVersion ) throws SQLException {
43
+ this (conn , assumedUtPlsVersion , null );
42
44
}
43
45
44
- public CompatibilityProxy (Connection conn , boolean skipCompatibilityCheck , DatabaseInformation databaseInformation ) throws SQLException {
46
+ public CompatibilityProxy (Connection conn , @ Nullable Version assumedUtPlsqlVersion , @ Nullable DatabaseInformation databaseInformation ) throws SQLException {
45
47
this .databaseInformation = (databaseInformation != null )
46
48
? databaseInformation
47
49
: new DefaultDatabaseInformation ();
48
50
49
- if (skipCompatibilityCheck ) {
50
- doExpectCompatibility ();
51
+ realDbPlsqlVersion = this .databaseInformation .getUtPlsqlFrameworkVersion (conn );
52
+ if ( assumedUtPlsqlVersion != null ) {
53
+ utPlsqlVersion = assumedUtPlsqlVersion ;
54
+ compatible = utPlsqlVersion .getNormalizedString ().startsWith (UTPLSQL_COMPATIBILITY_VERSION );
51
55
} else {
52
56
doCompatibilityCheckWithDatabase (conn );
53
57
}
@@ -61,18 +65,18 @@ public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck, Datab
61
65
* @throws SQLException
62
66
*/
63
67
private void doCompatibilityCheckWithDatabase (Connection conn ) throws SQLException {
64
- databaseVersion = databaseInformation . getUtPlsqlFrameworkVersion ( conn ) ;
68
+ utPlsqlVersion = realDbPlsqlVersion ;
65
69
Version clientVersion = Version .create (UTPLSQL_COMPATIBILITY_VERSION );
66
70
67
- if (databaseVersion == null ) {
71
+ if (utPlsqlVersion == null ) {
68
72
throw new DatabaseNotCompatibleException ("Could not get database version" , clientVersion , null , null );
69
73
}
70
74
71
- if (databaseVersion .getMajor () == null ) {
72
- throw new DatabaseNotCompatibleException ("Illegal database version: " + databaseVersion .toString (), clientVersion , databaseVersion , null );
75
+ if (utPlsqlVersion .getMajor () == null ) {
76
+ throw new DatabaseNotCompatibleException ("Illegal database version: " + utPlsqlVersion .toString (), clientVersion , utPlsqlVersion , null );
73
77
}
74
78
75
- if (OptionalFeatures .FRAMEWORK_COMPATIBILITY_CHECK .isAvailableFor (databaseVersion )) {
79
+ if (OptionalFeatures .FRAMEWORK_COMPATIBILITY_CHECK .isAvailableFor (utPlsqlVersion )) {
76
80
try {
77
81
compatible = versionCompatibilityCheck (conn , UTPLSQL_COMPATIBILITY_VERSION , null );
78
82
} catch (SQLException e ) {
@@ -83,14 +87,6 @@ private void doCompatibilityCheckWithDatabase(Connection conn) throws SQLExcepti
83
87
}
84
88
}
85
89
86
- /**
87
- * Just prepare the proxy to expect compatibility, expecting the database framework to be the same version as the API
88
- */
89
- private void doExpectCompatibility () {
90
- databaseVersion = Version .LATEST ;
91
- compatible = true ;
92
- }
93
-
94
90
/**
95
91
* Check the utPLSQL version compatibility.
96
92
*
@@ -120,10 +116,10 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
120
116
private boolean versionCompatibilityCheckPre303 (String requested ) {
121
117
Version requestedVersion = Version .create (requested );
122
118
123
- Objects .requireNonNull (databaseVersion .getMajor (), "Illegal database Version: " + databaseVersion .toString ());
124
- return databaseVersion .getMajor ().equals (requestedVersion .getMajor ())
119
+ Objects .requireNonNull (utPlsqlVersion .getMajor (), "Illegal database Version: " + utPlsqlVersion .toString ());
120
+ return utPlsqlVersion .getMajor ().equals (requestedVersion .getMajor ())
125
121
&& (requestedVersion .getMinor () == null
126
- || requestedVersion .getMinor ().equals (databaseVersion .getMinor ()));
122
+ || requestedVersion .getMinor ().equals (utPlsqlVersion .getMinor ()));
127
123
}
128
124
129
125
/**
@@ -132,18 +128,23 @@ private boolean versionCompatibilityCheckPre303(String requested) {
132
128
*/
133
129
public void failOnNotCompatible () throws DatabaseNotCompatibleException {
134
130
if (!isCompatible ()) {
135
- throw new DatabaseNotCompatibleException (databaseVersion );
131
+ throw new DatabaseNotCompatibleException (utPlsqlVersion );
136
132
}
137
133
}
138
134
139
135
public boolean isCompatible () {
140
136
return compatible ;
141
137
}
142
138
143
- public Version getDatabaseVersion () {
144
- return databaseVersion ;
139
+ @ Deprecated
140
+ public Version getDatabaseVersion () { return utPlsqlVersion ; }
141
+
142
+ public Version getUtPlsqlVersion () {
143
+ return utPlsqlVersion ;
145
144
}
146
145
146
+ public Version getRealDbPlsqlVersion () { return realDbPlsqlVersion ; }
147
+
147
148
/**
148
149
* Returns a TestRunnerStatement compatible with the current framework
149
150
*
@@ -153,7 +154,7 @@ public Version getDatabaseVersion() {
153
154
* @throws SQLException
154
155
*/
155
156
public TestRunnerStatement getTestRunnerStatement (TestRunnerOptions options , Connection conn ) throws SQLException {
156
- return TestRunnerStatementProvider .getCompatibleTestRunnerStatement (databaseVersion , options , conn );
157
+ return TestRunnerStatementProvider .getCompatibleTestRunnerStatement (utPlsqlVersion , options , conn );
157
158
}
158
159
159
160
/**
@@ -165,6 +166,6 @@ public TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Con
165
166
* @throws SQLException
166
167
*/
167
168
public OutputBuffer getOutputBuffer (Reporter reporter , Connection conn ) throws SQLException {
168
- return OutputBufferProvider .getCompatibleOutputBuffer (databaseVersion , reporter , conn );
169
+ return OutputBufferProvider .getCompatibleOutputBuffer (utPlsqlVersion , reporter , conn );
169
170
}
170
171
}
0 commit comments