1 package com.daffodilwoods.daffodildb.server.sql99.expression.stringvalueexpression; 2 3 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 4 import com.daffodilwoods.daffodildb.server.serversystem.*; 5 import com.daffodilwoods.daffodildb.server.sql99.common.*; 6 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*; 7 import com.daffodilwoods.daffodildb.server.sql99.token.*; 8 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 9 import com.daffodilwoods.daffodildb.utils.*; 10 import com.daffodilwoods.daffodildb.utils.field.*; 11 import com.daffodilwoods.database.resource.*; 12 import in.co.daffodil.db.jdbc.DatabaseProperties; 13 14 public class spacefunction extends AbstractStringValueExpression implements charactervaluefunction { 15 public Srightparen_1874859514 _Srightparen_18748595140; 16 public stringlength _stringlength1; 17 public Sleftparen653880241 _Sleftparen6538802412; 18 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439223; 19 20 21 public Object run(Object object) throws com.daffodilwoods.database.resource. 22 DException { 23 FieldBase result = (FieldBase) _stringlength1.run(object); 24 if (result.isNull()) { 25 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 26 } 27 return getResult(result); 28 } 29 30 public ParameterInfo[] getParameterInfo() throws DException { 31 ParameterInfo[] paramInfo = _stringlength1.getParameterInfo(); 32 for (int i = 0; i < paramInfo.length; i++) { 33 if (paramInfo[i].getQuestionMark()){ 34 paramInfo[i].setDataType(INTEGER); 35 paramInfo[i].setName("SPACE Arg"); 36 return paramInfo; 37 } 38 } 39 return getThisParameterInfo(); 40 } 41 42 protected ParameterInfo[] getThisParameterInfo() throws DException { 43 ParameterInfo parameterInfo = new ParameterInfo(); 44 parameterInfo.setName(toString()); 45 parameterInfo.setDataType(Datatypes.CHARACTER); 46 return new ParameterInfo[] { 47 parameterInfo}; 48 } 49 50 public ColumnDetails[] getChildColumnDetails() throws DException { 51 return columnDetails; 52 } 53 54 protected String getNameOfColumn(ColumnDetails[] columnDetails) throws 55 DException { 56 String nameOfColumn = ""; 57 for (int i = 0; i < columnDetails.length; ++i) { 58 nameOfColumn += columnDetails[i].getColumn(); 59 } 60 return nameOfColumn; 61 } 62 63 83 84 private Object getResult(FieldBase result) throws DException { 85 Object object = result.getObject(); 86 int type = getDataType(result); 87 if (type <= 15) 88 return calculatingSpace( ( (Number ) object).intValue()); 89 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "SPACE"}); 90 111 } 112 113 private Object calculatingSpace(int count) throws DException { 114 if (count < 0) { 115 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, Datatype.CHARACTER); 116 } 117 String spaces = ""; 118 for (int i = 0; i < count; ++i) { 119 spaces += " "; 120 } 121 return new FieldStringLiteral(spaces, Datatype.CHARACTER); 122 } 123 124 public AbstractRowValueExpression[] getChilds() { 125 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 126 (AbstractRowValueExpression) (_stringlength1)}; 127 return childs; 128 129 } 130 131 public String getType() throws DException { 132 return (String ) _SRESERVEDWORD12065439223.run(null); 133 } 134 135 public String toString() { 136 StringBuffer sb = new StringBuffer (); 137 sb.append(" "); 138 sb.append(_SRESERVEDWORD12065439223); 139 sb.append(" "); 140 sb.append(_Sleftparen6538802412); 141 sb.append(" "); 142 sb.append(_stringlength1); 143 sb.append(" "); 144 sb.append(_Srightparen_18748595140); 145 return sb.toString(); 146 } 147 148 public Object clone() throws CloneNotSupportedException { 149 spacefunction tempClass = new spacefunction(); 150 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 151 _Srightparen_18748595140.clone(); 152 tempClass._stringlength1 = (stringlength) _stringlength1.clone(); 153 tempClass._Sleftparen6538802412 = (Sleftparen653880241) 154 _Sleftparen6538802412.clone(); 155 tempClass._SRESERVEDWORD12065439223 = (SRESERVEDWORD1206543922) 156 _SRESERVEDWORD12065439223.clone(); 157 return tempClass; 158 } 159 160 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 161 _Reference[] ref = super.checkSemantic(parent); 162 if(ref!=null) { 163 return ref; 164 } 165 int type = _stringlength1.getByteComparison(parent).getDataTypes()[0]; 166 if (type == -1 || type <= 15) { 167 return ref; 168 } 169 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "SPACE"}); 170 } 171 172 public int getColumnSize(Object object) throws DException { 173 ColumnDetails[] columnDetails = getChildColumnDetails(); 174 179 if (columnDetails[0].getQuestion()) { 180 return DatabaseProperties.maxCharLiteralLength; 181 } 182 else if (columnDetails[0].getType() != TypeConstants.CONSTANT || 183 columnDetails[0].getSize() != -5) { 184 return columnDetails[0].getSize(); 185 } 186 else { 187 FieldBase field = (FieldBase) _stringlength1.run(object); 188 field.setDatatype(columnDetails[0].getDatatype()); 189 return field.getLength(); 190 } 191 } 192 193 } 194 | Popular Tags |