01: /*
02: * Copyright 2006 Davide Deidda
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: /*
18: * Teacher.java
19: *
20: * Created on 25 aprile 2005, 9.58
21: */
22:
23: package it.biobytes.ammentos.test;
24:
25: import it.biobytes.ammentos.*;
26: import static it.biobytes.ammentos.FieldTypeEnum.*;
27: import java.util.*;
28:
29: @PersistentEntity(sourceDomain="teachers",targetDomain="teachers",primaryKey="id")
30: public class Teacher extends Person {
31: @PersistentField(fieldName="id",description="code",type=STRING)
32: private String m_id;
33:
34: @PersistentList(itemsClass="it.biobytes.ammentos.test.Course",query="teacher_id=?",cascadeOnDelete=true)
35: private List<Course> m_courses;
36:
37: /** Creates a new instance of Teacher */
38: public Teacher(String id) {
39: super (id);
40: m_id = id;
41: m_courses = new ArrayList<Course>();
42: }
43:
44: private Teacher() {
45: super (null);
46: }
47:
48: public String getId() {
49: return m_id;
50: }
51:
52: public void addCourse(Course course) {
53: m_courses.add(course);
54: course.setTeacher(this );
55: }
56:
57: public void removeCourse(Course course) {
58: m_courses.remove(course);
59: }
60:
61: public int getCoursesCount() {
62: System.out.println("m_courses: " + m_courses);
63: return m_courses.size();
64: }
65:
66: public List<Course> getCourses() {
67: return Collections.unmodifiableList(m_courses);
68: }
69:
70: public boolean equals(Object obj) {
71: boolean res = false;
72: try {
73: res = (obj != null)
74: && (Ammentos.diff(this , obj).size() == 0);
75: } catch (Exception e) {
76:
77: }
78: return res;
79: }
80:
81: }
|