Skip to content

Commit 20dbfd9

Browse files
blafondDavideD
authored andcommitted
[hibernate#929] Added H2 database for testing
1 parent d15360b commit 20dbfd9

File tree

2 files changed

+124
-1
lines changed

2 files changed

+124
-1
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/DatabaseConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public enum DBType {
2525
POSTGRESQL( PostgreSQLDatabase.INSTANCE, 5432, "POSTGRES", "PG" ),
2626
COCKROACHDB( CockroachDBDatabase.INSTANCE, 26257, "COCKROACH" ),
2727
SQLSERVER( MSSQLServerDatabase.INSTANCE, 1433, "MSSQL", "MSSQLSERVER" ),
28-
ORACLE( OracleDatabase.INSTANCE, 1521 );
28+
ORACLE( OracleDatabase.INSTANCE, 1521 ),
29+
H2( H2Database.INSTANCE, -1 );
2930

3031
private final TestableDatabase configuration;
3132
private final int defaultPort;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/* Hibernate, Relational Persistence for Idiomatic Java
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Copyright: Red Hat Inc. and Hibernate Authors
5+
*/
6+
package org.hibernate.reactive.containers;
7+
8+
import java.io.Serializable;
9+
import java.math.BigDecimal;
10+
import java.math.BigInteger;
11+
import java.net.URL;
12+
import java.sql.Time;
13+
import java.sql.Timestamp;
14+
import java.time.Duration;
15+
import java.time.Instant;
16+
import java.time.LocalDate;
17+
import java.time.LocalDateTime;
18+
import java.time.LocalTime;
19+
import java.util.Date;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
import java.util.TimeZone;
23+
import java.util.UUID;
24+
25+
import org.hibernate.type.NumericBooleanType;
26+
import org.hibernate.type.TextType;
27+
import org.hibernate.type.TrueFalseType;
28+
import org.hibernate.type.YesNoType;
29+
import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor;
30+
31+
public class H2Database implements TestableDatabase {
32+
public static H2Database INSTANCE = new H2Database();
33+
34+
private static Map<Class<?>, String> expectedDBTypeForClass = new HashMap<>();
35+
36+
static {{
37+
expectedDBTypeForClass.put( boolean.class, "BOOLEAN" );
38+
expectedDBTypeForClass.put( Boolean.class, "BOOLEAN" );
39+
expectedDBTypeForClass.put( NumericBooleanType.class, "INTEGER" );
40+
expectedDBTypeForClass.put( TrueFalseType.class, "CHARACTER" );
41+
expectedDBTypeForClass.put( YesNoType.class, "CHARACTER" );
42+
expectedDBTypeForClass.put( int.class, "INTEGER" );
43+
expectedDBTypeForClass.put( Integer.class, "INTEGER" );
44+
expectedDBTypeForClass.put( long.class, "BIGINT" );
45+
expectedDBTypeForClass.put( Long.class, "BIGINT" );
46+
expectedDBTypeForClass.put( float.class, "DOUBLE PRECISION" );
47+
expectedDBTypeForClass.put( Float.class, "DOUBLE PRECISION" );
48+
expectedDBTypeForClass.put( double.class, "DOUBLE PRECISION" );
49+
expectedDBTypeForClass.put( Double.class, "DOUBLE PRECISION" );
50+
expectedDBTypeForClass.put( byte.class, "TINYINT" );
51+
expectedDBTypeForClass.put( Byte.class, "TINYINT" );
52+
expectedDBTypeForClass.put( PrimitiveByteArrayTypeDescriptor.class, "BINARY VARYING" );
53+
expectedDBTypeForClass.put( URL.class, "VARCHAR_IGNORECASE" );
54+
expectedDBTypeForClass.put( TimeZone.class, "VARCHAR_IGNORECASE" );
55+
expectedDBTypeForClass.put( Date.class, "DATE" );
56+
expectedDBTypeForClass.put( Timestamp.class, "TIMESTAMP" );
57+
expectedDBTypeForClass.put( Time.class, "TIME" );
58+
expectedDBTypeForClass.put( LocalDate.class, "DATE" );
59+
expectedDBTypeForClass.put( LocalTime.class, "time" );
60+
expectedDBTypeForClass.put( LocalDateTime.class, "TIMESTAMP" );
61+
expectedDBTypeForClass.put( BigInteger.class, "NUMERIC" );
62+
expectedDBTypeForClass.put( BigDecimal.class, "NUMERIC" );
63+
expectedDBTypeForClass.put( Serializable.class, "BINARY VARYING" );
64+
expectedDBTypeForClass.put( UUID.class, "binary" );
65+
expectedDBTypeForClass.put( Instant.class, "datetime" );
66+
expectedDBTypeForClass.put( Duration.class, "bigint" );
67+
expectedDBTypeForClass.put( Character.class, "VARCHAR_IGNORECASE" );
68+
expectedDBTypeForClass.put( char.class, "VARCHAR_IGNORECASE" );
69+
expectedDBTypeForClass.put( TextType.class, "text" );
70+
expectedDBTypeForClass.put( String.class, "VARCHAR_IGNORECASE" );
71+
}}
72+
73+
private String getRegularJdbcUrl() {
74+
return "jdbc:h2:~/test;DATABASE_TO_UPPER=FALSE";
75+
}
76+
77+
@Override
78+
public String getJdbcUrl() {
79+
return "jdbc:h2:~/test;DATABASE_TO_UPPER=FALSE";
80+
}
81+
82+
@Override
83+
public String getUri() {
84+
return "h2:~/test;DATABASE_TO_UPPER=FALSE";
85+
}
86+
87+
88+
@Override
89+
public String getScheme() {
90+
return "h2";
91+
}
92+
93+
@Override
94+
public String getNativeDatatypeQuery(String tableName, String columnName) {
95+
return "SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS COLS " +
96+
"WHERE COLS.TABLE_NAME = '" + tableName + "'" +
97+
"AND COLS.COLUMN_NAME= '" + columnName + "'";
98+
}
99+
100+
@Override
101+
public String getExpectedNativeDatatype(Class<?> dataType) {
102+
return expectedDBTypeForClass.get( dataType );
103+
}
104+
105+
@Override
106+
public String createJdbcUrl(String host, int port, String database, Map<String, String> params) {
107+
return getRegularJdbcUrl();
108+
}
109+
110+
@Override
111+
public String jdbcStartQuery() {
112+
return ";";
113+
}
114+
115+
@Override
116+
public String jdbcParamDelimiter() {
117+
return ";";
118+
}
119+
120+
private H2Database() {
121+
}
122+
}

0 commit comments

Comments
 (0)