KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.expression.datetimevalueexpression;
2
3 import java.sql.*;
4 import java.sql.Date JavaDoc;
5 import java.util.*;
6
7 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
8 import com.daffodilwoods.daffodildb.server.serversystem.*;
9 import com.daffodilwoods.daffodildb.server.sql99.common.*;
10 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
11 import com.daffodilwoods.daffodildb.server.sql99.token.*;
12 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
13 import com.daffodilwoods.daffodildb.utils.*;
14 import com.daffodilwoods.daffodildb.utils.field.*;
15 import com.daffodilwoods.database.resource.*;
16 import com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression.numericvaluefunction;
17 import com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression.AbstractNumericValueFunction;
18
19 public class monthfunction extends /*AbstractDateTimeValueFunction*/ AbstractNumericValueFunction implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter, /*datetimevaluefunction*/numericvaluefunction , TypeConstants, Datatypes {
20    public Srightparen_1874859514 _Srightparen_18748595140;
21    public datetimevalueexpression _datetimevalueexpression1;
22    public Sleftparen653880241 _Sleftparen6538802412;
23    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439223;
24
25
26    protected ParameterInfo[] getThisParameterInfo() throws DException {
27       ParameterInfo parameterInfo = new ParameterInfo();
28       parameterInfo.setName(toString());
29       parameterInfo.setDataType(INTEGER);
30       return new ParameterInfo[] {parameterInfo};
31    }
32
33    protected Object JavaDoc getResult(int type, Object JavaDoc object) throws DException {
34       if (object == null) {
35          return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, Datatype.INTEGER);
36       }
37       GregorianCalendar calendar = new GregorianCalendar();
38       switch (type) {
39          case BYTE:
40          case TINYINT:
41          case INTEGER:
42          case INT:
43          case SHORT:
44          case SMALLINT:
45             Number JavaDoc operand = (Number JavaDoc) object;
46             calendar.set(Calendar.DAY_OF_YEAR, operand.intValue());
47             return new FieldLiteral(new Integer JavaDoc(calendar.get(Calendar.MONTH) + 1), Datatype.INTEGER);
48          case REAL:
49          case DOUBLE:
50          case FLOAT:
51          case DOUBLEPRECISION:
52          case LONG:
53          case BIGINT:
54          case BIGDECIMAL:
55          case DEC:
56          case DECIMAL:
57          case NUMERIC:
58             throw new DException("DSE8106", new Object JavaDoc[] {StaticClass.getDataTypeName(type)});
59          case CHARACTER:
60          case VARCHAR:
61          case CHAR:
62          case CHARACTERVARYING:
63            String JavaDoc string = (String JavaDoc)object;
64            try {
65              Timestamp timestamp =TypeValidityHandler.getTimestamp(string);
66              Date JavaDoc d1 = new com.daffodilwoods.daffodildb.utils.DBDate(timestamp.getTime());
67              calendar.setTime(d1);
68              return new FieldLiteral(new Integer JavaDoc(calendar.get(Calendar.MONTH) + 1), Datatype.INTEGER);
69            }
70            catch (DException ex) {
71              try {
72                Date JavaDoc d2 = TypeValidityHandler.getDBDate(string);
73                calendar.setTime(d2);
74                return new FieldLiteral(new Integer JavaDoc(calendar.get(Calendar.MONTH) + 1), Datatype.INTEGER);
75              }
76              catch (DException ex1) {
77                try {
78                  Time time = TypeValidityHandler.getTime(string);
79                  Date JavaDoc d = new com.daffodilwoods.daffodildb.utils.DBDate(time.getTime());
80                  calendar.setTime(d);
81                  return new FieldLiteral(new Integer JavaDoc(calendar.get(Calendar.MONTH) + 1), Datatype.INTEGER);
82                }
83                catch (DException ex2) {
84                  try {
85                    calendar.set(Calendar.DAY_OF_YEAR, new Integer JavaDoc(string).intValue());
86                    return new FieldLiteral(new Integer JavaDoc(calendar.get(Calendar.MONTH) + 1), Datatype.INTEGER);
87                  }
88                  catch (Exception JavaDoc ex3) {
89                    throw new DException("DSE419", new Object JavaDoc[]{string});
90                  }
91                }
92              }
93            }
94          case DATE:
95             Date JavaDoc d2 = (Date JavaDoc) object;
96             calendar.setTime(d2);
97             return new FieldLiteral(new Integer JavaDoc(calendar.get(Calendar.MONTH) + 1), Datatype.INTEGER);
98          case TIME:
99             Time time = (Time) object;
100             Date JavaDoc d = new com.daffodilwoods.daffodildb.utils.DBDate(time.getTime());
101             calendar.setTime(d);
102             return new FieldLiteral(new Integer JavaDoc(calendar.get(Calendar.MONTH) + 1), Datatype.INTEGER);
103          case TIMESTAMP:
104             Timestamp time1 = (Timestamp) object;
105             Date JavaDoc d1 = new com.daffodilwoods.daffodildb.utils.DBDate(time1.getTime());
106             calendar.setTime(d1);
107             return new FieldLiteral(new Integer JavaDoc(calendar.get(Calendar.MONTH) + 1), Datatype.INTEGER);
108          default:
109             throw new DException("DSE419", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "MONTH"});
110       }
111    }
112
113    /* protected Object getResult(int type,Object object) throws DException {
114       if(object == null)
115         return new FieldLiteral(FieldUtility.NULLBUFFERRANGE,Datatype.INTEGER);
116        GregorianCalendar calendar = new GregorianCalendar();
117        switch(type){
118          case BYTE : case TINYINT :
119              calendar.set(Calendar.DATE,((Byte)object).intValue());
120              return new FieldLiteral(new Integer(calendar.get(Calendar.MONTH) + 1 ),Datatype.INTEGER);
121            case INTEGER : case INT :
122              Integer integer = (Integer)object;
123              calendar.set(Calendar.DATE,integer.intValue());
124              return new FieldLiteral(new Integer(calendar.get(Calendar.MONTH) + 1 ),Datatype.INTEGER);
125           case REAL :
126              Float floatV = (Float)object;
127              calendar.set(Calendar.DATE,floatV.intValue());
128              return new FieldLiteral(new Integer(calendar.get(Calendar.MONTH) + 1 ),Datatype.INTEGER);
129            case DOUBLE : case FLOAT : case DOUBLEPRECISION :
130              Double doubleV = (Double)object;
131              calendar.set(Calendar.DATE,doubleV.intValue());
132              return new FieldLiteral(new Integer(calendar.get(Calendar.MONTH) + 1 ),Datatype.INTEGER);
133            case LONG : case BIGINT :
134              Long longV = (Long)object;
135              calendar.set(Calendar.DATE,longV.intValue());
136              return new FieldLiteral(new Integer(calendar.get(Calendar.MONTH) + 1 ),Datatype.INTEGER);
137            case SHORT : case SMALLINT :
138              Short shortV = (Short)object;
139              calendar.set(Calendar.DATE,shortV.intValue());
140              return new FieldLiteral(new Integer(calendar.get(Calendar.MONTH) + 1 ),Datatype.INTEGER);
141            case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
142              BigDecimal bigDecimal = (BigDecimal)object;
143              calendar.set(Calendar.DATE,bigDecimal.intValue());
144              return new FieldLiteral(new Integer(calendar.get(Calendar.MONTH) + 1 ),Datatype.INTEGER);
145            case CHARACTER :case VARCHAR: case CHAR: case CHARACTERVARYING:
146              throw new DException("DSE537",null);
147           case DATE :
148              Date d2 = (Date)object;
149              calendar.setTime(d2);
150              return new FieldLiteral(new Integer(calendar.get(Calendar.MONTH) + 1 ),Datatype.INTEGER);
151           case TIME :
152              Time time = (Time)object;
153              Date d = new com.daffodilwoods.daffodildb.utils.DBDate(time.getTime());
154              calendar.setTime(d);
155              return new FieldLiteral(new Integer(calendar.get(Calendar.MONTH) + 1 ),Datatype.INTEGER);
156           case TIMESTAMP :
157              Timestamp time1 = (Timestamp)object;
158              Date d1 = new com.daffodilwoods.daffodildb.utils.DBDate(time1.getTime());
159              calendar.setTime(d1);
160              return new FieldLiteral(new Integer(calendar.get(Calendar.MONTH) + 1 ),Datatype.INTEGER);
161           default :
162              throw new DException("DSE419",new Object[]{StaticClass.getDataTypeName(type),"MONTH"});
163        }
164     } */

165
166    public AbstractRowValueExpression[] getChilds() {
167       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { (AbstractRowValueExpression) (_datetimevalueexpression1)};
168       return childs;
169
170    }
171
172
173    public String JavaDoc toString() {
174       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
175       sb.append(" ");
176       sb.append(_SRESERVEDWORD12065439223);
177       sb.append(" ");
178       sb.append(_Sleftparen6538802412);
179       sb.append(" ");
180       sb.append(_datetimevalueexpression1);
181       sb.append(" ");
182       sb.append(_Srightparen_18748595140);
183       return sb.toString();
184    }
185
186    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
187       monthfunction tempClass = new monthfunction();
188       tempClass._Srightparen_18748595140 = (Srightparen_1874859514) _Srightparen_18748595140.clone();
189       tempClass._datetimevalueexpression1 = (datetimevalueexpression) _datetimevalueexpression1.clone();
190       tempClass._Sleftparen6538802412 = (Sleftparen653880241) _Sleftparen6538802412.clone();
191       tempClass._SRESERVEDWORD12065439223 = (SRESERVEDWORD1206543922) _SRESERVEDWORD12065439223.clone();
192       return tempClass;
193    }
194
195    public ByteComparison getByteComparison(Object JavaDoc object) throws DException {
196    ByteComparison byteComparison = new ByteComparison(false, new int[] {INTEGER});
197    byteComparison.setSize(getColumnSize(object));
198    return byteComparison;
199    }
200
201    public String JavaDoc getType() throws DException {
202       return (String JavaDoc) _SRESERVEDWORD12065439223.run(null);
203    }
204
205    public _Reference[] checkSemantic(_ServerSession parent) throws DException {
206       _Reference[] ref = super.checkSemantic(parent);
207       if(ref!=null) {
208         return ref;
209        }
210       int type = _datetimevalueexpression1.getByteComparison(parent).getDataTypes()[0];
211       switch (type) {
212          case -1:
213          case BYTE:
214          case TINYINT:
215          case INTEGER:
216          case INT:
217          case REAL:
218          case DOUBLE:
219          case FLOAT:
220          case DOUBLEPRECISION:
221          case LONG:
222          case BIGINT:
223          case SHORT:
224          case SMALLINT:
225          case BIGDECIMAL:
226          case DEC:
227          case DECIMAL:
228          case NUMERIC:
229          case DATE:
230          case TIME:
231          case TIMESTAMP:
232             return ref;
233          case CHARACTER:
234          case VARCHAR:
235          case CHAR:
236          case CHARACTERVARYING:
237          default:
238             throw new DException("DSE419", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "MONTH"});
239       }
240    }
241
242    public ParameterInfo[] getParameterInfo() throws DException {
243      ParameterInfo[] paramInfo = super.getParameterInfo();
244      for (int i = 0; i < paramInfo.length; i++) {
245        if (paramInfo[i].getQuestionMark()) {
246          paramInfo[i].setDataType(Datatypes.DATE);
247          paramInfo[i].setName("MONTH Arg");
248           }
249       }
250      return paramInfo;
251    }
252
253    public int getColumnSize( Object JavaDoc object) throws DException {
254      return Datatypes.INTSIZE;
255    }
256
257 }
258
Popular Tags