Interface DataSourceProvider

All Known Subinterfaces:
Tenant
All Known Implementing Classes:
AbstractTenant, MasterTenant, MockTenant, SlaveTenant, TestSlaveTenantStub, TestTenantStub

public interface DataSourceProvider
Abstraction for tenant to provide access to data source(s).

( This interface has been created for code clarification only - don't use it elsewhere ! )

  • Method Details

    • getDataSource

      HybrisDataSource getDataSource(String className)
      Returns new data source. (experimental (related to PLA-7861))
    • getMasterDataSource

      HybrisDataSource getMasterDataSource()
      Returns master data source no matter which one is currently active.
    • getDataSource

      HybrisDataSource getDataSource()
      Returns currently active data source.
    • isSlaveDataSource

      boolean isSlaveDataSource()
      Tells whether current data source is a slave data source.
      Returns:
      true if the DataSourceProvider is a slave data source
    • isAlternativeMasterDataSource

      boolean isAlternativeMasterDataSource()
      Tells whether the current active data source is a alternative master data source.
    • isForceMaster

      boolean isForceMaster()
      If on the current data source (slave/master) the method forceMasterDataSource() was called then this method returns true. A deactivateAlternativeDataSource() will reset this state.
      Returns:
      true if the master data source is forced
    • activateSlaveDataSource

      String activateSlaveDataSource()
      Switches to a slave data source for the current thread. If the current data source is already a slave one this has no effect. Use as follows:
       Tenant t = Registry.getCurrentTenant();
       try
       {
              t.activateSlaveDataSource();
              // ... business logic ...
       }
       finally
       {
              t.deactivateSlaveSource();
       }
       
      See Also:
    • activateSlaveDataSource

      void activateSlaveDataSource(String id)
      Switches to a specified (by the id) slave data source for the current thread. If the current data source is already a slave one this has no effect. Use as follows:
       Tenant t = Registry.getCurrentTenant();
       try
       {
              t.activateSlaveDataSource("your_slave_id");
              // ... business logic ...
       }
       finally
       {
              t.deactivateSlaveSource();
       }
       
      Parameters:
      id - the id string of the slave data source
      Throws:
      IllegalArgumentException - if the given id is not configured
      IllegalStateException - if the given id was found but cannot connect to given slave data source
      See Also:
    • activateAlternativeMasterDataSource

      void activateAlternativeMasterDataSource(String id)
      Switches to a specified (by the id) master data source for the current thread. Use as follows:
       Tenant t = Registry.getCurrentTenant();
       try
       {
              t.activateMasterDataSource("your_slave_id");
              // ... business logic ...
       }
       finally
       {
              t.deactivateSlaveSource();
       }
       
      Parameters:
      id - the id string of the slave data source
      Throws:
      IllegalArgumentException - if the given id is not configured
      IllegalStateException - if the given id was found but cannot connect to given slave data source
      See Also:
    • getAllSlaveDataSources

      Collection<HybrisDataSource> getAllSlaveDataSources()
      Returns all known slave data sources as Collection.
      Returns:
      a Set with HybrisDataSource objects
    • getAllAlternativeMasterDataSources

      Collection<HybrisDataSource> getAllAlternativeMasterDataSources()
      Returns all known alternative master data sources as Collection.
      Returns:
      a Set with HybrisDataSource objects
    • getAllDataSourceIDs

      @Deprecated(since="ages", forRemoval=true) Set<String> getAllDataSourceIDs()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getAllSlaveDataSourceIDs

      Set<String> getAllSlaveDataSourceIDs()
      Provides IDs of all available slave data sources.
    • getAllAlternativeMasterDataSourceIDs

      Set<String> getAllAlternativeMasterDataSourceIDs()
      Provides IDs of all available alternative master data sources.
    • deactivateSlaveDataSource

      @Deprecated(since="ages", forRemoval=true) void deactivateSlaveDataSource()
      Deprecated, for removal: This API element is subject to removal in a future version.
      After slave data source has been activated for the current thread it's necessary to de-activate it again! After this the master data source is active (again).
      See Also:
    • deactivateAlternativeDataSource

      void deactivateAlternativeDataSource()
      After a alternative slave or master data source has been activated for the current thread it's necessary to de-activate it again! After this the base master data source is active (again).
      See Also:
    • forceMasterDataSource

      void forceMasterDataSource()
      Enforces the usage of a master data source for all subsequent calls to getDataSource() no matter if a slave data source has been activated or not.

      Please note that this does not affect chosen alternative master data sources. If you want to switch back to the main master data source use deactivateAlternativeDataSource().