HHH-14456 Add DialectResolutionInfo#unwrap to be able to detect Cockroach in dialect resultion. Cleanup dialect resolution code.
This commit is contained in:
parent
130733af17
commit
dc884e077b
|
@ -10,11 +10,17 @@ import java.util.Objects;
|
||||||
|
|
||||||
import org.hibernate.dialect.CUBRIDDialect;
|
import org.hibernate.dialect.CUBRIDDialect;
|
||||||
import org.hibernate.dialect.Cache71Dialect;
|
import org.hibernate.dialect.Cache71Dialect;
|
||||||
|
import org.hibernate.dialect.CacheDialect;
|
||||||
|
import org.hibernate.dialect.CockroachDialect;
|
||||||
import org.hibernate.dialect.DB2390Dialect;
|
import org.hibernate.dialect.DB2390Dialect;
|
||||||
import org.hibernate.dialect.DB2390V8Dialect;
|
import org.hibernate.dialect.DB2390V8Dialect;
|
||||||
import org.hibernate.dialect.DB2400Dialect;
|
import org.hibernate.dialect.DB2400Dialect;
|
||||||
import org.hibernate.dialect.DB2400V7R3Dialect;
|
import org.hibernate.dialect.DB2400V7R3Dialect;
|
||||||
|
import org.hibernate.dialect.DB297Dialect;
|
||||||
import org.hibernate.dialect.DB2Dialect;
|
import org.hibernate.dialect.DB2Dialect;
|
||||||
|
import org.hibernate.dialect.DB2iDialect;
|
||||||
|
import org.hibernate.dialect.DB2zDialect;
|
||||||
|
import org.hibernate.dialect.DerbyDialect;
|
||||||
import org.hibernate.dialect.DerbyTenFiveDialect;
|
import org.hibernate.dialect.DerbyTenFiveDialect;
|
||||||
import org.hibernate.dialect.DerbyTenSevenDialect;
|
import org.hibernate.dialect.DerbyTenSevenDialect;
|
||||||
import org.hibernate.dialect.DerbyTenSixDialect;
|
import org.hibernate.dialect.DerbyTenSixDialect;
|
||||||
|
@ -25,29 +31,52 @@ import org.hibernate.dialect.HANACloudColumnStoreDialect;
|
||||||
import org.hibernate.dialect.HANAColumnStoreDialect;
|
import org.hibernate.dialect.HANAColumnStoreDialect;
|
||||||
import org.hibernate.dialect.HANARowStoreDialect;
|
import org.hibernate.dialect.HANARowStoreDialect;
|
||||||
import org.hibernate.dialect.HSQLDialect;
|
import org.hibernate.dialect.HSQLDialect;
|
||||||
|
import org.hibernate.dialect.Informix10Dialect;
|
||||||
import org.hibernate.dialect.InformixDialect;
|
import org.hibernate.dialect.InformixDialect;
|
||||||
import org.hibernate.dialect.Ingres10Dialect;
|
import org.hibernate.dialect.Ingres10Dialect;
|
||||||
import org.hibernate.dialect.Ingres9Dialect;
|
import org.hibernate.dialect.Ingres9Dialect;
|
||||||
import org.hibernate.dialect.IngresDialect;
|
import org.hibernate.dialect.IngresDialect;
|
||||||
|
import org.hibernate.dialect.MariaDB102Dialect;
|
||||||
|
import org.hibernate.dialect.MariaDB103Dialect;
|
||||||
|
import org.hibernate.dialect.MariaDB10Dialect;
|
||||||
|
import org.hibernate.dialect.MariaDB53Dialect;
|
||||||
|
import org.hibernate.dialect.MariaDBDialect;
|
||||||
|
import org.hibernate.dialect.MaxDBDialect;
|
||||||
import org.hibernate.dialect.MimerSQLDialect;
|
import org.hibernate.dialect.MimerSQLDialect;
|
||||||
|
import org.hibernate.dialect.MySQL55Dialect;
|
||||||
import org.hibernate.dialect.MySQL57Dialect;
|
import org.hibernate.dialect.MySQL57Dialect;
|
||||||
import org.hibernate.dialect.MySQL5Dialect;
|
import org.hibernate.dialect.MySQL5Dialect;
|
||||||
import org.hibernate.dialect.MySQL8Dialect;
|
import org.hibernate.dialect.MySQL8Dialect;
|
||||||
|
import org.hibernate.dialect.MySQLDialect;
|
||||||
import org.hibernate.dialect.Oracle10gDialect;
|
import org.hibernate.dialect.Oracle10gDialect;
|
||||||
|
import org.hibernate.dialect.Oracle12cDialect;
|
||||||
import org.hibernate.dialect.Oracle8iDialect;
|
import org.hibernate.dialect.Oracle8iDialect;
|
||||||
import org.hibernate.dialect.Oracle9iDialect;
|
import org.hibernate.dialect.Oracle9iDialect;
|
||||||
|
import org.hibernate.dialect.OracleDialect;
|
||||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||||
import org.hibernate.dialect.PostgreSQL82Dialect;
|
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQL91Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQL92Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQL93Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQL94Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQL95Dialect;
|
||||||
import org.hibernate.dialect.PostgreSQL9Dialect;
|
import org.hibernate.dialect.PostgreSQL9Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
import org.hibernate.dialect.PostgresPlusDialect;
|
import org.hibernate.dialect.PostgresPlusDialect;
|
||||||
|
import org.hibernate.dialect.RDMSOS2200Dialect;
|
||||||
import org.hibernate.dialect.SAPDBDialect;
|
import org.hibernate.dialect.SAPDBDialect;
|
||||||
import org.hibernate.dialect.SQLServer2005Dialect;
|
import org.hibernate.dialect.SQLServer2005Dialect;
|
||||||
import org.hibernate.dialect.SQLServer2008Dialect;
|
import org.hibernate.dialect.SQLServer2008Dialect;
|
||||||
|
import org.hibernate.dialect.SQLServer2012Dialect;
|
||||||
import org.hibernate.dialect.SQLServerDialect;
|
import org.hibernate.dialect.SQLServerDialect;
|
||||||
|
import org.hibernate.dialect.SpannerDialect;
|
||||||
import org.hibernate.dialect.Sybase11Dialect;
|
import org.hibernate.dialect.Sybase11Dialect;
|
||||||
import org.hibernate.dialect.SybaseASE157Dialect;
|
import org.hibernate.dialect.SybaseASE157Dialect;
|
||||||
import org.hibernate.dialect.SybaseASE15Dialect;
|
import org.hibernate.dialect.SybaseASE15Dialect;
|
||||||
|
import org.hibernate.dialect.SybaseASEDialect;
|
||||||
import org.hibernate.dialect.SybaseAnywhereDialect;
|
import org.hibernate.dialect.SybaseAnywhereDialect;
|
||||||
|
import org.hibernate.dialect.SybaseDialect;
|
||||||
|
import org.hibernate.dialect.Teradata14Dialect;
|
||||||
import org.hibernate.dialect.TeradataDialect;
|
import org.hibernate.dialect.TeradataDialect;
|
||||||
import org.hibernate.dialect.TimesTenDialect;
|
import org.hibernate.dialect.TimesTenDialect;
|
||||||
|
|
||||||
|
@ -59,194 +88,146 @@ public class DefaultDialectSelector implements LazyServiceResolver<Dialect> {
|
||||||
if ( name.isEmpty() ) {
|
if ( name.isEmpty() ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//Let's organize all string matches in groups by first letter:
|
switch ( name ) {
|
||||||
final char n = name.charAt( 0 );
|
case "Cache":
|
||||||
switch ( n ) {
|
return CacheDialect.class;
|
||||||
case 'C': return caseC( name );
|
case "Cache71":
|
||||||
case 'D': return caseD( name );
|
|
||||||
case 'F': return caseF( name );
|
|
||||||
case 'H': return caseH( name );
|
|
||||||
case 'I': return caseI( name );
|
|
||||||
case 'M': return caseM( name );
|
|
||||||
case 'O': return caseO( name );
|
|
||||||
case 'P': return caseP( name );
|
|
||||||
case 'S': return caseS( name );
|
|
||||||
case 'T': return caseT( name );
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<? extends Dialect> caseC(final String name) {
|
|
||||||
if ( name.equals( "Cache71" ) ) {
|
|
||||||
return Cache71Dialect.class;
|
return Cache71Dialect.class;
|
||||||
}
|
case "Cockroach":
|
||||||
// todo (6.0): add CockroachDB
|
return CockroachDialect.class;
|
||||||
// if ( name.equals( "CockroachDB192" ) ) {
|
case "CUBRID":
|
||||||
// return CockroachDB192Dialect.class;
|
|
||||||
// }
|
|
||||||
// if ( name.equals( "CockroachDB201" ) ) {
|
|
||||||
// return CockroachDB201Dialect.class;
|
|
||||||
// }
|
|
||||||
if ( name.equals( "CUBRID" ) ) {
|
|
||||||
return CUBRIDDialect.class;
|
return CUBRIDDialect.class;
|
||||||
}
|
case "DB2":
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<? extends Dialect> caseD(final String name) {
|
|
||||||
if ( name.equals( "DB2" ) ) {
|
|
||||||
return DB2Dialect.class;
|
return DB2Dialect.class;
|
||||||
}
|
case "DB2i":
|
||||||
if ( name.equals( "DB2390" ) ) {
|
return DB2iDialect.class;
|
||||||
|
case "DB2z":
|
||||||
|
return DB2zDialect.class;
|
||||||
|
case "DB297":
|
||||||
|
return DB297Dialect.class;
|
||||||
|
case "DB2390":
|
||||||
return DB2390Dialect.class;
|
return DB2390Dialect.class;
|
||||||
}
|
case "DB2390V8":
|
||||||
if ( name.equals( "DB2390V8" ) ) {
|
|
||||||
return DB2390V8Dialect.class;
|
return DB2390V8Dialect.class;
|
||||||
}
|
case "DB2400":
|
||||||
if ( name.equals( "DB2400" ) ) {
|
|
||||||
return DB2400Dialect.class;
|
return DB2400Dialect.class;
|
||||||
}
|
case "DB2400V7R3":
|
||||||
if ( name.equals( "DB2400V7R3" ) ) {
|
|
||||||
return DB2400V7R3Dialect.class;
|
return DB2400V7R3Dialect.class;
|
||||||
}
|
case "Derby":
|
||||||
if ( name.equals( "DerbyTenFive" ) ) {
|
return DerbyDialect.class;
|
||||||
|
case "DerbyTenFive":
|
||||||
return DerbyTenFiveDialect.class;
|
return DerbyTenFiveDialect.class;
|
||||||
}
|
case "DerbyTenSix":
|
||||||
if ( name.equals( "DerbyTenSix" ) ) {
|
|
||||||
return DerbyTenSixDialect.class;
|
return DerbyTenSixDialect.class;
|
||||||
}
|
case "DerbyTenSeven":
|
||||||
if ( name.equals( "DerbyTenSeven" ) ) {
|
|
||||||
return DerbyTenSevenDialect.class;
|
return DerbyTenSevenDialect.class;
|
||||||
}
|
case "Firebird":
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<? extends Dialect> caseF(final String name) {
|
|
||||||
if ( name.equals( "Firebird" ) ) {
|
|
||||||
return FirebirdDialect.class;
|
return FirebirdDialect.class;
|
||||||
}
|
case "H2":
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<? extends Dialect> caseH(final String name) {
|
|
||||||
if ( name.equals( "H2" ) ) {
|
|
||||||
return H2Dialect.class;
|
return H2Dialect.class;
|
||||||
}
|
case "HANACloudColumnStore":
|
||||||
if ( name.equals( "HANACloudColumnStore" ) ) {
|
|
||||||
return HANACloudColumnStoreDialect.class;
|
return HANACloudColumnStoreDialect.class;
|
||||||
}
|
case "HANAColumnStore":
|
||||||
if ( name.equals( "HANAColumnStore" ) ) {
|
|
||||||
return HANAColumnStoreDialect.class;
|
return HANAColumnStoreDialect.class;
|
||||||
}
|
case "HANARowStore":
|
||||||
if ( name.equals( "HANARowStore" ) ) {
|
|
||||||
return HANARowStoreDialect.class;
|
return HANARowStoreDialect.class;
|
||||||
}
|
case "HSQL":
|
||||||
if ( name.equals( "HSQL" ) ) {
|
|
||||||
return HSQLDialect.class;
|
return HSQLDialect.class;
|
||||||
}
|
case "Informix":
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<? extends Dialect> caseI(final String name) {
|
|
||||||
if ( name.equals( "Informix" ) ) {
|
|
||||||
return InformixDialect.class;
|
return InformixDialect.class;
|
||||||
}
|
case "Informix10":
|
||||||
if ( name.equals( "Ingres" ) ) {
|
return Informix10Dialect.class;
|
||||||
|
case "Ingres":
|
||||||
return IngresDialect.class;
|
return IngresDialect.class;
|
||||||
}
|
case "Ingres9":
|
||||||
if ( name.equals( "Ingres9" ) ) {
|
|
||||||
return Ingres9Dialect.class;
|
return Ingres9Dialect.class;
|
||||||
}
|
case "Ingres10":
|
||||||
if ( name.equals( "Ingres10" ) ) {
|
|
||||||
return Ingres10Dialect.class;
|
return Ingres10Dialect.class;
|
||||||
}
|
case "MariaDB":
|
||||||
return null;
|
return MariaDBDialect.class;
|
||||||
}
|
case "MariaDB53":
|
||||||
|
return MariaDB53Dialect.class;
|
||||||
private static Class<? extends Dialect> caseM(final String name) {
|
case "MariaDB10":
|
||||||
if ( name.equals( "MimerSQL" ) ) {
|
return MariaDB10Dialect.class;
|
||||||
|
case "MariaDB102":
|
||||||
|
return MariaDB102Dialect.class;
|
||||||
|
case "MariaDB103":
|
||||||
|
return MariaDB103Dialect.class;
|
||||||
|
case "MaxDB":
|
||||||
|
return MaxDBDialect.class;
|
||||||
|
case "MimerSQL":
|
||||||
return MimerSQLDialect.class;
|
return MimerSQLDialect.class;
|
||||||
}
|
case "MySQL":
|
||||||
if ( name.equals( "MySQL5" ) ) {
|
return MySQLDialect.class;
|
||||||
|
case "MySQL5":
|
||||||
return MySQL5Dialect.class;
|
return MySQL5Dialect.class;
|
||||||
}
|
case "MySQL55":
|
||||||
if ( name.equals( "MySQL57" ) ) {
|
return MySQL55Dialect.class;
|
||||||
|
case "MySQL57":
|
||||||
return MySQL57Dialect.class;
|
return MySQL57Dialect.class;
|
||||||
}
|
case "MySQL8":
|
||||||
if ( name.equals( "MySQL8" ) ) {
|
|
||||||
return MySQL8Dialect.class;
|
return MySQL8Dialect.class;
|
||||||
}
|
case "Oracle":
|
||||||
return null;
|
return OracleDialect.class;
|
||||||
}
|
case "Oracle8i":
|
||||||
|
|
||||||
private static Class<? extends Dialect> caseO(final String name) {
|
|
||||||
if ( name.equals( "Oracle8i" ) ) {
|
|
||||||
return Oracle8iDialect.class;
|
return Oracle8iDialect.class;
|
||||||
}
|
case "Oracle9i":
|
||||||
if ( name.equals( "Oracle9i" ) ) {
|
|
||||||
return Oracle9iDialect.class;
|
return Oracle9iDialect.class;
|
||||||
}
|
case "Oracle10g":
|
||||||
if ( name.equals( "Oracle10g" ) ) {
|
|
||||||
return Oracle10gDialect.class;
|
return Oracle10gDialect.class;
|
||||||
}
|
case "Oracle12c":
|
||||||
return null;
|
return Oracle12cDialect.class;
|
||||||
}
|
case "PostgresPlus":
|
||||||
|
|
||||||
private static Class<? extends Dialect> caseP(final String name) {
|
|
||||||
if ( name.equals( "PostgresPlus" ) ) {
|
|
||||||
return PostgresPlusDialect.class;
|
return PostgresPlusDialect.class;
|
||||||
}
|
case "PostgreSQL":
|
||||||
if ( name.equals( "PostgreSQL81" ) ) {
|
return PostgreSQLDialect.class;
|
||||||
|
case "PostgreSQL81":
|
||||||
return PostgreSQL81Dialect.class;
|
return PostgreSQL81Dialect.class;
|
||||||
}
|
case "PostgreSQL82":
|
||||||
if ( name.equals( "PostgreSQL82" ) ) {
|
|
||||||
return PostgreSQL82Dialect.class;
|
return PostgreSQL82Dialect.class;
|
||||||
}
|
case "PostgreSQL9":
|
||||||
if ( name.equals( "PostgreSQL9" ) ) {
|
|
||||||
return PostgreSQL9Dialect.class;
|
return PostgreSQL9Dialect.class;
|
||||||
}
|
case "PostgreSQL91":
|
||||||
return null;
|
return PostgreSQL91Dialect.class;
|
||||||
}
|
case "PostgreSQL92":
|
||||||
|
return PostgreSQL92Dialect.class;
|
||||||
private static Class<? extends Dialect> caseS(final String name) {
|
case "PostgreSQL93":
|
||||||
if ( name.equals( "SAPDB" ) ) {
|
return PostgreSQL93Dialect.class;
|
||||||
|
case "PostgreSQL94":
|
||||||
|
return PostgreSQL94Dialect.class;
|
||||||
|
case "PostgreSQL95":
|
||||||
|
return PostgreSQL95Dialect.class;
|
||||||
|
case "RDMSOS2200":
|
||||||
|
return RDMSOS2200Dialect.class;
|
||||||
|
case "SAPDB":
|
||||||
return SAPDBDialect.class;
|
return SAPDBDialect.class;
|
||||||
}
|
case "Spanner":
|
||||||
if ( name.equals( "SQLServer" ) ) {
|
return SpannerDialect.class;
|
||||||
|
case "SQLServer":
|
||||||
return SQLServerDialect.class;
|
return SQLServerDialect.class;
|
||||||
}
|
case "SQLServer2005":
|
||||||
if ( name.equals( "SQLServer2005" ) ) {
|
|
||||||
return SQLServer2005Dialect.class;
|
return SQLServer2005Dialect.class;
|
||||||
}
|
case "SQLServer2008":
|
||||||
if ( name.equals( "SQLServer2008" ) ) {
|
|
||||||
return SQLServer2008Dialect.class;
|
return SQLServer2008Dialect.class;
|
||||||
}
|
case "SQLServer2012":
|
||||||
if ( name.equals( "Sybase11" ) ) {
|
return SQLServer2012Dialect.class;
|
||||||
|
case "Sybase":
|
||||||
|
return SybaseDialect.class;
|
||||||
|
case "Sybase11":
|
||||||
return Sybase11Dialect.class;
|
return Sybase11Dialect.class;
|
||||||
}
|
case "SybaseAnywhere":
|
||||||
if ( name.equals( "SybaseAnywhere" ) ) {
|
|
||||||
return SybaseAnywhereDialect.class;
|
return SybaseAnywhereDialect.class;
|
||||||
}
|
case "SybaseASE":
|
||||||
if ( name.equals( "Sybase11" ) ) {
|
return SybaseASEDialect.class;
|
||||||
return Sybase11Dialect.class;
|
case "SybaseASE15":
|
||||||
}
|
|
||||||
if ( name.equals( "SybaseAnywhere" ) ) {
|
|
||||||
return SybaseAnywhereDialect.class;
|
|
||||||
}
|
|
||||||
if ( name.equals( "SybaseASE15" ) ) {
|
|
||||||
return SybaseASE15Dialect.class;
|
return SybaseASE15Dialect.class;
|
||||||
}
|
case "SybaseASE157":
|
||||||
if ( name.equals( "SybaseASE157" ) ) {
|
|
||||||
return SybaseASE157Dialect.class;
|
return SybaseASE157Dialect.class;
|
||||||
}
|
case "Teradata":
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<? extends Dialect> caseT(final String name) {
|
|
||||||
if ( name.equals( "Teradata" ) ) {
|
|
||||||
return TeradataDialect.class;
|
return TeradataDialect.class;
|
||||||
}
|
case "Teradata14":
|
||||||
if ( name.equals( "TimesTen" ) ) {
|
return Teradata14Dialect.class;
|
||||||
|
case "TimesTen":
|
||||||
return TimesTenDialect.class;
|
return TimesTenDialect.class;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -6,6 +6,12 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.dialect;
|
package org.hibernate.dialect;
|
||||||
|
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
import org.hibernate.engine.jdbc.dialect.spi.BasicSQLExceptionConverter;
|
||||||
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
|
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,7 +83,7 @@ public enum Database {
|
||||||
DERBY {
|
DERBY {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new DerbyDialect(info);
|
return new DerbyDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
@ -85,7 +91,7 @@ public enum Database {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getDriverClassName(String jdbcUrl) {
|
public String getDriverClassName(String jdbcUrl) {
|
||||||
return jdbcUrl.startsWith("jdbc:derby://")
|
return jdbcUrl.startsWith( "jdbc:derby://" )
|
||||||
? "org.apache.derby.jdbc.ClientDriver"
|
? "org.apache.derby.jdbc.ClientDriver"
|
||||||
: "org.apache.derby.jdbc.EmbeddedDriver";
|
: "org.apache.derby.jdbc.EmbeddedDriver";
|
||||||
}
|
}
|
||||||
|
@ -94,7 +100,7 @@ public enum Database {
|
||||||
ENTERPRISEDB {
|
ENTERPRISEDB {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new PostgresPlusDialect();
|
return new PostgresPlusDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
@ -113,7 +119,7 @@ public enum Database {
|
||||||
FIREBIRD {
|
FIREBIRD {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new FirebirdDialect(info);
|
return new FirebirdDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
@ -132,7 +138,7 @@ public enum Database {
|
||||||
H2 {
|
H2 {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new H2Dialect(info);
|
return new H2Dialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
@ -147,7 +153,7 @@ public enum Database {
|
||||||
HANA {
|
HANA {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new HANAColumnStoreDialect(info);
|
return new HANAColumnStoreDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
@ -166,7 +172,7 @@ public enum Database {
|
||||||
HSQL {
|
HSQL {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new HSQLDialect(info);
|
return new HSQLDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
@ -185,12 +191,12 @@ public enum Database {
|
||||||
INFORMIX {
|
INFORMIX {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new InformixDialect(info);
|
return new InformixDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
//usually "Informix Dynamic Server"
|
//usually "Informix Dynamic Server"
|
||||||
return databaseName.toLowerCase().startsWith("informix");
|
return databaseName.toLowerCase().startsWith( "informix" );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getDriverClassName(String jdbcUrl) {
|
public String getDriverClassName(String jdbcUrl) {
|
||||||
|
@ -205,11 +211,11 @@ public enum Database {
|
||||||
INGRES {
|
INGRES {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new IngresDialect(info);
|
return new IngresDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
return databaseName.toLowerCase().startsWith("ingres");
|
return databaseName.toLowerCase().startsWith( "ingres" );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getDriverClassName(String jdbcUrl) {
|
public String getDriverClassName(String jdbcUrl) {
|
||||||
|
@ -226,12 +232,12 @@ public enum Database {
|
||||||
else {
|
else {
|
||||||
//in case the product name has been set to MySQL
|
//in case the product name has been set to MySQL
|
||||||
String driverName = info.getDriverName();
|
String driverName = info.getDriverName();
|
||||||
return driverName != null && driverName.startsWith("MariaDB");
|
return driverName != null && driverName.startsWith( "MariaDB" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new MariaDBDialect(info);
|
return new MariaDBDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String productName) {
|
public boolean productNameMatches(String productName) {
|
||||||
|
@ -250,8 +256,8 @@ public enum Database {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
return databaseName.toLowerCase().startsWith("sap db")
|
return databaseName.toLowerCase().startsWith( "sap db" )
|
||||||
|| databaseName.toLowerCase().startsWith("maxdb");
|
|| databaseName.toLowerCase().startsWith( "maxdb" );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getDriverClassName(String jdbcUrl) {
|
public String getDriverClassName(String jdbcUrl) {
|
||||||
|
@ -270,7 +276,7 @@ public enum Database {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
return databaseName.startsWith("Mimer SQL");
|
return databaseName.startsWith( "Mimer SQL" );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getDriverClassName(String jdbcUrl) {
|
public String getDriverClassName(String jdbcUrl) {
|
||||||
|
@ -281,7 +287,7 @@ public enum Database {
|
||||||
MYSQL {
|
MYSQL {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new MySQLDialect(info);
|
return new MySQLDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
@ -296,7 +302,7 @@ public enum Database {
|
||||||
ORACLE {
|
ORACLE {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new OracleDialect(info);
|
return new OracleDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
@ -311,7 +317,11 @@ public enum Database {
|
||||||
POSTGRESQL {
|
POSTGRESQL {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new PostgreSQLDialect(info);
|
final String version = getVersion( info.unwrap( DatabaseMetaData.class ) );
|
||||||
|
if ( version.startsWith( "Cockroach" ) ) {
|
||||||
|
return new CockroachDialect( info );
|
||||||
|
}
|
||||||
|
return new PostgreSQLDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
@ -321,12 +331,39 @@ public enum Database {
|
||||||
public String getDriverClassName(String jdbcUrl) {
|
public String getDriverClassName(String jdbcUrl) {
|
||||||
return "org.postgresql.Driver";
|
return "org.postgresql.Driver";
|
||||||
}
|
}
|
||||||
|
private String getVersion(DatabaseMetaData databaseMetaData) {
|
||||||
|
try (Statement statement = databaseMetaData.getConnection().createStatement() ) {
|
||||||
|
final ResultSet rs = statement.executeQuery( "select version()" );
|
||||||
|
if ( rs.next() ) {
|
||||||
|
return rs.getString( 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
throw BasicSQLExceptionConverter.INSTANCE.convert( e );
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
SPANNER {
|
||||||
|
@Override
|
||||||
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
|
return new SpannerDialect();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
return databaseName.startsWith( "Google Cloud Spanner" );
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getDriverClassName(String jdbcUrl) {
|
||||||
|
return "com.google.cloud.spanner.jdbc.JdbcDriver";
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
SQLSERVER {
|
SQLSERVER {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new SQLServerDialect(info);
|
return new SQLServerDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
@ -343,7 +380,7 @@ public enum Database {
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
final String databaseName = info.getDatabaseName();
|
final String databaseName = info.getDatabaseName();
|
||||||
if ( isASE( databaseName ) ) {
|
if ( isASE( databaseName ) ) {
|
||||||
return new SybaseASEDialect(info);
|
return new SybaseASEDialect( info );
|
||||||
}
|
}
|
||||||
if ( isASA( databaseName ) ) {
|
if ( isASA( databaseName ) ) {
|
||||||
return new SybaseAnywhereDialect();
|
return new SybaseAnywhereDialect();
|
||||||
|
@ -364,15 +401,15 @@ public enum Database {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean matchesUrl(String jdbcUrl) {
|
public boolean matchesUrl(String jdbcUrl) {
|
||||||
return jdbcUrl.startsWith("jdbc:sybase:")
|
return jdbcUrl.startsWith( "jdbc:sybase:" )
|
||||||
|| jdbcUrl.startsWith("jdbc:sqlanywhere:");
|
|| jdbcUrl.startsWith( "jdbc:sqlanywhere:" );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
TERADATA {
|
TERADATA {
|
||||||
@Override
|
@Override
|
||||||
public Dialect createDialect(DialectResolutionInfo info) {
|
public Dialect createDialect(DialectResolutionInfo info) {
|
||||||
return new TeradataDialect(info);
|
return new TeradataDialect( info );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
|
@ -391,7 +428,7 @@ public enum Database {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean productNameMatches(String databaseName) {
|
public boolean productNameMatches(String databaseName) {
|
||||||
return databaseName.toLowerCase().startsWith("timesten");
|
return databaseName.toLowerCase().startsWith( "timesten" );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class PostgreSQLDialect extends Dialect {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostgreSQLDialect() {
|
public PostgreSQLDialect() {
|
||||||
this(800);
|
this( 800 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostgreSQLDialect(int version) {
|
public PostgreSQLDialect(int version) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.sql.SQLException;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
|
|
||||||
import org.hibernate.dialect.function.CommonFunctionFactory;
|
import org.hibernate.dialect.function.CommonFunctionFactory;
|
||||||
|
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
|
||||||
import org.hibernate.query.spi.QueryEngine;
|
import org.hibernate.query.spi.QueryEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +20,7 @@ import org.hibernate.query.spi.QueryEngine;
|
||||||
* @author Jim Mlodgenski
|
* @author Jim Mlodgenski
|
||||||
*/
|
*/
|
||||||
public class PostgresPlusDialect extends PostgreSQLDialect {
|
public class PostgresPlusDialect extends PostgreSQLDialect {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a PostgresPlusDialect
|
* Constructs a PostgresPlusDialect
|
||||||
*/
|
*/
|
||||||
|
@ -26,6 +28,14 @@ public class PostgresPlusDialect extends PostgreSQLDialect {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PostgresPlusDialect(DialectResolutionInfo info) {
|
||||||
|
super( info );
|
||||||
|
}
|
||||||
|
|
||||||
|
public PostgresPlusDialect(int version) {
|
||||||
|
super( version );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initializeFunctionRegistry(QueryEngine queryEngine) {
|
public void initializeFunctionRegistry(QueryEngine queryEngine) {
|
||||||
super.initializeFunctionRegistry( queryEngine );
|
super.initializeFunctionRegistry( queryEngine );
|
||||||
|
|
|
@ -55,9 +55,9 @@ public class DialectFactoryImpl implements DialectFactory, ServiceRegistryAwareS
|
||||||
@Override
|
@Override
|
||||||
public Dialect buildDialect(Map configValues, DialectResolutionInfoSource resolutionInfoSource) throws HibernateException {
|
public Dialect buildDialect(Map configValues, DialectResolutionInfoSource resolutionInfoSource) throws HibernateException {
|
||||||
final Object dialectReference = configValues.get( AvailableSettings.DIALECT );
|
final Object dialectReference = configValues.get( AvailableSettings.DIALECT );
|
||||||
Dialect dialect = !isEmpty(dialectReference) ?
|
Dialect dialect = !isEmpty( dialectReference ) ?
|
||||||
constructDialect(dialectReference, resolutionInfoSource) :
|
constructDialect( dialectReference, resolutionInfoSource ) :
|
||||||
determineDialect(resolutionInfoSource);
|
determineDialect( resolutionInfoSource );
|
||||||
logSelectedDialect( dialect );
|
logSelectedDialect( dialect );
|
||||||
return dialect;
|
return dialect;
|
||||||
}
|
}
|
||||||
|
@ -66,10 +66,10 @@ public class DialectFactoryImpl implements DialectFactory, ServiceRegistryAwareS
|
||||||
LOG.usingDialect( dialect );
|
LOG.usingDialect( dialect );
|
||||||
|
|
||||||
Class<? extends Dialect> dialectClass = dialect.getClass();
|
Class<? extends Dialect> dialectClass = dialect.getClass();
|
||||||
if ( dialectClass.isAnnotationPresent(Deprecated.class) ) {
|
if ( dialectClass.isAnnotationPresent( Deprecated.class ) ) {
|
||||||
Class<?> superDialectClass = dialectClass.getSuperclass();
|
Class<?> superDialectClass = dialectClass.getSuperclass();
|
||||||
if ( !superDialectClass.isAnnotationPresent(Deprecated.class)
|
if ( !superDialectClass.isAnnotationPresent( Deprecated.class )
|
||||||
&& !superDialectClass.equals(Dialect.class) ) {
|
&& !superDialectClass.equals( Dialect.class ) ) {
|
||||||
DEPRECATION_LOGGER.deprecatedDialect( dialectClass.getSimpleName(), superDialectClass.getName() );
|
DEPRECATION_LOGGER.deprecatedDialect( dialectClass.getSimpleName(), superDialectClass.getName() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -101,7 +101,7 @@ public class DialectFactoryImpl implements DialectFactory, ServiceRegistryAwareS
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
if (resolutionInfoSource != null) {
|
if (resolutionInfoSource != null) {
|
||||||
return dialectClass.getConstructor(DialectResolutionInfo.class).newInstance(
|
return dialectClass.getConstructor( DialectResolutionInfo.class ).newInstance(
|
||||||
resolutionInfoSource.getDialectResolutionInfo()
|
resolutionInfoSource.getDialectResolutionInfo()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,4 +87,12 @@ public class DatabaseMetaDataDialectResolutionInfoAdapter implements DialectReso
|
||||||
public int getDriverMinorVersion() {
|
public int getDriverMinorVersion() {
|
||||||
return interpretVersion( databaseMetaData.getDriverMinorVersion() );
|
return interpretVersion( databaseMetaData.getDriverMinorVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T unwrap(Class<T> clazz) {
|
||||||
|
if ( clazz.isInstance( databaseMetaData ) ) {
|
||||||
|
return clazz.cast( databaseMetaData );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,5 +91,15 @@ public interface DialectResolutionInfo {
|
||||||
*/
|
*/
|
||||||
public int getDriverMinorVersion();
|
public int getDriverMinorVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain access to the underlying object of the given type.
|
||||||
|
*
|
||||||
|
* Return <code>null</code> if the underlying object is not of the given type.
|
||||||
|
*
|
||||||
|
* @return The unwrapped object or <code>null</code>
|
||||||
|
*/
|
||||||
|
default <T> T unwrap(Class<T> clazz) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue