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