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