Class GenericReplicatingServiceBean

All Implemented Interfaces:
IBatchService, IGenericBaseService, IGenericLocalService, IGenericService, INamedQueryService, IQueryService, IStatelessService
Direct Known Subclasses:
GenericLocalServiceBean

public class GenericReplicatingServiceBean extends GenericServiceBean
NOT FINISHED YET!

Overrides the base service methods of GenericServiceBean to do actions on a list of jpa EntitiyManagers. The first entity manager is the root/main to do the service on. all other entity managers will be used for replications.

 Technical Mechanism:
  - on getting data by queries, the root/main entity manager will be used to evaluate the data. the others will persist this new data.
  - on storing new or changed data, all entity managers will do the same on their connection.
  - works only if auto-commit = true
 
Version:
$Revision$
Author:
Tom, Thomas Schneider
  • Field Details

    • replicationServices

      protected List<IGenericBaseService> replicationServices
    • replication

      protected IGenericBaseService replication
    • connected

      protected boolean connected
    • collectReplications

      protected boolean collectReplications
  • Constructor Details

    • GenericReplicatingServiceBean

      public GenericReplicatingServiceBean(javax.persistence.EntityManager entityManager, boolean createReplication)
      constructor
    • GenericReplicatingServiceBean

      public GenericReplicatingServiceBean(javax.persistence.EntityManager entityManager, List<IGenericBaseService> replicationServices)
      constructor
      Parameters:
      enitityManager -
      replications -
  • Method Details

    • createStandardReplication

      protected static List<IGenericBaseService> createStandardReplication()
      createStandardReplication
      Returns:
      list filled with service on persistence-unit 'replication'
    • getAvailableReplication

      protected IGenericBaseService getAvailableReplication()
    • switchToConnection

      public void switchToConnection(int index)
      setting default entitymanager.
      Parameters:
      index - index of replication (TODO: how to evaluate a name of an entity manager?)
    • connection

      public javax.persistence.EntityManager connection()
      Overrides:
      connection in class AbstractStatelessServiceBean
    • checkConnection

      public boolean checkConnection(boolean throwException)
    • checkConnection

      protected boolean checkConnection(IGenericBaseService service, boolean throwException)
      checkConnection
      Parameters:
      service - connection
      throwException - if true, the exception will be forwarded
      Returns:
      true, if connection could be established
    • doForReplication

      protected void doForReplication(Runnable replicationJob)
    • findByQuery

      public Collection<?> findByQuery(String queryString, boolean nativeQuery, int startIndex, int maxResult, Object[] args, Map<String,?> hints, Class... lazyRelations)
      Specified by:
      findByQuery in interface IGenericBaseService
      Overrides:
      findByQuery in class GenericServiceBean
    • addReplicationEntities

      protected void addReplicationEntities(IGenericBaseService repService, List<Object> reps, de.tsl2.nano.persistence.replication.Tree<Object,de.tsl2.nano.bean.def.BeanValue> container, Class... excludes)
    • addReplicationEntities

      protected void addReplicationEntities(IGenericBaseService repService, List<Object> reps, de.tsl2.nano.persistence.replication.Tree<Object,de.tsl2.nano.bean.def.BeanValue> container, boolean addRepsToContainer, Class... excludes)
      checks recursive the given list of objects to be replicated to the given service.
      Parameters:
      repService - service to check the new replication objects
      reps - objects to be checked if already persisted
    • persistNoTransaction

      public <T> T persistNoTransaction(T bean, boolean refreshBean, boolean flush, Class... lazyRelations)
      Specified by:
      persistNoTransaction in interface IGenericBaseService
      Overrides:
      persistNoTransaction in class GenericServiceBean
    • remove

      public void remove(Object bean)
      Specified by:
      remove in interface IGenericBaseService
      Overrides:
      remove in class GenericServiceBean