KickJava   Java API By Example, From Geeks To Geeks.

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


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 weekfunction 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 SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442553;
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.WEEK_OF_YEAR)), 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.WEEK_OF_YEAR)), 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.WEEK_OF_YEAR)), 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.WEEK_OF_YEAR)), 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.WEEK_OF_YEAR)), 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.WEEK_OF_YEAR)), 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.WEEK_OF_YEAR)), 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.WEEK_OF_YEAR)), Datatype.INTEGER);
108          default:
109             throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "WEEK"});
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.WEEK_OF_YEAR)),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.WEEK_OF_YEAR)),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.WEEK_OF_YEAR)),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.WEEK_OF_YEAR)),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.WEEK_OF_YEAR)),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.WEEK_OF_YEAR)),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.WEEK_OF_YEAR)),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.WEEK_OF_YEAR)),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.WEEK_OF_YEAR)),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.WEEK_OF_YEAR)),Datatype.INTEGER);
161            default :
162                        throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type),"WEEK"});
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(_SNONRESERVEDWORD1364442553);
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       weekfunction tempClass = new weekfunction();
188       tempClass._Srightparen_18748595140 = (Srightparen_1874859514) _Srightparen_18748595140.clone();
189       tempClass._datetimevalueexpression1 = (datetimevalueexpression) _datetimevalueexpression1.clone();
190       tempClass._Sleftparen6538802412 = (Sleftparen653880241) _Sleftparen6538802412.clone();
191       tempClass._SNONRESERVEDWORD1364442553 = (SNONRESERVEDWORD136444255) _SNONRESERVEDWORD1364442553.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) _SNONRESERVEDWORD1364442553.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
212       switch (type) {
213          case -1:
214          case BYTE:
215          case TINYINT:
216          case INTEGER:
217          case INT:
218          case REAL:
219          case DOUBLE:
220          case FLOAT:
221          case DOUBLEPRECISION:
222          case LONG:
223          case BIGINT:
224          case SHORT:
225          case SMALLINT:
226          case BIGDECIMAL:
227          case DEC:
228          case DECIMAL:
229          case NUMERIC:
230          case DATE:
231          case TIME:
232          case TIMESTAMP:
233             return ref;
234          default:
235             throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "WEEK"});
236       }
237
238    }
239    public ParameterInfo[] getParameterInfo() throws DException {
240      ParameterInfo[] paramInfo = super.getParameterInfo();
241      for (int i = 0; i < paramInfo.length; i++) {
242        if (paramInfo[i].getQuestionMark()) {
243          paramInfo[i].setDataType(Datatypes.DATE);
244          paramInfo[i].setName("WEEK Arg");
245        }
246      }
247      return paramInfo;
248    }
249
250    public int getColumnSize( Object JavaDoc object) throws DException {
251        return Datatypes.INTSIZE;
252    }
253
254 }
255
Popular Tags