SPT Object Database API

com.sptci.prevayler
Class PrevalentManager<P extends PrevalentObject>

java.lang.Object
  extended by com.sptci.prevayler.PrevalentManager<P>
All Implemented Interfaces:
AbstractDatabase<P>, Database<P>, Serializable

public class PrevalentManager<P extends PrevalentObject>
extends Object
implements Database<P>

A facade around the prevalent system used to present a more natural programming interface than that provided by prevayler.

The following shows sample use of this class:

   import com.sptci.prevayler.PrevalentException;
   import com.sptci.prevayler.PrevalentManager;

     ...
     MyPrevalentObject po = new MyPrevalentObject( ... );
     po.setXxx( ... );

     final PrevalentManager pm = new PrevalentManager();
     try
     {
       po = pm.save( po );
       System.out.format( "Total MyPrevalentObjects in system: %d%n",
           po.count( MyPrevalentObject.class ) );
     }
     catch ( PrevalentException pex )
     {
       // handle error
     }
 

© Copyright 2008 Sans Pareil Technologies, Inc.

Version:
$Id: PrevalentManager.java 22 2008-11-24 19:04:25Z sptrakesh $
Author:
Rakesh Vidyadharan 2008-07-12
See Also:
PrevalentSystemFactory, Serialized Form

Field Summary
private static long serialVersionUID
           
 
Constructor Summary
PrevalentManager()
           
 
Method Summary
 int count(Class type)
          Return the total number of persistent instance of the specified type in the prevalent system.
 P delete(P object)
          Delete the specified prevalent object from the prevalent system.
 Collection<P> fetch(Class type, long start, long end)
          Return the collection of prevalent objects in the specified range.
 P fetch(Class type, Object objectId)
          Return the prevalent object identified by the object id specified.
 Collection<P> fetch(Class type, String field, Object value)
          Retrieve the collection of prevelant objects of the specified type that are indexed by the specified field and value.
protected  Collection<P> fetchByIndices(Class type, Map<String,?> parameters, FetchByIndices.AggregationType resultType)
          Retrieve the collection of prevelant objects of the specified type that are indexed by the specified fields and values.
 Collection<P> fetchIntersection(Class type, Map<String,?> parameters)
          Retrieve the collection of prevelant objects of the specified type that are indexed by the specified fields and values.
 Collection<P> fetchUnion(Class type, Map<String,?> parameters)
          Retrieve the collection of prevelant objects of the specified type that are indexed by the specified fields and values.
 P save(P object)
          Save the specified prevalent object to the prevalent system.
 Collection<P> search(org.apache.lucene.search.Query query, org.apache.lucene.search.Filter filter, int count)
          Execute the specified lucene query and return the collection of matching prevalent objects.
 Collection<P> search(org.apache.lucene.search.Query query, org.apache.lucene.search.Filter filter, int count, org.apache.lucene.search.Sort sort)
          Execute the specified lucene query and return the collection of matching prevalent objects.
 Collection<P> search(org.apache.lucene.search.Query query, int count)
          Execute the specified lucene query and return the collection of matching prevalent objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

PrevalentManager

public PrevalentManager()
Method Detail

save

public P save(P object)
                               throws PrevalentException
Save the specified prevalent object to the prevalent system. If the object does not exist, it is created. It it exists, the persisted object is updated.

Specified by:
save in interface Database<P extends PrevalentObject>
Parameters:
object - The prevalent object to save to the prevalent system.
Returns:
The updated prevalent object instance.
Throws:
PrevalentException - If errors are encountered while saving the prevalent object.

delete

public P delete(P object)
                                 throws PrevalentException
Delete the specified prevalent object from the prevalent system. Note that constraint rules may cause an exception to be raised leaving the object still persisted.

Specified by:
delete in interface Database<P extends PrevalentObject>
Parameters:
object - The prevalent object to delete from the prevalent system.
Returns:
The modified prevalent object. In particular the PrevalentObject.getObjectId() will return null if the object is deleted.
Throws:
PrevalentException - If errors are encountered while deleting the object. More specific sub-classes such as DeleteException are thrown when configured rules are violated.

count

public int count(Class type)
          throws PrevalentException
Return the total number of persistent instance of the specified type in the prevalent system. This method is typically used to implement paginated views of the persistent data.

Specified by:
count in interface AbstractDatabase<P extends PrevalentObject>
Parameters:
type - The type of object whose persistent instance count is to be retrieved.
Returns:
The total number of persistent instances of the specified type.
Throws:
PrevalentException - If errors are encountered while fetching the object count.

fetch

public P fetch(Class type,
               Object objectId)
                                throws PrevalentException
Return the prevalent object identified by the object id specified.

Specified by:
fetch in interface AbstractDatabase<P extends PrevalentObject>
Parameters:
type - The type of the persisted object which has the specified object id.
objectId - The object id of the prevalent object.
Returns:
The prevalent object if found or null.
Throws:
PrevalentException - If errors are encountered while fetching the persistent object.

fetch

public Collection<P> fetch(Class type,
                           long start,
                           long end)
                                            throws PrevalentException
Return the collection of prevalent objects in the specified range. Objects are returned in insertion order.

Specified by:
fetch in interface AbstractDatabase<P extends PrevalentObject>
Parameters:
type - The type of the persisted objects which are to be fetched.
start - The starting index (inclusive) of the range of objects to fetch.
end - The ending index (exclusive) of the range of objects to fetch.
Returns:
The collection of persistent objects. Returns an empty collection if no objects are found in the specified range.
Throws:
PrevalentException - If errors are encountered while retrieving the persisted objects.
See Also:
PrimaryStorage.get( long, long )

fetch

public Collection<P> fetch(Class type,
                           String field,
                           Object value)
                                            throws PrevalentException
Retrieve the collection of prevelant objects of the specified type that are indexed by the specified field and value.

Specified by:
fetch in interface AbstractDatabase<P extends PrevalentObject>
Parameters:
type - The type of the persisted objects which are to be fetched.
field - The name of the indexed field in the prevalent class.
value - The value of the indexed field in the prevalent class.
Returns:
The collection of persistent objects. Returns an empty collection if no objects are found with the specified indexed value.
Throws:
PrevalentException - If errors are encountered while retrieving the persisted objects.

fetchUnion

public Collection<P> fetchUnion(Class type,
                                Map<String,?> parameters)
                                                 throws PrevalentException
Retrieve the collection of prevelant objects of the specified type that are indexed by the specified fields and values. The results represent a union of the prevalent objects matching each parameter in the collection of parameters (an or query).

Specified by:
fetchUnion in interface AbstractDatabase<P extends PrevalentObject>
Parameters:
type - The type of the persisted objects which are to be fetched.
parameters - The map of field-name to value mappings to use to fetch instances.
Returns:
The collection of persistent objects. Returns an empty collection if no objects are found with the specified indexed value.
Throws:
PrevalentException - If errors are encountered while retrieving the persisted objects.
See Also:
fetchByIndices(java.lang.Class, java.util.Map, com.sptci.prevayler.query.FetchByIndices.AggregationType)

fetchIntersection

public Collection<P> fetchIntersection(Class type,
                                       Map<String,?> parameters)
                                                        throws PrevalentException
Retrieve the collection of prevelant objects of the specified type that are indexed by the specified fields and values. The results represent an intersection of the prevalent objects matching each parameter in the collection of parameters (an or query).

Specified by:
fetchIntersection in interface AbstractDatabase<P extends PrevalentObject>
Parameters:
type - The type of the persisted objects which are to be fetched.
parameters - The map of field-name to value mappings to use to fetch instances.
Returns:
The collection of persistent objects. Returns an empty collection if no objects are found with the specified indexed value.
Throws:
PrevalentException - If errors are encountered while retrieving the persisted objects.
See Also:
fetchByIndices(java.lang.Class, java.util.Map, com.sptci.prevayler.query.FetchByIndices.AggregationType)

search

public Collection<P> search(org.apache.lucene.search.Query query,
                            int count)
                                             throws PrevalentException
Execute the specified lucene query and return the collection of matching prevalent objects.

Specified by:
search in interface Database<P extends PrevalentObject>
Parameters:
query - The lucene query that is to be executed to find matching prevalent object instances.
count - The maximum number to top hits for the search to return.
Returns:
The collection of matching instances or an empty collection.
Throws:
PrevalentException - If errors are encountered while reconstituting the prevalent objects being returned.

search

public Collection<P> search(org.apache.lucene.search.Query query,
                            org.apache.lucene.search.Filter filter,
                            int count)
                                             throws PrevalentException
Execute the specified lucene query and return the collection of matching prevalent objects.

Specified by:
search in interface Database<P extends PrevalentObject>
Parameters:
query - The lucene query that is to be executed to find matching prevalent object instances.
filter - The filter to apply to restrict the query results.
count - The maximum number to top hits for the search to return.
Returns:
The collection of matching instances or an empty collection.
Throws:
PrevalentException - If errors are encountered while reconstituting the prevalent objects being returned.

search

public Collection<P> search(org.apache.lucene.search.Query query,
                            org.apache.lucene.search.Filter filter,
                            int count,
                            org.apache.lucene.search.Sort sort)
                                             throws PrevalentException
Execute the specified lucene query and return the collection of matching prevalent objects.

Notes:

Specified by:
search in interface AbstractDatabase<P extends PrevalentObject>
Parameters:
query - The lucene query that is to be executed to find matching prevalent object instances.
filter - The filter to apply to restrict the query results.
count - The maximum number to top hits for the search to return.
sort - The sort criteria to use for the results.
Returns:
The collection of matching instances or an empty collection.
Throws:
PrevalentException - If errors are encountered while reconstituting the prevalent objects being returned.

fetchByIndices

protected Collection<P> fetchByIndices(Class type,
                                       Map<String,?> parameters,
                                       FetchByIndices.AggregationType resultType)
                                                        throws PrevalentException
Retrieve the collection of prevelant objects of the specified type that are indexed by the specified fields and values.

Parameters:
type - The type of the persisted objects which are to be fetched.
parameters - The map of field-name to value mappings to use to fetch instances.
resultType - The type of aggregation to be used for the result set.
Returns:
The collection of persistent objects. Returns an empty collection if no objects are found with the specified indexed value.
Throws:
PrevalentException - If errors are encountered while retrieving the persisted objects.

SPT Object Database API