public class UserFactory extends Factory<User>
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.
| Modifier and Type | Field and Description |
|---|---|
static UserFactory |
userFactory
The singleton instance of the DAO.
|
| Constructor and Description |
|---|
UserFactory() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
public static final UserFactory userFactory
public static UserFactory getInstance()
public User fetchByUserName(String userName, javax.jdo.PersistenceManager pm) throws javax.jdo.JDOException
User uniquely identified by the specified
User.userName field value.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.null
if no object matching the specified userName was found.javax.jdo.JDOException - If errors are encountered while fetching the
record.public long count(javax.jdo.PersistenceManager pm)
throws javax.jdo.JDOException
User object in the data store.pm - The persistence manager to use to fetch the object count. It
is assumed that an active transaction exists.javax.jdo.JDOException - If errors are encountered while fetching the count.Factory.count( Class, PersistenceManager )public Collection<User> fetch(long start, long end, javax.jdo.PersistenceManager pm) throws javax.jdo.JDOException
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.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).javax.jdo.JDOException - If errors are encountered while fetching the
objects.Factory.fetch( Class, long, long, PersistenceManager )public Collection<User> fetch(long start, long end, String sortClause, javax.jdo.PersistenceManager pm) throws javax.jdo.JDOException
count(javax.jdo.PersistenceManager) method to fetch the total number of
persistent instances in the data store.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).javax.jdo.JDOException - If errors are encountered while fetching the
objects.public Collection<User> fetchAll(javax.jdo.PersistenceManager pm) throws javax.jdo.JDOException
pm - The persistence manager to use. It is assumed that an
active transaction exists (if non-transaction read is not enabled).javax.jdo.JDOException - If errors are encountered while fetching the
objects.Factory.fetchAll( Class, PersistenceManager )