
Build a distributed application with the Java adapter 241
The following example shows the assembler class’s doCreate(), doUpdate(), and
doDelete() methods:
private ChangeObject doCreate(ChangeObject co)
{
ContactDAO dao = new ContactDAO();
Contact contact = dao.create((Contact) co.getNewVersion());
co.setNewVersion(contact);
return co;
}
private void doUpdate(ChangeObject co)
{
ContactDAO dao = new ContactDAO();
try
{
dao.update((Contact) co.getNewVersion(), (Contact)
co.getPreviousVersion());
}
catch (ConcurrencyException e)
{
System.err.println("*** Throwing DataSyncException when trying to
update contact id=" + ((Contact) co.getNewVersion()).getContactId() );
throw new DataSyncException(co);
}
}
private void doDelete(ChangeObject co)
{
ContactDAO dao = new ContactDAO();
try
{
dao.delete((Contact) co.getPreviousVersion());
}
catch (ConcurrencyException e)
{
System.err.println("*** Throwing DataSyncException when trying to
delete contact id=" + ((Contact) co.getNewVersion()).getContactId() );
throw new DataSyncException(co);
}
}
Komentarze do niniejszej Instrukcji