|
Fish & Chips Club 4.10.0.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object hirondelle.fish.main.member.MemberDAO
public class MemberDAO
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 Member s 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 |
---|
public MemberDAO()
Method Detail |
---|
public static MemberDAO getInstance()
The underlying mechanism for swapping between the two implementations relies on a simple System property.
List<Member> list() throws DAOException
Member
objects, sorted by Member Name.
DAOException
public Member fetch(Id aMemberId) throws DAOException
Member
identified by its id.
DAOException
Id add(Member aMember) throws DAOException, DuplicateException
Member
to the database.
The name of the Member must be unique. If there is a name
conflict, then a DuplicateException
is thrown.
DAOException
DuplicateException
boolean change(Member aMember) throws DAOException, DuplicateException
Member
.
The name of the Member must be unique. If there is a name
conflict, then a DuplicateException
is thrown.
DAOException
DuplicateException
int delete(Id aMemberId) throws DAOException
Member
.
If an item is linked to this Member
, then deletion will fail, and a
DAOException
is thrown.
DAOException
int deleteMany(Collection<Id> aMemberIds) throws DAOException
Member
s 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.)
DAOException
Integer getNumActiveMembers() throws DAOException
DAOException
|
Fish & Chips Club 4.10.0.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |