com.github.naoghuman.lib.database.api.ICrudService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lib-database-objectdb Show documentation
Show all versions of lib-database-objectdb Show documentation
Lib-Database-ObjectDB is a library for easy accessing an ObjectDB database in a JavaFX & Maven desktop application. See https://github.com/Naoghuman/lib-database-objectdb for more details.
/*
* Copyright (C) 2014 PRo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.github.naoghuman.lib.database.api;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;
/**
* The Interface
for the class {@link com.github.naoghuman.lib.database.CrudService}.
* A common Interface
for all CRUD-Component implementations. The
* type of the entity is specified in the implementation.
*
* @author PRo
* @see com.github.naoghuman.lib.database.CrudService
* @see com.github.naoghuman.lib.database.api.DatabaseFacade
*/
public interface ICrudService {
/**
* Start a resource transaction.
*
* Internal following methods will be executed in following order:
*
* - {@link javax.persistence.EntityTransaction#begin()}
*
*/
public void beginTransaction();
/**
* Commit the current resource transaction, writing any unflushed changes
* to the database.
*
* Internal following methods will be executed in following order:
*
* - {@link javax.persistence.EntityTransaction#commit()}
* - {@link javax.persistence.EntityManager#clear()}
*
*/
public void commitTransaction();
/**
* Count all entitys in the given table.
*
* @param table The table which entitys should be counted.
* @return The number of entitys in the table or -1 if the table doesn't exists.
*/
public Long count(String table);
/**
* Make an entity managed and persistent.
* Deletes to {@link ICrudService#create(java.lang.Object, java.lang.Boolean)}
* with the parameter isSingleTransaction = true
.
*
* @param
* @param entity
* @return
* @see ICrudService#create(java.lang.Object, java.lang.Boolean)
*/
public T create(T entity);
/**
* Make an entity managed and persistent.
*
* Internal following methods will be executed in following order:
*
* - if
isSingleTransaction == true
then {@link com.github.naoghuman.lib.database.CrudService#beginTransaction()}
* - {@link javax.persistence.EntityManager#persist(java.lang.Object)}
* - {@link javax.persistence.EntityManager#flush() }
* - {@link javax.persistence.EntityManager#refresh(java.lang.Object) }
* - if
isSingleTransaction == true
then {@link com.github.naoghuman.lib.database.CrudService#commitTransaction()}
*
*
* @param
* @param entity
* @param isSingleTransaction
* @return
* @see ICrudService#create(java.lang.Object)
*/
public T create(T entity, Boolean isSingleTransaction);
/**
* TODO Add JavaDoc
* Deletes to {@link ICrudService#delete(java.lang.Class, java.lang.Object, java.lang.Boolean)}
* with the parameter isSingleTransaction = true
.
*
* @param
* @param type
* @param id
* @see ICrudService#delete(java.lang.Class, java.lang.Object, java.lang.Boolean)
*/
public void delete(Class type, Object id);
/**
* TODO Add JavaDoc
*
* @param
* @param type
* @param id
* @param isSingleTransaction
* @see ICrudService#delete(java.lang.Class, java.lang.Object)
*/
public void delete(Class type, Object id, Boolean isSingleTransaction);
/**
* Returns the associated {@link javax.persistence.EntityManager}.
*
* @return The EntityManager.
*/
public EntityManager getEntityManager();
/**
* TODO Add JavaDoc
* Delegates to {@link ICrudService#update(java.lang.Object, java.lang.Boolean) }
* with the parameter isSingleTransaction = true
.
*
* @param
* @param entity
* @return
* @see ICrudService#update(java.lang.Object, java.lang.Boolean)
*/
public T update(T entity);
/**
* Merge the state of the given entity into the current persistence context.
*
* @param
* @param entity
* @param isSingleTransaction
* @return
* @see ICrudService#update(java.lang.Object)
*/
public T update(T entity, Boolean isSingleTransaction);
/**
* Find by primary key. Search for an entity of the specified class and
* primary key. If the entity instance is contained in the persistence
* context, it is returned from there.
*
* @param
* @param type
* @param id
* @return
*/
public T findById(Class type, Object id);
/**
* TODO Add JavaDoc
*
* @param
* @param type
* @param queryName
* @return
*/
public List findByNamedQuery(Class type, String queryName);
/**
* TODO Add JavaDoc
*
* @param
* @param type
* @param queryName
* @param resultLimit
* @return
*/
public List findByNamedQuery(Class type, String queryName, int resultLimit);
/**
* TODO Add JavaDoc
*
* @param
* @param type
* @param queryName
* @param parameters
* @return
*/
public List findByNamedQuery(Class type, String queryName, Map parameters);
/**
* TODO Add JavaDoc
*
* @param
* @param type
* @param queryName
* @param parameters
* @param resultLimit
* @return
*/
public List findByNamedQuery(Class type, String queryName, Map parameters, int resultLimit);
/**
* TODO Add JavaDoc
*
* @param
* @param type
* @param sql
* @return
*/
public List findByNativeQuery(Class type, String sql);
/**
* TODO Add JavaDoc
*
* @param
* @param type
* @param sql
* @param resultLimit
* @return
*/
public List findByNativeQuery(Class type, String sql, int resultLimit);
/**
* TODO Add JavaDoc
*
* @param
* @param type
* @param sql
* @param parameters
* @return
*/
public List findByNativeQuery(Class type, String sql, Map parameters);
/**
* TODO Add JavaDoc
*
* @param
* @param type
* @param sql
* @param parameters
* @param resultLimit
* @return
*/
public List findByNativeQuery(Class type, String sql, Map parameters, int resultLimit);
/**
* TODO Add JavaDoc
*
* @param name
*/
public void shutdown(String name);
}