3333import io .agroal .api .security .NamePrincipal ;
3434import io .agroal .api .security .SimplePassword ;
3535
36+ import static java .util .stream .Collectors .toMap ;
3637import static org .hibernate .cfg .AgroalSettings .AGROAL_CONFIG_PREFIX ;
3738import static org .hibernate .engine .jdbc .env .internal .JdbcEnvironmentInitiator .allowJdbcMetadataAccess ;
3839
@@ -68,7 +69,7 @@ public class AgroalConnectionProvider implements ConnectionProvider, Configurabl
6869 // --- Configurable
6970
7071 private static String extractIsolationAsString (Map <String , Object > properties ) {
71- Integer isolation = ConnectionProviderInitiator .extractIsolation ( properties );
72+ final Integer isolation = ConnectionProviderInitiator .extractIsolation ( properties );
7273 if ( isolation != null ) {
7374 // Agroal resolves transaction isolation from the 'nice' name
7475 return ConnectionProviderInitiator .toIsolationNiceName ( isolation );
@@ -77,34 +78,34 @@ private static String extractIsolationAsString(Map<String, Object> properties) {
7778 }
7879
7980 private static void resolveIsolationSetting (Map <String , Object > properties , AgroalConnectionFactoryConfigurationSupplier cf ) {
80- String isolationString = extractIsolationAsString ( properties );
81+ final String isolationString = extractIsolationAsString ( properties );
8182 if ( isolationString != null ) {
8283 cf .jdbcTransactionIsolation ( AgroalConnectionFactoryConfiguration .TransactionIsolation .valueOf ( isolationString ) );
8384 }
8485 }
8586
8687 private static <T > void copyProperty (Map <String , Object > properties , String key , Consumer <T > consumer , Function <String , T > converter ) {
87- Object value = properties .get ( key );
88- if ( value instanceof String ) {
89- consumer .accept ( converter .apply ( ( String ) value ) );
88+ final Object value = properties .get ( key );
89+ if ( value instanceof String string ) {
90+ consumer .accept ( converter .apply ( string ) );
9091 }
9192 }
9293
9394 @ Override
94- public void configure (Map <String , Object > props ) throws HibernateException {
95- isMetadataAccessAllowed = allowJdbcMetadataAccess ( props );
95+ public void configure (Map <String , Object > properties ) throws HibernateException {
96+ isMetadataAccessAllowed = allowJdbcMetadataAccess ( properties );
9697
9798 ConnectionInfoLogger .INSTANCE .configureConnectionPool ( "Agroal" );
9899 try {
99- AgroalPropertiesReader agroalProperties = new AgroalPropertiesReader ( CONFIG_PREFIX )
100- .readProperties ( ( Map ) props ); //TODO: this is a garbage cast
100+ final AgroalPropertiesReader agroalProperties = new AgroalPropertiesReader ( CONFIG_PREFIX )
101+ .readProperties ( toStringValuedProperties ( properties ) );
101102 agroalProperties .modify ().connectionPoolConfiguration ( cp -> cp .connectionFactoryConfiguration ( cf -> {
102- copyProperty ( props , AvailableSettings .DRIVER , cf ::connectionProviderClassName , Function .identity () );
103- copyProperty ( props , AvailableSettings .URL , cf ::jdbcUrl , Function .identity () );
104- copyProperty ( props , AvailableSettings .USER , cf ::principal , NamePrincipal ::new );
105- copyProperty ( props , AvailableSettings .PASS , cf ::credential , SimplePassword ::new );
106- copyProperty ( props , AvailableSettings .AUTOCOMMIT , cf ::autoCommit , Boolean ::valueOf );
107- resolveIsolationSetting ( props , cf );
103+ copyProperty ( properties , AvailableSettings .DRIVER , cf ::connectionProviderClassName , Function .identity () );
104+ copyProperty ( properties , AvailableSettings .URL , cf ::jdbcUrl , Function .identity () );
105+ copyProperty ( properties , AvailableSettings .USER , cf ::principal , NamePrincipal ::new );
106+ copyProperty ( properties , AvailableSettings .PASS , cf ::credential , SimplePassword ::new );
107+ copyProperty ( properties , AvailableSettings .AUTOCOMMIT , cf ::autoCommit , Boolean ::valueOf );
108+ resolveIsolationSetting ( properties , cf );
108109 return cf ;
109110 } ) );
110111
@@ -116,6 +117,11 @@ public void configure(Map<String, Object> props) throws HibernateException {
116117 }
117118 }
118119
120+ private static Map <String ,String > toStringValuedProperties (Map <String ,Object > properties ) {
121+ return properties .entrySet ().stream ()
122+ .collect ( toMap ( Map .Entry ::getKey , e -> e .getValue ().toString () ) );
123+ }
124+
119125 // --- ConnectionProvider
120126
121127 @ Override
0 commit comments