initial work on DialectVersionDetails.isAfterDatabaseVersion

This commit is contained in:
Steve Ebersole 2021-12-02 21:36:52 -06:00
parent 1c96f30edb
commit c190d37a57
2 changed files with 76 additions and 46 deletions

View File

@ -13,11 +13,7 @@ package org.hibernate.engine.jdbc.dialect.spi;
* The information here mimics part of the JDBC {@link java.sql.DatabaseMetaData} contract, specifically the portions * The information here mimics part of the JDBC {@link java.sql.DatabaseMetaData} contract, specifically the portions
* about database and driver names and versions. * about database and driver names and versions.
*/ */
public interface DialectResolutionInfo { public interface DialectResolutionInfo extends DialectVersionDetails {
/**
* Constant used to indicate that no version is defined
*/
int NO_VERSION = -9999;
/** /**
* Obtain access to the database name, as returned from {@link java.sql.DatabaseMetaData#getDatabaseProductName()} * Obtain access to the database name, as returned from {@link java.sql.DatabaseMetaData#getDatabaseProductName()}
@ -39,26 +35,6 @@ public interface DialectResolutionInfo {
*/ */
String getDatabaseVersion(); String getDatabaseVersion();
/**
* Obtain access to the database major version, as returned from
* {@link java.sql.DatabaseMetaData#getDatabaseMajorVersion()} for the target database.
*
* @return The database major version, or {@value #NO_VERSION} to indicate "no version information"
*
* @see java.sql.DatabaseMetaData#getDatabaseMajorVersion()
*/
int getDatabaseMajorVersion();
/**
* Obtain access to the database minor version, as returned from
* {@link java.sql.DatabaseMetaData#getDatabaseMinorVersion()} for the target database.
*
* @return The database minor version, or {@value #NO_VERSION} to indicate "no version information"
*
* @see java.sql.DatabaseMetaData#getDatabaseMinorVersion()
*/
int getDatabaseMinorVersion();
/** /**
* Obtain access to the name of the JDBC driver, as returned from {@link java.sql.DatabaseMetaData#getDriverName()} * Obtain access to the name of the JDBC driver, as returned from {@link java.sql.DatabaseMetaData#getDriverName()}
* for the target database * for the target database
@ -69,26 +45,6 @@ public interface DialectResolutionInfo {
*/ */
String getDriverName(); String getDriverName();
/**
* Obtain access to the major version of the JDBC driver, as returned from
* {@link java.sql.DatabaseMetaData#getDriverMajorVersion()} ()} for the target database.
*
* @return The JDBC driver major version, or {@value #NO_VERSION} to indicate "no version information"
*
* @see java.sql.DatabaseMetaData#getDriverMajorVersion()
*/
int getDriverMajorVersion();
/**
* Obtain access to the minor version of the JDBC driver, as returned from
* {@link java.sql.DatabaseMetaData#getDriverMinorVersion()} for the target database.
*
* @return The JDBC driver minor version, or {@value #NO_VERSION} to indicate "no version information"
*
* @see java.sql.DatabaseMetaData#getDriverMinorVersion()
*/
int getDriverMinorVersion();
/** /**
* Obtain access to the SQL keywords of the JDBC driver, as returned from * Obtain access to the SQL keywords of the JDBC driver, as returned from
* {@link java.sql.DatabaseMetaData#getSQLKeywords()} for the target database. * {@link java.sql.DatabaseMetaData#getSQLKeywords()} for the target database.
@ -109,5 +65,4 @@ public interface DialectResolutionInfo {
default <T> T unwrap(Class<T> clazz) { default <T> T unwrap(Class<T> clazz) {
return null; return null;
} }
} }

View File

@ -0,0 +1,75 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.engine.jdbc.dialect.spi;
/**
* @author Steve Ebersole
*/
public interface DialectVersionDetails {
/**
* Constant used to indicate that no version is defined
*/
int NO_VERSION = -9999;
/**
* Obtain access to the database major version, as returned from
* {@link java.sql.DatabaseMetaData#getDatabaseMajorVersion()} for the target database.
*
* @return The database major version, or {@value #NO_VERSION} to indicate "no version information"
*
* @see java.sql.DatabaseMetaData#getDatabaseMajorVersion()
*/
int getDatabaseMajorVersion();
/**
* Obtain access to the database minor version, as returned from
* {@link java.sql.DatabaseMetaData#getDatabaseMinorVersion()} for the target database.
*
* @return The database minor version, or {@value #NO_VERSION} to indicate "no version information"
*
* @see java.sql.DatabaseMetaData#getDatabaseMinorVersion()
*/
int getDatabaseMinorVersion();
/**
* Obtain access to the major version of the JDBC driver, as returned from
* {@link java.sql.DatabaseMetaData#getDriverMajorVersion()} ()} for the target database.
*
* @return The JDBC driver major version, or {@value #NO_VERSION} to indicate "no version information"
*
* @see java.sql.DatabaseMetaData#getDriverMajorVersion()
*/
int getDriverMajorVersion();
/**
* Obtain access to the minor version of the JDBC driver, as returned from
* {@link java.sql.DatabaseMetaData#getDriverMinorVersion()} for the target database.
*
* @return The JDBC driver minor version, or {@value #NO_VERSION} to indicate "no version information"
*
* @see java.sql.DatabaseMetaData#getDriverMinorVersion()
*/
int getDriverMinorVersion();
default boolean isAfterDatabaseVersion(DialectVersionDetails other) {
return isAfterDatabaseVersion( other.getDatabaseMajorVersion(), other.getDatabaseMinorVersion() );
}
default boolean isAfterDatabaseVersion(int major, int minor) {
return getDatabaseMajorVersion() > major
|| ( getDatabaseMajorVersion() == major && getDatabaseMinorVersion() > minor );
}
default boolean isAfterDriverVersion(DialectVersionDetails other) {
return isAfterDriverVersion( other.getDatabaseMajorVersion(), other.getDatabaseMinorVersion() );
}
default boolean isAfterDriverVersion(int major, int minor) {
return getDriverMajorVersion() > major
|| ( getDriverMajorVersion() == major && getDriverMinorVersion() > minor );
}
}