KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > expression > datetimevalueexpression > AbstractDateTimeValueFunction


1 package com.daffodilwoods.daffodildb.server.sql99.expression.datetimevalueexpression;
2
3 import java.math.*;
4 import java.sql.*;
5
6 import com.daffodilwoods.daffodildb.server.sql99.common.*;
7 import com.daffodilwoods.daffodildb.server.sql99.expression.*;
8 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
9 import com.daffodilwoods.daffodildb.utils.field.*;
10 import com.daffodilwoods.database.resource.*;
11 import com.daffodilwoods.database.utility.P;
12
13 public abstract class AbstractDateTimeValueFunction extends AbstractValueExpression implements datetimevalueexpression {
14
15
16    public abstract AbstractRowValueExpression[] getChilds();
17
18    public String JavaDoc getType() throws DException {
19       throw new UnsupportedOperationException JavaDoc("METHOD NOT IMPLEMENTED " + getClass());
20    }
21
22    ColumnDetails column;
23
24    public ColumnDetails[] getColumnDetails() throws DException {
25       initializeChildren();
26       ColumnDetails columnDetails[] = childs[0].getColumnDetails();
27       column = new ColumnDetails();
28       String JavaDoc nameOfColumn = getNameOfColumn(columnDetails);
29       String JavaDoc type = getType();
30       column.setFunctionType(type);
31       column.setType(SCALARFUNCTION);
32       column.setObject(this);
33       column.setColumnName(new String JavaDoc[] {type + "(" + nameOfColumn + ")"});
34       this.columnDetails = columnDetails;
35       return new ColumnDetails[] {column};
36    }
37
38    public Object JavaDoc run(Object JavaDoc object) throws com.daffodilwoods.database.resource.DException {
39       initializeChildren();
40       if (childs.length == 1) {
41          FieldBase result = (FieldBase) childs[0].run(object);
42          int type = result.getDatatype();
43          if (type == -1) {
44             result.setDatatype( -1);
45             type = result.getDatatype();
46          }
47          return getResult(type, result.getObject());
48       }
49       throw new DException("DSE3554", new Object JavaDoc[] {new Integer JavaDoc(1)});
50    }
51
52    protected Object JavaDoc getResult(int type, Object JavaDoc object) throws DException {
53       throw new UnsupportedOperationException JavaDoc("METHOD NOT IMPLEMENTED " + getClass());
54    }
55
56    protected String JavaDoc getNameOfColumn(ColumnDetails[] columnDetails) throws DException {
57       String JavaDoc nameOfColumn = "";
58       for (int i = 0; i < columnDetails.length; ++i) {
59          nameOfColumn += columnDetails[i].getColumn();
60       }
61       return nameOfColumn;
62    }
63
64    public ColumnDetails[] getChildColumnDetails() throws DException {
65       return columnDetails;
66    }
67
68    protected boolean checkForVariableColumn() throws DException {
69       for (int i = 0; i < columnDetails.length; ++i) {
70          if (columnDetails[i].getColumn().equals("?")) {
71             return true;
72          }
73       }
74       return false;
75    }
76
77    public ParameterInfo[] getParameterInfo() throws DException {
78       initializeChildren();
79       ParameterInfo[] params = childs[0].getParameterInfo();
80        for (int i = 0; i < params.length; i++) {
81          if(params[i].getQuestionMark())
82            return params;
83        }
84        return getThisParameterInfo();
85
86    }
87
88    protected ParameterInfo[] getThisParameterInfo() throws DException {
89      throw new UnsupportedOperationException JavaDoc("METHOD NOT IMPLEMENTED " + getClass());
90    }
91
92    protected int getDataType(Object JavaDoc object) throws DException {
93       if (object instanceof Integer JavaDoc) {
94          return INTEGER;
95       } else if (object instanceof Float JavaDoc) {
96          return FLOAT;
97       } else if (object instanceof Double JavaDoc) {
98          return DOUBLE;
99       } else if (object instanceof Long JavaDoc) {
100          return LONG;
101       } else if (object instanceof String JavaDoc) {
102          return CHARACTER;
103       } else if (object instanceof Short JavaDoc) {
104          return SHORT;
105       } else if (object instanceof BigDecimal) {
106          return BIGDECIMAL;
107       } else if (object instanceof Date) {
108          return DATE;
109       } else if (object instanceof Time) {
110          return TIME;
111       } else if (object instanceof Timestamp) {
112          return TIMESTAMP;
113       } else if (object instanceof Byte JavaDoc) {
114          return BYTE;
115       } else {
116          throw new DException("DSE419", new Object JavaDoc[] {getType()});
117       }
118    }
119
120  public abstract int getColumnSize(Object JavaDoc object) throws DException ;
121
122  public void releaseResource() throws DException {
123
124   }
125
126 }
127
Popular Tags