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.query;
009:
010: //base classes
011: import java.util.ArrayList;
012:
013: //project specific classes
014:
015: //other classes
016:
017: public class ColumnContainer {
018:
019: private final static Integer APP_STRING = new Integer(1);
020: private final static Integer SYS_STRING = new Integer(2);
021: private final static Integer APP_DECIMAL = new Integer(3);
022: private final static Integer SYS_DECIMAL = new Integer(4);
023: private final static Integer APP_BOOLEAN = new Integer(5);
024: private final static Integer SYS_BOOLEAN = new Integer(6);
025: //
026: public final static Integer AGG_COUNT = new Integer(-1);
027: public final static Integer AGG_AVG = new Integer(-2);
028: public final static Integer AGG_SUM = new Integer(-3);
029: public final static Integer AGG_MIN = new Integer(-4);
030: public final static Integer AGG_MAX = new Integer(-5);
031:
032: private ArrayList types = null;
033: private ArrayList names = null;
034: private ArrayList funcs = null;
035:
036: //creation functions
037: private ColumnContainer() {
038: this .types = new ArrayList();
039: this .names = new ArrayList();
040: this .funcs = new ArrayList();
041: }
042:
043: public final static ColumnContainer createColumnContainer() {
044:
045: ColumnContainer outValue = new ColumnContainer();
046: return outValue;
047: }
048:
049: //register functions
050: public void registerCountAll() {
051: this .names.add(null);
052: this .types.add(null);
053: this .funcs.add(AGG_COUNT);
054: }
055:
056: public void registerSystemString(String inName, String inFunction) {
057: this .names.add(inName.toUpperCase());
058: this .types.add(SYS_STRING);
059: this .funcs.add(inFunction);
060: }
061:
062: public void registerSystemDecimal(String inName, String inFunction) {
063: this .names.add(inName.toUpperCase());
064: this .types.add(SYS_DECIMAL);
065: this .funcs.add(inFunction);
066: }
067:
068: public void registerSystemBoolean(String inName, String inFunction) {
069: this .names.add(inName.toUpperCase());
070: this .types.add(SYS_BOOLEAN);
071: this .funcs.add(inFunction);
072: }
073:
074: public void registerApplicationString(String inName,
075: String inFunction) {
076: this .names.add(inName.toUpperCase());
077: this .types.add(APP_STRING);
078: this .funcs.add(inFunction);
079: }
080:
081: public void registerApplicationDecimal(String inName,
082: String inFunction) {
083: this .names.add(inName.toUpperCase());
084: this .types.add(APP_DECIMAL);
085: this .funcs.add(inFunction);
086: }
087:
088: public void registerApplicationBoolean(String inName,
089: String inFunction) {
090: this .names.add(inName.toUpperCase());
091: this .types.add(APP_BOOLEAN);
092: this .funcs.add(inFunction);
093: }
094:
095: //access functions
096: public int getColumnCount() {
097: return this .names.size();
098: }
099:
100: public String getColumnName(int inIndex) {
101: return (String) this .names.get(inIndex);
102: }
103:
104: public boolean isSystemColumn(int inIndex) {
105: Integer outValue = (Integer) this .types.get(inIndex);
106: return (((outValue.intValue()) % 2) == 0);
107: }
108:
109: public boolean isStringColumn(int inIndex) {
110: Integer outValue = (Integer) this .types.get(inIndex);
111: return (outValue.equals(APP_STRING) || outValue
112: .equals(SYS_STRING));
113: }
114:
115: public boolean isDecimalColumn(int inIndex) {
116: Integer outValue = (Integer) this .types.get(inIndex);
117: return (outValue.equals(APP_DECIMAL) || outValue
118: .equals(SYS_DECIMAL));
119: }
120:
121: public boolean isBooleanColumn(int inIndex) {
122: Integer outValue = (Integer) this .types.get(inIndex);
123: return (outValue.equals(APP_BOOLEAN) || outValue
124: .equals(SYS_BOOLEAN));
125: }
126:
127: //locating functions
128: public int[] getColumnIndexes(String inAttrName, int inAttrType,
129: int inAttrClass) {
130:
131: int outValue[] = null;
132: Integer columnType = null;
133: ArrayList selectedColumns = new ArrayList();
134:
135: if (inAttrType == BaseDBQueryVendor.SYSTEM
136: && inAttrClass == BaseDBQueryVendor.DECIMAL) {
137: columnType = SYS_DECIMAL;
138: } else if (inAttrType == BaseDBQueryVendor.SYSTEM
139: && inAttrClass == BaseDBQueryVendor.BOOLEAN) {
140: columnType = SYS_BOOLEAN;
141: } else if (inAttrType == BaseDBQueryVendor.SYSTEM
142: && inAttrClass == BaseDBQueryVendor.STRING) {
143: columnType = SYS_STRING;
144: } else if (inAttrType == BaseDBQueryVendor.APPLICATION
145: && inAttrClass == BaseDBQueryVendor.DECIMAL) {
146: columnType = APP_DECIMAL;
147: } else if (inAttrType == BaseDBQueryVendor.APPLICATION
148: && inAttrClass == BaseDBQueryVendor.BOOLEAN) {
149: columnType = APP_BOOLEAN;
150: } else if (inAttrType == BaseDBQueryVendor.APPLICATION
151: && inAttrClass == BaseDBQueryVendor.STRING) {
152: columnType = APP_STRING;
153: }
154:
155: for (int i = 0; i < this .names.size(); i++) {
156: if (this .names.get(i).equals(inAttrName)
157: && this .types.get(i).equals(columnType)) {
158: selectedColumns.add(new Integer(i));
159: }
160: }
161:
162: outValue = new int[selectedColumns.size()];
163: for (int i = 0; i < selectedColumns.size(); i++) {
164: outValue[i] = ((Integer) selectedColumns.get(i)).intValue();
165: }
166:
167: return outValue;
168: }
169: }
|