KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > expressionbuilders > ProcessIteratorExpressionBuilderDODS


1 /* ProcessIteratorExpressionBuilderDODS.java */
2
3 package org.enhydra.shark.expressionbuilders;
4
5 import java.util.Iterator JavaDoc;
6 import java.util.Properties JavaDoc;
7
8 import org.enhydra.shark.api.RootException;
9 import org.enhydra.shark.api.common.ProcessIteratorExpressionBuilder;
10 import org.enhydra.shark.api.common.SharkConstants;
11
12 /**
13  * ProcessIteratorExpressionBuilderDODS
14  *
15  * @author V.Puskas
16  * @version 0.21
17  */

18 public class ProcessIteratorExpressionBuilderDODS extends
19                                                 BasicExpressionBuilder implements
20                                                                       ProcessIteratorExpressionBuilder {
21
22    private static final String JavaDoc sqlProcDefName = " PDefName ";
23    private static final String JavaDoc sqlId = " Id ";
24    private static final String JavaDoc sqlName = " Name ";
25    private static final String JavaDoc sqlState = " State ";
26    private static final String JavaDoc sqlPriority = " Priority ";
27    private static final String JavaDoc sqlCreated = " Created ";
28    private static final String JavaDoc sqlStarted = " Started ";
29    private static final String JavaDoc sqlLastStateTime = " LastStateTime ";
30    private static final String JavaDoc sqlResourceRequesterId = " ResourceRequesterId ";
31
32    public ProcessIteratorExpressionBuilderDODS(Properties JavaDoc p) {
33       super(p);
34    }
35
36    public ProcessIteratorExpressionBuilder and() {
37       this.operator = AND_OPERATOR;
38       return this;
39    }
40
41    public ProcessIteratorExpressionBuilder or() {
42       this.operator = OR_OPERATOR;
43       return this;
44    }
45
46    public ProcessIteratorExpressionBuilder not() {
47       this.operator |= NOT_OPERATOR;
48       return this;
49    }
50
51    public ProcessIteratorExpressionBuilder addPackageIdEquals(String JavaDoc exp) {
52       addEqualsWithSubQuery(SharkConstants.PROC_MGR_PACKAGE_ID,
53                             " ProcessDefinition ",
54                             "IN (SELECT "
55                             + objectid_column_name
56                             + " FROM ProcessDefinitions WHERE PackageId = ",
57                             exp,
58                             ") ");
59       return this;
60    }
61
62    public ProcessIteratorExpressionBuilder addProcessDefIdEquals(String JavaDoc exp) {
63       addEqualsWithSubQuery(SharkConstants.PROC_MGR_PROCESS_DEFINITION_ID,
64                             " ProcessDefinition ",
65                             "IN (SELECT "
66                             + objectid_column_name
67                             + " FROM ProcessDefinitions WHERE ProcessDefinitionId = ",
68                             exp,
69                             ") ");
70       return this;
71    }
72
73    public ProcessIteratorExpressionBuilder addMgrNameEquals(String JavaDoc exp) {
74       addEqualsWithSubQuery(SharkConstants.PROC_MGR_NAME,
75                             " ProcessDefinition ",
76                             "IN (SELECT "
77                             + objectid_column_name
78                             + " FROM ProcessDefinitions WHERE Name = ",
79                             exp,
80                             ") ");
81       return this;
82    }
83
84    public ProcessIteratorExpressionBuilder addVersionEquals(String JavaDoc exp) {
85       addEqualsWithSubQuery(SharkConstants.PROC_MGR_VERSION,
86                             " ProcessDefinition ",
87                             "IN (SELECT "
88                             + objectid_column_name
89                             + " FROM ProcessDefinitions WHERE ProcessDefinitionVersion = ",
90                             exp,
91                             ") ");
92       return this;
93    }
94
95    public ProcessIteratorExpressionBuilder addIsMgrEnabled() {
96       addEqualsWithSubQuery(SharkConstants.PROC_MGR_ENABLED,
97                             " ProcessDefinition ",
98                             "IN (SELECT "
99                             + objectid_column_name
100                             + " FROM ProcessDefinitions WHERE State = ",
101                             "0",
102                             ") ");
103       return this;
104    }
105
106    public ProcessIteratorExpressionBuilder addStateEquals(String JavaDoc arg) {
107       addEqualsWithSubQuery(SharkConstants.PROC_STATE,
108                             sqlState,
109                             "IN (SELECT "
110                             + objectid_column_name
111                             + " FROM ProcessStates WHERE Name = ",
112                             arg,
113                             ") ");
114       return this;
115    }
116
117    public ProcessIteratorExpressionBuilder addStateStartsWith(String JavaDoc arg) {
118       addStartsWithSubQuery(SharkConstants.PROC_STATE,
119                             sqlState,
120                             "IN (SELECT "
121                             + objectid_column_name
122                             + " FROM ProcessStates WHERE Name LIKE ",
123                             arg,
124                             ") ");
125       return this;
126    }
127
128    public ProcessIteratorExpressionBuilder addIdEquals(String JavaDoc arg) {
129       addEquals(SharkConstants.PROC_KEY, sqlId, arg);
130       return this;
131    }
132
133    public ProcessIteratorExpressionBuilder addNameEquals(String JavaDoc arg) {
134       addEquals(SharkConstants.PROC_NAME, sqlName, arg);
135       return this;
136    }
137
138    public ProcessIteratorExpressionBuilder addPriorityEquals(int arg) {
139       addEquals(SharkConstants.PROC_PRIORITY, sqlPriority, arg);
140       return this;
141    }
142
143    public ProcessIteratorExpressionBuilder addDescriptionEquals(String JavaDoc arg) {
144       addEquals(SharkConstants.PROC_DESCRIPTION, " Description ", arg);
145       return this;
146    }
147
148    public ProcessIteratorExpressionBuilder addDescriptionContains(String JavaDoc arg) {
149       addContains(SharkConstants.PROC_DESCRIPTION, " Description ", arg);
150       return this;
151    }
152
153    public ProcessIteratorExpressionBuilder addRequesterIdEquals(String JavaDoc arg) {
154       addEqualsWithSubQueryTwice(SharkConstants.PROC_REQUESTER_ID,
155                                  sqlId,
156                                  "IN (SELECT Id FROM ProcessRequesters WHERE ActivityRequester IN (SELECT "
157                                  + objectid_column_name
158                                  + "FROM Activities WHERE Id = ",
159                                  arg,
160                                  ") OR ResourceRequester IN (SELECT "
161                                  + objectid_column_name
162                                  + "FROM ResourcesTable WHERE Username = ",
163                                  ")) ");
164       return this;
165    }
166
167    public ProcessIteratorExpressionBuilder addRequesterUsernameEquals(String JavaDoc arg) {
168       addEquals(SharkConstants.PROC_REQUESTER_RESOURCE,
169                             sqlResourceRequesterId,
170                             arg);
171       return this;
172    }
173
174    public ProcessIteratorExpressionBuilder addCreatedTimeEquals(long arg) {
175       addEquals(SharkConstants.PROC_CREATED_TIME_MS, sqlCreated, arg);
176       return this;
177    }
178
179    public ProcessIteratorExpressionBuilder addCreatedTimeBefore(long arg) {
180       addLessThan(SharkConstants.PROC_CREATED_TIME_MS, sqlCreated, arg);
181       return this;
182    }
183
184    public ProcessIteratorExpressionBuilder addCreatedTimeAfter(long arg) {
185       addGreaterThan(SharkConstants.PROC_START_TIME_MS, sqlCreated, arg);
186       return this;
187    }
188
189    public ProcessIteratorExpressionBuilder addStartTimeEquals(long arg) {
190       addEquals(SharkConstants.PROC_START_TIME_MS, sqlStarted, arg);
191       return this;
192    }
193
194    public ProcessIteratorExpressionBuilder addStartTimeBefore(long arg) {
195       addLessThan(SharkConstants.PROC_START_TIME_MS, sqlStarted, arg);
196       return this;
197    }
198
199    public ProcessIteratorExpressionBuilder addStartTimeAfter(long arg) {
200       addGreaterThan(SharkConstants.PROC_START_TIME_MS, sqlStarted, arg);
201       return this;
202    }
203
204    public ProcessIteratorExpressionBuilder addLastStateTimeEquals(long arg) {
205       addEquals(SharkConstants.PROC_LAST_STATE_TIME_MS,
206             sqlLastStateTime,
207                 arg);
208       return this;
209    }
210
211    public ProcessIteratorExpressionBuilder addLastStateTimeBefore(long arg) {
212       addLessThan(SharkConstants.PROC_LAST_STATE_TIME_MS,
213             sqlLastStateTime,
214                   arg);
215       return this;
216    }
217
218    public ProcessIteratorExpressionBuilder addLastStateTimeAfter(long arg) {
219       addGreaterThan(SharkConstants.PROC_LAST_STATE_TIME_MS,
220                      sqlLastStateTime,
221                      arg);
222       return this;
223    }
224
225    public ProcessIteratorExpressionBuilder addActiveActivitiesCountEquals(long arg) {
226       String JavaDoc javaName = SharkConstants.PROC_ACTIVE_ACTIVITIES_NO;
227       char _notPrecedes = appendOperator(true);
228       this.bshExpression.add(_notPrecedes
229                              + javaName + ".longValue()=="+arg+" ");
230       this.sqlExpression.add("1 = 1");
231       if (!this.propertiesUsed.contains(javaName)) {
232          this.propertiesUsed.add(javaName);
233       }
234       sqlComplete=false;
235       return this;
236    }
237
238    public ProcessIteratorExpressionBuilder addActiveActivitiesCountGreaterThan(long arg) {
239       String JavaDoc javaName = SharkConstants.PROC_ACTIVE_ACTIVITIES_NO;
240       char _notPrecedes = appendOperator(true);
241       this.bshExpression.add(_notPrecedes
242                              + javaName + ".longValue()>" + arg + " ");
243       this.sqlExpression.add("1 = 1");
244       if (!this.propertiesUsed.contains(javaName)) {
245          this.propertiesUsed.add(javaName);
246       }
247       sqlComplete=false;
248       return this;
249    }
250
251    public ProcessIteratorExpressionBuilder addActiveActivitiesCountLessThan(long arg) {
252       String JavaDoc javaName = SharkConstants.PROC_ACTIVE_ACTIVITIES_NO;
253       char _notPrecedes = appendOperator(true);
254       this.bshExpression.add(_notPrecedes
255                              + javaName + ".longValue()<" + arg + " ");
256       this.sqlExpression.add("1 = 1");
257       if (!this.propertiesUsed.contains(javaName)) {
258          this.propertiesUsed.add(javaName);
259       }
260       sqlComplete=false;
261       
262       return this;
263    }
264
265    public ProcessIteratorExpressionBuilder addVariableEquals(String JavaDoc vName,
266                                                              Object JavaDoc vValue) throws RootException {
267       if (vValue instanceof String JavaDoc) {
268          addVariableEquals(vName, (String JavaDoc)vValue);
269       } else if (vValue instanceof Long JavaDoc) {
270          addVariableEquals(vName, ((Long JavaDoc)vValue).longValue());
271       } else if (vValue instanceof Double JavaDoc) {
272          addVariableEquals(vName, ((Double JavaDoc)vValue).doubleValue());
273       } else if (vValue instanceof Boolean JavaDoc) {
274          addEqualsWithSubQuery(SharkConstants.PROC_CONTEXT_ + vName,
275                                objectid_column_name,
276                                "IN (SELECT Process FROM ProcessData"
277                                +(this.usingStandardVariableModel?"":"WOB")
278                                +" WHERE VariableValueBOOL = ",
279                                ((Boolean JavaDoc)vValue).booleanValue()? 1L: 0L,
280                                ") ");
281       } else {
282          throw new RootException("Class "+ vValue.getClass().getName()+ " not supported");
283       }
284       return this;
285    }
286
287    public ProcessIteratorExpressionBuilder addVariableEquals(String JavaDoc vName,
288                                                              String JavaDoc vValue) {
289       addEqualsWithSubQuery(SharkConstants.PROC_CONTEXT_ + vName,
290                             objectid_column_name,
291                             "IN (SELECT Process FROM ProcessData"
292                             +(this.usingStandardVariableModel?"":"WOB")
293                             +" WHERE VariableValueVCHAR = ",
294                             vValue,
295                             ") ");
296       return this;
297    }
298
299    public ProcessIteratorExpressionBuilder addVariableEquals(String JavaDoc vName,
300                                                              long vValue) {
301       addEqualsWithSubQuery(SharkConstants.PROC_CONTEXT_ + vName,
302                             objectid_column_name,
303                             "IN (SELECT Process FROM ProcessData"
304                             +(this.usingStandardVariableModel?"":"WOB")
305                             +" WHERE VariableValueLONG = ",
306                             vValue,
307                             ") ");
308       return this;
309    }
310
311    public ProcessIteratorExpressionBuilder addVariableGreaterThan(String JavaDoc vName,
312                                                                   long vValue) {
313       addGreaterThanWithSubQuery(SharkConstants.PROC_CONTEXT_ + vName,
314                                  objectid_column_name,
315                                  "IN (SELECT Process FROM ProcessData"
316                                  +(this.usingStandardVariableModel?"":"WOB")
317                                  +" WHERE VariableValueLONG ",
318                                  vValue,
319                                  ") ");
320       return this;
321    }
322
323    public ProcessIteratorExpressionBuilder addVariableLessThan(String JavaDoc vName,
324                                                                long vValue) {
325       addLessThanWithSubQuery(SharkConstants.PROC_CONTEXT_ + vName,
326                               objectid_column_name,
327                               "IN (SELECT Process FROM ProcessData"
328                               +(this.usingStandardVariableModel?"":"WOB")
329                               +" WHERE VariableValueLONG ",
330                               vValue,
331                               ") ");
332       return this;
333    }
334
335    public ProcessIteratorExpressionBuilder addVariableEquals(String JavaDoc vName,
336                                                              double vValue) {
337       addEqualsWithSubQuery(SharkConstants.PROC_CONTEXT_ + vName,
338                             objectid_column_name,
339                             "IN (SELECT Process FROM ProcessData"
340                             +(this.usingStandardVariableModel?"":"WOB")
341                             +" WHERE VariableValueDBL = ",
342                             vValue,
343                             ") ");
344       return this;
345    }
346
347    public ProcessIteratorExpressionBuilder addVariableGreaterThan(String JavaDoc vName,
348                                                                   double vValue) {
349       addGreaterThanWithSubQuery(SharkConstants.PROC_CONTEXT_ + vName,
350                                  objectid_column_name,
351                                  "IN (SELECT Process FROM ProcessData"
352                                  +(this.usingStandardVariableModel?"":"WOB")
353                                  +" WHERE VariableValueDBL ",
354                                  vValue,
355                                  ") ");
356       return this;
357    }
358
359    public ProcessIteratorExpressionBuilder addVariableLessThan(String JavaDoc vName,
360                                                                double vValue) {
361       addLessThanWithSubQuery(SharkConstants.PROC_CONTEXT_ + vName,
362                               objectid_column_name,
363                               "IN (SELECT Process FROM ProcessData"
364                               +(this.usingStandardVariableModel?"":"WOB")
365                               +" WHERE VariableValueDBL ",
366                               vValue,
367                               ") ");
368       return this;
369    }
370
371    public ProcessIteratorExpressionBuilder addExpression(String JavaDoc exp) {
372       sqlComplete = false;
373       appendOperator(false);
374       this.bshExpression.add(exp);
375       return this;
376    }
377
378    public ProcessIteratorExpressionBuilder addExpression(ProcessIteratorExpressionBuilder eb) {
379       appendOperator(eb.isComplete());
380       this.bshExpression.add(eb);
381       this.sqlExpression.add(eb);
382       for (Iterator JavaDoc it = ((BasicExpressionBuilder)eb).propertiesUsed.iterator(); it.hasNext();) {
383          Object JavaDoc element = it.next();
384          if (!this.propertiesUsed.contains(element)) {
385             this.propertiesUsed.add(element);
386          }
387       }
388       sqlComplete |= eb.isComplete();
389       return this;
390    }
391
392    public ProcessIteratorExpressionBuilder setOrderByMgrName(boolean ascending) {
393       super.setOrderBy(sqlProcDefName, ascending);
394       return this;
395    }
396
397    public ProcessIteratorExpressionBuilder setOrderById(boolean ascending) {
398       super.setOrderBy(sqlId, ascending);
399       return this;
400    }
401
402    public ProcessIteratorExpressionBuilder setOrderByName(boolean ascending) {
403       super.setOrderBy(sqlName, ascending);
404       return this;
405    }
406
407    public ProcessIteratorExpressionBuilder setOrderByState(boolean ascending) {
408       super.setOrderBy(sqlState, ascending);
409       return this;
410    }
411
412    public ProcessIteratorExpressionBuilder setOrderByPriority(boolean ascending) {
413       super.setOrderBy(sqlPriority, ascending);
414       return this;
415    }
416
417    public ProcessIteratorExpressionBuilder setOrderByCreatedTime(boolean ascending) {
418       super.setOrderBy(sqlCreated, ascending);
419       return this;
420    }
421
422    public ProcessIteratorExpressionBuilder setOrderByStartTime(boolean ascending) {
423       super.setOrderBy(sqlStarted, ascending);
424       return this;
425    }
426
427    public ProcessIteratorExpressionBuilder setOrderByLastStateTime(boolean ascending) {
428       super.setOrderBy(sqlLastStateTime, ascending);
429       return this;
430    }
431
432    public ProcessIteratorExpressionBuilder setOrderByResourceRequesterId(boolean ascending) {
433       super.setOrderBy(sqlLastStateTime, ascending);
434       return this;
435    }
436    
437 }
438
Popular Tags