KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > expression > numericvalueexpression > signfunction


1 package com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression;
2
3 import java.math.*;
4
5 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
6 import com.daffodilwoods.daffodildb.server.serversystem.*;
7 import com.daffodilwoods.daffodildb.server.sql99.common.*;
8 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
9 import com.daffodilwoods.daffodildb.server.sql99.token.*;
10 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
11 import com.daffodilwoods.daffodildb.utils.*;
12 import com.daffodilwoods.daffodildb.utils.field.*;
13 import com.daffodilwoods.database.resource.*;
14
15 public class signfunction extends AbstractNumericValueFunction {
16
17    public parennumericvalueexpression _parennumericvalueexpression0;
18    public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442551;
19
20    protected Object JavaDoc getResult(int type, Object JavaDoc object) throws DException {
21       if (object == null) {
22          return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, Datatype.INTEGER);
23       }
24       switch (type) {
25          case BYTE:
26          case TINYINT:
27             Byte JavaDoc byteV = (Byte JavaDoc) object;
28             byte bytevalue = byteV.byteValue();
29             return bytevalue > 0 ? FieldUtility.Int1 : bytevalue < 0 ?
30                 FieldUtility.Int_1 : FieldUtility.Int0;
31          case INTEGER:
32          case INT:
33             Integer JavaDoc integer = (Integer JavaDoc) object;
34             int value = integer.intValue();
35             return value > 0 ? FieldUtility.Int1 : value < 0 ?
36                 FieldUtility.Int_1 : FieldUtility.Int0;
37          case REAL:
38             Float JavaDoc floatV = (Float JavaDoc) object;
39             float value1 = floatV.floatValue();
40             return value1 > 0 ? FieldUtility.Int1 : value1 < 0 ?
41                 FieldUtility.Int_1 : FieldUtility.Int0;
42
43          case DOUBLE:
44          case FLOAT:
45          case DOUBLEPRECISION:
46             Double JavaDoc doubleV = (Double JavaDoc) object;
47             double value2 = doubleV.doubleValue();
48             return value2 > 0 ? FieldUtility.Int1 : value2 < 0 ?
49                 FieldUtility.Int_1 : FieldUtility.Int0;
50
51          case LONG:
52          case BIGINT:
53             Long JavaDoc longV = (Long JavaDoc) object;
54             long value3 = longV.longValue();
55             return value3 > 0 ? FieldUtility.Int1 : value3 < 0 ?
56                 FieldUtility.Int_1 : FieldUtility.Int0;
57
58          case SHORT:
59          case SMALLINT:
60             Short JavaDoc shortV = (Short JavaDoc) object;
61             short value4 = shortV.shortValue();
62             return value4 > 0 ? FieldUtility.Int1 : value4 < 0 ?
63                 FieldUtility.Int_1 : FieldUtility.Int0;
64          case BIGDECIMAL:
65          case DEC:
66          case DECIMAL:
67          case NUMERIC:
68             BigDecimal bigDecimal = (BigDecimal) object;
69             double value5 = bigDecimal.doubleValue();
70             return value5 > 0 ? FieldUtility.Int1 : value5 < 0 ?
71                 FieldUtility.Int_1 : FieldUtility.Int0;
72          default:
73             throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "SIGN"});
74       }
75    }
76
77    public AbstractRowValueExpression[] getChilds() {
78       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { (AbstractRowValueExpression) _parennumericvalueexpression0};
79       return childs;
80    }
81
82    public String JavaDoc getType() throws DException {
83       return (String JavaDoc) _SNONRESERVEDWORD1364442551.run(null);
84    }
85
86    public String JavaDoc toString() {
87       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
88       sb.append(" ");
89       sb.append(_SNONRESERVEDWORD1364442551);
90       sb.append(_parennumericvalueexpression0);
91       return sb.toString();
92    }
93
94    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
95       signfunction tempClass = new signfunction();
96       tempClass._parennumericvalueexpression0 = (parennumericvalueexpression) _parennumericvalueexpression0.clone();
97       tempClass._SNONRESERVEDWORD1364442551 = (SNONRESERVEDWORD136444255) _SNONRESERVEDWORD1364442551.clone();
98       return tempClass;
99    }
100
101    public ParameterInfo[] getParameterInfo() throws DException {
102      ParameterInfo[] paramInfo = super.getParameterInfo();
103      for (int i = 0; i < paramInfo.length; i++) {
104        if (paramInfo[i].getQuestionMark()) {
105          paramInfo[i].setDataType(Datatypes.BIGDECIMAL);
106          paramInfo[i].setName("SIGN Arg");
107        }
108      }
109      return paramInfo;
110    }
111
112    public ByteComparison getByteComparison(Object JavaDoc object) throws DException {
113    ByteComparison byteComparison = new ByteComparison(false, new int[] {INTEGER});
114    byteComparison.setSize(getColumnSize(object));
115    return byteComparison;
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 = _parennumericvalueexpression0.getByteComparison(parent).getDataTypes()[0];
124       if (type == -1 || type <= 15) {
125          return ref;
126       }
127       throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "SIGN"});
128    }
129
130   public int getColumnSize(Object JavaDoc object) throws DException {
131           return Datatypes.INTSIZE;
132    }
133
134 }
135
Popular Tags