1111import org .utplsql .api .testRunner .TestRunnerStatement ;
1212import org .utplsql .api .testRunner .TestRunnerStatementProvider ;
1313
14+ import javax .annotation .Nullable ;
1415import java .sql .Connection ;
1516import java .sql .SQLException ;
1617import java .util .Objects ;
@@ -26,28 +27,31 @@ public class CompatibilityProxy {
2627
2728 public static final String UTPLSQL_COMPATIBILITY_VERSION = "3" ;
2829 private final DatabaseInformation databaseInformation ;
29- private Version databaseVersion ;
30+ private Version utPlsqlVersion ;
31+ private Version realDbPlsqlVersion ;
3032 private boolean compatible = false ;
3133
3234 public CompatibilityProxy (Connection conn ) throws SQLException {
33- this (conn , false , null );
35+ this (conn , null , null );
3436 }
3537
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 );
3840 }
3941
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 );
4244 }
4345
44- public CompatibilityProxy (Connection conn , boolean skipCompatibilityCheck , DatabaseInformation databaseInformation ) throws SQLException {
46+ public CompatibilityProxy (Connection conn , @ Nullable Version assumedUtPlsqlVersion , @ Nullable DatabaseInformation databaseInformation ) throws SQLException {
4547 this .databaseInformation = (databaseInformation != null )
4648 ? databaseInformation
4749 : new DefaultDatabaseInformation ();
4850
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 );
5155 } else {
5256 doCompatibilityCheckWithDatabase (conn );
5357 }
@@ -61,18 +65,18 @@ public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck, Datab
6165 * @throws SQLException
6266 */
6367 private void doCompatibilityCheckWithDatabase (Connection conn ) throws SQLException {
64- databaseVersion = databaseInformation . getUtPlsqlFrameworkVersion ( conn ) ;
68+ utPlsqlVersion = realDbPlsqlVersion ;
6569 Version clientVersion = Version .create (UTPLSQL_COMPATIBILITY_VERSION );
6670
67- if (databaseVersion == null ) {
71+ if (utPlsqlVersion == null ) {
6872 throw new DatabaseNotCompatibleException ("Could not get database version" , clientVersion , null , null );
6973 }
7074
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 );
7377 }
7478
75- if (OptionalFeatures .FRAMEWORK_COMPATIBILITY_CHECK .isAvailableFor (databaseVersion )) {
79+ if (OptionalFeatures .FRAMEWORK_COMPATIBILITY_CHECK .isAvailableFor (utPlsqlVersion )) {
7680 try {
7781 compatible = versionCompatibilityCheck (conn , UTPLSQL_COMPATIBILITY_VERSION , null );
7882 } catch (SQLException e ) {
@@ -83,14 +87,6 @@ private void doCompatibilityCheckWithDatabase(Connection conn) throws SQLExcepti
8387 }
8488 }
8589
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-
9490 /**
9591 * Check the utPLSQL version compatibility.
9692 *
@@ -120,10 +116,10 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
120116 private boolean versionCompatibilityCheckPre303 (String requested ) {
121117 Version requestedVersion = Version .create (requested );
122118
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 ())
125121 && (requestedVersion .getMinor () == null
126- || requestedVersion .getMinor ().equals (databaseVersion .getMinor ()));
122+ || requestedVersion .getMinor ().equals (utPlsqlVersion .getMinor ()));
127123 }
128124
129125 /**
@@ -132,18 +128,23 @@ private boolean versionCompatibilityCheckPre303(String requested) {
132128 */
133129 public void failOnNotCompatible () throws DatabaseNotCompatibleException {
134130 if (!isCompatible ()) {
135- throw new DatabaseNotCompatibleException (databaseVersion );
131+ throw new DatabaseNotCompatibleException (utPlsqlVersion );
136132 }
137133 }
138134
139135 public boolean isCompatible () {
140136 return compatible ;
141137 }
142138
143- public Version getDatabaseVersion () {
144- return databaseVersion ;
139+ @ Deprecated
140+ public Version getDatabaseVersion () { return utPlsqlVersion ; }
141+
142+ public Version getUtPlsqlVersion () {
143+ return utPlsqlVersion ;
145144 }
146145
146+ public Version getRealDbPlsqlVersion () { return realDbPlsqlVersion ; }
147+
147148 /**
148149 * Returns a TestRunnerStatement compatible with the current framework
149150 *
@@ -153,7 +154,7 @@ public Version getDatabaseVersion() {
153154 * @throws SQLException
154155 */
155156 public TestRunnerStatement getTestRunnerStatement (TestRunnerOptions options , Connection conn ) throws SQLException {
156- return TestRunnerStatementProvider .getCompatibleTestRunnerStatement (databaseVersion , options , conn );
157+ return TestRunnerStatementProvider .getCompatibleTestRunnerStatement (utPlsqlVersion , options , conn );
157158 }
158159
159160 /**
@@ -165,6 +166,6 @@ public TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Con
165166 * @throws SQLException
166167 */
167168 public OutputBuffer getOutputBuffer (Reporter reporter , Connection conn ) throws SQLException {
168- return OutputBufferProvider .getCompatibleOutputBuffer (databaseVersion , reporter , conn );
169+ return OutputBufferProvider .getCompatibleOutputBuffer (utPlsqlVersion , reporter , conn );
169170 }
170171}
0 commit comments