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

org.finra.herd.dao.BaseJpaDao Maven / Gradle / Ivy

Go to download

This project contains the database application layer (DAL) code. This contains code for accessing various external data sources such as databases, AWS services, etc.

There is a newer version: 0.28.0
Show newest version
/*
* Copyright 2015 herd contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.finra.herd.dao;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;

/**
 * Functionality for a generic JPA DAO.
 */
public interface BaseJpaDao
{
    /**
     * Gets the entity manager instance.
     *
     * @return the entity  manager.
     */
    public EntityManager getEntityManager();

    /**
     * Get an entity based on its class and entity Id.
     *
     * @param entityClass the entity class.
     * @param entityId the entity Id.
     * @param  the type of class.
     *
     * @return the entity.
     */
    public  T findById(Class entityClass, Object entityId);

    /**
     * Gets a list of entities based on the entity class.
     *
     * @param entityClass the entity class.
     * @param  the type of class.
     *
     * @return the list of entities.
     */
    public  List findAll(Class entityClass);

    /**
     * Finds a collection of entities based on an entity class name and named parameters.
     *
     * @param entityClass the entity class to retrieve.
     * @param params the named parameters.
     * @param  the type of class.
     *
     * @return the list of entities.
     */
    public  List findByNamedProperties(Class entityClass, Map params);

    /**
     * Finds an entity based on an entity class name and named parameters.  If more than 1 entity is found, an exception is returned.
     *
     * @param entityClass the entity class to retrieve.
     * @param params the named parameters.
     * @param  the type of class.
     *
     * @return the entity.
     */
    public  T findUniqueByNamedProperties(Class entityClass, Map params);

    /**
     * Executes a query string with a named set of parameters.
     *
     * @param queryString the query string.
     * @param params the named parameter map.
     * @param  the type of class to be returned.
     *
     * @return the results of the query.
     */
    public  List queryByNamedParams(String queryString, Map params);

    /**
     * Executes a query string and returns the results.
     *
     * @param queryString the query string.
     * @param  the type of entity being returned.
     *
     * @return the list of entities.
     */
    public  List query(String queryString);

    /**
     * Saves an entity.
     *
     * @param entity the entity to save.
     * @param  the type of entity.
     *
     * @return the saved entity.
     */
    public  T save(T entity);

    /**
     * Saves, flushes, and refreshes an entity.
     *
     * @param entity the entity to save.
     * @param  the type of entity.
     *
     * @return the saved entity.
     */
    public  T saveAndRefresh(T entity);

    /**
     * Deletes an entity.
     *
     * @param entity the entity to delete.
     * @param  the type of entity.
     */
    public  void delete(T entity);

    /**
     * Detaches an entity.
     *
     * @param entity the entity to detach.
     * @param  the type of entity.
     */
    public  void detach(T entity);

    /**
     * Gets the current timestamp.
     *
     * @return current timestamp
     */
    public Timestamp getCurrentTimestamp();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy