55 */
66package org .hibernate .reactive .containers ;
77
8+ import java .lang .reflect .Field ;
89import java .util .Arrays ;
910import java .util .Map ;
1011import java .util .Objects ;
1112import java .util .stream .Stream ;
1213
1314import org .hibernate .dialect .CockroachDialect ;
1415import org .hibernate .dialect .DB2Dialect ;
16+ import org .hibernate .dialect .DatabaseVersion ;
1517import org .hibernate .dialect .Dialect ;
1618import org .hibernate .dialect .MariaDBDialect ;
1719import org .hibernate .dialect .MySQLDialect ;
@@ -28,15 +30,16 @@ public class DatabaseConfiguration {
2830 public static final boolean USE_DOCKER = Boolean .getBoolean ("docker" );
2931
3032 public enum DBType {
31- DB2 ( DB2Database .INSTANCE , 50000 , "com.ibm.db2.jcc.DB2Driver" , DB2Dialect .class ),
32- MYSQL ( MySQLDatabase .INSTANCE , 3306 , "com.mysql.cj.jdbc.Driver" , MySQLDialect .class ),
33- MARIA ( MariaDatabase .INSTANCE , 3306 , "org.mariadb.jdbc.Driver" , MariaDBDialect .class , "mariadb" ),
34- POSTGRESQL ( PostgreSQLDatabase .INSTANCE , 5432 , "org.postgresql.Driver" , PostgreSQLDialect .class , "POSTGRES" , "PG" ),
35- COCKROACHDB ( CockroachDBDatabase .INSTANCE , 26257 , "org.postgresql.Driver" , CockroachDialect .class , "COCKROACH" ),
36- SQLSERVER ( MSSQLServerDatabase .INSTANCE , 1433 , "com.microsoft.sqlserver.jdbc.SQLServerDriver" , SQLServerDialect .class , "MSSQL" , "MSSQLSERVER" ),
37- ORACLE ( OracleDatabase .INSTANCE , 1521 , "oracle.jdbc.OracleDriver" , OracleDialect .class );
33+ DB2 ( DB2Database .INSTANCE , "DB2" , 50000 , "com.ibm.db2.jcc.DB2Driver" , DB2Dialect .class ),
34+ MYSQL ( MySQLDatabase .INSTANCE , "MySQL" , 3306 , "com.mysql.cj.jdbc.Driver" , MySQLDialect .class ),
35+ MARIA ( MariaDatabase .INSTANCE , "MariaDB" , 3306 , "org.mariadb.jdbc.Driver" , MariaDBDialect .class , "mariadb" ),
36+ POSTGRESQL ( PostgreSQLDatabase .INSTANCE , "PostgreSQL" , 5432 , "org.postgresql.Driver" , PostgreSQLDialect .class , "POSTGRES" , "PG" ),
37+ COCKROACHDB ( CockroachDBDatabase .INSTANCE , "CockroachDb" , 26257 , "org.postgresql.Driver" , CockroachDialect .class , "COCKROACH" ),
38+ SQLSERVER ( MSSQLServerDatabase .INSTANCE , "Microsoft SQL Server" , 1433 , "com.microsoft.sqlserver.jdbc.SQLServerDriver" , SQLServerDialect .class , "MSSQL" , "MSSQLSERVER" ),
39+ ORACLE ( OracleDatabase .INSTANCE , "Oracle" , 1521 , "oracle.jdbc.OracleDriver" , OracleDialect .class );
3840
3941 private final TestableDatabase configuration ;
42+ private final String productName ;
4043 private final int defaultPort ;
4144
4245 // A list of alternative names that can be used to select the db
@@ -47,8 +50,9 @@ public enum DBType {
4750
4851 private final Class <? extends Dialect > dialect ;
4952
50- DBType (TestableDatabase configuration , int defaultPort , String jdbcDriver , Class <? extends Dialect > dialect , String ... aliases ) {
53+ DBType (TestableDatabase configuration , String productName , int defaultPort , String jdbcDriver , Class <? extends Dialect > dialect , String ... aliases ) {
5154 this .configuration = configuration ;
55+ this .productName = productName ;
5256 this .defaultPort = defaultPort ;
5357 this .aliases = aliases ;
5458 this .dialect = dialect ;
@@ -81,6 +85,10 @@ public static DBType fromString(String dbName) {
8185 .toString ( DBType .values () ) );
8286 }
8387
88+ public String getProductName () {
89+ return productName ;
90+ }
91+
8492 public int getDefaultPort () {
8593 return defaultPort ;
8694 }
@@ -92,6 +100,24 @@ public String getJdbcDriver() {
92100 public Class <? extends Dialect > getDialectClass () {
93101 return dialect ;
94102 }
103+
104+ /**
105+ * The minimum version of the database supported by the dialect.
106+ * <p>
107+ * We use reflection because it's not accessible from the tests.
108+ * Copied from MetadataAccessTests in Hibernate ORM.
109+ * </p>
110+ */
111+ public DatabaseVersion getMinimumVersion () {
112+ try {
113+ Field field = dialect .getDeclaredField ( "MINIMUM_VERSION" );
114+ field .setAccessible ( true );
115+ return (DatabaseVersion ) field .get ( null );
116+ }
117+ catch (IllegalAccessException | NoSuchFieldException e ) {
118+ throw new RuntimeException ( "Error extracting 'MINIMUM_VERSION' from '" + dialect + "'" , e );
119+ }
120+ }
95121 }
96122
97123 public static final String USERNAME = "hreact" ;
@@ -101,7 +127,7 @@ public Class<? extends Dialect> getDialectClass() {
101127 private static DBType dbType ;
102128
103129 public static DBType dbType () {
104- if (dbType == null ) {
130+ if ( dbType == null ) {
105131 String dbTypeString = System .getProperty ( "db" , DBType .POSTGRESQL .name () );
106132 dbType = DBType .fromString ( dbTypeString );
107133 System .out .println ( "Using database type: " + dbType .name () );
@@ -131,5 +157,4 @@ public static String expectedDatatype(Class<?> dataType) {
131157
132158 private DatabaseConfiguration () {
133159 }
134-
135160}
0 commit comments