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.token.dateliteral; 17 18 public class datefunction 19 extends AbstractDateTimeValueFunction 20 implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter, 21 datetimevaluefunction, TypeConstants, Datatypes { 22 23 public Srightparen_1874859514 _Srightparen_18748595140; 24 public datetimevalueexpression _datetimevalueexpression1; 25 public Sleftparen653880241 _Sleftparen6538802412; 26 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439223; 27 28 29 protected ParameterInfo[] getThisParameterInfo() throws DException { 30 ParameterInfo parameterInfo = new ParameterInfo(); 31 parameterInfo.setName(toString()); 32 parameterInfo.setDataType(DATE); 33 return new ParameterInfo[] {parameterInfo}; 34 } 35 36 37 38 protected Object getResult(int type, Object object) throws DException { 39 if (object == null) 40 return new FieldDateLiteral(FieldUtility.NULLBUFFERRANGE); 41 switch (type) { 42 case TIMESTAMP: 43 Timestamp timestamp = (Timestamp) object; 44 return new FieldDateLiteral(getDate(timestamp)); 45 case CHARACTER: 46 case VARCHAR: 47 case CHAR: 48 case CHARACTERVARYING: 49 String string = (String ) object; 50 try { 51 Timestamp timestamps = TypeValidityHandler.getTimestamp(string); 52 return new FieldDateLiteral(getDate(timestamps)); 53 } 54 catch (DException ex1) { 55 try { 56 Date date = TypeValidityHandler.getDBDate(string); 57 return new FieldDateLiteral(date); 58 } 59 catch (DException ex) { 60 throw new DException("DSE419", new Object [] {string}); 61 } 62 63 } 64 default: 65 throw new DException("DSE4108", 66 new Object [] {StaticClass.getDataTypeName(type), 67 "DATE"}); 68 } 69 } 70 71 public AbstractRowValueExpression[] getChilds() { 72 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 73 (AbstractRowValueExpression) (_datetimevalueexpression1)}; 74 return childs; 75 76 } 77 78 public int getFunctionType() { 79 return DATEFUNCTION; 80 } 81 82 public String toString() { 83 StringBuffer sb = new StringBuffer (); 84 sb.append(" "); 85 sb.append(_SRESERVEDWORD12065439223); 86 sb.append(" "); 87 sb.append(_Sleftparen6538802412); 88 sb.append(" "); 89 sb.append(_datetimevalueexpression1); 90 sb.append(" "); 91 sb.append(_Srightparen_18748595140); 92 return sb.toString(); 93 } 94 95 public Object clone() throws CloneNotSupportedException { 96 hourfunction tempClass = new hourfunction(); 97 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 98 _Srightparen_18748595140.clone(); 99 tempClass._datetimevalueexpression1 = (datetimevalueexpression) 100 _datetimevalueexpression1.clone(); 101 tempClass._Sleftparen6538802412 = (Sleftparen653880241) 102 _Sleftparen6538802412.clone(); 103 tempClass._SRESERVEDWORD12065439223 = (SRESERVEDWORD1206543922) 104 _SRESERVEDWORD12065439223.clone(); 105 return tempClass; 106 } 107 108 public ByteComparison getByteComparison(Object object) throws DException { 109 ByteComparison byteComparison=new ByteComparison(false, new int[] {DATE}); 110 byteComparison.setSize(getColumnSize(object)); 111 return byteComparison; 112 } 113 114 public String getType() throws DException { 115 return (String ) _SRESERVEDWORD12065439223.run(null); 116 } 117 118 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 119 _Reference[] ref = super.checkSemantic(parent); 120 if(ref!=null) { 121 return ref; 122 } 123 int type = _datetimevalueexpression1.getByteComparison(parent).getDataTypes()[0]; 124 switch (type) { 125 case -1: 126 case TIMESTAMP: 127 case CHARACTER: 128 case VARCHAR: 129 case CHAR: 130 case CHARACTERVARYING: 131 132 return ref; 133 default: 134 throw new DException("DSE4108", 135 new Object [] {StaticClass.getDataTypeName(type), 136 "DATE"}); 137 } 138 } 139 140 public ParameterInfo[] getParameterInfo() throws DException { 141 ParameterInfo[] paramInfo = super.getParameterInfo(); 142 for (int i = 0; i < paramInfo.length; i++) { 143 if (paramInfo[i].getQuestionMark()) { 144 paramInfo[i].setDataType(Datatypes.DATE); 145 paramInfo[i].setName("DATE Arg"); 146 } 147 } 148 return paramInfo; 149 } 150 151 private Date getDate(Timestamp timestamp) { 152 return new Date (timestamp.getTime()); 153 157 } 158 159 public int getColumnSize(Object object) throws DException { 160 return Datatypes.DATESIZE; 161 } 162 163 } 164 | Popular Tags |