1
2
3
4
5
6
7
8
9
10 package com.sri.emo.dbobj;
11
12 import com.jcorporate.expresso.core.controller.ControllerRequest;
13 import com.jcorporate.expresso.core.db.DBConnection;
14 import com.jcorporate.expresso.core.db.DBException;
15 import com.jcorporate.expresso.core.dbobj.DBField;
16 import com.jcorporate.expresso.core.dbobj.RowSecuredDBObject;
17 import com.jcorporate.expresso.core.security.ReadOnlyUser;
18
19
20 /***
21 * a row in a scoring or design matrix or covar matrix. The first two matrices
22 * are for Measurement Model. Covar matrix was added later in Student Model. first
23 * two matrices have rows corresponding to ObservableVar, while covar matrix
24 * has both row & column for SMVs. Covar usage was added last, so some
25 * methods calling for Obs.Var. are repurposed to "RowId".
26 *
27 * @author larry hamel
28 */
29 public class MatrixCell extends RowSecuredDBObject {
30 /***
31 *
32 */
33 private static final long serialVersionUID = 1L;
34
35 /***
36 * id of attribute linking matrix rows to measurement model attributes for matrices
37 * i.e., this attribute is stored as part of the measurement model node,
38 * and references information through this MatrixCell
39 */
40 public static final String ATTRIB_ID = Attribute.ATTRIBUTE_ID;
41
42 /***
43 * row id, which is the attribute ID for the observable variable category
44 * or, for covar matrix, for SMV id
45 */
46 public static final String ROW_ID = "OV_CAT_ID";
47
48 /***
49 * the column id
50 * is null for continuous SMVs,
51 * is SMV Category ID for discrete SMVs for a scoring matrix
52 * is the id of the observable variables for a design matrix
53 */
54 public static final String COL_ID = "COL_ID";
55 public static final String VALUE = "VALUE";
56 public static final String MATRIX_DESCRIPTION = "MatrixCell";
57
58 /***
59 * @throws DBException If the new object cannot be created
60 */
61 public MatrixCell() throws DBException {
62 }
63
64 /***
65 * constructor for new cell
66 *
67 * @param attrib existing attribute for matrix, or null if new
68 * @param columnId is either at the node ID for the student model variable (scoring matrix) or the attribute ID for the category (design matrix)
69 * @throws DBException If the new object cannot be created
70 */
71 public MatrixCell(final Attribute attrib, final String columnId, final int rowId, final String value) throws
72 DBException {
73 if (attrib != null) {
74 setField(MatrixCell.ATTRIB_ID, attrib.getAttribId());
75 }
76
77 setField(ROW_ID, rowId);
78 setField(COL_ID, columnId);
79 setField(VALUE, value);
80 }
81
82 public MatrixCell(final String attribId)
83 throws DBException {
84 setField(MatrixCell.ATTRIB_ID, attribId);
85 }
86
87 /***
88 * Constructor
89 *
90 * @param theConnection DBConnection to be used to
91 * communicate with the database
92 * @param theUser User name attempting to access the
93 * object
94 * @throws DBException If the user cannot access this
95 * object or the object cannot be initialized
96 */
97 public MatrixCell(final DBConnection theConnection, final int theUser)
98 throws DBException {
99 super(theConnection, theUser);
100 }
101
102 /***
103 * Constructor for security setup.
104 *
105 * @param userSecurity ReadOnlyUser security context.
106 * @throws DBException upon construction error.
107 */
108 public MatrixCell(final ReadOnlyUser userSecurity) throws DBException {
109 super(userSecurity);
110 }
111
112
113 /***
114 * Defines the database table name and fields for this DB object
115 *
116 * @throws DBException if the operation cannot be performed
117 */
118 protected synchronized void setupFields() throws DBException {
119 setTargetTable("matrixCell");
120 setDescription(MATRIX_DESCRIPTION);
121
122
123 addField(ATTRIB_ID, DBField.INTEGER_TYPE, 0, false,
124 "foreign key to attribute table");
125
126
127 addField(ROW_ID, DBField.INTEGER_TYPE, 0, false, "row ID");
128
129
130 addField(COL_ID, DBField.VARCHAR_TYPE, 254, false,
131 "column ID: variable definition field: SMV node ID for scoring, OV for design");
132 addField(VALUE, DBField.VARCHAR_TYPE, 254, false, "value");
133
134
135 addKey(ATTRIB_ID);
136 addKey(ROW_ID);
137 addKey(COL_ID);
138
139 addIndex("attrib_idx", ATTRIB_ID, false);
140 }
141
142 /***
143 * @return this cells attrib number which specifies its membership in a matrix (same attrib id for all cells)
144 */
145 public String getAttribId() throws DBException {
146
147
148 return getField(ATTRIB_ID);
149 }
150
151 public String getValue() throws DBException {
152 return getField(VALUE);
153 }
154
155 public String getOVCatId() throws DBException {
156 return getField(ROW_ID);
157 }
158
159 /***
160 * @return ID for student model variable, which is stored in the "COL_ID" field for scoring matrices
161 */
162 public String getSMVId() throws DBException {
163 return getField(COL_ID);
164 }
165
166 /***
167 * will throw if SMV not found
168 */
169 public Node getSMV(ControllerRequest request) throws DBException {
170 Node smv = new Node(request, getSMVId());
171 smv.retrieve();
172
173 return smv;
174 }
175
176 /***
177 * will throw if SMV not found
178 */
179 public Node getSMV() throws DBException {
180 Node smv = new Node(getSMVId());
181 smv.retrieve();
182
183 return smv;
184 }
185
186 /***
187 * will throw if OV Category not found
188 */
189 public Attribute getOVCat()
190 throws DBException {
191 Attribute ovCat = new Attribute(getOVCatId());
192 ovCat.retrieve();
193
194 return ovCat;
195 }
196
197 /***
198 * @return column id for this cell. for a scoring matrix, this is equivalent to getSMVId(); for a design matrix, this is a OVCat ID, but not to be confused with the other dimension
199 */
200 public String getColumnId() throws DBException {
201 return getField(COL_ID);
202 }
203
204 /***
205 * @return row id. must be an integer.
206 */
207 public String getRowId() throws DBException {
208 return getField(ROW_ID);
209 }
210
211 public Attribute getAttrib(final ControllerRequest request)
212 throws DBException {
213 Attribute attrib = new Attribute(getAttribId());
214 attrib.retrieve();
215
216 return attrib;
217 }
218
219 public void setValue(final String value) throws DBException {
220 setField(VALUE, value);
221 }
222
223 public void setColId(final String colId) throws DBException {
224 setField(COL_ID, colId);
225 }
226
227 public void setRowId(final String rowId) throws DBException {
228 setField(ROW_ID, rowId);
229 }
230
231 public void setRowId(final int rowId) throws DBException {
232 setField(ROW_ID, rowId);
233 }
234
235 public void setAttribID(final String attribId) throws DBException {
236 setField(ATTRIB_ID, attribId);
237 }
238 }