package de.hsadmin.core.model;

import java.util.List;

/**
 * Represents a CRUD (Create, Retrieve, Update, Delete) interface for generic
 * entity instances.
 * @author peter
 */
public interface ModuleInterface {
	
	public Transaction getTransaction();
	
	/**
	 * initializes a newly created entity.
	 */
	public AbstractEntity initialize(AbstractEntity newEntity) throws HSAdminException;

	/**
	 * Adds a new entity instance to the model.
	 */
	public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException;

	/**
	 * Finds an entity instance in the model, using its primary key.
	 */
	public AbstractEntity find(Class<? extends AbstractEntity> entityClass, Object key) throws HSAdminException;

	/**
	 * Finds an entity instance in the model, using its primary key in a String
	 * representation.
	 */
	public AbstractEntity findByString(Class<? extends AbstractEntity> entityClass, String key) throws HSAdminException;

	/**
	 * Searches entity instances in the model, using a simplified JPA-QL query.
	 */
	public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass, String query, String orderBy) throws HSAdminException;

	/**
	 * Updates an existing entity in the model.
	 */
	public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException;

	/**
	 * Deletes an existing entity from the model.
	 */
	public void delete(AbstractEntity existingEntity) throws HSAdminException;

}
