The Source for Java Technology Collaboration


pd4j

  • Java persistence
  • Objects available on main memory
  • Transparent persistence
  • Begin\Commit\Rollback functions
  • Fully Recoverable
  • XML and stardart serialization Snapshots
  • Anotate methods that doesn't need a transaction to be generated

Source Code

Browse CVS

Intrested on contribute?

  • Translating
  • Developing
  • Webdesing
  • Documenting

QuestionsHELP


1 minute learn by example

Simple Example...

Account

public class Account implements Serializable{

   private int id;
   private int ammount;
   
   public int getAmmount() {
      return this.ammount;
   }
   public void setAmmount(int ammount) {
      this.ammount = ammount;
   }
   Account (int id) {
      this.id = id;
   }
   public int getId() {
      return this.id;
   }
   public void setId(int i) {
      this.id = i;
   }
   public void deposit(int ammount) {
      this.ammount += ammount;
   }
   public void withdraw(int ammount) {
      this.ammount -= ammount;
   }
}

Bank interface

public interface Banco extends PersistedSystem {
   
   public void addAccount(int id);

   // this methos will not generant a transaction
   @MethodNTX
   public Account getAccount(int id);
   
   public void transfer (int sourceId, int targetId, int ammount);

   public void deposit (int id, int ammount);
   
   public void withdraw (int id, int ammount);

}

Bank Implementation

public class BancoImpl implements Banco, Serializable {

   private List accounts;
   
   public BancoImpl() {
      this.accounts = new Vector();
   }
   
   public void addAccount(int id) {
      this.accounts.add(new Account(id));
   }

   public Account getAccount(int id) {
      Iterator i = this.accounts.iterator();
      while (i.hasNext()) {
         Account ac = (Account)i.next();
         if (ac.getId() == id) return ac;
      }
      return null;
      
   }

   public void transfer(int sourceId, int targetId, int ammount) {

      Account ac1 = (Account) getAccount(sourceId);
      Account ac2 = (Account) getAccount(targetId);
      
      if (ac1 != null && ac2 != null) {
         ac1.withdraw(ammount);
         ac2.deposit(ammount);
      }
   }
   
   public void deposit (int id, int ammount) {
      Account ac1 = getAccount(id);
      if (ac1 != null)
         ac1.deposit(ammount);
   }
   
    public void withdraw(int id, int ammount) {
        Account ac1 = getAccount(id);
        if (ac1 != null)
           ac1.withdraw(ammount);   
    }

    public void begin() { }
    public void commit() { }
    public void rollBack() { }
}

Client...

 
Banco proxied = new BancoImpl();
proxied = (Banco)PersistenceHandler.getProxiedSystem(proxied, "banco/");

proxied.addAccount(10);
proxied.deposit(10,100);

proxied.begin();
proxied.addAccount(20);
proxied.commit(); // or proxied.rollBack();

now you can execute ant persist your bank operations!

very simple!!!

-- Main.felt - 07 Jul 2005

Topic PersistenceDeviceforJava . { Edit | Ref-By | Printable | Diffs r5 < r4 < r3 < r2 < r1 | More }
 XML java.net RSS

Revision r5 - 15 Feb 2007 - 13:50:31 - Main.felt
Parents: WebHome