Fish & Chips Club 4.10.0.0

hirondelle.fish.main.member
Class MemberDAO

Object
  extended by hirondelle.fish.main.member.MemberDAO
Direct Known Subclasses:
MemberDAOFake

public class MemberDAO
extends Object

Data Access Object (DAO) for Member objects.

Design Note

This class is not final. This allows creating MemberDAOFake as a subclass. Instead of using a subclass to define the fake DAO, some might prefer to define an interface for the DAO instead, along with two concrete implementations, one for the real DAO, and one for the fake DAO.

The subclass style was used here since it seems a bit more compact : only two top-level items need to be defined, not three.

Either style will work.


Constructor Summary
MemberDAO()
           
 
Method Summary
(package private)  Id add(Member aMember)
          Add a new Member to the database.
(package private)  boolean change(Member aMember)
          Update an existing Member.
(package private)  int delete(Id aMemberId)
          Delete a single Member.
(package private)  int deleteMany(Collection<Id> aMemberIds)
          Delete one or more Members in one operation.
 Member fetch(Id aMemberId)
          Return a single Member identified by its id.
static MemberDAO getInstance()
          Return either a real or a fake DAO.
(package private)  Integer getNumActiveMembers()
          Return the number of currently active members.
(package private)  List<Member> list()
          Return a List of all Member objects, sorted by Member Name.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemberDAO

public MemberDAO()
Method Detail

getInstance

public static MemberDAO getInstance()
Return either a real or a fake DAO.

The underlying mechanism for swapping between the two implementations relies on a simple System property.


list

List<Member> list()
            throws DAOException
Return a List of all Member objects, sorted by Member Name.

Throws:
DAOException

fetch

public Member fetch(Id aMemberId)
             throws DAOException
Return a single Member identified by its id.

Throws:
DAOException

add

Id add(Member aMember)
 throws DAOException,
        DuplicateException
Add a new Member to the database.

The name of the Member must be unique. If there is a name conflict, then a DuplicateException is thrown.

Returns:
the autogenerated database id.
Throws:
DAOException
DuplicateException

change

boolean change(Member aMember)
         throws DAOException,
                DuplicateException
Update an existing Member.

The name of the Member must be unique. If there is a name conflict, then a DuplicateException is thrown.

Returns:
true only if a record is actually edited.
Throws:
DAOException
DuplicateException

delete

int delete(Id aMemberId)
     throws DAOException
Delete a single Member.

If an item is linked to this Member, then deletion will fail, and a DAOException is thrown.

Throws:
DAOException

deleteMany

int deleteMany(Collection<Id> aMemberIds)
         throws DAOException
Delete one or more Members in one operation.

Returns the total number of deleted items.

This method has an unusual policy regarding failed operations. Each delete operation is treated as a separate item. No transactions are used here. If one delete operation fails (for example, because of a foreign key constraint), then this method will not stop. Rather, it will keep trying to delete items in sequence, until it gets to the end of the given Member ids.

It is important to be aware of this policy. You may implement in another style, if desired. It's highly recommended that the calling action examine the return value of this method, and compare it with the number of Member Ids, to detect if an error has occurred.

(An interesting alternative policy would be to return not a single integer, but the list of Ids of items that were successfully (or unsuccessfully) deleted.)

Throws:
DAOException

getNumActiveMembers

Integer getNumActiveMembers()
                      throws DAOException
Return the number of currently active members.

Throws:
DAOException

Fish & Chips Club 4.10.0.0

Copyright Hirondelle Systems - Generated 2013Oct19.12.26