1
2
3
4
5
6
7
8
9
10
11
12
13 package com.sri.emo.dbobj;
14
15 import com.jcorporate.expresso.core.db.DBConnection;
16 import com.jcorporate.expresso.core.db.DBException;
17 import com.jcorporate.expresso.core.dbobj.DBField;
18 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
19 import org.apache.log4j.Logger;
20
21 import java.util.Comparator;
22
23 /***
24 * This function represents the many objects that are available to the decision
25 * set.
26 * <p/>
27 * DataObjects provide the low-level Object Relational mapping between these objects
28 * and a JDBC backend.</p>
29 *
30 * @author Michael Rimov
31 */
32
33 public class WizDecisionEntities extends SecuredDBObject {
34
35
36 /***
37 *
38 */
39 private static final long serialVersionUID = 1L;
40
41 /***
42 * The log4j logger instance for this class type. Send all logging output
43 * to this variable
44 */
45 private static final transient Logger log = Logger.getLogger(WizDecisionEntities.class);
46
47 /***
48 * Public constant for access to field
49 * "Item ID"
50 */
51 public static final String FLD_ID = "Id";
52
53 /***
54 * Public constant for access to field
55 * "Decision Set ID"
56 */
57 public static final String FLD_SETID = "SetId";
58
59 /***
60 * Public constant for access to field
61 * "Wizard Step Id"
62 */
63 public static final String FLD_STEPID = "StepId";
64
65 /***
66 * Public constant for access to field
67 * "Step Value"
68 */
69 public static final String FLD_STEPVALUE = "StepValue";
70
71
72 /***
73 * Creates an instance of WizDecisionEntities. Call setRequestingUid() and setDataContext()
74 * before using.
75 *
76 * @throws DBException upon initialization exception.
77 * @see com.jcorporate.expresso.core.dbobj.SecuredDBObject#SecuredDBObject
78 */
79 public WizDecisionEntities() throws DBException {
80 }
81
82
83 /***
84 * Creates an instance of WizDecisionEntities that uses an already grabbed DBConnection
85 * object. This is for use inside transactions. <p>Example: <code><pre>
86 * DBConnection oneConnection = DBConnectionPool.getInstance("default").getConnection();
87 * oneConnection.setAutoCommit(false);
88 * WizDecisionEntities myObj = new WizDecisionEntities(oneConnection);
89 * //Set fields here....
90 * myObj.add();
91 * myObj.clear();
92 * //more set fields
93 * myObj.add();
94 * //Commit the transaction
95 * oneConnection.commit();
96 * oneConnection.release();
97 * </pre></code>
98 * </p>
99 *
100 * @param dbConnection com.jcorporate.expresso.core.db.DBConnection
101 * @throws DBException upon construction error
102 */
103 public WizDecisionEntities(DBConnection dbConnection) throws DBException {
104 super(dbConnection);
105 }
106
107
108 /***
109 * <p/>
110 * Constructor that sets a connection as the object is created - typically
111 * this is used when a particular DBConnection is required for the purposes of
112 * maintaining a database transaction. If a specific connection is not used,
113 * there is no way to use commit() and rollback() in the event of failure, as a
114 * different DBConnection might be used for each phase of the transaction.
115 * Critial sections should therefore explicity request a DBConnection from the
116 * connection pool and pass it to each of the DB objects in that section.
117 * </p>
118 * <p>This constructor is neceesary to work with otherDBMap and transaction
119 * capabilities</p>
120 *
121 * @param dbConnection The DBConnection to utilize
122 * @param securityContext The data context that contains the setup (and
123 * security) tables for this object
124 * @throws DBException upon initialization error
125 */
126 public WizDecisionEntities(DBConnection dbConnection, String securityContext) throws DBException {
127 super(dbConnection, securityContext);
128 }
129
130
131
132 /***
133 * One time intiialization of all the field types. Set all specifications
134 * here such as field names, table name, friendly name of the data object,
135 * characterset, etc.
136 *
137 * @throws DBException upon error
138 */
139 protected void setupFields() throws DBException {
140 if (log.isDebugEnabled()) {
141 log.debug("Initializing field members");
142 }
143
144 super.setupFields();
145 setTargetTable("WIZDECISIONENTITIES");
146
147 setDescription("Wizard Decision Details");
148 setCharset("ISO-8859-1");
149
150 addField(FLD_ID, DBField.AUTOINC_TYPE, 0, false, "Item ID");
151 addKey(FLD_ID);
152
153 addField(FLD_SETID, DBField.INTEGER_TYPE, 0, false, "Decision Set ID");
154
155 addField(FLD_STEPID, DBField.INTEGER_TYPE, 0, false, "Wizard Step Id");
156
157 addField(FLD_STEPVALUE, DBField.VARCHAR_TYPE, 254, false, "Step Value");
158
159 addIndex("WIZDECISION_SETID", FLD_SETID, false);
160
161
162 }
163
164 public void setStepId(int stepValue) throws DBException {
165 setField(FLD_STEPID, stepValue);
166 }
167
168 public int getStepId() throws DBException {
169 return getFieldInt(FLD_STEPID);
170 }
171
172
173 public void setDecisionValue(int decisionValue) throws DBException {
174 setField(FLD_STEPVALUE, decisionValue);
175 }
176
177 public int getDecisionValue() throws DBException {
178 return getFieldInt(FLD_STEPVALUE);
179 }
180
181
182 /***
183 * Comparator that sorts on id.
184 *
185 * @author Michael Rimov
186 */
187 public static class DecisionComparator implements Comparator {
188 /***
189 * Default constructor.
190 */
191 public DecisionComparator() {
192 }
193
194 /***
195 * Compares its two arguments for order.
196 *
197 * @param o1 the first object to be compared.
198 * @param o2 the second object to be compared.
199 * @return a negative integer, zero, or a positive integer as the
200 * first argument is less than, equal to, or greater than the
201 * second.
202 */
203 public int compare(Object o1, Object o2) {
204 WizDecisionEntities entity1 = (WizDecisionEntities) o1;
205 WizDecisionEntities entity2 = (WizDecisionEntities) o2;
206
207 try {
208 if (entity1.getDecisionValue() > entity2.getDecisionValue()) {
209 return 1;
210 } else if (entity1.getDecisionValue()
211 < entity2.getDecisionValue()) {
212 return -1;
213 } else {
214 return 0;
215 }
216 } catch (DBException ex) {
217 throw new IllegalStateException("Error performing comparison");
218 }
219 }
220
221 /***
222 * Indicates whether some other object is "equal to" this
223 * Comparator.
224 *
225 * @param obj the reference object with which to compare.
226 * @return <code>true</code> only if the specified object is also a
227 * comparator and it imposes the same ordering as this comparator.
228 */
229 public boolean equals(Object obj) {
230 return DecisionComparator.class.equals(obj.getClass());
231 }
232
233 /***
234 * Returns a hash code value for the object.
235 *
236 * @return a hash code value for this object.
237 */
238 public int hashCode() {
239 return DecisionComparator.class.hashCode();
240 }
241
242
243 }
244 }