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 ;
25
26
public class CompatibilityProxy {
26
27
27
28
public static final String UTPLSQL_COMPATIBILITY_VERSION = "3" ;
28
- private static final String UTPLSQL_API_VERSION = "3.1.1" ;
29
29
private final DatabaseInformation databaseInformation ;
30
- private Version databaseVersion ;
30
+ private Version utPlsqlVersion ;
31
+ private Version realDbPlsqlVersion ;
31
32
private boolean compatible = false ;
32
33
33
34
public CompatibilityProxy (Connection conn ) throws SQLException {
34
- this (conn , false , null );
35
+ this (conn , null , null );
35
36
}
36
37
37
- public CompatibilityProxy (Connection conn , DatabaseInformation databaseInformation ) throws SQLException {
38
- this (conn , false , databaseInformation );
38
+ @ Deprecated
39
+ public CompatibilityProxy (Connection conn , boolean skipCompatibilityCheck ) throws SQLException {
40
+ this (conn , skipCompatibilityCheck , null );
39
41
}
40
42
41
- public CompatibilityProxy (Connection conn , boolean skipCompatibilityCheck ) throws SQLException {
42
- this (conn , skipCompatibilityCheck , null );
43
+ @ Deprecated
44
+ public CompatibilityProxy (Connection conn , boolean skipCompatibilityCheck , @ Nullable DatabaseInformation databaseInformation ) throws SQLException {
45
+ this (conn , skipCompatibilityCheck ? Version .LATEST : null , databaseInformation );
46
+ }
47
+
48
+ public CompatibilityProxy (Connection conn , @ Nullable DatabaseInformation databaseInformation ) throws SQLException {
49
+ this (conn , null , databaseInformation );
43
50
}
44
51
45
- public CompatibilityProxy (Connection conn , boolean skipCompatibilityCheck , DatabaseInformation databaseInformation ) throws SQLException {
52
+ public CompatibilityProxy (Connection conn , @ Nullable Version assumedUtPlsVersion ) throws SQLException {
53
+ this (conn , assumedUtPlsVersion , null );
54
+ }
55
+
56
+ public CompatibilityProxy (Connection conn , @ Nullable Version assumedUtPlsqlVersion , @ Nullable DatabaseInformation databaseInformation ) throws SQLException {
46
57
this .databaseInformation = (databaseInformation != null )
47
58
? databaseInformation
48
59
: new DefaultDatabaseInformation ();
49
60
50
- if (skipCompatibilityCheck ) {
51
- doExpectCompatibility ();
61
+ realDbPlsqlVersion = this .databaseInformation .getUtPlsqlFrameworkVersion (conn );
62
+ if ( assumedUtPlsqlVersion != null ) {
63
+ utPlsqlVersion = assumedUtPlsqlVersion ;
64
+ compatible = utPlsqlVersion .getNormalizedString ().startsWith (UTPLSQL_COMPATIBILITY_VERSION );
52
65
} else {
53
66
doCompatibilityCheckWithDatabase (conn );
54
67
}
@@ -62,18 +75,18 @@ public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck, Datab
62
75
* @throws SQLException
63
76
*/
64
77
private void doCompatibilityCheckWithDatabase (Connection conn ) throws SQLException {
65
- databaseVersion = databaseInformation . getUtPlsqlFrameworkVersion ( conn ) ;
78
+ utPlsqlVersion = realDbPlsqlVersion ;
66
79
Version clientVersion = Version .create (UTPLSQL_COMPATIBILITY_VERSION );
67
80
68
- if (databaseVersion == null ) {
81
+ if (utPlsqlVersion == null ) {
69
82
throw new DatabaseNotCompatibleException ("Could not get database version" , clientVersion , null , null );
70
83
}
71
84
72
- if (databaseVersion .getMajor () == null ) {
73
- throw new DatabaseNotCompatibleException ("Illegal database version: " + databaseVersion .toString (), clientVersion , databaseVersion , null );
85
+ if (utPlsqlVersion .getMajor () == null ) {
86
+ throw new DatabaseNotCompatibleException ("Illegal database version: " + utPlsqlVersion .toString (), clientVersion , utPlsqlVersion , null );
74
87
}
75
88
76
- if (OptionalFeatures .FRAMEWORK_COMPATIBILITY_CHECK .isAvailableFor (databaseVersion )) {
89
+ if (OptionalFeatures .FRAMEWORK_COMPATIBILITY_CHECK .isAvailableFor (utPlsqlVersion )) {
77
90
try {
78
91
compatible = versionCompatibilityCheck (conn , UTPLSQL_COMPATIBILITY_VERSION , null );
79
92
} catch (SQLException e ) {
@@ -84,14 +97,6 @@ private void doCompatibilityCheckWithDatabase(Connection conn) throws SQLExcepti
84
97
}
85
98
}
86
99
87
- /**
88
- * Just prepare the proxy to expect compatibility, expecting the database framework to be the same version as the API
89
- */
90
- private void doExpectCompatibility () {
91
- databaseVersion = Version .create (UTPLSQL_API_VERSION );
92
- compatible = true ;
93
- }
94
-
95
100
/**
96
101
* Check the utPLSQL version compatibility.
97
102
*
@@ -121,10 +126,10 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
121
126
private boolean versionCompatibilityCheckPre303 (String requested ) {
122
127
Version requestedVersion = Version .create (requested );
123
128
124
- Objects .requireNonNull (databaseVersion .getMajor (), "Illegal database Version: " + databaseVersion .toString ());
125
- return databaseVersion .getMajor ().equals (requestedVersion .getMajor ())
129
+ Objects .requireNonNull (utPlsqlVersion .getMajor (), "Illegal database Version: " + utPlsqlVersion .toString ());
130
+ return utPlsqlVersion .getMajor ().equals (requestedVersion .getMajor ())
126
131
&& (requestedVersion .getMinor () == null
127
- || requestedVersion .getMinor ().equals (databaseVersion .getMinor ()));
132
+ || requestedVersion .getMinor ().equals (utPlsqlVersion .getMinor ()));
128
133
}
129
134
130
135
/**
@@ -133,16 +138,29 @@ private boolean versionCompatibilityCheckPre303(String requested) {
133
138
*/
134
139
public void failOnNotCompatible () throws DatabaseNotCompatibleException {
135
140
if (!isCompatible ()) {
136
- throw new DatabaseNotCompatibleException (databaseVersion );
141
+ throw new DatabaseNotCompatibleException (utPlsqlVersion );
137
142
}
138
143
}
139
144
140
145
public boolean isCompatible () {
141
146
return compatible ;
142
147
}
143
148
144
- public Version getDatabaseVersion () {
145
- return databaseVersion ;
149
+ @ Deprecated
150
+ public Version getDatabaseVersion () { return utPlsqlVersion ; }
151
+
152
+ public Version getUtPlsqlVersion () {
153
+ return utPlsqlVersion ;
154
+ }
155
+
156
+ public Version getRealDbPlsqlVersion () { return realDbPlsqlVersion ; }
157
+
158
+ public String getVersionDescription () {
159
+ if ( utPlsqlVersion != realDbPlsqlVersion ) {
160
+ return realDbPlsqlVersion .toString () + " (Assumed: " + utPlsqlVersion .toString () + ")" ;
161
+ } else {
162
+ return utPlsqlVersion .toString ();
163
+ }
146
164
}
147
165
148
166
/**
@@ -154,7 +172,7 @@ public Version getDatabaseVersion() {
154
172
* @throws SQLException
155
173
*/
156
174
public TestRunnerStatement getTestRunnerStatement (TestRunnerOptions options , Connection conn ) throws SQLException {
157
- return TestRunnerStatementProvider .getCompatibleTestRunnerStatement (databaseVersion , options , conn );
175
+ return TestRunnerStatementProvider .getCompatibleTestRunnerStatement (utPlsqlVersion , options , conn );
158
176
}
159
177
160
178
/**
@@ -166,6 +184,6 @@ public TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Con
166
184
* @throws SQLException
167
185
*/
168
186
public OutputBuffer getOutputBuffer (Reporter reporter , Connection conn ) throws SQLException {
169
- return OutputBufferProvider .getCompatibleOutputBuffer (databaseVersion , reporter , conn );
187
+ return OutputBufferProvider .getCompatibleOutputBuffer (utPlsqlVersion , reporter , conn );
170
188
}
171
189
}
0 commit comments