Source code: com/clra/rowing/EnrollmentSnapshot.java
1 /*
2 * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3 * Distributed under the GPL license. See doc/COPYING.
4 * $RCSfile: EnrollmentSnapshot.java,v $
5 * $Date: 2003/02/26 03:38:45 $
6 * $Revision: 1.3 $
7 */
8
9 package com.clra.rowing;
10
11 import com.clra.member.MemberSnapshot;
12 import com.clra.rowing.Attendance;
13 import com.clra.rowing.ParticipantSnapshot;
14 import com.clra.rowing.RowingSessionLevel;
15 import com.clra.rowing.RowingSessionSnapshot;
16 import com.clra.rowing.RowingSessionState;
17 import com.clra.rowing.RowingSessionType;
18 import com.clra.rowing.SeatPreference;
19 import java.io.Serializable;
20 import java.sql.ResultSet;
21 import java.sql.SQLException;
22 import java.util.Date;
23
24 /**
25 * Read-only information about enrollment of a member in a rowing session.
26 * Unlike a Participant entity, which is non-null only if a member is signed
27 * up for a rowing session, an enrollment instance is guaranteed to be non-null
28 * regardless of whether a member is signed up in a rowing session.
29 * An enrollment instance is a derived view that doesn't correspond to
30 * a persistent object in the database.</p><p>
31 *
32 * An enrollment is composed of a member_id, a rowing_id, and a participant_id.
33 * The member_id and rowing_id must be non-null. The participant_id is
34 * non-null only if the member has signed up for the rowing session.
35 * In addition to these primary keys, an enrollment object caches some
36 * frequently needed data from the member, rowing session and participant
37 * entities.</p><p>
38 *
39 * @version $Revision: 1.3 $ $Date: 2003/02/26 03:38:45 $
40 * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
41 */
42 public class EnrollmentSnapshot implements Serializable {
43
44 /** Snapshot of rowing session (guaranteed to be non-null) */
45 private RowingSessionSnapshot rowingSessionSnapshot = null;
46
47 /** Snapshot of participation (may be null) */
48 private ParticipantSnapshot participantSnapshot = null;
49
50 /** Primary key of member (guaranteed to be non-null) */
51 private Integer member_id = null;
52
53 /** Returns the id of the rowing session associated with this enrollment */
54 public Integer getRowingId() {
55 return this.rowingSessionSnapshot.getId();
56 }
57
58 /** Returns the id of the member associated with this enrollment */
59 public Integer getMemberId() {
60 return this.member_id;
61 }
62
63 /**
64 * Returns the id of the participant associated with this enrollment.
65 * May be null.
66 */
67 public Integer getParticipantId() {
68 Integer retVal = null;
69 if ( participantSnapshot != null ) {
70 retVal = participantSnapshot.getParticipantId();
71 }
72 return retVal;
73 }
74
75 /** Returns a snapshot of data about the rowing session */
76 public RowingSessionSnapshot getRowingSessionSnapshot() {
77 return this.rowingSessionSnapshot;
78 }
79
80 /**
81 * Returns a snapshot of participant data in a rowing session.
82 * May be null.
83 */
84 public ParticipantSnapshot getParticipantSnapshot() {
85 return this.participantSnapshot;
86 }
87
88 /** Produces an invalid EnrollmentSnapshot. Used during deserialization */
89 public EnrollmentSnapshot() {}
90
91 /**
92 * @param memberId a non-null primary key for a member
93 * @param rs a non-null snapshot of a rowing session
94 * @param ps a snapshot of a participant, possibly null. If non-null,
95 * then the member and rowing id's associated with the participant
96 * must match the id's of the preceding parameters.
97 */
98 public EnrollmentSnapshot(
99 Integer memberId, RowingSessionSnapshot rs, ParticipantSnapshot ps ) {
100
101 // Preconditions
102 if ( memberId == null ) {
103 throw new IllegalArgumentException( "null member id" );
104 }
105 if ( rs == null ) {
106 throw new IllegalArgumentException( "null rowing snapshot" );
107 }
108 if ( ps != null && !ps.getMemberId().equals( memberId ) ) {
109 String msg = "mismatch between participant and member";
110 throw new IllegalArgumentException( msg );
111 }
112 if ( ps != null && !ps.getRowingId().equals( rs.getId() ) ) {
113 String msg = "mismatch between participant and rowing session";
114 throw new IllegalArgumentException( msg );
115 }
116
117 this.member_id = memberId;
118 this.rowingSessionSnapshot = rs;
119 this.participantSnapshot = ps;
120
121 } // ctor(..)
122
123 } // EnrollmentSnapshot
124
125 /*
126 * $Log: EnrollmentSnapshot.java,v $
127 * Revision 1.3 2003/02/26 03:38:45 rphall
128 * Added copyright and GPL license
129 *
130 * Revision 1.2 2002/01/30 14:41:52 rphall
131 * Changed a comment
132 *
133 * Revision 1.4 2002/01/30 00:10:58 rphall
134 * Change to a comment
135 *
136 * Revision 1.3 2001/12/13 21:22:12 rphall
137 * Removed 'throws RowingException' from ctor
138 *
139 * Revision 1.2 2001/12/13 01:30:21 rphall
140 * Enrollment business and web objects
141 *
142 * Revision 1.1 2001/12/12 12:26:29 rphall
143 * Snapshot of a member's enrollment status in a rowing session
144 *
145 * Revision 1.2 2001/12/12 04:10:19 rphall
146 * Fixed build problems
147 *
148 * Revision 1.1 2001/12/11 09:16:11 rphall
149 * Checkpt
150 *
151 */
152