01: package com.odal.petstore.service;
02:
03: import com.completex.objective.components.persistency.transact.Transaction;
04: import com.completex.objective.components.persistency.transact.TransactionManager;
05: import com.odal.petstore.OdalPetstoreException;
06: import com.odal.petstore.domain.Account;
07: import com.odal.petstore.persistence.iface.AccountDao;
08:
09: /**
10: * @author Gennady Krizhevsky
11: */
12: public class AccountService {
13: private AccountDao accountDao;
14: private TransactionManager transactionManager;
15:
16: public AccountService(TransactionManager transactionManager,
17: AccountDao accountDao) {
18: this .accountDao = accountDao;
19: this .transactionManager = transactionManager;
20: }
21:
22: public Account getAccount(final String username)
23: throws OdalPetstoreException {
24: Transaction transaction = transactionManager.beginUnchecked();
25: try {
26: return accountDao.getAccount(username);
27: } finally {
28: transactionManager.rollbackSilently(transaction);
29: }
30: }
31:
32: public Account getAccount(final String username,
33: final String password) throws OdalPetstoreException {
34: Transaction transaction = transactionManager.beginUnchecked();
35: try {
36: return accountDao.getAccount(username, password);
37: } finally {
38: transactionManager.rollbackSilently(transaction);
39: }
40: }
41:
42: public void insertAccount(final Account account)
43: throws OdalPetstoreException {
44: Transaction transaction = transactionManager.beginUnchecked();
45: try {
46: accountDao.insertAccount(account);
47: transaction.commitUnchecked();
48: } finally {
49: transactionManager.rollbackSilently(transaction);
50: }
51: }
52:
53: public void updateAccount(final Account account)
54: throws OdalPetstoreException {
55: Transaction transaction = transactionManager.beginUnchecked();
56: try {
57: accountDao.updateAccount(account);
58: transaction.commitUnchecked();
59: } finally {
60: transactionManager.rollbackSilently(transaction);
61: }
62: }
63:
64: public void updateAccount2(final Account account)
65: throws OdalPetstoreException {
66: Transaction transaction = transactionManager.beginUnchecked();
67: try {
68: Account accountToUpdate = accountDao.getAccount(account
69: .getUserName());
70: accountToUpdate.setAddress1(account.getAddress1());
71: accountDao.updateAccount(accountToUpdate);
72: transaction.commitUnchecked();
73: } finally {
74: transactionManager.rollbackSilently(transaction);
75: }
76: }
77:
78: }
|