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 secondfunction 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 protected ParameterInfo[] getThisParameterInfo() throws DException { 26 ParameterInfo parameterInfo = new ParameterInfo(); 27 parameterInfo.setName(toString()); 28 parameterInfo.setDataType(INTEGER); 29 return new ParameterInfo[] {parameterInfo}; 30 } 31 32 protected Object getResult(int type, Object object) throws DException { 33 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.SECOND, operand.intValue()); 47 return new FieldLiteral(new Integer (calendar.get(Calendar.SECOND)), 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.SECOND)), 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.SECOND)), 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.SECOND)), Datatype.INTEGER); 82 } 83 catch (DException ex2) { 84 try { 85 calendar.set(Calendar.SECOND, new Integer (string).intValue()); 86 return new FieldLiteral(new Integer (calendar.get(Calendar.SECOND)), 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.SECOND)), 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.SECOND)), 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.SECOND)), Datatype.INTEGER); 108 default: 109 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "SECOND"}); 110 } 111 112 } 113 114 168 169 public AbstractRowValueExpression[] getChilds() { 170 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { (AbstractRowValueExpression) (_datetimevalueexpression1)}; 171 return childs; 172 173 } 174 175 176 public String toString() { 177 StringBuffer sb = new StringBuffer (); 178 sb.append(" "); 179 sb.append(_SRESERVEDWORD12065439223); 180 sb.append(" "); 181 sb.append(_Sleftparen6538802412); 182 sb.append(" "); 183 sb.append(_datetimevalueexpression1); 184 sb.append(" "); 185 sb.append(_Srightparen_18748595140); 186 return sb.toString(); 187 } 188 189 public Object clone() throws CloneNotSupportedException { 190 secondfunction tempClass = new secondfunction(); 191 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) _Srightparen_18748595140.clone(); 192 tempClass._datetimevalueexpression1 = (datetimevalueexpression) _datetimevalueexpression1.clone(); 193 tempClass._Sleftparen6538802412 = (Sleftparen653880241) _Sleftparen6538802412.clone(); 194 tempClass._SRESERVEDWORD12065439223 = (SRESERVEDWORD1206543922) _SRESERVEDWORD12065439223.clone(); 195 return tempClass; 196 } 197 198 public ByteComparison getByteComparison(Object object) throws DException { 199 ByteComparison byteComparison = new ByteComparison(false, new int[] {INTEGER}); 200 byteComparison.setSize(getColumnSize(object)); 201 return byteComparison; 202 } 203 204 public String getType() throws DException { 205 return (String ) _SRESERVEDWORD12065439223.run(null); 206 } 207 208 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 209 _Reference[] ref = super.checkSemantic(parent); 210 if(ref!=null) { 211 return ref; 212 } 213 int type = _datetimevalueexpression1.getByteComparison(parent).getDataTypes()[0]; 214 switch (type) { 215 case -1: 216 case BYTE: 217 case TINYINT: 218 case INTEGER: 219 case INT: 220 case REAL: 221 case DOUBLE: 222 case FLOAT: 223 case DOUBLEPRECISION: 224 case LONG: 225 case BIGINT: 226 case SHORT: 227 case SMALLINT: 228 case BIGDECIMAL: 229 case DEC: 230 case DECIMAL: 231 case NUMERIC: 232 case DATE: 233 case TIME: 234 case TIMESTAMP: 235 return ref; 236 case CHARACTER: 237 case VARCHAR: 238 case CHAR: 239 case CHARACTERVARYING: 240 default: 241 throw new DException("DSE419", new Object [] {StaticClass.getDataTypeName(type), "SECOND"}); 242 } 243 } 244 public ParameterInfo[] getParameterInfo() throws DException { 245 ParameterInfo[] paramInfo = super.getParameterInfo(); 246 for (int i = 0; i < paramInfo.length; i++) { 247 if (paramInfo[i].getQuestionMark()) { 248 paramInfo[i].setDataType(Datatypes.TIME); 249 paramInfo[i].setName("SECOND Arg"); 250 } 251 } 252 return paramInfo; 253 } 254 public int getColumnSize( Object object) throws DException { 255 return Datatypes.INTSIZE; 256 } 257 258 } 259 | Popular Tags |