KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > expression > numericvalueexpression > AbstractNumericValueFunction


1 package com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression;
2
3 import com.daffodilwoods.daffodildb.server.sql99.common.*;
4 import com.daffodilwoods.daffodildb.server.sql99.expression.*;
5 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
6 import com.daffodilwoods.daffodildb.utils.field.*;
7 import com.daffodilwoods.database.resource.*;
8 import com.daffodilwoods.database.utility.P;
9
10 public abstract class AbstractNumericValueFunction extends AbstractValueExpression implements numericvaluefunction, Datatypes, TypeConstants {
11
12    public Object JavaDoc run(Object JavaDoc object) throws DException {
13       initializeChildren();
14       if (childs.length == 1) {
15          FieldBase result = (FieldBase) childs[0].run(object);
16          int type = result.getDatatype();
17          if (type == -1) {
18             result.setDatatype( -1);
19             type = result.getDatatype();
20          }
21          return getResult(type, result.getObject());
22       }
23       throw new DException("DSE3554", new Object JavaDoc[] {new Integer JavaDoc(1)});
24    }
25
26    public ParameterInfo[] getParameterInfo() throws DException {
27       initializeChildren();
28       if (childs.length == 1) {
29         ParameterInfo[] params = childs[0].getParameterInfo();
30         for (int i = 0; i < params.length; i++) {
31           if(params[i].getQuestionMark())
32             return params;
33         }
34         return getThisParameterInfo();
35       }
36       throw new DException("DSE3554", new Object JavaDoc[] {new Integer JavaDoc(1)});
37    }
38
39    public ColumnDetails[] getChildColumnDetails() throws DException {
40       return columnDetails;
41    }
42
43    protected ParameterInfo[] getThisParameterInfo() throws DException {
44       ParameterInfo parameterInfo = new ParameterInfo();
45       parameterInfo.setName(toString());
46       parameterInfo.setDataType(Datatypes.DOUBLE);
47       return new ParameterInfo[] {parameterInfo};
48    }
49
50    protected Object JavaDoc getResult(int type, Object JavaDoc object) throws DException {
51       return null;
52    }
53
54    protected String JavaDoc getNameOfColumn(ColumnDetails[] columnDetails) throws DException {
55       String JavaDoc nameOfColumn = "";
56       for (int i = 0; i < columnDetails.length; ++i) {
57          nameOfColumn += columnDetails[i].getColumn();
58       }
59       return nameOfColumn;
60    }
61
62   protected ColumnDetails[] columnDetails;
63   protected ColumnDetails column;
64
65    public ColumnDetails[] getColumnDetails() throws DException {
66       initializeChildren();
67       ColumnDetails columnDetails[] = childs[0].getColumnDetails();
68       column = new ColumnDetails();
69       String JavaDoc nameOfColumn = getNameOfColumn(columnDetails);
70       String JavaDoc type = getType();
71       column.setFunctionType(type);
72       column.setType(SCALARFUNCTION);
73       column.setObject(this);
74       column.setColumnName(new String JavaDoc[] {type + "(" + nameOfColumn + ")"});
75       this.columnDetails = columnDetails;
76       return new ColumnDetails[] {column};
77    }
78
79    public String JavaDoc getType() throws DException {
80       throw new UnsupportedOperationException JavaDoc("METHOD NOT IMPLEMENTED " + getClass());
81    }
82
83    public void releaseResource() throws DException {
84
85    }
86
87    public ByteComparison getByteComparison(Object JavaDoc object) throws DException {
88       initializeChildren();
89       int childsLength = childs.length;
90       int[][] parms = new int[childsLength][];
91       int length = 0;
92       boolean canUseByteComparison = true;
93       for (int i = 0; i < childsLength; i++) {
94          if (childs[i] != null) {
95             ByteComparison bc = childs[i].getByteComparison(object);
96             if (!bc.canUseByteComparison()) {
97                canUseByteComparison = false;
98             }
99             parms[i] = bc.getDataTypes();
100             length += parms[i].length;
101          }
102       }
103       int[] dataTypes = new int[length];
104       int index = 0;
105       for (int i = 0; i < childsLength; i++) {
106          int[] par = parms[i];
107          for (int j = 0; j < par.length; j++) {
108             dataTypes[index++] = par[j];
109          }
110       }
111       return new ByteComparison(canUseByteComparison, dataTypes);
112    }
113
114    public int getCardinality() throws DException {
115       return 1;
116    }
117
118    void setParameterDataType(ParameterInfo[] paramInfo, int dataType) throws DException {
119      for (int i = 0; i < paramInfo.length; i++)
120        if(paramInfo[i].getDataType() < 1)
121          paramInfo[i].setDataType(dataType);
122    }
123
124   public int getColumnSize(Object JavaDoc object) throws DException {
125      return Datatypes.DOUBLESIZE;
126    }
127
128
129    protected boolean checkForVariableColumn() throws DException {
130       for (int i = 0; i < columnDetails.length; ++i) {
131          if (columnDetails[i].getColumn().equals("?")) {
132             return true;
133          }
134       }
135       return false;
136    }
137
138 }
139
Popular Tags