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 weekfunction 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 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.DAY_OF_YEAR, operand.intValue()); 47 return new FieldLiteral(new Integer (calendar.get(Calendar.WEEK_OF_YEAR)), 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 Timestamp timestamp = TypeValidityHandler.getTimestamp(string); 66 Date d1 = new com.daffodilwoods.daffodildb.utils.DBDate(timestamp.getTime()); 67 calendar.setTime(d1); 68 return new FieldLiteral(new Integer (calendar.get(Calendar.WEEK_OF_YEAR)), Datatype.INTEGER); 69 } 70 catch (DException ex) { 71 try { 72 Date d2 = TypeValidityHandler.getDBDate(string); 73 calendar.setTime(d2); 74 return new FieldLiteral(new Integer (calendar.get(Calendar.WEEK_OF_YEAR)), Datatype.INTEGER); 75 } 76 catch (DException ex1) { 77 try { 78 Time time = TypeValidityHandler.getTime(string); 79 Date d = new com.daffodilwoods.daffodildb.utils.DBDate(time.getTime()); 80 calendar.setTime(d); 81 return new FieldLiteral(new Integer (calendar.get(Calendar.WEEK_OF_YEAR)), Datatype.INTEGER); 82 } 83 catch (DException ex2) { 84 try { 85 calendar.set(Calendar.DAY_OF_YEAR, new Integer (string).intValue()); 86 return new FieldLiteral(new Integer (calendar.get(Calendar.WEEK_OF_YEAR)), 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.WEEK_OF_YEAR)), 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.WEEK_OF_YEAR)), 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.WEEK_OF_YEAR)), Datatype.INTEGER); 108 default: 109 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "WEEK"}); 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(_SNONRESERVEDWORD1364442553); 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 weekfunction tempClass = new weekfunction(); 188 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) _Srightparen_18748595140.clone(); 189 tempClass._datetimevalueexpression1 = (datetimevalueexpression) _datetimevalueexpression1.clone(); 190 tempClass._Sleftparen6538802412 = (Sleftparen653880241) _Sleftparen6538802412.clone(); 191 tempClass._SNONRESERVEDWORD1364442553 = (SNONRESERVEDWORD136444255) _SNONRESERVEDWORD1364442553.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 ) _SNONRESERVEDWORD1364442553.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 212 switch (type) { 213 case -1: 214 case BYTE: 215 case TINYINT: 216 case INTEGER: 217 case INT: 218 case REAL: 219 case DOUBLE: 220 case FLOAT: 221 case DOUBLEPRECISION: 222 case LONG: 223 case BIGINT: 224 case SHORT: 225 case SMALLINT: 226 case BIGDECIMAL: 227 case DEC: 228 case DECIMAL: 229 case NUMERIC: 230 case DATE: 231 case TIME: 232 case TIMESTAMP: 233 return ref; 234 default: 235 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "WEEK"}); 236 } 237 238 } 239 public ParameterInfo[] getParameterInfo() throws DException { 240 ParameterInfo[] paramInfo = super.getParameterInfo(); 241 for (int i = 0; i < paramInfo.length; i++) { 242 if (paramInfo[i].getQuestionMark()) { 243 paramInfo[i].setDataType(Datatypes.DATE); 244 paramInfo[i].setName("WEEK Arg"); 245 } 246 } 247 return paramInfo; 248 } 249 250 public int getColumnSize( Object object) throws DException { 251 return Datatypes.INTSIZE; 252 } 253 254 } 255 | Popular Tags |