KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.expression.
2     datetimevalueexpression;
3
4 import java.sql.*;
5
6 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
7 import com.daffodilwoods.daffodildb.server.serversystem.*;
8 import com.daffodilwoods.daffodildb.server.sql99.common.*;
9 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
10 import com.daffodilwoods.daffodildb.server.sql99.token.*;
11 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
12 import com.daffodilwoods.daffodildb.utils.*;
13 import com.daffodilwoods.daffodildb.utils.field.*;
14 import com.daffodilwoods.database.resource.*;
15
16 public class timefunction
17     extends AbstractDateTimeValueFunction
18     implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter,
19     datetimevaluefunction, TypeConstants, Datatypes {
20
21   public Srightparen_1874859514 _Srightparen_18748595140;
22   public datetimevalueexpression _datetimevalueexpression1;
23   public Sleftparen653880241 _Sleftparen6538802412;
24   public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439223;
25
26
27   protected ParameterInfo[] getThisParameterInfo() throws DException {
28     ParameterInfo parameterInfo = new ParameterInfo();
29     parameterInfo.setName(toString());
30     parameterInfo.setDataType(Datatype.TIME);
31     return new ParameterInfo[] {
32         parameterInfo};
33   }
34
35   protected Object JavaDoc getResult(int type, Object JavaDoc object) throws DException {
36     if (object == null) {
37       return new FieldTimeLiteral(FieldUtility.NULLBUFFERRANGE);
38     }
39     switch (type) {
40       case TIMESTAMP:
41         return new FieldTimeLiteral(new Time( ( (Timestamp) object).getTime()));
42       case CHARACTER:
43       case VARCHAR:
44       case CHAR:
45       case CHARACTERVARYING:
46         String JavaDoc string = (String JavaDoc) object;
47         try {
48           Timestamp timestamps = TypeValidityHandler.getTimestamp(string);
49           return new FieldTimeLiteral(new Time(timestamps.getTime()));
50         }
51         catch (DException ex) {
52           try {
53             Time time = TypeValidityHandler.getTime(string);
54             return new FieldTimeLiteral(time);
55           }
56           catch (DException ex1) {
57           throw new DException("DSE419", new Object JavaDoc[] {string});
58           }
59         }
60         default:
61           throw new DException("DSE4108",
62                                new Object JavaDoc[] {StaticClass.getDataTypeName(type),
63                                "TIME"});
64     }
65   }
66
67   public AbstractRowValueExpression[] getChilds() {
68     AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {
69         (AbstractRowValueExpression) (_datetimevalueexpression1)};
70     return childs;
71
72   }
73
74   public int getFunctionType() {
75     return DATEFUNCTION;
76   }
77
78   public String JavaDoc toString() {
79     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
80     sb.append(" ");
81     sb.append(_SRESERVEDWORD12065439223);
82     sb.append(" ");
83     sb.append(_Sleftparen6538802412);
84     sb.append(" ");
85     sb.append(_datetimevalueexpression1);
86     sb.append(" ");
87     sb.append(_Srightparen_18748595140);
88     return sb.toString();
89   }
90
91   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
92     hourfunction tempClass = new hourfunction();
93     tempClass._Srightparen_18748595140 = (Srightparen_1874859514)
94         _Srightparen_18748595140.clone();
95     tempClass._datetimevalueexpression1 = (datetimevalueexpression)
96         _datetimevalueexpression1.clone();
97     tempClass._Sleftparen6538802412 = (Sleftparen653880241)
98         _Sleftparen6538802412.clone();
99     tempClass._SRESERVEDWORD12065439223 = (SRESERVEDWORD1206543922)
100         _SRESERVEDWORD12065439223.clone();
101     return tempClass;
102   }
103
104   public ByteComparison getByteComparison(Object JavaDoc object) throws DException {
105    ByteComparison byteComparison = new ByteComparison(false, new int[] {TIME});
106    byteComparison.setSize(getColumnSize(object));
107    return byteComparison;
108   }
109
110   public String JavaDoc getType() throws DException {
111     return (String JavaDoc) _SRESERVEDWORD12065439223.run(null);
112   }
113
114   public _Reference[] checkSemantic(_ServerSession parent) throws DException {
115     _Reference[] ref = super.checkSemantic(parent);
116     if(ref!=null) {
117         return ref;
118        }
119     int type = _datetimevalueexpression1.getByteComparison(parent).getDataTypes()[
120         0];
121     switch (type) {
122       case -1:
123       case TIMESTAMP:
124       case CHARACTER:
125       case VARCHAR:
126       case CHAR:
127       case CHARACTERVARYING:
128         return ref;
129       default:
130         throw new DException("DSE4108",
131                              new Object JavaDoc[] {StaticClass.getDataTypeName(type),
132                              "TIME()"});
133     }
134   }
135
136   private static Time getTime(Timestamp timestamp) {
137     String JavaDoc hh = String.valueOf(timestamp.getHours());
138     String JavaDoc mm = String.valueOf(timestamp.getMinutes());
139     String JavaDoc ss = String.valueOf(timestamp.getSeconds());
140     return Time.valueOf(hh + ":" + mm + ":" + ss);
141   }
142 /*
143   public static void main(String[] args) {
144     GregorianCalendar calendar = new GregorianCalendar();
145     Timestamp operand = new Timestamp(2004, 03, 12, 4, 20, 20, 20);
146
147   }
148 /*/

149  public ParameterInfo[] getParameterInfo() throws DException {
150   ParameterInfo[] paramInfo = super.getParameterInfo();
151   for (int i = 0; i < paramInfo.length; i++) {
152   if (paramInfo[i].getQuestionMark()) {
153     paramInfo[i].setDataType(Datatypes.TIME);
154     paramInfo[i].setName("TIME Arg");
155      }
156    }
157   return paramInfo;
158 }
159
160   public int getColumnSize( Object JavaDoc object) throws DException {
161        return Datatypes.TIMESIZE;
162   }
163
164 }
165
Popular Tags