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 dayofweekfunction 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 SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442553; 24 25 public Object run(Object object) throws com.daffodilwoods.database.resource. 26 DException { 27 FieldBase result = (FieldBase) _datetimevalueexpression1.run(object); 28 29 return (result.isNull()) ? 30 new FieldLiteral(FieldUtility.NULLBUFFERRANGE, INTEGER) : 31 getResult(getDataType(result), result.getObject()); 32 } 33 34 protected ParameterInfo[] getThisParameterInfo() throws DException { 35 ParameterInfo parameterInfo = new ParameterInfo(); 36 parameterInfo.setName(toString()); 37 parameterInfo.setDataType(INTEGER); 38 return new ParameterInfo[] {parameterInfo}; 39 } 40 41 protected Object getResult(int type, Object object) throws DException { 42 if (object == null) { 43 return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, Datatype.INTEGER); 44 } 45 GregorianCalendar calendar = new GregorianCalendar(); 46 switch (type) { 47 case BYTE: 48 case TINYINT: 49 case INTEGER: 50 case INT: 51 case SHORT: 52 case SMALLINT: 53 Number operand = (Number ) object; 54 calendar.set(Calendar.DAY_OF_WEEK, operand.intValue()); 55 return new FieldLiteral(new Integer ( (calendar.get(Calendar.DAY_OF_WEEK) % 7) + 1), Datatype.INTEGER); 56 case REAL: 57 case DOUBLE: 58 case FLOAT: 59 case DOUBLEPRECISION: 60 case LONG: 61 case BIGINT: 62 case BIGDECIMAL: 63 case DEC: 64 case DECIMAL: 65 case NUMERIC: 66 throw new DException("DSE8106", new Object [] {StaticClass.getDataTypeName(type)}); 67 case CHARACTER: 68 case VARCHAR: 69 case CHAR: 70 case CHARACTERVARYING: 71 String string = (String ) object; 72 try 73 { 74 Timestamp timestamp = TypeValidityHandler.getTimestamp(string); 75 Date d1 = new com.daffodilwoods.daffodildb.utils.DBDate(timestamp.getTime()); 76 calendar.setTime(d1); 77 return new FieldLiteral(new Integer (calendar.get(Calendar.DAY_OF_WEEK)), Datatype.INTEGER); 78 } 79 catch (DException ex) { 80 try { 81 Date d2 = TypeValidityHandler.getDBDate(string); 82 calendar.setTime(d2); 83 return new FieldLiteral(new Integer (calendar.get(Calendar.DAY_OF_WEEK)), Datatype.INTEGER); 84 } 85 catch (DException ex1) { 86 try { 87 Time time = TypeValidityHandler.getTime(string); 88 Date d = new com.daffodilwoods.daffodildb.utils.DBDate(time.getTime()); 89 calendar.setTime(d); 90 return new FieldLiteral(new Integer (calendar.get(Calendar.DAY_OF_WEEK)), Datatype.INTEGER); 91 } 92 catch (DException ex2) { 93 try { 94 calendar.set(Calendar.DAY_OF_WEEK, (new Integer (string)).intValue()); 95 return new FieldLiteral(new Integer ( (calendar.get(Calendar.DAY_OF_WEEK) % 7) + 1), Datatype.INTEGER); 96 } 97 catch (Exception ex3) { 98 throw new DException("DSE419", new Object []{string}); 99 } 100 } 101 } 102 } 103 case DATE: 104 Date d2 = (Date ) object; 105 calendar.setTime(d2); 106 return new FieldLiteral(new Integer (calendar.get(Calendar.DAY_OF_WEEK)), Datatype.INTEGER); 107 case TIME: 108 Time time = (Time) object; 109 Date d = new com.daffodilwoods.daffodildb.utils.DBDate(time.getTime()); 110 calendar.setTime(d); 111 return new FieldLiteral(new Integer (calendar.get(Calendar.DAY_OF_WEEK)), Datatype.INTEGER); 112 case TIMESTAMP: 113 Timestamp time1 = (Timestamp) object; 114 Date d1 = new com.daffodilwoods.daffodildb.utils.DBDate(time1.getTime()); 115 calendar.setTime(d1); 116 return new FieldLiteral(new Integer (calendar.get(Calendar.DAY_OF_WEEK)), Datatype.INTEGER); 117 default: 118 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "DAYOFWEEK"}); 119 } 120 } 121 122 174 175 public AbstractRowValueExpression[] getChilds() { 176 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { (AbstractRowValueExpression) (_datetimevalueexpression1)}; 177 return childs; 178 179 } 180 181 182 public String toString() { 183 StringBuffer sb = new StringBuffer (); 184 sb.append(" "); 185 sb.append(_SNONRESERVEDWORD1364442553); 186 sb.append(" "); 187 sb.append(_Sleftparen6538802412); 188 sb.append(" "); 189 sb.append(_datetimevalueexpression1); 190 sb.append(" "); 191 sb.append(_Srightparen_18748595140); 192 return sb.toString(); 193 } 194 195 public Object clone() throws CloneNotSupportedException { 196 dayofweekfunction tempClass = new dayofweekfunction(); 197 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) _Srightparen_18748595140.clone(); 198 tempClass._datetimevalueexpression1 = (datetimevalueexpression) _datetimevalueexpression1.clone(); 199 tempClass._Sleftparen6538802412 = (Sleftparen653880241) _Sleftparen6538802412.clone(); 200 tempClass._SNONRESERVEDWORD1364442553 = (SNONRESERVEDWORD136444255) _SNONRESERVEDWORD1364442553.clone(); 201 return tempClass; 202 } 203 204 public ByteComparison getByteComparison(Object object) throws DException { 205 ByteComparison byteComparison =new ByteComparison(false, new int[] {INTEGER}); 206 byteComparison.setSize(getColumnSize(object)); 207 return byteComparison; 208 } 209 210 211 public String getType() throws DException { 212 return (String ) _SNONRESERVEDWORD1364442553.run(null); 213 } 214 215 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 216 _Reference[] ref = super.checkSemantic(parent); 217 if(ref!=null) { 218 return ref; 219 } 220 int type = _datetimevalueexpression1.getByteComparison(parent).getDataTypes()[0]; 221 switch (type) { 222 case -1: 223 case BYTE: 224 case TINYINT: 225 case INTEGER: 226 case INT: 227 case REAL: 228 case DOUBLE: 229 case FLOAT: 230 case DOUBLEPRECISION: 231 case LONG: 232 case BIGINT: 233 case SHORT: 234 case SMALLINT: 235 case BIGDECIMAL: 236 case DEC: 237 case DECIMAL: 238 case NUMERIC: 239 case DATE: 240 case TIME: 241 case TIMESTAMP: 242 return ref; 243 case CHARACTER: 244 case VARCHAR: 245 case CHAR: 246 case CHARACTERVARYING: 247 default: 248 throw new DException("DSE419", new Object [] {StaticClass.getDataTypeName(type), "MONTH"}); 249 } 250 } 251 public ParameterInfo[] getParameterInfo() throws DException { 252 ParameterInfo[] paramInfo = super.getParameterInfo(); 253 for (int i = 0; i < paramInfo.length; i++) { 254 if (paramInfo[i].getQuestionMark()) { 255 paramInfo[i].setDataType(Datatypes.DATE); 256 paramInfo[i].setName("DAYOFWEEK Arg"); 257 } 258 } 259 return paramInfo; 260 } 261 262 public int getColumnSize(Object object) throws DException { 263 return Datatypes.INTSIZE; 264 } 265 } 266 | Popular Tags |