org.ektorp.support
Class CouchDbRepositorySupport<T>

java.lang.Object
  extended by org.ektorp.support.CouchDbRepositorySupport<T>
Type Parameters:
T -
All Implemented Interfaces:
GenericRepository<T>

public class CouchDbRepositorySupport<T>
extends java.lang.Object
implements GenericRepository<T>

Provides "out of the box" CRUD functionality for sub classes. Note that this class will try to access the standard design document named according to this convention: _design/[repository type simple name] e.g. _design/Sofa if this repository's handled type is foo.bar.Sofa It is preferable that this design document must define a view named "all". The "all"-view should only return document id's that refer to documents that can be loaded as this repository's handled type.

Author:
henrik lundgren

Field Summary
protected  CouchDbConnector db
           
protected  org.slf4j.Logger log
           
 
Constructor Summary
protected CouchDbRepositorySupport(java.lang.Class<T> type, CouchDbConnector db)
           
 
Method Summary
 void add(T entity)
           
 boolean contains(java.lang.String docId)
           
protected  ViewQuery createQuery(java.lang.String viewName)
          Creates a ViewQuery pre-configured with correct dbPath, design document id and view name.
 T get(java.lang.String id)
           
 java.util.List<T> getAll()
          If the repository's design document has a view named "all" it will be used to fetch all documents of this repository's handled type.
 void initStandardDesignDocument()
           Will create the standard design document if it does not exists in the database.
protected  java.util.List<T> queryView(java.lang.String viewName)
          Allows subclasses to query a view and load the result as the repository's handled type.
protected  java.util.List<T> queryView(java.lang.String viewName, java.lang.String keyValue)
          Allows subclasses to query views with simple String value keys and load the result as the repository's handled type.
 void remove(T entity)
           
 void update(T entity)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.slf4j.Logger log

db

protected final CouchDbConnector db
Constructor Detail

CouchDbRepositorySupport

protected CouchDbRepositorySupport(java.lang.Class<T> type,
                                   CouchDbConnector db)
Method Detail

add

public void add(T entity)
Specified by:
add in interface GenericRepository<T>

getAll

public java.util.List<T> getAll()
If the repository's design document has a view named "all" it will be used to fetch all documents of this repository's handled type. "all" must return document ids that refers documents that are readable by this repository. If the "all"-view is not defined, all documents in the database (except design documents) will be fetched. In this case the database must only contain documents that are readable by this repository.

Specified by:
getAll in interface GenericRepository<T>
Returns:
all objects of this repository's handled type in the db.

get

public T get(java.lang.String id)
Specified by:
get in interface GenericRepository<T>

remove

public void remove(T entity)
Specified by:
remove in interface GenericRepository<T>

update

public void update(T entity)
Specified by:
update in interface GenericRepository<T>

createQuery

protected ViewQuery createQuery(java.lang.String viewName)
Creates a ViewQuery pre-configured with correct dbPath, design document id and view name.

Parameters:
viewName -
Returns:

queryView

protected java.util.List<T> queryView(java.lang.String viewName,
                                      java.lang.String keyValue)
Allows subclasses to query views with simple String value keys and load the result as the repository's handled type. The viewName must be defined in this repository's design document. The view must return doc ids that refer to documents that can be loaded as this repository's handled type.

Parameters:
viewName -
keyValue -
Returns:

queryView

protected java.util.List<T> queryView(java.lang.String viewName)
Allows subclasses to query a view and load the result as the repository's handled type. The viewName must be defined in this repository's design document. The view must return doc ids that refer to documents that can be loaded as this repository's handled type.

Parameters:
viewName -
Returns:

initStandardDesignDocument

public void initStandardDesignDocument()

Will create the standard design document if it does not exists in the database.

Will also generate view definitions for finder methods defined in this class and annotated by the @GenerateView annotation. The method name must adhere to the name convention of findBy[Property].

The method:


contains

public boolean contains(java.lang.String docId)
Specified by:
contains in interface GenericRepository<T>


Copyright © 2010. All Rights Reserved.