001: package org.apache.ojb.broker;
002:
003: import java.io.Serializable;
004: import java.util.Collection;
005:
006: import org.apache.commons.lang.builder.EqualsBuilder;
007: import org.apache.commons.lang.builder.ToStringBuilder;
008:
009: /**
010: * Helper class centralize test classes.
011: *
012: * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
013: * @version $Id: ObjectRepository.java,v 1.6.2.2 2005/12/17 01:39:10 arminw Exp $
014: */
015: public class ObjectRepository {
016: public static class Component implements ComponentIF {
017: Integer id;
018: int type;
019: String name;
020: Group group;
021: ComponentIF parentComponent;
022: Collection childComponents;
023:
024: public boolean equals(Object obj) {
025: boolean result = false;
026: if (obj instanceof ComponentIF) {
027: ComponentIF other = (ComponentIF) obj;
028: result = new EqualsBuilder().append(this .getId(),
029: other.getId()).append(this .getName(),
030: other.getName()).append(this .getType(),
031: other.getType()).isEquals();
032: }
033: return result;
034: }
035:
036: public String toString() {
037: return ToStringBuilder.reflectionToString(this );
038: }
039:
040: public Integer getId() {
041: return id;
042: }
043:
044: public void setId(Integer id) {
045: this .id = id;
046: }
047:
048: public Group getGroup() {
049: return group;
050: }
051:
052: public void setGroup(Group group) {
053: this .group = group;
054: }
055:
056: public ComponentIF getParentComponent() {
057: return parentComponent;
058: }
059:
060: public void setParentComponent(ComponentIF parentComponent) {
061: this .parentComponent = parentComponent;
062: }
063:
064: public Collection getChildComponents() {
065: return childComponents;
066: }
067:
068: public void setChildComponents(Collection childComponents) {
069: this .childComponents = childComponents;
070: }
071:
072: public int getType() {
073: return type;
074: }
075:
076: public void setType(int type) {
077: this .type = type;
078: }
079:
080: public String getName() {
081: return name;
082: }
083:
084: public void setName(String name) {
085: this .name = name;
086: }
087: }
088:
089: public static interface ComponentIF extends Serializable {
090: Integer getId();
091:
092: void setId(Integer id);
093:
094: ObjectRepository.Group getGroup();
095:
096: void setGroup(ObjectRepository.Group group);
097:
098: ComponentIF getParentComponent();
099:
100: void setParentComponent(ComponentIF parentComponent);
101:
102: Collection getChildComponents();
103:
104: void setChildComponents(Collection childComponents);
105:
106: int getType();
107:
108: void setType(int type);
109:
110: String getName();
111:
112: void setName(String name);
113: }
114:
115: public static class Group implements Serializable {
116: Integer id;
117: String name;
118:
119: public Integer getId() {
120: return id;
121: }
122:
123: public void setId(Integer id) {
124: this .id = id;
125: }
126:
127: public String getName() {
128: return name;
129: }
130:
131: public void setName(String name) {
132: this .name = name;
133: }
134: }
135:
136: public static abstract class AB implements Serializable {
137: private int id;
138: /**
139: * This special attribute telling OJB which concrete class this Object has.
140: * NOTE: this attribute MUST be called ojbConcreteClass
141: */
142: private String ojbConcreteClass;
143:
144: protected AB() {
145: // this guarantee that always the correct class name will be set
146: this .ojbConcreteClass = this .getClass().getName();
147: }
148:
149: protected AB(int id) {
150: this ();
151: this .id = id;
152: }
153:
154: public int getId() {
155: return id;
156: }
157:
158: public void setId(int id) {
159: this .id = id;
160: }
161:
162: public String getOjbConcreteClass() {
163: return ojbConcreteClass;
164: }
165:
166: public void setOjbConcreteClass(String ojbConcreteClass) {
167: this .ojbConcreteClass = ojbConcreteClass;
168: }
169: }
170:
171: public static interface AAlone {
172: }
173:
174: public static class A extends AB implements AAlone {
175: private int someValue;
176: private String someAField;
177:
178: public A() {
179: super ();
180: }
181:
182: public A(int pId, int pSomeValue) {
183: super (pId);
184: this .someValue = pSomeValue;
185: }
186:
187: public String getSomeAField() {
188: return someAField;
189: }
190:
191: public void setSomeAField(String someAField) {
192: this .someAField = someAField;
193: }
194:
195: public int getSomeValue() {
196: return someValue;
197: }
198:
199: public void setSomeValue(int someValue) {
200: this .someValue = someValue;
201: }
202: }
203:
204: public static class B extends AB {
205: private int someValue;
206: private String someBField;
207:
208: public B() {
209: super ();
210: }
211:
212: public B(int pId, int pSomeValue) {
213: super (pId);
214: this .someValue = pSomeValue;
215: }
216:
217: public String getSomeBField() {
218: return someBField;
219: }
220:
221: public void setSomeBField(String someBField) {
222: this .someBField = someBField;
223: }
224:
225: public int getSomeValue() {
226: return someValue;
227: }
228:
229: public void setSomeValue(int someValue) {
230: this .someValue = someValue;
231: }
232: }
233:
234: public static class B1 extends B {
235: public B1() {
236: super ();
237: }
238:
239: public B1(int pId, int pSomeValue) {
240: super (pId, pSomeValue);
241: }
242: }
243:
244: public static class C implements Serializable {
245: private String ojbConcreteClass;
246: private int id;
247: private int someValue;
248:
249: public C() {
250: ojbConcreteClass = this .getClass().getName();
251: }
252:
253: public C(int pId, int pSomeValue) {
254: this ();
255: this .id = pId;
256: this .someValue = pSomeValue;
257: }
258:
259: public int getId() {
260: return id;
261: }
262:
263: public void setId(int id) {
264: this .id = id;
265: }
266:
267: public String getOjbConcreteClass() {
268: return ojbConcreteClass;
269: }
270:
271: public void setOjbConcreteClass(String ojbConcreteClass) {
272: this .ojbConcreteClass = ojbConcreteClass;
273: }
274:
275: public int getSomeValue() {
276: return someValue;
277: }
278:
279: public void setSomeValue(int someValue) {
280: this .someValue = someValue;
281: }
282: }
283:
284: public static class D extends C {
285: public D() {
286: super ();
287: }
288:
289: public D(int pId, int pSomeValue) {
290: super (pId, pSomeValue);
291: }
292: }
293:
294: public static class E implements Serializable {
295: private Integer id;
296: private int someSuperValue;
297:
298: public Integer getId() {
299: return id;
300: }
301:
302: public void setId(Integer id) {
303: this .id = id;
304: }
305:
306: public int getSomeSuperValue() {
307: return someSuperValue;
308: }
309:
310: public void setSomeSuperValue(int someSuperValue) {
311: this .someSuperValue = someSuperValue;
312: }
313: }
314:
315: /**
316: * important note:
317: * This class uses an anonymous field to hold the foreign key referencing to the parent table.
318: * thus there is no attribute holding the FK in the class.
319: * There is also no additional coding required to populate the inherited attributes
320: * on loading or persiting an instance of this class.
321: */
322: public static class F extends E implements Serializable {
323: int someValue;
324:
325: public int getSomeValue() {
326: return someValue;
327: }
328:
329: public void setSomeValue(int someValue) {
330: this .someValue = someValue;
331: }
332: }
333:
334: public static class G extends F implements Serializable {
335: int someSubValue;
336:
337: public int getSomeSubValue() {
338: return someSubValue;
339: }
340:
341: public void setSomeSubValue(int someSubValue) {
342: this .someSubValue = someSubValue;
343: }
344: }
345:
346: public static class F1 extends E implements Serializable {
347: int someValue;
348:
349: public int getSomeValue() {
350: return someValue;
351: }
352:
353: public void setSomeValue(int someValue) {
354: this .someValue = someValue;
355: }
356: }
357:
358: public static class G1 extends F1 implements Serializable {
359: int someSubValue;
360:
361: public int getSomeSubValue() {
362: return someSubValue;
363: }
364:
365: public void setSomeSubValue(int someSubValue) {
366: this.someSubValue = someSubValue;
367: }
368: }
369: }
|