initial work on DatabaseVersion#isAfter
This commit is contained in:
parent
ad48a01e2c
commit
43206b02fc
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* 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.dialect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Details about the underlying database, as understood by a Dialect.
|
||||||
|
*
|
||||||
|
* Also used in conjunction with {@link org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo}
|
||||||
|
* to help resolve the Dialect to use.
|
||||||
|
*/
|
||||||
|
public interface DatabaseVersion {
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
|
||||||
|
default boolean isAfter(DatabaseVersion other) {
|
||||||
|
return isAfter( other.getDatabaseMajorVersion(), other.getDatabaseMinorVersion() );
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean isAfter(int major, int minor) {
|
||||||
|
return getDatabaseMajorVersion() > major
|
||||||
|
|| ( getDatabaseMajorVersion() == major && getDatabaseMinorVersion() > minor );
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean isAfter(Integer major, Integer minor) {
|
||||||
|
return isAfter( (int) major, minor == null ? NO_VERSION : minor );
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.engine.jdbc.dialect.spi;
|
package org.hibernate.engine.jdbc.dialect.spi;
|
||||||
|
|
||||||
|
import org.hibernate.dialect.DatabaseVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exposes information about the database and JDBC driver that can be used in resolving the appropriate Dialect
|
* Exposes information about the database and JDBC driver that can be used in resolving the appropriate Dialect
|
||||||
* to use.
|
* to use.
|
||||||
|
@ -13,7 +15,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 extends DialectVersionDetails {
|
public interface DialectResolutionInfo extends DatabaseVersion {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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()}
|
||||||
|
@ -45,6 +47,26 @@ public interface DialectResolutionInfo extends DialectVersionDetails {
|
||||||
*/
|
*/
|
||||||
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.
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 );
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue