KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > expression > stringvalueexpression > spacefunction


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 JavaDoc run(Object JavaDoc 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 JavaDoc getNameOfColumn(ColumnDetails[] columnDetails) throws
55        DException {
56       String JavaDoc nameOfColumn = "";
57       for (int i = 0; i < columnDetails.length; ++i) {
58          nameOfColumn += columnDetails[i].getColumn();
59       }
60       return nameOfColumn;
61    }
62
63    /*private int getDataType(Object object) throws DException {
64      if (object instanceof Integer)
65        return INTEGER;
66      else if (object instanceof Float)
67        return FLOAT;
68      else if (object instanceof Double)
69        return DOUBLE;
70      else if (object instanceof Long)
71        return LONG;
72      else if (object instanceof String)
73        return CHARACTER;
74      else if (object instanceof Short)
75        return SHORT;
76      else if (object instanceof BigDecimal)
77        return BIGDECIMAL;
78      else if (object instanceof Byte)
79        return BYTE;
80      else
81        throw new DException("DSE419", new Object[] {"SPACE"});
82       }*/

83
84    private Object JavaDoc getResult(FieldBase result) throws DException {
85       Object JavaDoc object = result.getObject();
86       int type = getDataType(result);
87       if (type <= 15)
88         return calculatingSpace( ( (Number JavaDoc) object).intValue());
89       throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "SPACE"});
90       /*switch (type) {
91          case BYTE:
92          case TINYINT:
93          case SHORT:
94          case SMALLINT:
95          case INTEGER:
96          case INT:
97          case REAL:
98          case LONG:
99          case BIGINT:
100          case BIGDECIMAL:
101          case DEC:
102          case DECIMAL:
103          case NUMERIC:
104          case DOUBLE:
105          case FLOAT:
106          case DOUBLEPRECISION:
107             return calculatingSpace( ( (Number) object).intValue());
108          default:
109             throw new DException("DSE4108", new Object[] {StaticClass.getDataTypeName(type), "SPACE"});
110       }*/

111    }
112
113    private Object JavaDoc calculatingSpace(int count) throws DException {
114       if (count < 0) {
115          return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, Datatype.CHARACTER);
116       }
117       String JavaDoc 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 JavaDoc getType() throws DException {
132       return (String JavaDoc) _SRESERVEDWORD12065439223.run(null);
133    }
134
135    public String JavaDoc toString() {
136       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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 JavaDoc clone() throws CloneNotSupportedException JavaDoc {
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 JavaDoc[] {StaticClass.getDataTypeName(type), "SPACE"});
170    }
171
172    public int getColumnSize(Object JavaDoc object) throws DException {
173      ColumnDetails[] columnDetails = getChildColumnDetails();
174      /**
175       * commented by sube singh because it should return
176       * size according to given expression or size return by the
177       * columndetail.
178       */

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