Created
July 9, 2014 10:06
-
-
Save cokeSchlumpf/fa7e7b3b6f6a335dd374 to your computer and use it in GitHub Desktop.
DAO Interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Interface for Data Access Objects. The interface encapsulates the access from the underlying persistence method. | |
* | |
* @author [email protected] | |
* @since 4/14/14 | |
*/ | |
trait DAOCapabilities[ID, ENTITY] { | |
/** | |
* @return The display name of the entity (used for logging, generic ui, ...) | |
*/ | |
def entityName: String | |
/** | |
* Find the attribute by its id. | |
* | |
* @param id | |
* The id to look for. | |
* @param request | |
* The current request context. | |
* @return | |
* Some entity if it exists, else None. | |
*/ | |
def findById(id: ID)(implicit request: RequestWithAttributes[_]): Option[ENTITY] | |
/** | |
* Return the count of all existing entities. | |
* | |
* @param request | |
* The current request context. | |
* @return | |
* The calculated count of existing entities. | |
*/ | |
def count(implicit request: RequestWithAttributes[_]): Int | |
/** | |
* Insert a new entity. | |
* | |
* @param entity | |
* The entity to insert. | |
* @param request | |
* The current request context. | |
* @return | |
* The inserted entity. | |
*/ | |
def insert(entity: ENTITY)(implicit request: RequestWithAttributes[_]): ENTITY | |
/** | |
* Insert a whole list of new entities. | |
* | |
* @param entities | |
* The entities to insert. | |
* @param request | |
* The current request context. | |
* @return | |
* A list with the entities containing their new id. | |
*/ | |
def insertAll(entities: Seq[ENTITY])(implicit request: RequestWithAttributes[_]): Seq[ENTITY] = entities.map(insert) | |
/** | |
* Get a list of all available entities. | |
* | |
* @param request | |
* The current request context. | |
* @return | |
* The list of all available entities. | |
*/ | |
def list(implicit request: RequestWithAttributes[_]): Seq[ENTITY] | |
/** | |
* Update an existing entity. | |
* @param entity | |
* The entity to update. | |
* @param request | |
* The current request context. | |
* @return | |
* The updated entity. | |
*/ | |
def update(entity: ENTITY)(implicit request: RequestWithAttributes[_]): ENTITY | |
/** | |
* Deletes an existing entity. | |
* | |
* @param entity | |
* The entity which should be deleted. | |
* @param request | |
* The current request context. | |
* @return | |
*/ | |
def delete(entity: ENTITY)(implicit request: RequestWithAttributes[_]): Unit | |
/** | |
* Deletes an existing entity. | |
* | |
* @param id | |
* The id of the entity which should be deleted. | |
* @param request | |
* The current request context. | |
* @return | |
*/ | |
def deleteById(id: ID)(implicit request: RequestWithAttributes[_]): Unit | |
/** | |
* Companion method to insert or update an entity (depending if it's already stored or not). | |
* | |
* @param entity | |
* The entity to be stored. | |
* @param request | |
* The current request context. | |
* @return | |
* The saved entity. | |
*/ | |
def save(entity: ENTITY)(implicit request: RequestWithAttributes[_]): ENTITY | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment