1 package com.daffodilwoods.daffodildb.server.sql99.expression.datetimevalueexpression; 2 3 import java.sql.*; 4 import java.sql.Date ; 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 hourfunction extends AbstractNumericValueFunction implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter, 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 getResult(int type, Object 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 operand = (Number ) object; 46 calendar.set(Calendar.HOUR_OF_DAY, operand.intValue()); 47 return new FieldLiteral(new Integer (calendar.get(Calendar.HOUR_OF_DAY)), 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 [] {StaticClass.getDataTypeName(type)}); 59 case CHARACTER: 60 case VARCHAR: 61 case CHAR: 62 case CHARACTERVARYING: 63 String string = (String ) object; 64 try { 65 Time time = TypeValidityHandler.getTime(string); 66 Date d = new com.daffodilwoods.daffodildb.utils.DBDate(time.getTime()); 67 calendar.setTime(d); 68 return new FieldLiteral(new Integer (calendar.get(Calendar.HOUR_OF_DAY)), Datatype.INTEGER); 69 } 70 catch (DException ex) { 71 try { 72 Timestamp time1 = TypeValidityHandler.getTimestamp(string); 73 Date d1 = new com.daffodilwoods.daffodildb.utils.DBDate(time1.getTime()); 74 calendar.setTime(d1); 75 return new FieldLiteral(new Integer (calendar.get(Calendar.HOUR_OF_DAY)), Datatype.INTEGER); 76 } 77 catch (DException ex1) { 78 try { 79 Date d2 = TypeValidityHandler.getDBDate(string); 80 calendar.setTime(d2); 81 return new FieldLiteral(new Integer (calendar.get(Calendar.HOUR_OF_DAY)), Datatype.INTEGER); 82 } 83 catch (DException ex2) { 84 try { 85 calendar.set(Calendar.HOUR_OF_DAY,new Integer (string).intValue()); 86 return new FieldLiteral(new Integer (calendar.get(Calendar.HOUR_OF_DAY)), Datatype.INTEGER); 87 } 88 catch (Exception ex3) { 89 throw new DException("DSE419", new Object []{string}); 90 } 91 } 92 } 93 } 94 case DATE: 95 Date d2 = (Date ) object; 96 calendar.setTime(d2); 97 return new FieldLiteral(new Integer (calendar.get(Calendar.HOUR_OF_DAY)), Datatype.INTEGER); 98 case TIME: 99 Time time = (Time) object; 100 Date d = new com.daffodilwoods.daffodildb.utils.DBDate(time.getTime()); 101 calendar.setTime(d); 102 return new FieldLiteral(new Integer (calendar.get(Calendar.HOUR_OF_DAY)), Datatype.INTEGER); 103 case TIMESTAMP: 104 Timestamp time1 = (Timestamp) object; 105 Date d1 = new com.daffodilwoods.daffodildb.utils.DBDate(time1.getTime()); 106 calendar.setTime(d1); 107 return new FieldLiteral(new Integer (calendar.get(Calendar.HOUR_OF_DAY)), Datatype.INTEGER); 108 default: 109 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "HOUR"}); 110 } 111 } 112 113 165 166 public AbstractRowValueExpression[] getChilds() { 167 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { (AbstractRowValueExpression) (_datetimevalueexpression1)}; 168 return childs; 169 170 } 171 172 173 public String toString() { 174 StringBuffer sb = new StringBuffer (); 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 clone() throws CloneNotSupportedException { 187 hourfunction tempClass = new hourfunction(); 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 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 getType() throws DException { 202 return (String ) _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 default: 234 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "HOUR"}); 235 } 236 237 } 238 public ParameterInfo[] getParameterInfo() throws DException { 239 ParameterInfo[] paramInfo = super.getParameterInfo(); 240 for (int i = 0; i < paramInfo.length; i++) { 241 if (paramInfo[i].getQuestionMark()) { 242 paramInfo[i].setDataType(Datatypes.TIME); 243 paramInfo[i].setName("HOUR Arg"); 244 } 245 } 246 return paramInfo; 247 } 248 249 public int getColumnSize( Object object) throws DException { 250 return Datatypes.INTSIZE; 251 } 252 253 254 } 255 | Popular Tags |