From 641a7ddb4b04b672b9a44ed09a16d926491e0064 Mon Sep 17 00:00:00 2001 From: marko-bekhta Date: Wed, 3 Jan 2024 17:51:21 +0100 Subject: [PATCH] Provide a way to override global env properties in a test ConnectionProviderBuilder --- .../testing/env/ConnectionProviderBuilder.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java b/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java index 7f3ddb1949..ba3859717a 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java @@ -12,6 +12,7 @@ import java.lang.reflect.Proxy; import java.sql.Connection; import java.sql.SQLException; import java.util.Collections; +import java.util.Map; import java.util.Properties; import javax.sql.DataSource; @@ -26,7 +27,6 @@ import org.hibernate.internal.util.ReflectHelper; import org.hibernate.testing.DialectCheck; import org.hibernate.testing.jdbc.ConnectionProviderDelegate; -import org.hibernate.testing.jdbc.SharedDriverManagerConnectionProviderImpl; import org.hibernate.testing.util.ServiceRegistryUtil; /** @@ -46,7 +46,14 @@ public class ConnectionProviderBuilder implements DialectCheck { public static final String PASS = ""; public static Properties getConnectionProviderProperties(String dbName) { + return getConnectionProviderProperties( dbName, Collections.emptyMap() ); + } + + public static Properties getConnectionProviderProperties(String dbName, Map environmentOverrides) { final Properties globalProperties = Environment.getProperties(); + // since returned global properties are a copy, we just add our overrides to them: + globalProperties.putAll( environmentOverrides ); + assert globalProperties.getProperty( Environment.URL ).startsWith( "jdbc:h2:" ) : "Connection provider properties are only usable when running against H2"; final Properties props = new Properties( null ); @@ -95,6 +102,10 @@ public class ConnectionProviderBuilder implements DialectCheck { return buildConnectionProvider( getConnectionProviderProperties( dbName ), false ); } + public static ConnectionProvider buildConnectionProvider(String dbName, Map environmentOverrides) { + return buildConnectionProvider( getConnectionProviderProperties( dbName, environmentOverrides ), false ); + } + public static ConnectionProvider buildDataSourceConnectionProvider(String dbName) { final Properties globalProperties = Environment.getProperties(); assert globalProperties.getProperty( Environment.URL ).startsWith( "jdbc:h2:" )