View Javadoc

1   /*
2    * Created on 6 Nov 2007
3    * 
4    */
5   package org.sourceforge.jemm.sample.demo1;
6   
7   import org.sourceforge.jemm.Session;
8   import org.sourceforge.jemm.sample.AbstractDemo;
9   import org.sourceforge.jemm.sample.demo1.model.orig.Account;
10  import org.sourceforge.jemm.sample.demo1.model.orig.Person;
11  import org.sourceforge.jemm.sample.demo1.model.orig.SavingsAccount;
12  
13  /**
14   * A simple demonstration program. The demo uses a persistent memory store (the
15   * data is stored in memory and persisted to disk on shutdown. It is a simple
16   * example that looks to see if a Foo is already stored, if so it finds the
17   * associated Bar and increments the counter. If no Foo is found it creates a
18   * new one and places it into the store.
19   * 
20   * @author Rory Graves
21   * 
22   */
23  public final class Demo1Weaved extends AbstractDemo {
24  
25  	static final char POUND ='\u00A3';
26  
27  	private Demo1Weaved(String[] cmdArgs) {
28  		super("Demo1Weaved",true,cmdArgs);
29  	}
30  
31  	/**
32  	 * Main method, runs the example using the command line store configuration
33  	 * 
34  	 * @param args Program arguments - see AbstractDemo.
35  	 */
36  	public static void main(String[] args) {
37  		Demo1Weaved demo = new Demo1Weaved(args);
38  		demo.runDemo();
39  	}
40  
41  	/**
42  	 * Runs the actual demo with the given store implementation.
43  	 */
44  	public void runDemo() {
45  		try {
46  			
47  			Account account;
48  			// sets foo as a root object, foo and any objects
49  			Person storedPerson = (Person) store.getRoot("client");
50  
51  			if (storedPerson == null) {
52  				System.out.println("person was null - storing new");
53  				// creates a model class - live until it goes out of scope.
54  				Person person = new Person("Fred");
55  
56  				account = new SavingsAccount();
57  				person.setAccount(account);
58  				store.setRoot("client", person);
59  			} else {
60  				System.out.println("Person was valid");
61  				System.out.println("Adding " + POUND + "100");
62  				account = storedPerson.getAccount();
63  				account.deposit(100.0);
64  			}
65  			
66  			System.out.println("CurrentBalance=" + POUND + account.getBalance());
67  		} finally {
68  			Session.shutdown();
69  		}
70  	}
71  }