HHH-13029 Avoid static singletons to hold on Strategy Registration Implementations

This commit is contained in:
Sanne Grinovero 2018-10-12 16:54:15 +01:00
parent e3ae85f8c1
commit fcd3b56fdd
8 changed files with 80 additions and 98 deletions

View File

@ -6,24 +6,24 @@
*/ */
package org.hibernate.agroal.internal; package org.hibernate.agroal.internal;
import java.util.Collections;
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl; import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
import org.hibernate.boot.registry.selector.StrategyRegistration; import org.hibernate.boot.registry.selector.StrategyRegistration;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import java.util.Collections;
import java.util.List;
/** /**
* Provides the {@link AgroalConnectionProvider} to the * Provides the {@link AgroalConnectionProvider} to the
* {@link org.hibernate.boot.registry.selector.spi.StrategySelector} service. * {@link org.hibernate.boot.registry.selector.spi.StrategySelector} service.
* *
* @author Luis Barreiro * @author Luis Barreiro
*/ */
public class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider { public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
private static final List<StrategyRegistration> REGISTRATIONS = Collections.singletonList( @Override
new SimpleStrategyRegistrationImpl<>( public Iterable<StrategyRegistration> getStrategyRegistrations() {
final SimpleStrategyRegistrationImpl<ConnectionProvider> strategyRegistration = new SimpleStrategyRegistrationImpl<>(
ConnectionProvider.class, ConnectionProvider.class,
AgroalConnectionProvider.class, AgroalConnectionProvider.class,
AgroalConnectionProvider.class.getSimpleName(), AgroalConnectionProvider.class.getSimpleName(),
@ -31,11 +31,7 @@ public class StrategyRegistrationProviderImpl implements StrategyRegistrationPro
"Agroal", "Agroal",
// for consistency's sake // for consistency's sake
"org.hibernate.connection.AgroalConnectionProvider" "org.hibernate.connection.AgroalConnectionProvider"
)
); );
return Collections.singleton( strategyRegistration );
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return REGISTRATIONS;
} }
} }

View File

@ -7,7 +7,6 @@
package org.hibernate.c3p0.internal; package org.hibernate.c3p0.internal;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl; import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
import org.hibernate.boot.registry.selector.StrategyRegistration; import org.hibernate.boot.registry.selector.StrategyRegistration;
@ -20,9 +19,12 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
* *
* @author Brett Meyer * @author Brett Meyer
*/ */
public class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider { public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
private static final List<StrategyRegistration> REGISTRATIONS = Collections.singletonList(
(StrategyRegistration) new SimpleStrategyRegistrationImpl<ConnectionProvider>( @Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
final SimpleStrategyRegistrationImpl<ConnectionProvider> c3p0 = new SimpleStrategyRegistrationImpl<>(
ConnectionProvider.class, ConnectionProvider.class,
C3P0ConnectionProvider.class, C3P0ConnectionProvider.class,
"c3p0", "c3p0",
@ -31,12 +33,7 @@ public class StrategyRegistrationProviderImpl implements StrategyRegistrationPro
"org.hibernate.connection.C3P0ConnectionProvider", "org.hibernate.connection.C3P0ConnectionProvider",
// legacy // legacy
"org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider" "org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider"
)
); );
return Collections.singleton( c3p0 );
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return REGISTRATIONS;
} }
} }

View File

@ -20,11 +20,12 @@ import org.hibernate.cache.spi.RegionFactory;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider { public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() { public Iterable<StrategyRegistration> getStrategyRegistrations() {
final List<StrategyRegistration> strategyRegistrations = new ArrayList<StrategyRegistration>(); final List<StrategyRegistration> strategyRegistrations = new ArrayList<StrategyRegistration>( 2 );
strategyRegistrations.add( strategyRegistrations.add(
new SimpleStrategyRegistrationImpl( new SimpleStrategyRegistrationImpl(

View File

@ -20,9 +20,12 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
* *
* @author Brett Meyer * @author Brett Meyer
*/ */
public class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider { public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
private static final List<StrategyRegistration> REGISTRATIONS = Collections.singletonList(
(StrategyRegistration) new SimpleStrategyRegistrationImpl<ConnectionProvider>( @Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
final SimpleStrategyRegistrationImpl<ConnectionProvider> strategyRegistration = new SimpleStrategyRegistrationImpl<>(
ConnectionProvider.class, ConnectionProvider.class,
HikariCPConnectionProvider.class, HikariCPConnectionProvider.class,
"hikari", "hikari",
@ -30,12 +33,7 @@ public class StrategyRegistrationProviderImpl implements StrategyRegistrationPro
HikariCPConnectionProvider.class.getSimpleName(), HikariCPConnectionProvider.class.getSimpleName(),
// for consistency's sake // for consistency's sake
"org.hibernate.connection.HikariCPConnectionProvider" "org.hibernate.connection.HikariCPConnectionProvider"
)
); );
return Collections.singleton( strategyRegistration );
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return REGISTRATIONS;
} }
} }

View File

@ -6,8 +6,7 @@
*/ */
package org.hibernate.cache.jcache.internal; package org.hibernate.cache.jcache.internal;
import java.util.ArrayList; import java.util.Collections;
import java.util.List;
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl; import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
import org.hibernate.boot.registry.selector.StrategyRegistration; import org.hibernate.boot.registry.selector.StrategyRegistration;
@ -22,14 +21,12 @@ import org.hibernate.cache.spi.RegionFactory;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider { public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() { public Iterable<StrategyRegistration> getStrategyRegistrations() {
final List<StrategyRegistration> strategyRegistrations = new ArrayList<StrategyRegistration>(); final SimpleStrategyRegistrationImpl simpleStrategyRegistration = new SimpleStrategyRegistrationImpl(
strategyRegistrations.add(
new SimpleStrategyRegistrationImpl(
RegionFactory.class, RegionFactory.class,
JCacheRegionFactory.class, JCacheRegionFactory.class,
ConfigSettings.SIMPLE_FACTORY_NAME, ConfigSettings.SIMPLE_FACTORY_NAME,
@ -37,9 +34,8 @@ public class StrategyRegistrationProviderImpl implements StrategyRegistrationPro
JCacheRegionFactory.class.getSimpleName(), JCacheRegionFactory.class.getSimpleName(),
// legacy impl class name // legacy impl class name
"org.hibernate.cache.jcache.JCacheRegionFactory" "org.hibernate.cache.jcache.JCacheRegionFactory"
)
); );
return strategyRegistrations; return Collections.singleton( simpleStrategyRegistration );
} }
} }

View File

@ -24,7 +24,7 @@ public class TestStrategyRegistrationProvider implements StrategyRegistrationPro
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() { public Iterable<StrategyRegistration> getStrategyRegistrations() {
return Collections.singletonList( return Collections.singletonList(
(StrategyRegistration) new SimpleStrategyRegistrationImpl( new SimpleStrategyRegistrationImpl(
Calendar.class, Calendar.class,
GregorianCalendar.class, GregorianCalendar.class,
GREGORIAN GREGORIAN

View File

@ -7,7 +7,6 @@
package org.hibernate.proxool.internal; package org.hibernate.proxool.internal;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl; import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
import org.hibernate.boot.registry.selector.StrategyRegistration; import org.hibernate.boot.registry.selector.StrategyRegistration;
@ -20,9 +19,13 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
* *
* @author Brett Meyer * @author Brett Meyer
*/ */
public class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider { public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
private static final List<StrategyRegistration> REGISTRATIONS = Collections.singletonList(
(StrategyRegistration) new SimpleStrategyRegistrationImpl<ConnectionProvider>( @Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return Collections.singletonList(
new SimpleStrategyRegistrationImpl<ConnectionProvider>(
ConnectionProvider.class, ConnectionProvider.class,
ProxoolConnectionProvider.class, ProxoolConnectionProvider.class,
"proxool", "proxool",
@ -31,12 +34,6 @@ public class StrategyRegistrationProviderImpl implements StrategyRegistrationPro
"org.hibernate.connection.ProxoolConnectionProvider", "org.hibernate.connection.ProxoolConnectionProvider",
// legacy // legacy
"org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider" "org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider"
) ) );
);
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return REGISTRATIONS;
} }
} }

View File

@ -7,23 +7,26 @@
package org.hibernate.vibur.internal; package org.hibernate.vibur.internal;
import java.util.Collections;
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl; import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
import org.hibernate.boot.registry.selector.StrategyRegistration; import org.hibernate.boot.registry.selector.StrategyRegistration;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import java.util.Collections;
import java.util.List;
/** /**
* Provides the {@link ViburDBCPConnectionProvider} to the * Provides the {@link ViburDBCPConnectionProvider} to the
* {@link org.hibernate.boot.registry.selector.spi.StrategySelector} service. * {@link org.hibernate.boot.registry.selector.spi.StrategySelector} service.
* *
* @author Simeon Malchev * @author Simeon Malchev
*/ */
public class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider { public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
private static final List<StrategyRegistration> REGISTRATIONS = Collections.singletonList(
(StrategyRegistration) new SimpleStrategyRegistrationImpl<>( @Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return Collections.singletonList(
new SimpleStrategyRegistrationImpl<>(
ConnectionProvider.class, ConnectionProvider.class,
ViburDBCPConnectionProvider.class, ViburDBCPConnectionProvider.class,
"vibur", "vibur",
@ -33,12 +36,6 @@ public class StrategyRegistrationProviderImpl implements StrategyRegistrationPro
"org.vibur.dbcp.integration.ViburDBCPConnectionProvider", "org.vibur.dbcp.integration.ViburDBCPConnectionProvider",
// for consistency's sake // for consistency's sake
"org.hibernate.connection.ViburDBCPConnectionProvider" "org.hibernate.connection.ViburDBCPConnectionProvider"
) ) );
);
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return REGISTRATIONS;
} }
} }