5
5
*/
6
6
package org .hibernate .reactive .containers ;
7
7
8
+ import java .lang .reflect .Field ;
8
9
import java .util .Arrays ;
9
10
import java .util .Map ;
10
11
import java .util .Objects ;
11
12
import java .util .stream .Stream ;
12
13
13
14
import org .hibernate .dialect .CockroachDialect ;
14
15
import org .hibernate .dialect .DB2Dialect ;
16
+ import org .hibernate .dialect .DatabaseVersion ;
15
17
import org .hibernate .dialect .Dialect ;
16
18
import org .hibernate .dialect .MariaDBDialect ;
17
19
import org .hibernate .dialect .MySQLDialect ;
@@ -28,15 +30,16 @@ public class DatabaseConfiguration {
28
30
public static final boolean USE_DOCKER = Boolean .getBoolean ("docker" );
29
31
30
32
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 );
38
40
39
41
private final TestableDatabase configuration ;
42
+ private final String productName ;
40
43
private final int defaultPort ;
41
44
42
45
// A list of alternative names that can be used to select the db
@@ -47,8 +50,9 @@ public enum DBType {
47
50
48
51
private final Class <? extends Dialect > dialect ;
49
52
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 ) {
51
54
this .configuration = configuration ;
55
+ this .productName = productName ;
52
56
this .defaultPort = defaultPort ;
53
57
this .aliases = aliases ;
54
58
this .dialect = dialect ;
@@ -81,6 +85,10 @@ public static DBType fromString(String dbName) {
81
85
.toString ( DBType .values () ) );
82
86
}
83
87
88
+ public String getProductName () {
89
+ return productName ;
90
+ }
91
+
84
92
public int getDefaultPort () {
85
93
return defaultPort ;
86
94
}
@@ -92,6 +100,24 @@ public String getJdbcDriver() {
92
100
public Class <? extends Dialect > getDialectClass () {
93
101
return dialect ;
94
102
}
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
+ }
95
121
}
96
122
97
123
public static final String USERNAME = "hreact" ;
@@ -101,7 +127,7 @@ public Class<? extends Dialect> getDialectClass() {
101
127
private static DBType dbType ;
102
128
103
129
public static DBType dbType () {
104
- if (dbType == null ) {
130
+ if ( dbType == null ) {
105
131
String dbTypeString = System .getProperty ( "db" , DBType .POSTGRESQL .name () );
106
132
dbType = DBType .fromString ( dbTypeString );
107
133
System .out .println ( "Using database type: " + dbType .name () );
@@ -131,5 +157,4 @@ public static String expectedDatatype(Class<?> dataType) {
131
157
132
158
private DatabaseConfiguration () {
133
159
}
134
-
135
160
}
0 commit comments