1
2
3
4 package org.sourceforge.jemm.sample.demo1.model;
5
6 import org.sourceforge.jemm.Entity;
7 import org.sourceforge.jemm.lifecycle.ConstructorLifecycle;
8 import org.sourceforge.jemm.lifecycle.ShadowUserObject;
9
10
11
12
13
14
15
16 @Entity
17 public class SavingsAccount extends Account {
18
19 double lastInterestAmount;
20
21
22
23
24 public SavingsAccount() {
25 ConstructorLifecycle.preConstructor(SavingsAccount.class.getName());
26 ConstructorLifecycle.beginConstructor(this);
27 try {
28 lastInterestAmount = 0;
29 ConstructorLifecycle.endConstructor(this);
30 }catch(Throwable t) {
31 ConstructorLifecycle.failedConstructor(this);
32
33 throw new RuntimeException(t);
34 }
35 }
36
37 public SavingsAccount(ShadowUserObject jemmOIF) {
38 super(jemmOIF);
39 }
40
41
42
43
44
45
46
47 public SavingsAccount(double initialBalance) {
48
49 super(initialBalance);
50 ConstructorLifecycle.preConstructor(SavingsAccount.class.getName());
51 ConstructorLifecycle.beginConstructor(this);
52
53 try {
54 ConstructorLifecycle.endConstructor(this);
55 }catch(Throwable t) {
56 ConstructorLifecycle.failedConstructor(this);
57
58 throw new RuntimeException(t);
59 }
60 }
61
62
63
64
65
66
67
68 public void addInterest(double interestRate) {
69 jemmOIF.entityEntered("org.sourceforge.jemm.sample.demo1.model.SavingsAccount#addInterest (D)V");
70 jemmOIF.beginLock();
71 try {
72 lastInterestAmount = balance * interestRate / 100;
73 balance = balance + lastInterestAmount;
74 } finally {
75 jemmOIF.endLock();
76 jemmOIF.entityExited("org.sourceforge.jemm.sample.demo1.model.SavingsAccount#addInterest (D)V");
77 }
78 }
79 }