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,36 +6,32 @@
*/
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 {
private static final List<StrategyRegistration> REGISTRATIONS = Collections.singletonList(
new SimpleStrategyRegistrationImpl<>(
ConnectionProvider.class,
AgroalConnectionProvider.class,
AgroalConnectionProvider.class.getSimpleName(),
"agroal",
"Agroal",
// for consistency's sake
"org.hibernate.connection.AgroalConnectionProvider"
)
);
public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return REGISTRATIONS;
final SimpleStrategyRegistrationImpl<ConnectionProvider> strategyRegistration = new SimpleStrategyRegistrationImpl<>(
ConnectionProvider.class,
AgroalConnectionProvider.class,
AgroalConnectionProvider.class.getSimpleName(),
"agroal",
"Agroal",
// for consistency's sake
"org.hibernate.connection.AgroalConnectionProvider"
);
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,23 +19,21 @@ 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>(
ConnectionProvider.class,
C3P0ConnectionProvider.class,
"c3p0",
C3P0ConnectionProvider.class.getSimpleName(),
// legacy
"org.hibernate.connection.C3P0ConnectionProvider",
// legacy
"org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider"
)
);
public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return REGISTRATIONS;
final SimpleStrategyRegistrationImpl<ConnectionProvider> c3p0 = new SimpleStrategyRegistrationImpl<>(
ConnectionProvider.class,
C3P0ConnectionProvider.class,
"c3p0",
C3P0ConnectionProvider.class.getSimpleName(),
// legacy
"org.hibernate.connection.C3P0ConnectionProvider",
// legacy
"org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider"
);
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,22 +20,20 @@ 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>(
ConnectionProvider.class,
HikariCPConnectionProvider.class,
"hikari",
"hikaricp",
HikariCPConnectionProvider.class.getSimpleName(),
// for consistency's sake
"org.hibernate.connection.HikariCPConnectionProvider"
)
);
public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return REGISTRATIONS;
final SimpleStrategyRegistrationImpl<ConnectionProvider> strategyRegistration = new SimpleStrategyRegistrationImpl<>(
ConnectionProvider.class,
HikariCPConnectionProvider.class,
"hikari",
"hikaricp",
HikariCPConnectionProvider.class.getSimpleName(),
// for consistency's sake
"org.hibernate.connection.HikariCPConnectionProvider"
);
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,24 +21,21 @@ 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(
RegionFactory.class,
JCacheRegionFactory.class,
ConfigSettings.SIMPLE_FACTORY_NAME,
JCacheRegionFactory.class.getName(),
JCacheRegionFactory.class.getSimpleName(),
// legacy impl class name
"org.hibernate.cache.jcache.JCacheRegionFactory"
)
final SimpleStrategyRegistrationImpl simpleStrategyRegistration = new SimpleStrategyRegistrationImpl(
RegionFactory.class,
JCacheRegionFactory.class,
ConfigSettings.SIMPLE_FACTORY_NAME,
JCacheRegionFactory.class.getName(),
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,23 +19,21 @@ 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>(
ConnectionProvider.class,
ProxoolConnectionProvider.class,
"proxool",
ProxoolConnectionProvider.class.getSimpleName(),
// legacy
"org.hibernate.connection.ProxoolConnectionProvider",
// legacy
"org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider"
)
);
public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return REGISTRATIONS;
return Collections.singletonList(
new SimpleStrategyRegistrationImpl<ConnectionProvider>(
ConnectionProvider.class,
ProxoolConnectionProvider.class,
"proxool",
ProxoolConnectionProvider.class.getSimpleName(),
// legacy
"org.hibernate.connection.ProxoolConnectionProvider",
// legacy
"org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider"
) );
}
}

View File

@ -7,38 +7,35 @@
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<>(
ConnectionProvider.class,
ViburDBCPConnectionProvider.class,
"vibur",
"viburdbcp",
ViburDBCPConnectionProvider.class.getSimpleName(),
// for backward compatibility with pre-existing Vibur project Hibernate integration artifacts
"org.vibur.dbcp.integration.ViburDBCPConnectionProvider",
// for consistency's sake
"org.hibernate.connection.ViburDBCPConnectionProvider"
)
);
public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return REGISTRATIONS;
return Collections.singletonList(
new SimpleStrategyRegistrationImpl<>(
ConnectionProvider.class,
ViburDBCPConnectionProvider.class,
"vibur",
"viburdbcp",
ViburDBCPConnectionProvider.class.getSimpleName(),
// for backward compatibility with pre-existing Vibur project Hibernate integration artifacts
"org.vibur.dbcp.integration.ViburDBCPConnectionProvider",
// for consistency's sake
"org.hibernate.connection.ViburDBCPConnectionProvider"
) );
}
}