25.12.2013 Views

Developer Notes - ITwelzel.biz

Developer Notes - ITwelzel.biz

Developer Notes - ITwelzel.biz

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

+ e.getMessage());<br />

}<br />

return dao;<br />

public ContactsDAO getContactsDAO()<br />

{<br />

return (ContactsDAO)lookupDAO(ConfigFile.CONTACTS_DAO_CLASS);<br />

}<br />

public PersonDAO getPersonDAO()<br />

{<br />

return (PersonDAO)lookupDAO(ConfigFile.PERSON_DAO_CLASS);<br />

}<br />

public AddressDAO getAddressDAO()<br />

{<br />

return (AddressDAO)lookupDAO(ConfigFile.ADDRESS_DAO_CLASS);<br />

}<br />

}<br />

public CompanyDAO getCompanyDAO()<br />

{<br />

return (CompanyDAO)lookupDAO(ConfigFile.COMPANY_DAO_CLASS);<br />

}<br />

The DAO Client<br />

A client application or service retrieves the desired DAO factory, which is used to<br />

retrieve the desired DAO instance. Once the DAO instance is retrieved, the client<br />

can call data access methods on the instance without worrying about the<br />

underlying data access code:<br />

// retrieve the desired DAO Factory<br />

DAOFactory hsqldbFactory =<br />

DAOFactory.getDAOFactory(DAOFactory.HSQLDB);<br />

<strong>Developer</strong> <strong>Notes</strong><br />

// retrieve the DAO<br />

ContactsDAO ContactsDAO = hsqldbFactory.getContactsDAO();<br />

// create a new Contact<br />

String contactID = contactsDAO.addContact(addStr);<br />

// get the new Contact object.<br />

Contact contact = contactsDAO.getContact(contactID);<br />

// modify the Contact object using SQL statements<br />

contactsDAO.modifyContact(contactID, modifyStr);<br />

// delete the Contact object<br />

contactsDAO.deleteContact(aContact);<br />

N o v e m b e r 2 0 0 2<br />

55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!