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: * Student.java
19: *
20: * Created on 22 aprile 2005, 20.53
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="students",targetDomain="students",primaryKey="code",superKey="person_id")
30: public class Student extends Person {
31: @PersistentField(fieldName="code",description="student code",type=STRING)
32: private String m_code;
33:
34: @PersistentField(fieldName="media",description="student media")
35: private int m_media;
36:
37: @PersistentField(fieldName="person_id",description="person_id",type=STRING)
38: private String m_personId;
39:
40: @PersistentMap(query="student_id=?",deleteOnRemove=true,cascadeOnDelete=true,keyField="course_id")
41: private Map<Course, Mark> m_marks;
42:
43: /** Creates a new instance of Student */
44: public Student(String code, String personId) {
45: super (personId);
46: m_personId = personId;
47: m_code = code;
48: m_marks = new HashMap<Course, Mark>();
49: }
50:
51: private Student() {
52: super (null);
53: }
54:
55: public String getCode() {
56: return m_code;
57: }
58:
59: public int getMedia() {
60: return m_media;
61: }
62:
63: public void setMedia(int m_media) {
64: this .m_media = m_media;
65: }
66:
67: public void setMark(Course course, float value) {
68: m_marks.put(course, new Mark(course, this , value));
69: }
70:
71: public void removeMark(Course course) {
72: m_marks.remove(course);
73: }
74:
75: public Collection<Mark> getMarks() {
76: return m_marks.values();
77: }
78:
79: public double getMark(Course course) {
80: System.out.println("m_marks: " + m_marks);
81: return m_marks.get(course).getValue();
82: }
83:
84: public float getFloatMark(Course course) {
85: return m_marks.get(course).getFloatValue();
86: }
87:
88: }
|