Skip to content

Commit

Permalink
HSEARCH-5281 Do not use hibernate.dialect in test configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Dec 3, 2024
1 parent 74f2c45 commit 37ff4d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@

class OutboxPollingCustomEntityMappingIT {

private static final String POSTGRESQL_DIALECT = "org.hibernate.dialect.PostgreSQLDialect";
private static final String MSSQL_DIALECT = "org.hibernate.dialect.SQLServerDialect";

private static final String CUSTOM_SCHEMA = "CUSTOM_SCHEMA";
private static final String ORIGINAL_OUTBOX_EVENT_TABLE_NAME =
HibernateOrmMapperOutboxPollingSettings.Defaults.COORDINATION_ENTITY_MAPPING_OUTBOX_EVENT_TABLE;
Expand Down Expand Up @@ -417,18 +414,14 @@ void defaultUuidDataType() {
JdbcType agent = idJdbcType( sessionFactory, Agent.class );
JdbcType event = idJdbcType( sessionFactory, OutboxEvent.class );

String dialect = DatabaseContainer.configuration().dialect();

switch ( dialect ) {
case POSTGRESQL_DIALECT:
case MSSQL_DIALECT:
assertThat( agent.getDdlTypeCode() ).isEqualTo( SqlTypes.UUID );
assertThat( event.getDdlTypeCode() ).isEqualTo( SqlTypes.UUID );
break;
default:
assertThat( agent.getDdlTypeCode() ).isIn( SqlTypes.UUID, SqlTypes.BINARY, SqlTypes.CHAR );
assertThat( event.getDdlTypeCode() ).isIn( SqlTypes.UUID, SqlTypes.BINARY, SqlTypes.CHAR );
break;
if ( DatabaseContainer.configuration().is( DatabaseContainer.SupportedDatabase.POSTGRES,
DatabaseContainer.SupportedDatabase.MSSQL ) ) {
assertThat( agent.getDdlTypeCode() ).isEqualTo( SqlTypes.UUID );
assertThat( event.getDdlTypeCode() ).isEqualTo( SqlTypes.UUID );
}
else {
assertThat( agent.getDdlTypeCode() ).isIn( SqlTypes.UUID, SqlTypes.BINARY, SqlTypes.CHAR );
assertThat( event.getDdlTypeCode() ).isIn( SqlTypes.UUID, SqlTypes.BINARY, SqlTypes.CHAR );
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
spring.jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
hibernate.search:
backend:
directory.root: ${LUCENE_ROOT_PATH:target/test-indexes}/${random.uuid}
Expand All @@ -10,4 +8,4 @@ spring.datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1
username: sa
password: sa
password: sa
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ public static Configuration configuration() {
// Let's see if an external DB connection was provided:
String url = System.getProperty( "jdbc.url" );
if ( url != null && !url.trim().isEmpty() ) {
// -Dhibernate.dialect=${db.dialect}
// -Dhibernate.connection.driver_class=${jdbc.driver}
// -Dhibernate.connection.url=${jdbc.url}
// -Dhibernate.connection.username=${jdbc.user}
// -Dhibernate.connection.password=${jdbc.pass}
// -Dhibernate.connection.isolation=${jdbc.isolation}
return DATABASE.configuration( url, DATABASE_CONTAINER )
.withDialect( System.getProperty( "db.dialect" ) )
.withDriver( System.getProperty( "jdbc.driver" ) )
.withUser( System.getProperty( "jdbc.user" ) )
.withPass( System.getProperty( "jdbc.pass" ) )
Expand Down Expand Up @@ -97,7 +95,7 @@ String dialect() {
@Override
Configuration configuration(JdbcDatabaseContainer<?> container) {
return new Configuration(
dialect(),
this,
"org.h2.Driver",
"jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1",
"sa",
Expand Down Expand Up @@ -317,7 +315,7 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {

Configuration configuration(JdbcDatabaseContainer<?> container) {
return new Configuration(
dialect(),
this,
container.getDriverClassName(),
container.getJdbcUrl(),
container.getUsername(),
Expand All @@ -328,7 +326,7 @@ Configuration configuration(JdbcDatabaseContainer<?> container) {

Configuration configuration(String jdbcUrl, JdbcDatabaseContainer<?> container) {
return new Configuration(
dialect(),
this,
container.getDriverClassName(),
jdbcUrl,
container.getUsername(),
Expand Down Expand Up @@ -439,26 +437,23 @@ protected String getTestQueryString() {


public static class Configuration {
private final String dialect;
private final DatabaseContainer.SupportedDatabase database;
private final String driver;
private final String url;
private final String user;
private final String pass;
private final String isolation;

private Configuration(String dialect, String driver, String url, String user, String pass, String isolation) {
this.dialect = dialect;
private Configuration(DatabaseContainer.SupportedDatabase database, String driver, String url, String user, String pass,
String isolation) {
this.database = database;
this.driver = driver;
this.url = url;
this.user = user;
this.pass = pass;
this.isolation = isolation;
}

public String dialect() {
return dialect;
}

public String driver() {
return driver;
}
Expand All @@ -480,12 +475,12 @@ public String isolation() {
}

public boolean is(DatabaseContainer.SupportedDatabase database) {
return database.dialect().equals( dialect );
return this.database.equals( database );
}

public boolean is(DatabaseContainer.SupportedDatabase... databases) {
for ( SupportedDatabase database : databases ) {
if ( database.dialect().equals( dialect ) ) {
if ( this.database.equals( database ) ) {
return true;
}
}
Expand All @@ -494,7 +489,6 @@ public boolean is(DatabaseContainer.SupportedDatabase... databases) {

@SuppressWarnings("deprecation") // since DialectContext is using the deprecated properties we cannot switch to JAKARTA_* for now...
public void add(Map<String, Object> map) {
map.put( JdbcSettings.DIALECT, this.dialect );
map.put( JdbcSettings.DRIVER, this.driver );
map.put( JdbcSettings.URL, this.url );
map.put( JdbcSettings.USER, this.user );
Expand All @@ -509,46 +503,39 @@ public void addAsSpring(BiConsumer<String, String> consumer) {
consumer.accept( "spring.datasource.password", this.pass );
}

private Configuration withDialect(String dialect) {
if ( dialect == null ) {
return this;
}
return new Configuration( dialect, driver, url, user, pass, isolation );
}

private Configuration withDriver(String driver) {
if ( driver == null ) {
return this;
}
return new Configuration( dialect, driver, url, user, pass, isolation );
return new Configuration( database, driver, url, user, pass, isolation );
}

private Configuration withUrl(String url) {
if ( url == null ) {
return this;
}
return new Configuration( dialect, driver, url, user, pass, isolation );
return new Configuration( database, driver, url, user, pass, isolation );
}

private Configuration withUser(String user) {
if ( user == null ) {
return this;
}
return new Configuration( dialect, driver, url, user, pass, isolation );
return new Configuration( database, driver, url, user, pass, isolation );
}

private Configuration withPass(String pass) {
if ( pass == null ) {
return this;
}
return new Configuration( dialect, driver, url, user, pass, isolation );
return new Configuration( database, driver, url, user, pass, isolation );
}

private Configuration withIsolation(String isolation) {
if ( isolation == null ) {
return this;
}
return new Configuration( dialect, driver, url, user, pass, isolation );
return new Configuration( database, driver, url, user, pass, isolation );
}
}
}

0 comments on commit 37ff4d1

Please sign in to comment.