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 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 and 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 and Description
    --- | ---
    `protected ConcurrentHashMap<String,String>` | `aliases`
    `protected MDRepositoryBean.SelectorType` | `dataSourceSelection`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MDRepositoryBean()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `beforeUnregister()` Method called before bean unregister.
    `protected abstract Class<? extends T>` | `findClassForDataSource(DataSource dataSource)` Method returns class implementing repository which supports data source instance provided in parameter.
    `String` | `getName()` Returns name of a bean
    `protected Map<String,T>` | `getRepositories()` Provides access to unmodifiable map domain to repository instance
    `protected T` | `getRepository(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(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(String name)`
    `protected 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(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 ConcurrentHashMap<String,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 String getName()

      Returns name of a bean
      Returns:
        name of a bean

    - #### setDataSourceBean

          public void setDataSourceBean(DataSourceBean dataSourceBean)

    - #### registerIfNotExists

          public void registerIfNotExists(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 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 Stream<T> repositoriesStream()

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

    - #### getRepositories

          protected Map<String,T> getRepositories()

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

    - #### getRepository

          protected T getRepository(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(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(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

Copyright © 2004–2020 "Tigase, Inc.". All rights reserved.