SPT Core API

com.sptci.jdo
Class UserFactory

java.lang.Object
  extended by com.sptci.jdo.Factory<User>
      extended by com.sptci.jdo.UserFactory

public class UserFactory
extends Factory<User>

The repository class for interactions with the User JDO JavaBean.

The following code illustrates use of this class and associated JavaBean:

   import javax.jdo.PersistenceManager;

   import com.sptci.jdo.User;
   import com.sptci.jdo.UserFactory;

     ...
     UserFactory factory = UserFactory().getInstance();
     PersistenceManager pm = factory.getPersistenceManager();

     try
     {
       pm.currentTransaction().begin();

       String userName = "test";
       User user = factory.fetchByUserName( userName, pm );
       if ( user != null )
       {
         user.getPassword( "mypassword" );
       }

       pm.currentTransaction().commit();
     }
     finally
     {
       factory.close( pm );
     }
 

© Copyright 2006 Sans Pareil Technologies, Inc.

Version:
$Id: UserFactory.java 4594 2009-01-29 17:43:03Z rakesh $
Author:
Rakesh Vidyadharan 2006-05-10

Field Summary
static UserFactory userFactory
          The singleton instance of the DAO.
 
Fields inherited from class com.sptci.jdo.Factory
logger
 
Constructor Summary
UserFactory()
           
 
Method Summary
 long count(javax.jdo.PersistenceManager pm)
          Return a count of the total number of persistent instances of the User object in the data store.
 Collection<User> fetch(long start, long end, javax.jdo.PersistenceManager pm)
          Return a collection that contains all User instances in the data store within the specified range.
 Collection<User> fetch(long start, long end, String sortClause, javax.jdo.PersistenceManager pm)
          Return a collection that contains all instances in the data store of the specified class within the specified range.
 Collection<User> fetchAll(javax.jdo.PersistenceManager pm)
          Return a collection that contains all instances in the data store of the specified class.
 User fetchByUserName(String userName, javax.jdo.PersistenceManager pm)
          Retrieve the User uniquely identified by the specified User.userName field value.
static UserFactory getInstance()
          Return the singleton instance of this class.
 
Methods inherited from class com.sptci.jdo.Factory
addAlphabeticalIndex, begin, close, close, commit, count, delete, fetch, fetch, fetch, fetchAll, getPersistenceManager, removeStartLetter, rollback, save
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

userFactory

public static final UserFactory userFactory
The singleton instance of the DAO.

Constructor Detail

UserFactory

public UserFactory()
Method Detail

getInstance

public static UserFactory getInstance()
Return the singleton instance of this class.

Returns:
The singleton repository class instance.

fetchByUserName

public User fetchByUserName(String userName,
                            javax.jdo.PersistenceManager pm)
                     throws javax.jdo.JDOException
Retrieve the User uniquely identified by the specified User.userName field value.

Parameters:
userName - The unique userName to use to lookup the object.
pm - The persistence manager to use to fetch the object. It is assumed that an active transaction already exists.
Returns:
The appropriate object instance. Returns null if no object matching the specified userName was found.
Throws:
javax.jdo.JDOException - If errors are encountered while fetching the record.

count

public long count(javax.jdo.PersistenceManager pm)
           throws javax.jdo.JDOException
Return a count of the total number of persistent instances of the User object in the data store.

Parameters:
pm - The persistence manager to use to fetch the object count. It is assumed that an active transaction exists.
Returns:
The total number of instances in the data store.
Throws:
javax.jdo.JDOException - If errors are encountered while fetching the count.
See Also:
Factory.count( Class, PersistenceManager )

fetch

public Collection<User> fetch(long start,
                              long end,
                              javax.jdo.PersistenceManager pm)
                       throws javax.jdo.JDOException
Return a collection that contains all User instances in the data store within the specified range. This method is typically used to implement paginated view of the data in the data store. Use the count(javax.jdo.PersistenceManager) method to fetch the total number of persistent instances in the data store.

Parameters:
start - The index (inclusive) from which objects are to be retrieved from the data store.
end - The index (exclusive) till which objects are to be retrieved from the data store.
pm - The persistence manager to use. It is assumed that an active transaction exists (if non-transaction read is not enabled).
Returns:
The collection of objects. Returns an empty collection if no objects exist in the data store.
Throws:
javax.jdo.JDOException - If errors are encountered while fetching the objects.
See Also:
Factory.fetch( Class, long, long, PersistenceManager )

fetch

public Collection<User> fetch(long start,
                              long end,
                              String sortClause,
                              javax.jdo.PersistenceManager pm)
                       throws javax.jdo.JDOException
Return a collection that contains all instances in the data store of the specified class within the specified range. This method is typically used to implement paginated view of the data in the data store. Use the count(javax.jdo.PersistenceManager) method to fetch the total number of persistent instances in the data store.

Parameters:
start - The index (inclusive) from which objects are to be retrieved from the data store.
end - The index (exclusive) till which objects are to be retrieved from the data store.
sortClause - The sort clause to use to order the query results. See Query.setOrdering(java.lang.String) for details on how to specify this parameter.
pm - The persistence manager to use. It is assumed that an active transaction exists (if non-transaction read is not enabled).
Returns:
The collection of objects. Returns an empty collection if no objects exist in the data store.
Throws:
javax.jdo.JDOException - If errors are encountered while fetching the objects.

fetchAll

public Collection<User> fetchAll(javax.jdo.PersistenceManager pm)
                          throws javax.jdo.JDOException
Return a collection that contains all instances in the data store of the specified class. Note that all sub-classes of the specified type are also returned.

Parameters:
pm - The persistence manager to use. It is assumed that an active transaction exists (if non-transaction read is not enabled).
Returns:
The collection of objects. Returns an empty collection if no objects exist in the data store.
Throws:
javax.jdo.JDOException - If errors are encountered while fetching the objects.
See Also:
Factory.fetchAll( Class, PersistenceManager )

SPT Core API