KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > bean > Person


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.aop.bean;
23 import java.util.ArrayList JavaDoc;
24 /**
25  *
26  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
27  * @version $Revision: 37406 $
28  */

29 public class Person
30 {
31    public Person() {}
32
33    public Person(String JavaDoc name,
34                  int age,
35                  Address address)
36    {
37       this.name = name;
38       this.age = age;
39       this.address = address;
40       this.hobbies = new ArrayList JavaDoc();
41    }
42
43    private String JavaDoc name;
44    private int age;
45    private Address address;
46    private ArrayList JavaDoc hobbies;
47
48    public void testOptimisticLock()
49    {
50       name = "Billy";
51       requiresNew();
52    }
53
54    public void requiresNew()
55    {
56       name = "William";
57    }
58
59    public void testRollback()
60    {
61       name = "Billy";
62       throw new RuntimeException JavaDoc("Roll it back");
63    }
64
65    public void setNameTransactional(String JavaDoc newName)
66    {
67       name = newName;
68    }
69
70    public void setName(String JavaDoc newName)
71    {
72       name = newName;
73    }
74
75    public String JavaDoc getName()
76    {
77       return name;
78    }
79
80    public int getAge() { return age; }
81    public void setAge(int newAge) { age = newAge; }
82
83    public void testDifferentFields()
84    {
85       age = 5;
86       requiresNew();
87    }
88
89    public void testOptimisticLockWithAddress()
90    {
91       address.setCity("Billerica");
92       requiresNewForAddress();
93    }
94
95    public void requiresNewForAddress()
96    {
97       address.setCity("Rutland");
98    }
99
100    
101    public void testRollbackForAddress()
102    {
103       address.setCity("Billerica");
104       throw new RuntimeException JavaDoc("Roll it back");
105    }
106
107    public void testDifferentFieldsForAddress()
108    {
109       address.setState("VT");
110       requiresNewForAddress();
111    }
112
113    public Address getAddress() { return address; }
114    public ArrayList JavaDoc getHobbies() { return hobbies; }
115
116    public void testListOptimisticLock()
117    {
118       hobbies.add("baseball");
119       try
120       {
121          requiresNewForList();
122       }
123       catch (RuntimeException JavaDoc ex)
124       {
125          ex.printStackTrace();
126          throw ex;
127       }
128    }
129
130    public void requiresNewForList()
131    {
132       hobbies.add("football");
133    }
134
135
136    public void testListRollback()
137    {
138       hobbies.add("tennis");
139       throw new RuntimeException JavaDoc("Roll it back");
140    }
141
142    public void addHobby(String JavaDoc hobbie)
143    {
144       hobbies.add(hobbie);
145    }
146    
147 }
148
149
Popular Tags