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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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