001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.workflow.lifecycle;
009:
010: //base classes
011: import java.util.ArrayList;
012:
013: //project specific classes
014: import org.jfolder.workflow.query.AndQC;
015: import org.jfolder.workflow.query.AppBooleanIsFalseQC;
016: import org.jfolder.workflow.query.AppBooleanIsTrueQC;
017: import org.jfolder.workflow.query.AppDecIsEqualQC;
018: import org.jfolder.workflow.query.AppDecIsGreaterThanOrEqualQC;
019: import org.jfolder.workflow.query.AppDecIsGreaterThanQC;
020: import org.jfolder.workflow.query.AppDecIsLessThanOrEqualQC;
021: import org.jfolder.workflow.query.AppDecIsLessThanQC;
022: import org.jfolder.workflow.query.AppDecIsNotEqualQC;
023: import org.jfolder.workflow.query.AppStringIsEqualQC;
024: import org.jfolder.workflow.query.AppStringIsLikeQC;
025: import org.jfolder.workflow.query.AppStringIsNotEqualQC;
026: import org.jfolder.workflow.query.AppStringIsNotLikeQC;
027: import org.jfolder.workflow.query.BaseDBQueryVendor;
028: import org.jfolder.workflow.query.NotQC;
029: import org.jfolder.workflow.query.OrQC;
030: import org.jfolder.workflow.query.QueryContainer;
031: import org.jfolder.workflow.query.SysBooleanIsFalseQC;
032: import org.jfolder.workflow.query.SysBooleanIsTrueQC;
033: import org.jfolder.workflow.query.SysDecIsEqualQC;
034: import org.jfolder.workflow.query.SysDecIsGreaterThanOrEqualQC;
035: import org.jfolder.workflow.query.SysDecIsGreaterThanQC;
036: import org.jfolder.workflow.query.SysDecIsLessThanOrEqualQC;
037: import org.jfolder.workflow.query.SysDecIsLessThanQC;
038: import org.jfolder.workflow.query.SysDecIsNotEqualQC;
039: import org.jfolder.workflow.query.SysStringIsEqualQC;
040: import org.jfolder.workflow.query.SysStringIsLikeQC;
041: import org.jfolder.workflow.query.SysStringIsNotEqualQC;
042: import org.jfolder.workflow.query.SysStringIsNotLikeQC;
043:
044: //other classes
045:
046: class QueryConstructor {
047:
048: //protected final static String T_JFOLDER_WORKFLOWS = "T_JFOLDER_WORKFLOWS";
049: protected final static String T_USERS = "T_USERS";
050: protected final static String T_WORKFLOWS = "T_WORKFLOWS";
051: protected final static String T_DEPLOYED_SCRIPTS = "T_DEPLOYED_SCRIPTS";
052: protected final static String T_ATTRIBUTES = BaseDBQueryVendor.T_ATTRIBUTES;
053: protected final static String T_TRIGGERS = "T_TRIGGERS";
054: //
055: protected final static String WF_INSTANCE = "WF_INSTANCE";
056: protected final static String STATE_CODE = "STATE_CODE";
057: protected final static String ID = BaseDBQueryVendor.ID;
058: protected final static String SECURITY_CLASS = "SECURITY_CLASS";
059: protected final static String USER_NAME = "USER_NAME";
060: protected final static String SCRIPT_NAME = "SCRIPT_NAME";
061: protected final static String WORKFLOW_ID = "WORKFLOW_ID";
062: protected final static String HANDLE = "HANDLE";
063: protected final static String CONTENT = "CONTENT";
064: protected final static String AUDIT_ID = "AUDIT_ID";
065: protected final static String AUDIT_USER_ID = "AUDIT_USER_ID";
066: protected final static String AUDIT_TIMESTAMP = "AUDIT_TIMESTAMP";
067: protected final static String AUDIT_STATUS = "AUDIT_STATUS";
068: protected final static String AUDIT_COMMENT = "AUDIT_COMMENT";
069: protected final static String AUDIT_EXCEPTION_MESSAGE = "AUDIT_EXCEPTION_MESSAGE";
070: protected final static String AUDIT_EXCEPTION_SOURCE = "AUDIT_EXCEPTION_SOURCE";
071:
072: //
073: protected final static String JF_ID = BaseDBQueryVendor.JF_ID;
074: protected final static String ATTR_NAME = BaseDBQueryVendor.ATTR_NAME;
075: protected final static String ATTR_TYPE = BaseDBQueryVendor.ATTR_TYPE;
076: protected final static String DECIMAL_VALUE = BaseDBQueryVendor.DECIMAL_VALUE;
077: protected final static String BOOLEAN_VALUE = BaseDBQueryVendor.BOOLEAN_VALUE;
078: protected final static String STRING_VALUE = BaseDBQueryVendor.STRING_VALUE;
079: protected final static String LONG_STRING_VALUE = BaseDBQueryVendor.LONG_STRING_VALUE;
080: //private final static String ID = BaseDBWorkflowLifecycleBean.ID;
081: //private final static String T_ATTRIBUTES =
082: // BaseDBWorkflowLifecycleBean.T_ATTRIBUTES;
083: //private final static String JF_ID = BaseDBWorkflowLifecycleBean.JF_ID;
084: //private final static String ATTR_NAME =
085: // BaseDBWorkflowLifecycleBean.ATTR_NAME;
086: //private final static String DECIMAL_VALUE =
087: // BaseDBWorkflowLifecycleBean.DECIMAL_VALUE;
088: //private final static String BOOLEAN_VALUE =
089: // BaseDBWorkflowLifecycleBean.BOOLEAN_VALUE;
090: //private final static String STRING_VALUE =
091: // BaseDBWorkflowLifecycleBean.STRING_VALUE;
092: //private final static String LONG_STRING_VALUE =
093: // BaseDBWorkflowLifecycleBean.LONG_STRING_VALUE;
094:
095: final static String APP_PREFIX = "APP_";
096: final static String SYS_PREFIX = "SYS_";
097:
098: public final static QueryPreparer createConstructor(
099: QueryContainer inQuery) {
100:
101: QueryPreparer outValue = new QueryPreparer();
102:
103: String query = null;
104: ArrayList parameters = new ArrayList();
105:
106: if (inQuery instanceof AndQC) {
107: AndQC qc = (AndQC) inQuery;
108:
109: QueryContainer leftQuery = qc.getLeftQuery();
110: QueryContainer rightQuery = qc.getRightQuery();
111:
112: QueryPreparer qpLeft = createConstructor(leftQuery);
113: QueryPreparer qpRight = createConstructor(rightQuery);
114:
115: query = "select " + JF_ID + " from " + T_ATTRIBUTES
116: + " where " + JF_ID + " in (" + qpLeft.getQuery()
117: + ") and " + JF_ID + " in (" + qpRight.getQuery()
118: + ")";
119:
120: parameters = qpLeft.getParameters();
121: parameters.addAll(qpRight.getParameters());
122: } else if (inQuery instanceof AppBooleanIsFalseQC) {
123: AppBooleanIsFalseQC qc = (AppBooleanIsFalseQC) inQuery;
124:
125: query = "select " + JF_ID + " from " + T_ATTRIBUTES
126: + " where " + ATTR_NAME + " = ? and "
127: + BOOLEAN_VALUE + " IS FALSE";
128:
129: parameters.add(APP_PREFIX + qc.getAttributeName());
130: } else if (inQuery instanceof AppBooleanIsTrueQC) {
131: AppBooleanIsTrueQC qc = (AppBooleanIsTrueQC) inQuery;
132:
133: query = "select " + JF_ID + " from " + T_ATTRIBUTES
134: + " where " + ATTR_NAME + " = ? and "
135: + BOOLEAN_VALUE + " IS TRUE";
136:
137: parameters.add(APP_PREFIX + qc.getAttributeName());
138: } else if (inQuery instanceof AppDecIsEqualQC) {
139: AppDecIsEqualQC qc = (AppDecIsEqualQC) inQuery;
140:
141: query = "select " + JF_ID + " from " + T_ATTRIBUTES
142: + " where " + ATTR_NAME + " = ? and "
143: + DECIMAL_VALUE + " = ?";
144:
145: parameters.add(APP_PREFIX + qc.getAttributeName());
146: parameters.add(qc.getDecimalValue());
147: } else if (inQuery instanceof AppDecIsGreaterThanOrEqualQC) {
148: AppDecIsGreaterThanOrEqualQC qc = (AppDecIsGreaterThanOrEqualQC) inQuery;
149:
150: query = "select " + JF_ID + " from " + T_ATTRIBUTES
151: + " where " + ATTR_NAME + " = ? and "
152: + DECIMAL_VALUE + " >= ?";
153:
154: parameters.add(APP_PREFIX + qc.getAttributeName());
155: parameters.add(qc.getDecimalValue());
156: } else if (inQuery instanceof AppDecIsGreaterThanQC) {
157: AppDecIsGreaterThanQC qc = (AppDecIsGreaterThanQC) inQuery;
158:
159: query = "select " + JF_ID + " from " + T_ATTRIBUTES
160: + " where " + ATTR_NAME + " = ? and "
161: + DECIMAL_VALUE + " > ?";
162:
163: parameters.add(APP_PREFIX + qc.getAttributeName());
164: parameters.add(qc.getDecimalValue());
165: } else if (inQuery instanceof AppDecIsLessThanOrEqualQC) {
166: AppDecIsLessThanOrEqualQC qc = (AppDecIsLessThanOrEqualQC) inQuery;
167:
168: query = "select " + JF_ID + " from " + T_ATTRIBUTES
169: + " where " + ATTR_NAME + " = ? and "
170: + DECIMAL_VALUE + " <= ?";
171:
172: parameters.add(APP_PREFIX + qc.getAttributeName());
173: parameters.add(qc.getDecimalValue());
174: } else if (inQuery instanceof AppDecIsLessThanQC) {
175: AppDecIsLessThanQC qc = (AppDecIsLessThanQC) inQuery;
176:
177: query = "select " + JF_ID + " from " + T_ATTRIBUTES
178: + " where " + ATTR_NAME + " = ? and "
179: + DECIMAL_VALUE + " <= ?";
180:
181: parameters.add(APP_PREFIX + qc.getAttributeName());
182: parameters.add(qc.getDecimalValue());
183: } else if (inQuery instanceof AppDecIsNotEqualQC) {
184: AppDecIsNotEqualQC qc = (AppDecIsNotEqualQC) inQuery;
185:
186: query = "select " + JF_ID + " from " + T_ATTRIBUTES
187: + " where " + ATTR_NAME + " = ? and "
188: + DECIMAL_VALUE + " <> ?";
189:
190: parameters.add(APP_PREFIX + qc.getAttributeName());
191: parameters.add(qc.getDecimalValue());
192: } else if (inQuery instanceof AppStringIsEqualQC) {
193: AppStringIsEqualQC qc = (AppStringIsEqualQC) inQuery;
194:
195: query = "select " + JF_ID + " from " + T_ATTRIBUTES
196: + " where " + ATTR_NAME + " = ? and "
197: + STRING_VALUE + " = ?";
198:
199: parameters.add(APP_PREFIX + qc.getAttributeName());
200: parameters.add(qc.getStringValue());
201: } else if (inQuery instanceof AppStringIsLikeQC) {
202: AppStringIsLikeQC qc = (AppStringIsLikeQC) inQuery;
203:
204: query = "select " + JF_ID + " from " + T_ATTRIBUTES
205: + " where " + ATTR_NAME + " = ? and "
206: + STRING_VALUE + " LIKE ?";
207:
208: parameters.add(APP_PREFIX + qc.getAttributeName());
209: parameters.add(qc.getStringValue());
210: } else if (inQuery instanceof AppStringIsNotEqualQC) {
211: AppStringIsNotEqualQC qc = (AppStringIsNotEqualQC) inQuery;
212:
213: query = "select " + JF_ID + " from " + T_ATTRIBUTES
214: + " where " + ATTR_NAME + " = ? and "
215: + STRING_VALUE + " <> ?";
216:
217: parameters.add(APP_PREFIX + qc.getAttributeName());
218: parameters.add(qc.getStringValue());
219: } else if (inQuery instanceof AppStringIsNotLikeQC) {
220: AppStringIsNotLikeQC qc = (AppStringIsNotLikeQC) inQuery;
221:
222: query = "select " + JF_ID + " from " + T_ATTRIBUTES
223: + " where " + ATTR_NAME + " = ? and "
224: + STRING_VALUE + " NOT LIKE ?";
225:
226: parameters.add(APP_PREFIX + qc.getAttributeName());
227: parameters.add(qc.getStringValue());
228: } else if (inQuery instanceof NotQC) {
229: NotQC qc = (NotQC) inQuery;
230:
231: QueryContainer subQuery = qc.getSubQuery();
232:
233: QueryPreparer qp = createConstructor(subQuery);
234:
235: query = "select " + JF_ID + " from " + T_ATTRIBUTES
236: + " where " + JF_ID + " not in (" + qp.getQuery()
237: + ")";
238:
239: parameters = qp.getParameters();
240: } else if (inQuery instanceof OrQC) {
241: OrQC qc = (OrQC) inQuery;
242:
243: QueryContainer leftQuery = qc.getLeftQuery();
244: QueryContainer rightQuery = qc.getRightQuery();
245:
246: QueryPreparer qpLeft = createConstructor(leftQuery);
247: QueryPreparer qpRight = createConstructor(rightQuery);
248:
249: query = "select " + JF_ID + " from " + T_ATTRIBUTES
250: + " where " + JF_ID + " in (" + qpLeft.getQuery()
251: + ") or " + JF_ID + " in (" + qpRight.getQuery()
252: + ")";
253:
254: parameters = qpLeft.getParameters();
255: parameters.addAll(qpRight.getParameters());
256: } else if (inQuery instanceof SysBooleanIsFalseQC) {
257: SysBooleanIsFalseQC qc = (SysBooleanIsFalseQC) inQuery;
258:
259: query = "select " + JF_ID + " from " + T_ATTRIBUTES
260: + " where " + ATTR_NAME + " = ? and "
261: + BOOLEAN_VALUE + " IS FALSE";
262:
263: parameters.add(SYS_PREFIX + qc.getAttributeName());
264: } else if (inQuery instanceof SysBooleanIsTrueQC) {
265: SysBooleanIsTrueQC qc = (SysBooleanIsTrueQC) inQuery;
266:
267: query = "select " + JF_ID + " from " + T_ATTRIBUTES
268: + " where " + ATTR_NAME + " = ? and "
269: + BOOLEAN_VALUE + " IS TRUE";
270:
271: parameters.add(SYS_PREFIX + qc.getAttributeName());
272: } else if (inQuery instanceof SysDecIsEqualQC) {
273: SysDecIsEqualQC qc = (SysDecIsEqualQC) inQuery;
274:
275: query = "select " + JF_ID + " from " + T_ATTRIBUTES
276: + " where " + ATTR_NAME + " = ? and "
277: + DECIMAL_VALUE + " = ?";
278:
279: parameters.add(SYS_PREFIX + qc.getAttributeName());
280: parameters.add(qc.getDecimalValue());
281: } else if (inQuery instanceof SysDecIsGreaterThanOrEqualQC) {
282: SysDecIsGreaterThanOrEqualQC qc = (SysDecIsGreaterThanOrEqualQC) inQuery;
283:
284: query = "select " + JF_ID + " from " + T_ATTRIBUTES
285: + " where " + ATTR_NAME + " = ? and "
286: + DECIMAL_VALUE + " >= ?";
287:
288: parameters.add(SYS_PREFIX + qc.getAttributeName());
289: parameters.add(qc.getDecimalValue());
290: } else if (inQuery instanceof SysDecIsGreaterThanQC) {
291: SysDecIsGreaterThanQC qc = (SysDecIsGreaterThanQC) inQuery;
292:
293: query = "select " + JF_ID + " from " + T_ATTRIBUTES
294: + " where " + ATTR_NAME + " = ? and "
295: + DECIMAL_VALUE + " > ?";
296:
297: parameters.add(SYS_PREFIX + qc.getAttributeName());
298: parameters.add(qc.getDecimalValue());
299: } else if (inQuery instanceof SysDecIsLessThanOrEqualQC) {
300: SysDecIsLessThanOrEqualQC qc = (SysDecIsLessThanOrEqualQC) inQuery;
301:
302: query = "select " + JF_ID + " from " + T_ATTRIBUTES
303: + " where " + ATTR_NAME + " = ? and "
304: + DECIMAL_VALUE + " <= ?";
305:
306: parameters.add(SYS_PREFIX + qc.getAttributeName());
307: parameters.add(qc.getDecimalValue());
308: } else if (inQuery instanceof SysDecIsLessThanQC) {
309: SysDecIsLessThanQC qc = (SysDecIsLessThanQC) inQuery;
310:
311: query = "select " + JF_ID + " from " + T_ATTRIBUTES
312: + " where " + ATTR_NAME + " = ? and "
313: + DECIMAL_VALUE + " < ?";
314:
315: parameters.add(SYS_PREFIX + qc.getAttributeName());
316: parameters.add(qc.getDecimalValue());
317: } else if (inQuery instanceof SysDecIsNotEqualQC) {
318: SysDecIsNotEqualQC qc = (SysDecIsNotEqualQC) inQuery;
319:
320: query = "select " + JF_ID + " from " + T_ATTRIBUTES
321: + " where " + ATTR_NAME + " = ? and "
322: + DECIMAL_VALUE + " <> ?";
323:
324: parameters.add(SYS_PREFIX + qc.getAttributeName());
325: parameters.add(qc.getDecimalValue());
326: } else if (inQuery instanceof SysStringIsEqualQC) {
327: SysStringIsEqualQC qc = (SysStringIsEqualQC) inQuery;
328:
329: query = "select " + JF_ID + " from " + T_ATTRIBUTES
330: + " where " + ATTR_NAME + " = ? and "
331: + STRING_VALUE + " = ?";
332:
333: parameters.add(SYS_PREFIX + qc.getAttributeName());
334: parameters.add(qc.getStringValue());
335: } else if (inQuery instanceof SysStringIsLikeQC) {
336: SysStringIsLikeQC qc = (SysStringIsLikeQC) inQuery;
337:
338: query = "select " + JF_ID + " from " + T_ATTRIBUTES
339: + " where " + ATTR_NAME + " = ? and "
340: + STRING_VALUE + " LIKE ?";
341:
342: parameters.add(SYS_PREFIX + qc.getAttributeName());
343: parameters.add(qc.getStringValue());
344: } else if (inQuery instanceof SysStringIsNotEqualQC) {
345: SysStringIsNotEqualQC qc = (SysStringIsNotEqualQC) inQuery;
346:
347: query = "select " + JF_ID + " from " + T_ATTRIBUTES
348: + " where " + ATTR_NAME + " = ? and "
349: + STRING_VALUE + " <> ?";
350:
351: parameters.add(SYS_PREFIX + qc.getAttributeName());
352: parameters.add(qc.getStringValue());
353: } else if (inQuery instanceof SysStringIsNotLikeQC) {
354: SysStringIsNotLikeQC qc = (SysStringIsNotLikeQC) inQuery;
355:
356: query = "select " + JF_ID + " from " + T_ATTRIBUTES
357: + " where " + ATTR_NAME + " = ? and "
358: + STRING_VALUE + " NOT LIKE ?";
359:
360: parameters.add(SYS_PREFIX + qc.getAttributeName());
361: parameters.add(qc.getStringValue());
362: } else {
363: //TO DO: consider throwing exception
364: }
365:
366: outValue.setQuery(query);
367: outValue.setParameters(parameters);
368:
369: return outValue;
370: }
371: }
|