Package tigase.db.beans

## Class MDRepositoryBean<T extends DataSourceAware>

- java.lang.Object
- - tigase.db.beans.MDRepositoryBean<T>

- All Implemented Interfaces:
    `Initializable`, `RegistrarBean`, `RegistrarBeanWithDefaultBeanClass`, `UnregisterAware`
  Direct Known Subclasses:
    `MDRepositoryBeanWithStatistics`

      public abstract class MDRepositoryBean<T extends DataSourceAware>
      extends java.lang.Object
      implements Initializable, UnregisterAware, RegistrarBeanWithDefaultBeanClass

  Abstract class implementing bean to which should be used to create name aware repository pool. This class is responsible for creation of correct repository instances for every DataSource configured.
  Created by andrzej on 15.03.2016.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `MDRepositoryBean.MDRepositoryConfigBean<A extends DataSourceAware>` | MDRepositoryConfigBean is bean responsible for basic management and initialization of repository for domain.
    `static class` | `MDRepositoryBean.SelectorType` | Determines behaviour of MDRepositoryBean.

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​java.lang.String>` | `aliases` |
    `protected MDRepositoryBean.SelectorType` | `dataSourceSelection` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `MDRepositoryBean()` |

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `beforeUnregister()` | Method called before bean unregister.
    `protected abstract java.lang.Class<? extends T>` | `findClassForDataSource​(DataSource dataSource)` | Method returns class implementing repository which supports data source instance provided in parameter.
    `java.lang.String` | `getName()` | Returns name of a bean
    `protected java.util.Map<java.lang.String,​T>` | `getRepositories()` | Provides access to unmodifiable map domain to repository instance
    `protected T` | `getRepository​(java.lang.String domain)` | Provides repository instance for passed domain name
    `void` | `initialize()` | Method will be called, when bean will be created, configured and ready to use.
    `protected void` | `initializeRepository​(java.lang.String domain, T repo)` | Method called to initialized passed repository instance for passed domain.
    `protected void` | `onDataSourceChange​(DataSourceBean.DataSourceChangedEvent event)` |
    `void` | `register​(Kernel kernel)` | Method called when bean is being registered allowing developer to programatically register other beans.
    `void` | `registerIfNotExists​(java.lang.String name)` |
    `protected java.util.stream.Stream<T>` | `repositoriesStream()` | Provides access to all available repository instances
    `void` | `setDataSourceBean​(DataSourceBean dataSourceBean)` |
    `void` | `unregister​(Kernel kernel)` | Method called while bean is being unregistered.
    `protected void` | `updateDataSourceAware​(java.lang.String domain, T newRepo, T oldRepo)` | Method called when repository instance for domain changes.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface tigase.kernel.beans.RegistrarBeanWithDefaultBeanClass

      `getDefaultBeanClass`

- - ### Field Detail

    - #### aliases

          @ConfigField(desc="Map of aliases for data sources to use")
          protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​java.lang.String> aliases

    - #### dataSourceSelection

          @ConfigField(desc="Create repositories for: every UserRepository, every data source, listed data sources")
          protected MDRepositoryBean.SelectorType dataSourceSelection

  - ### Constructor Detail

    - #### MDRepositoryBean

          public MDRepositoryBean()

  - ### Method Detail

    - #### getName

          public java.lang.String getName()

      Returns name of a bean
      Returns:
        name of a bean

    - #### setDataSourceBean

          public void setDataSourceBean​(DataSourceBean dataSourceBean)

    - #### registerIfNotExists

          public void registerIfNotExists​(java.lang.String name)

    - #### register

          public void register​(Kernel kernel)

      Description copied from interface: `RegistrarBean`
      Method called when bean is being registered allowing developer to programatically register other beans.
      Specified by:
        `register` in interface `RegistrarBean`
      Parameters:
        `kernel` - - instance from local scope

    - #### unregister

          public void unregister​(Kernel kernel)

      Description copied from interface: `RegistrarBean`
      Method called while bean is being unregistered.
      Specified by:
        `unregister` in interface `RegistrarBean`
      Parameters:
        `kernel` - - instance from local scope

    - #### initialize

          public void initialize()

      Description copied from interface: `Initializable`
      Method will be called, when bean will be created, configured and ready to use.
      Specified by:
        `initialize` in interface `Initializable`

    - #### beforeUnregister

          public void beforeUnregister()

      Description copied from interface: `UnregisterAware`
      Method called before bean unregister.
      Specified by:
        `beforeUnregister` in interface `UnregisterAware`

    - #### findClassForDataSource

          protected abstract java.lang.Class<? extends T> findClassForDataSource​(DataSource dataSource)
                                                                          throws DBInitException

      Method returns class implementing repository which supports data source instance provided in parameter.
      Returns:
        repository class
      Throws:
        `DBInitException`

    - #### repositoriesStream

          protected java.util.stream.Stream<T> repositoriesStream()

      Provides access to all available repository instances
      Returns:
        stream of repository instances

    - #### getRepositories

          protected java.util.Map<java.lang.String,​T> getRepositories()

      Provides access to unmodifiable map domain to repository instance
      Returns:
        map of domain to repository instance

    - #### getRepository

          protected T getRepository​(java.lang.String domain)

      Provides repository instance for passed domain name
      Returns:
        instance of repository

    - #### onDataSourceChange

          @HandleEvent
          protected void onDataSourceChange​(DataSourceBean.DataSourceChangedEvent event)

    - #### initializeRepository

          protected void initializeRepository​(java.lang.String domain,
                                              T repo)

      Method called to initialized passed repository instance for passed domain.
      Should be empty if no custom initialization is required.

    - #### updateDataSourceAware

          protected void updateDataSourceAware​(java.lang.String domain,
                                               T newRepo,
                                               T oldRepo)

      Method called when repository instance for domain changes.
      Parameters:
        `domain` - name of domain
        `newRepo` - new instance of repository
        `oldRepo` - old instance of repository