Top Description Methods
org.hibernate.boot.registry.selector.spi

public Interface StrategySelector

extends Service
Known Direct Implementers
org.hibernate.boot.registry.selector.internal.StrategySelectorImpl
Imports
java.util.Collection, java.util.concurrent.Callable, org.hibernate.service.Service, org.checkerframework.checker.nullness.qual.Nullable

Service which acts as a registry for named strategy implementations.

Strategies are more open-ended than services, though a strategy managed here might very well also be a service. The strategy is any interface that has multiple, (possibly short) named implementations.

StrategySelector manages resolution of particular implementation by (possibly short) name via the selectStrategyImplementor method, which is the main contract here. As indicated in the docs of that method the given name might be either a short registered name or the implementation FQN. As an example, consider resolving the org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder implementation to use. To use the JDBC-based TransactionCoordinatorBuilder the passed name might be either "jdbc" or "org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl".

Strategy implementations can be managed by registerStrategyImplementor and unRegisterStrategyImplementor. Originally designed to help the OSGi use case, though no longer used there.

The service also exposes a general typing API via resolveStrategy and resolveDefaultableStrategy which accept implementation references rather than implementation names, allowing for a multitude of interpretations of said "implementation reference". See the docs for resolveDefaultableStrategy for details.

Author
Steve Ebersole

Method Summary

Modifier and TypeMethod and Description
public <T> Collection<Class<? extends T>>

Returns:

The implementors. Should never return null
getRegisteredStrategyImplementors
(Class<T> strategy)

Retrieve all of the registered implementors of the given strategy.

public <
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
T
>
void
registerStrategyImplementor(Class<T>
The strategy contract.
strategy
,
String
The registration name
name
,
Class<? extends T>
The implementation Class
implementation
)

Registers a named implementor of a particular strategy contract.

public <
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
T
>
T

Returns:

The strategy instance
resolveDefaultableStrategy
(Class<T>
The type (interface) of the strategy to be resolved.
strategy
,
Object
The reference to the strategy for which we need to resolve an instance.
strategyReference
,
T
THe default value to use if strategyReference is null
defaultValue
)

Resolve strategy instances.

public <
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
T
>
T

Returns:

The strategy instance
resolveDefaultableStrategy
(Class<T>
The type (interface) of the strategy to be resolved.
strategy
,
Object
The reference to the strategy for which we need to resolve an instance.
strategyReference
,
Callable<T>
A strategy for resolving the default value strategyReference resolves to null.
defaultResolver
)

Resolve strategy instances.

public <
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
T
>
T

Returns:

The strategy instance
resolveStrategy
(Class<T>
The type (interface) of the strategy to be resolved.
strategy
,
@Nullable Object
The reference to the strategy for which we need to resolve an instance.
strategyReference
)

Resolve strategy instances.

public <T> T
resolveStrategy(Class<T> strategy, Object strategyReference, Callable<T> defaultResolver, StrategyCreator<T> creator)

public <T> T
resolveStrategy(Class<T> strategy, Object strategyReference, T defaultValue, StrategyCreator<T> creator)

public <
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
T
>
Class<? extends T>

Returns:

The named strategy implementation class.
selectStrategyImplementor
(Class<T>
The type of strategy to be resolved.
strategy
,
String
The name of the strategy to locate; might be either a registered name or the implementation FQN.
name
)

Locate the named strategy implementation.

public <
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
T
>
void
unRegisterStrategyImplementor(Class<T>
The strategy contract.
strategy
,
Class<? extends T>
The implementation Class
implementation
)

Un-registers a named implementor of a particular strategy contract.

Method Detail

getRegisteredStrategyImplementorsback to summary
public <T> Collection<Class<? extends T>> getRegisteredStrategyImplementors(Class<T> strategy)

Retrieve all of the registered implementors of the given strategy. Useful to allow defaulting the choice to the single registered implementor when only one is registered

Returns:Collection<Class<? extends T>>

The implementors. Should never return null

registerStrategyImplementorback to summary
public <T> void registerStrategyImplementor(Class<T> strategy, String name, Class<? extends T> implementation)

Registers a named implementor of a particular strategy contract.

Parameters
<T>
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
strategy:Class<T>

The strategy contract.

name:String

The registration name

implementation:Class<? extends T>

The implementation Class

resolveDefaultableStrategyback to summary
public <T> T resolveDefaultableStrategy(Class<T> strategy, Object strategyReference, T defaultValue)

Resolve strategy instances. The incoming reference might be:

  • null - in which case defaultValue is returned.
  • An actual instance of the strategy type - it is returned, as is
  • A reference to the implementation Class - an instance is created by calling Class#newInstance() (aka, the class's no-arg ctor).
  • The name of the implementation class - First the implementation's Class reference is resolved, and then an instance is created by calling Class#newInstance()
Parameters
<T>
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
strategy:Class<T>

The type (interface) of the strategy to be resolved.

strategyReference:Object

The reference to the strategy for which we need to resolve an instance.

defaultValue:T

THe default value to use if strategyReference is null

Returns:T

The strategy instance

resolveDefaultableStrategyback to summary
public <T> T resolveDefaultableStrategy(Class<T> strategy, Object strategyReference, Callable<T> defaultResolver)

Resolve strategy instances. The incoming reference might be:

  • null - in which case defaultValue is returned.
  • An actual instance of the strategy type - it is returned, as is
  • A reference to the implementation Class - an instance is created by calling Class#newInstance() (aka, the class's no-arg ctor).
  • The name of the implementation class - First the implementation's Class reference is resolved, and then an instance is created by calling Class#newInstance()
Parameters
<T>
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
strategy:Class<T>

The type (interface) of the strategy to be resolved.

strategyReference:Object

The reference to the strategy for which we need to resolve an instance.

defaultResolver:Callable<T>

A strategy for resolving the default value strategyReference resolves to null.

Returns:T

The strategy instance

resolveStrategyback to summary
public <T> T resolveStrategy(Class<T> strategy, @Nullable Object strategyReference)

Resolve strategy instances. See discussion on resolveDefaultableStrategy. Only difference is that here, the implied default value is null.

Parameters
<T>
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
strategy:Class<T>

The type (interface) of the strategy to be resolved.

strategyReference:@Nullable Object

The reference to the strategy for which we need to resolve an instance.

Returns:T

The strategy instance

resolveStrategyback to summary
public <T> T resolveStrategy(Class<T> strategy, Object strategyReference, Callable<T> defaultResolver, StrategyCreator<T> creator)
resolveStrategyback to summary
public <T> T resolveStrategy(Class<T> strategy, Object strategyReference, T defaultValue, StrategyCreator<T> creator)
selectStrategyImplementorback to summary
public <T> Class<? extends T> selectStrategyImplementor(Class<T> strategy, String name)

Locate the named strategy implementation.

Parameters
<T>
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
strategy:Class<T>

The type of strategy to be resolved.

name:String

The name of the strategy to locate; might be either a registered name or the implementation FQN.

Returns:Class<? extends T>

The named strategy implementation class.

unRegisterStrategyImplementorback to summary
public <T> void unRegisterStrategyImplementor(Class<T> strategy, Class<? extends T> implementation)

Un-registers a named implementor of a particular strategy contract. Un-registers all named registrations for the given strategy contract naming the given class.

Parameters
<T>
The type of the strategy. Used to make sure that the strategy and implementation are type compatible.
strategy:Class<T>

The strategy contract.

implementation:Class<? extends T>

The implementation Class