org.dasein.persist
Class PersistentFactory<T>

java.lang.Object
  extended by org.dasein.persist.PersistentFactory<T>
Type Parameters:
T - the type of object managed by this factory

Deprecated. This API is ancient and is being deprecated in favor of the new @{link PersistentCache}

public final class PersistentFactory<T>
extends Object

Manages the movement of persistent objects between the data store and a memory cache. This class is generally used as a delegate by true factory classes.

 public class EmployeeFactory {
   private PersistentFactory<Employee> factory;
   
   public EmployeeFactory() {
       factory = new PersistentFactory<Employee>(Employee.class, "employeeId", "ssn");
   }
   
   public Collection<Employee> findEmployees(String ln) throws PersistenceException {
       return factory.find("lastName", ln);
   }
   
   public Employee getEmployee(Long empid) throws PersistenceException {
       return factory.get("employeeId", empid);
   }
   
   public Employee getEmployee(String ssn) throws PersistenceException {
       return factory.get("ssn", ssn);
   }
   
   public void updateEmployee(Transaction xaction, Employee emp, Map<String,Object> state)
   throws PersistenceException {
       factory.update(xaction, emp, state);
   }
 }
 

This persistence is automatic. You may, however, specify your own queries that will be managed by passing in an extension of the Execution class.

Last modified: $Date: 2009/07/02 01:36:20 $

Version:
$Revision: 1.40 $
Author:
George Reese

Nested Class Summary
static interface PersistentFactory.DependencyManager<T>
          Deprecated.  
 
Field Summary
static String LISTING
          Deprecated. Convenience constant used by search executions as they key for multi-valued results.
static org.apache.log4j.Logger logger
          Deprecated.  
 
Constructor Summary
PersistentFactory(Class<T> cls, AutomatedSql.TranslationMethod transMeth, String... keys)
          Deprecated. Constructs a new persistent factory for objects of the specified class with the named unique identifier attributes.
PersistentFactory(Class<T> cls, boolean custom, String... keys)
          Deprecated. 
PersistentFactory(Class<T> cls, String... keys)
          Deprecated. Constructs a new persistent factory for objects of the specified class with the named unique identifier attributes.
 
Method Summary
 void addCounter(String field, Class<? extends Execution> cls)
          Deprecated. Adds a query for counts on a specified field.
 void addSearch(String field, Class<? extends Execution> cls)
          Deprecated. Adds a query for searches on a specified field.
 void addSingleton(String field, Class<? extends Execution> cls)
          Deprecated. Adds a query for searches on a specified field.
static Class<? extends Execution> compileTranslator(Class<?> t, String which)
          Deprecated.  
 long count()
          Deprecated. Counts the total number of objects governed by this factory in the database.
 long count(Class<? extends Execution> cls, Map<String,Object> criteria)
          Deprecated. Counts the number of items matching an arbitrary query.
 long count(SearchTerm[] terms)
          Deprecated.  
 long count(String field, Object val)
          Deprecated. Counts the total number of objects in the database matching the specified criteria.
 long countJoin(Class<? extends Object> jc, String key, Object val)
          Deprecated.  
 T create(Transaction xaction, Map<String,Object> state)
          Deprecated. Creates the specified object with the data provided in the specified state under the governance of the specified transaction.
 Collection<T> find(Class<? extends Execution> cls, Map<String,Object> criteria)
          Deprecated. Executes an arbitrary search using the passed in search class and criteria.
 Collection<T> find(Class<? extends Object> jc, String key, Object id)
          Deprecated.  
 Collection<T> find(SearchTerm... terms)
          Deprecated.  
 Collection<T> find(SearchTerm[] terms, Boolean orderDesc, String... orderFields)
          Deprecated.  
 Collection<T> find(SearchTerm[] terms, org.dasein.util.JiteratorFilter<T> filter, Boolean orderDesc, String... orderFields)
          Deprecated.  
 Collection<T> find(String field, Object val)
          Deprecated. Executes a search that may return multiple values.
 Collection<T> find(String field, Object val, Boolean orderDesc, String... orderFields)
          Deprecated.  
 T get(Map<String,Object> state)
          Deprecated.  
 T get(String id, Object val)
          Deprecated. Retrieves the object uniquely identified by the value for the specified ID field.
 String getKey()
          Deprecated.  
 long getNewKeyValue()
          Deprecated.  
 Collection<T> list()
          Deprecated. Loads all elements of this class from the data store.
 Collection<T> list(boolean orderDesc, String... orderFields)
          Deprecated.  
 Collection<T> list(Class<? extends Execution> cls)
          Deprecated.  
 Map<String,org.dasein.util.Translator<String>> loadTranslations(Transaction xaction, String idstr)
          Deprecated.  
 void loadXml(InputStream in)
          Deprecated.  
 void remove(Transaction xaction, T item)
          Deprecated. Removes the specified item from the system permanently.
 void removeTranslations(Transaction xaction, String idstr)
          Deprecated.  
 void saveTranslation(Transaction xaction, String idstr, String attr, org.dasein.util.Translator<String> val)
          Deprecated.  
 void setCreate(Class<? extends Execution> cls)
          Deprecated. Sets the class that manages the query that will create objects in this factory in the data store.
 void setDependency(PersistentFactory.DependencyManager<T> mgr)
          Deprecated. Sets the callback class to handle the management of dependencies.
 void setExportHook(ExportHook<T> hook)
          Deprecated.  
 void setImportHook(ImportHook<T> hook)
          Deprecated.  
 void setRemove(Class<? extends Execution> cls)
          Deprecated. Sets the class that manages the query that will remove objects in this factory from the data store.
 void setUpdate(Class<? extends Execution> cls)
          Deprecated. Sets the class that manages the query that will update objects in this factory in the data store.
 String toString()
          Deprecated.  
 void update(Transaction xaction, T item, Map<String,Object> state)
          Deprecated. Updates the specified object with the data provided in the specified state under the governance of the specified transaction.
 void write(File file, InputStream is)
          Deprecated.  
 void write(File file, String data)
          Deprecated.  
 void writeXml(PrintWriter output)
          Deprecated.  
 void writeXml(PrintWriter output, Class<? extends Execution> cls, Map<String,Object> criteria)
          Deprecated.  
 void writeXml(PrintWriter output, String field, Object val)
          Deprecated.  
 void writeXml(PrintWriter output, T item)
          Deprecated.  
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

public static final org.apache.log4j.Logger logger
Deprecated. 

LISTING

public static final String LISTING
Deprecated. 
Convenience constant used by search executions as they key for multi-valued results.

See Also:
Constant Field Values
Constructor Detail

PersistentFactory

public PersistentFactory(Class<T> cls,
                         String... keys)
Deprecated. 
Constructs a new persistent factory for objects of the specified class with the named unique identifier attributes.

Parameters:
cls - the class of objects managed by this factory
keys - a list of unique identifiers for instances of the specified class

PersistentFactory

@Deprecated
public PersistentFactory(Class<T> cls,
                                    boolean custom,
                                    String... keys)
Deprecated. 

Constructs a new persistent factory for objects of the specified class with the named unique identifier attributes.

Parameters:
cls - the class of objects managed by this factory
keys - a list of unique identifiers for instances of the specified class

PersistentFactory

public PersistentFactory(Class<T> cls,
                         AutomatedSql.TranslationMethod transMeth,
                         String... keys)
Deprecated. 
Constructs a new persistent factory for objects of the specified class with the named unique identifier attributes.

Parameters:
cls - the class of objects managed by this factory
keys - a list of unique identifiers for instances of the specified class
Method Detail

compileTranslator

public static Class<? extends Execution> compileTranslator(Class<?> t,
                                                           String which)
                                                    throws PersistenceException
Deprecated. 
Throws:
PersistenceException

addCounter

public void addCounter(String field,
                       Class<? extends Execution> cls)
Deprecated. 
Adds a query for counts on a specified field.

Parameters:
field - the field to count matches on
cls - the class of the query that performs the count

addSearch

public void addSearch(String field,
                      Class<? extends Execution> cls)
Deprecated. 
Adds a query for searches on a specified field.

Parameters:
field - the field to search on
cls - the class of the query that performs the search

addSingleton

public void addSingleton(String field,
                         Class<? extends Execution> cls)
Deprecated. 
Adds a query for searches on a specified field. These searches return unique values.

Parameters:
field - the field to search on
cls - the class of the query that performs the search

count

public long count()
           throws PersistenceException
Deprecated. 
Counts the total number of objects governed by this factory in the database.

Returns:
the number of objects in the database
Throws:
PersistenceException - an error occurred counting the elements in the database

count

public long count(String field,
                  Object val)
           throws PersistenceException
Deprecated. 
Counts the total number of objects in the database matching the specified criteria.

Parameters:
field - the field to match on
val - the value to match against
Returns:
the number of matching objects
Throws:
PersistenceException - an error occurred counting the elements in the database

count

public long count(SearchTerm[] terms)
           throws PersistenceException
Deprecated. 
Throws:
PersistenceException

count

public long count(Class<? extends Execution> cls,
                  Map<String,Object> criteria)
           throws PersistenceException
Deprecated. 
Counts the number of items matching an arbitrary query. This method expects the passed in query to have one field called 'count' in the map it returns. Anything else is ignored

Parameters:
cls - the execution class for the arbitrary query
criteria - the criteria to match against for the query
Returns:
the number of matches (essentially, the number returned from the arbitrary query in the 'count' field)
Throws:
PersistenceException - an error occurred executing the query.

countJoin

public long countJoin(Class<? extends Object> jc,
                      String key,
                      Object val)
               throws PersistenceException
Deprecated. 
Throws:
PersistenceException

create

public T create(Transaction xaction,
                Map<String,Object> state)
         throws PersistenceException
Deprecated. 
Creates the specified object with the data provided in the specified state under the governance of the specified transaction.

Parameters:
xaction - the transaction governing this event
state - the new state for the new object
Throws:
PersistenceException - an error occurred talking to the data store, or creates are not supported

find

public Collection<T> find(String field,
                          Object val)
                   throws PersistenceException
Deprecated. 
Executes a search that may return multiple values. The specified field must have been set up by a call to @{link #addSearch(String,Class)}.

Parameters:
field - the field being searched on
val - the value being searched against
Returns:
a list of objects that match the criteria
Throws:
PersistenceException - an error occurred talking to the data store

find

public Collection<T> find(String field,
                          Object val,
                          Boolean orderDesc,
                          String... orderFields)
                   throws PersistenceException
Deprecated. 
Throws:
PersistenceException

find

public Collection<T> find(SearchTerm... terms)
                   throws PersistenceException
Deprecated. 
Throws:
PersistenceException

find

public Collection<T> find(SearchTerm[] terms,
                          Boolean orderDesc,
                          String... orderFields)
                   throws PersistenceException
Deprecated. 
Throws:
PersistenceException

find

public Collection<T> find(SearchTerm[] terms,
                          org.dasein.util.JiteratorFilter<T> filter,
                          Boolean orderDesc,
                          String... orderFields)
                   throws PersistenceException
Deprecated. 
Throws:
PersistenceException

find

public Collection<T> find(Class<? extends Object> jc,
                          String key,
                          Object id)
                   throws PersistenceException
Deprecated. 
Throws:
PersistenceException

find

public Collection<T> find(Class<? extends Execution> cls,
                          Map<String,Object> criteria)
                   throws PersistenceException
Deprecated. 
Executes an arbitrary search using the passed in search class and criteria. This is useful for searches that simply do not fit well into the rest of the API.

Parameters:
cls - the class to perform the search
criteria - the search criteria
Returns:
the results of the search
Throws:
PersistenceException - an error occurred performing the search

get

public T get(Map<String,Object> state)
      throws PersistenceException
Deprecated. 
Throws:
PersistenceException

get

public T get(String id,
             Object val)
      throws PersistenceException
Deprecated. 
Retrieves the object uniquely identified by the value for the specified ID field.

Parameters:
id - the ID field identifying the object
val - the value that uniquely identifies the desired object
Returns:
the object matching the query criterion
Throws:
PersistenceException - an error occurred talking to the data store

getKey

public String getKey()
Deprecated. 

getNewKeyValue

public long getNewKeyValue()
                    throws PersistenceException
Deprecated. 
Throws:
PersistenceException

list

public Collection<T> list()
                   throws PersistenceException
Deprecated. 
Loads all elements of this class from the data store. Use this method only when you know exactly what you are doing. Otherwise, you will pull a lot of data.

Returns:
all objects from the database
Throws:
PersistenceException - an error occurred executing the query

list

public Collection<T> list(boolean orderDesc,
                          String... orderFields)
                   throws PersistenceException
Deprecated. 
Throws:
PersistenceException

list

public Collection<T> list(Class<? extends Execution> cls)
                   throws PersistenceException
Deprecated. 
Throws:
PersistenceException

loadTranslations

public Map<String,org.dasein.util.Translator<String>> loadTranslations(Transaction xaction,
                                                                       String idstr)
                                                                throws PersistenceException
Deprecated. 
Throws:
PersistenceException

loadXml

public void loadXml(InputStream in)
             throws PersistenceException
Deprecated. 
Throws:
PersistenceException

remove

public void remove(Transaction xaction,
                   T item)
            throws PersistenceException
Deprecated. 
Removes the specified item from the system permanently.

Parameters:
xaction - the transaction under which this event is occurring
item - the item to be removed
Throws:
PersistenceException - an error occurred talking to the data store or removal of these objects is prohibited

removeTranslations

public void removeTranslations(Transaction xaction,
                               String idstr)
                        throws PersistenceException
Deprecated. 
Throws:
PersistenceException

saveTranslation

public void saveTranslation(Transaction xaction,
                            String idstr,
                            String attr,
                            org.dasein.util.Translator<String> val)
                     throws PersistenceException
Deprecated. 
Throws:
PersistenceException

setCreate

public void setCreate(Class<? extends Execution> cls)
Deprecated. 
Sets the class that manages the query that will create objects in this factory in the data store.

Parameters:
cls - the execution class that creates objects in the data store

setDependency

public void setDependency(PersistentFactory.DependencyManager<T> mgr)
Deprecated. 
Sets the callback class to handle the management of dependencies.

Parameters:
mgr - the dependency manager to use for dependency management

setExportHook

public void setExportHook(ExportHook<T> hook)
Deprecated. 

setImportHook

public void setImportHook(ImportHook<T> hook)
Deprecated. 

setRemove

public void setRemove(Class<? extends Execution> cls)
Deprecated. 
Sets the class that manages the query that will remove objects in this factory from the data store.

Parameters:
cls - the execution class that removes objects from the data store

setUpdate

public void setUpdate(Class<? extends Execution> cls)
Deprecated. 
Sets the class that manages the query that will update objects in this factory in the data store.

Parameters:
cls - the execution class that updates objects in the data store

toString

public String toString()
Deprecated. 
Overrides:
toString in class Object

update

public void update(Transaction xaction,
                   T item,
                   Map<String,Object> state)
            throws PersistenceException
Deprecated. 
Updates the specified object with the data provided in the specified state under the governance of the specified transaction.

Parameters:
xaction - the transaction governing this event
item - the item to be updated
state - the new state for the updated object
Throws:
PersistenceException - an error occurred talking to the data store, or updates are not supported

write

public void write(File file,
                  String data)
           throws IOException
Deprecated. 
Throws:
IOException

write

public void write(File file,
                  InputStream is)
           throws IOException
Deprecated. 
Throws:
IOException

writeXml

public void writeXml(PrintWriter output)
              throws PersistenceException
Deprecated. 
Throws:
PersistenceException

writeXml

public void writeXml(PrintWriter output,
                     T item)
              throws PersistenceException
Deprecated. 
Throws:
PersistenceException

writeXml

public void writeXml(PrintWriter output,
                     String field,
                     Object val)
              throws PersistenceException
Deprecated. 
Throws:
PersistenceException

writeXml

public void writeXml(PrintWriter output,
                     Class<? extends Execution> cls,
                     Map<String,Object> criteria)
              throws PersistenceException
Deprecated. 
Throws:
PersistenceException


Copyright © 2011 enStratus Networks LLC. All Rights Reserved.