Prevayler Facade
Diego Miranda <[email protected]>
| Newsgroups | gmane.comp.java.prevayler |
|---|---|
| Message-ID | <[email protected]> |
Hi all!
For a project i'm developing i wrote a simple proxy that implements the
transactions using annotations.
Rigth now, this proxy needs that you implement an interface with the
annotations. But the idea is that you
define your prevalent object (without any interface) with those annotations.
These annotations are the prevayler
transactions:
@Query
@Transaction
@TransactionWithQuery
An example, following the prevayler demo examples:
public interface IBank implements Serializable {
@TransactionWithQuery public Account createAccount (String holder)
throws Account.InvalidHolder;
@Transaction public void deleteAccount(long number) throws
AccountNotFound;
}
The implementation of IBank:
public class Bank implements IBank {
...
public Account createAccount(String holder) throws Account.InvalidHolder
{
Account account = new Account(nextAccountNumber, holder);
accountsByNumber.put(new Long(nextAccountNumber++), account);
if (bankListener != null) bankListener.accountCreated(account);
return account;
}
public void deleteAccount(long number) throws AccountNotFound {
Account account = findAccount(number);
accountsByNumber.remove(new Long(number));
if (bankListener != null) bankListener.accountDeleted(account);
}
...
The code remains the same.
Generating the proxy is straighforward:
Bank bank = PrevaylerProxy.createInstance ( IBank.class, new Bank(), "Bank"
);
If you found this is useful (and if possible, of course) i would be glad to
contrib with the code. :)
Regards
Diego
--
Ley de Hofstadter: Siempre toma más tiempo del que se preveía, aun cuando se
tenga en cuenta la Ley de Hofstadter.
------------------------------------------------------------------------------
_______________________________________________
To unsubscribe go to the end of this page: http://lists.sourceforge.net/lists/listinfo/prevayler-discussion
_______________________________________________
"Databases in Memoriam" -- http://www.prevayler.org