All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.boot.registry.selector.spi.StrategySelector Maven / Gradle / Ivy

There is a newer version: 7.0.0.Alpha1
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.boot.registry.selector.spi;

import java.util.Collection;
import java.util.concurrent.Callable;

import org.hibernate.service.Service;

/**
 * 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 * {@link #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 {@link org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder} implementation to use. To use the * JDBC-based TransactionCoordinatorBuilder the passed name might be either {@code "jdbc"} or * {@code "org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl"} (which is the FQN). *

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

* The service also exposes a general typing API via {@link #resolveStrategy} and {@link #resolveDefaultableStrategy} * which accept implementation references rather than implementation names, allowing for a multitude of interpretations * of said "implementation reference". See the docs for {@link #resolveDefaultableStrategy} for details. * * @author Steve Ebersole */ public interface StrategySelector extends Service { /** * Registers a named implementor of a particular strategy contract. * * @param strategy The strategy contract. * @param name The registration name * @param implementation The implementation Class * @param The type of the strategy. Used to make sure that the strategy and implementation are type * compatible. */ void registerStrategyImplementor(Class strategy, String name, Class 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. * * @param strategy The strategy contract. * @param implementation The implementation Class * @param The type of the strategy. Used to make sure that the strategy and implementation are type * compatible. */ void unRegisterStrategyImplementor(Class strategy, Class implementation); /** * Locate the named strategy implementation. * * @param strategy The type of strategy to be resolved. * @param name The name of the strategy to locate; might be either a registered name or the implementation FQN. * @param The type of the strategy. Used to make sure that the strategy and implementation are type * compatible. * * @return The named strategy implementation class. */ Class selectStrategyImplementor(Class strategy, String name); /** * Resolve strategy instances. See discussion on {@link #resolveDefaultableStrategy}. * Only difference is that here, the implied default value is {@code null}. * * @param strategy The type (interface) of the strategy to be resolved. * @param strategyReference The reference to the strategy for which we need to resolve an instance. * @param The type of the strategy. Used to make sure that the strategy and implementation are type * compatible. * * @return The strategy instance */ T resolveStrategy(Class strategy, Object strategyReference); /** * Resolve strategy instances. The incoming reference might be:

    *
  • * {@code null} - in which case defaultValue is returned. *
  • *
  • * An actual instance of the strategy type - it is returned, as is *
  • *
  • * A reference to the implementation {@link Class} - an instance is created by calling * {@link Class#newInstance()} (aka, the class's no-arg ctor). *
  • *
  • * The name of the implementation class - First the implementation's {@link Class} reference * is resolved, and then an instance is created by calling {@link Class#newInstance()} *
  • *
* * @param strategy The type (interface) of the strategy to be resolved. * @param strategyReference The reference to the strategy for which we need to resolve an instance. * @param defaultValue THe default value to use if strategyReference is null * @param The type of the strategy. Used to make sure that the strategy and implementation are type * compatible. * * @return The strategy instance */ T resolveDefaultableStrategy(Class strategy, Object strategyReference, T defaultValue); /** * Resolve strategy instances. The incoming reference might be:
    *
  • * {@code null} - in which case defaultValue is returned. *
  • *
  • * An actual instance of the strategy type - it is returned, as is *
  • *
  • * A reference to the implementation {@link Class} - an instance is created by calling * {@link Class#newInstance()} (aka, the class's no-arg ctor). *
  • *
  • * The name of the implementation class - First the implementation's {@link Class} reference * is resolved, and then an instance is created by calling {@link Class#newInstance()} *
  • *
* * @param strategy The type (interface) of the strategy to be resolved. * @param strategyReference The reference to the strategy for which we need to resolve an instance. * @param defaultResolver A strategy for resolving the default value strategyReference resolves to null. * @param The type of the strategy. Used to make sure that the strategy and implementation are type * compatible. * * @return The strategy instance */ T resolveDefaultableStrategy(Class strategy, Object strategyReference, Callable defaultResolver); T resolveStrategy(Class strategy, Object strategyReference, Callable defaultResolver, StrategyCreator creator); T resolveStrategy(Class strategy, Object strategyReference, T defaultValue, StrategyCreator creator); /** * 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 * * @return The implementors. Should never return {@code null} */ Collection> getRegisteredStrategyImplementors(Class strategy); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy