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

com.cedarsoft.gdao.AbstractService Maven / Gradle / Ivy

There is a newer version: 1.3.7
Show newest version
package com.cedarsoft.gdao;

import org.jetbrains.annotations.NotNull;
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;

import java.util.List;

/**
 * Abstract base class for services.
 */
public abstract class AbstractService extends AbstractGenericDao {
  @NotNull
  protected final TransactionTemplate transactionTemplate;
  @NotNull
  protected final GenericDao dao;

  /**
   * Creates a new service
   *
   * @param dao                the dao
   * @param transactionManager the transaction manager that is used
   */
  protected AbstractService( @NotNull GenericDao dao, @NotNull AbstractPlatformTransactionManager transactionManager ) {
    this.dao = dao;
    this.transactionTemplate = new TransactionTemplate( transactionManager );
  }

  @NotNull
  protected TransactionTemplate getTransactionTemplate() {
    return transactionTemplate;
  }

  /**
   * Returns the underlying dao
   *
   * @return the dao
   */
  @NotNull
  public GenericDao getDao() {
    return dao;
  }

  @NotNull
  public List findAll() {
    return dao.findAll();
  }

  public int getCount() {
    return dao.getCount();
  }

  @NotNull
  public  Long save( @NotNull LT newInstance ) {
    return dao.save( newInstance );
  }

  @NotNull
  public T findById( @NotNull Long id ) {
    return dao.findById( id );
  }

  public  void update( @NotNull LT transientObject ) {
    dao.update( transientObject );
  }

  public  void saveOrUpdate( @NotNull LT transientObject ) {
    dao.saveOrUpdate( transientObject );
  }

  public  void delete( @NotNull LT persistentObject ) {
    dao.delete( persistentObject );
  }

  @NotNull
  public  T find( @NotNull Finder finder ) {
    return dao.find( finder );
  }

  public void shutdown() {
    dao.shutdown();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy