KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression;
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
13 public class modulusexpression extends AbstractNumericValueFunction {
14
15    public parencommanumericvalueexpression _parencommanumericvalueexpression0;
16    public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442551;
17
18    public Object JavaDoc run(Object JavaDoc object) throws com.daffodilwoods.database.resource.DException {
19       FieldBase[] res = GeneralPurposeStaticClass.changeIntoFieldBase( (Object JavaDoc[]) _parencommanumericvalueexpression0.run(object));
20       FieldBase result1 = res[0];
21       FieldBase result2 = res[1];
22       if (result1.isNull() || result2.isNull()) {
23          return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, DOUBLE);
24       }
25       if (result2.getObject().hashCode() == 0) {
26          throw new DException("DSE334", null);
27       }
28       return getResult(getDataType(result1), getDataType(result2),
29                        result1.getObject(), result2.getObject());
30    }
31
32    public ParameterInfo[] getParameterInfo() throws DException {
33      ParameterInfo[] paramInfo = super.getParameterInfo();
34      for (int i = 0; i < paramInfo.length; i++) {
35        if (paramInfo[i].getQuestionMark()) {
36          paramInfo[i].setDataType(Datatypes.DOUBLE);
37          paramInfo[i].setName("MODULUS Arg");
38        }
39      }
40      return paramInfo;
41    }
42
43    public ColumnDetails[] getExistingColumnDetails() throws DException {
44       return columnDetails;
45    }
46
47    private Object JavaDoc getResult(int type1, int type2, Object JavaDoc result1, Object JavaDoc result2) throws DException {
48      if(result2 instanceof Number JavaDoc) {
49        if ( ( (Number JavaDoc) result2).intValue() == 0) {
50          throw new DException("DSE334", null);
51        }
52      }
53      switch(type1){
54          case BYTE : case TINYINT :
55          case SHORT : case SMALLINT :
56          case INTEGER : case INT :
57          case LONG : case BIGINT :
58            switch(type2) {
59              case BYTE : case TINYINT :
60              case SHORT : case SMALLINT :
61              case INTEGER : case INT :
62              case LONG : case BIGINT :
63              long operand1 = ((Number JavaDoc)result1).longValue();
64              long operand2 = ((Number JavaDoc)result2).longValue();
65              return new FieldLiteral(new Double JavaDoc(operand1 % operand2),Datatype.DOUBLE);
66              case REAL : case DOUBLE :
67              case FLOAT : case DOUBLEPRECISION :
68              /*case BIGDECIMAL :*/ case DEC :
69              case DECIMAL : case NUMERIC :
70              long operand01 = ((Number JavaDoc)result1).longValue();
71              double operand02 = ((Number JavaDoc)result2).doubleValue();
72              return new FieldLiteral(new Double JavaDoc(operand01 % operand02),Datatype.DOUBLE);
73              default:
74              throw new DException("DSE4108",new Object JavaDoc[]{StaticClass.getDataTypeName(type2),"MOD"});
75            }
76          case REAL :
77          case DOUBLE : case FLOAT : case DOUBLEPRECISION :
78          /*case BIGDECIMAL :*/ case DEC : case DECIMAL : case NUMERIC :
79              switch(type2){
80                case BYTE : case TINYINT :
81                case SHORT : case SMALLINT :
82                case INTEGER : case INT :
83                case LONG : case BIGINT :
84                case REAL : case DOUBLE :
85                case FLOAT : case DOUBLEPRECISION :
86                /*case BIGDECIMAL :*/ case DEC :
87                case DECIMAL : case NUMERIC :
88                double operand1 = ((Number JavaDoc)result1).doubleValue();
89                double operand2 = ((Number JavaDoc)result2).doubleValue();
90                return new FieldLiteral(new Double JavaDoc(operand1 % operand2),Datatype.DOUBLE);
91                default:
92                throw new DException("DSE4108",new Object JavaDoc[]{StaticClass.getDataTypeName(type2),"MOD"});
93              }
94           default:
95              throw new DException("DSE4108",new Object JavaDoc[]{StaticClass.getDataTypeName(type1),"MOD"});
96        }
97    }
98
99    /*private Object getResult(int type1,int type2,Object result1,Object result2) throws DException {
100      switch(type1){
101        case BYTE : case TINYINT :
102          double operandb1 = ((Byte)result1).doubleValue();
103          switch(type2){
104            case BYTE : case TINYINT :
105              double operand12 = ((Byte)result2).doubleValue();
106              return new FieldLiteral(new Double(operandb1 % operand12),Datatype.DOUBLE);
107            case SHORT : case SMALLINT :
108              double operand1 = ((Short)result2).doubleValue();
109              return new FieldLiteral(new Double(operandb1 % operand1),Datatype.DOUBLE);
110            case INTEGER : case INT :
111                double operand2 = ((Integer)result2).doubleValue();
112                return new FieldLiteral(new Double(operandb1 % operand2),Datatype.DOUBLE);
113              case LONG : case BIGINT :
114                double operand3 = ((Long)result2).doubleValue();
115                return new FieldLiteral(new Double(operandb1 % operand3),Datatype.DOUBLE);
116             case REAL :
117                double operand4 = ((Float)result2).doubleValue();
118                return new FieldLiteral(new Double(operandb1 % operand4),Datatype.DOUBLE);
119              case DOUBLE : case FLOAT : case DOUBLEPRECISION :
120                double operand5 = ((Double)result2).doubleValue();
121                return new FieldLiteral(new Double(operandb1 % operand5),Datatype.DOUBLE);
122              case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
123                    double operand51 = ((BigDecimal)result2).doubleValue();
124                    return new FieldLiteral(new Double(operandb1 % operand51),Datatype.DOUBLE);
125                    default:
126                      throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type2),"MOD"});
127          }
128        case SHORT : case SMALLINT :
129          double operands1 = ((Short)result1).doubleValue();
130          switch(type2){
131            case BYTE : case TINYINT :
132              double operand12 = ((Byte)result2).doubleValue();
133              return new FieldLiteral(new Double(operands1 % operand12),Datatype.DOUBLE);
134            case SHORT : case SMALLINT :
135              double operand1 = ((Short)result2).doubleValue();
136              return new FieldLiteral(new Double(operands1 % operand1),Datatype.DOUBLE);
137            case INTEGER : case INT :
138                double operand2 = ((Integer)result2).doubleValue();
139                return new FieldLiteral(new Double(operands1 % operand2),Datatype.DOUBLE);
140              case LONG : case BIGINT :
141                double operand3 = ((Long)result2).doubleValue();
142                return new FieldLiteral(new Double(operands1 % operand3),Datatype.DOUBLE);
143             case REAL :
144                double operand4 = ((Float)result2).doubleValue();
145                return new FieldLiteral(new Double(operands1 % operand4),Datatype.DOUBLE);
146              case DOUBLE : case FLOAT : case DOUBLEPRECISION :
147                double operand5 = ((Double)result2).doubleValue();
148                return new FieldLiteral(new Double(operands1 % operand5),Datatype.DOUBLE);
149              case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
150                    double operand51 = ((BigDecimal)result2).doubleValue();
151                    return new FieldLiteral(new Double(operands1 % operand51),Datatype.DOUBLE);
152                    default:
153                      throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type2),"MOD"});
154          }
155        case INTEGER : case INT :
156            double operand1 = ((Integer)result1).doubleValue();
157            switch(type2){
158              case BYTE : case TINYINT :
159                double operand12 = ((Byte)result2).doubleValue();
160                return new FieldLiteral(new Double(operand1 % operand12),Datatype.DOUBLE);
161              case SHORT : case SMALLINT :
162                double operand13 = ((Short)result2).doubleValue();
163                return new FieldLiteral(new Double(operand1 % operand13),Datatype.DOUBLE);
164              case INTEGER : case INT :
165                  double operand2 = ((Integer)result2).doubleValue();
166                  return new FieldLiteral(new Double(operand1 % operand2),Datatype.DOUBLE);
167                case LONG : case BIGINT :
168                  double operand3 = ((Long)result2).doubleValue();
169                  return new FieldLiteral(new Double(operand1 % operand3),Datatype.DOUBLE);
170               case REAL :
171                  double operand4 = ((Float)result2).doubleValue();
172                  return new FieldLiteral(new Double(operand1 % operand4),Datatype.DOUBLE);
173                case DOUBLE : case FLOAT : case DOUBLEPRECISION :
174                  double operand5 = ((Double)result2).doubleValue();
175                  return new FieldLiteral(new Double(operand1 % operand5),Datatype.DOUBLE);
176                case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
177                      double operand51 = ((BigDecimal)result2).doubleValue();
178                      return new FieldLiteral(new Double(operand1 % operand51),Datatype.DOUBLE);
179                    default:
180                      throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type2),"MOD"});
181            }
182          case LONG : case BIGINT :
183            double operand11 = ((Long)result1).doubleValue();
184            switch(type2){
185              case BYTE : case TINYINT :
186                double operand12 = ((Byte)result2).doubleValue();
187                return new FieldLiteral(new Double(operand11 % operand12),Datatype.DOUBLE);
188              case SHORT : case SMALLINT :
189                double operand13 = ((Short)result2).doubleValue();
190                return new FieldLiteral(new Double(operand11 % operand13),Datatype.DOUBLE);
191              case INTEGER : case INT :
192                  double operand6 = ((Integer)result2).doubleValue();
193                  return new FieldLiteral(new Double(operand11 % operand6),Datatype.DOUBLE);
194                case LONG : case BIGINT :
195                  double operand7 = ((Long)result2).doubleValue();
196                  return new FieldLiteral(new Double(operand11 % operand7),Datatype.DOUBLE);
197               case REAL :
198                  double operand8 = ((Float)result2).doubleValue();
199                  return new FieldLiteral(new Double(operand11 % operand8),Datatype.DOUBLE);
200                case DOUBLE : case FLOAT : case DOUBLEPRECISION :
201                  double operand9 = ((Double)result2).doubleValue();
202                  return new FieldLiteral(new Double(operand11 % operand9),Datatype.DOUBLE);
203                case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
204                  double operand52 = ((BigDecimal)result2).doubleValue();
205                  return new FieldLiteral(new Double(operand11 % operand52),Datatype.DOUBLE);
206                default:
207                  throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type2),"MOD"});
208            }
209         case REAL :
210            double operand111 = ((Float)result1).doubleValue();
211            switch(type2){
212              case BYTE : case TINYINT :
213                double operand112 = ((Byte)result2).doubleValue();
214                return new FieldLiteral(new Double(operand111 % operand112),Datatype.DOUBLE);
215              case SHORT : case SMALLINT :
216                double operand10 = ((Short)result2).doubleValue();
217                return new FieldLiteral(new Double(operand111 % operand10),Datatype.DOUBLE);
218              case INTEGER : case INT :
219                  double operand12 = ((Integer)result2).doubleValue();
220                  return new FieldLiteral(new Double(operand111 % operand12),Datatype.DOUBLE);
221                case LONG : case BIGINT :
222                  double operand13 = ((Long)result2).doubleValue();
223                  return new FieldLiteral(new Double(operand111 % operand13),Datatype.DOUBLE);
224               case REAL :
225                  double operand14 = ((Float)result2).doubleValue();
226                  return new FieldLiteral(new Double(operand111 % operand14),Datatype.DOUBLE);
227                case DOUBLE : case FLOAT : case DOUBLEPRECISION :
228                  double operand15 = ((Double)result2).doubleValue();
229                  return new FieldLiteral(new Double(operand111 % operand15),Datatype.DOUBLE);
230                case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
231                  double operand53 = ((BigDecimal)result2).doubleValue();
232                  return new FieldLiteral(new Double(operand111 % operand53),Datatype.DOUBLE);
233                default:
234                  throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type2),"MOD"});
235            }
236          case DOUBLE : case FLOAT : case DOUBLEPRECISION :
237            double operand1111 = ((Double)result1).doubleValue();
238            switch(type2){
239              case BYTE : case TINYINT :
240                double operand15 = ((Byte)result2).doubleValue();
241                return new FieldLiteral(new Double(operand1111 % operand15),Datatype.DOUBLE);
242              case SHORT : case SMALLINT :
243                double operand10 = ((Short)result2).doubleValue();
244                return new FieldLiteral(new Double(operand1111 % operand10),Datatype.DOUBLE);
245              case INTEGER : case INT :
246                  double operand16 = ((Integer)result2).doubleValue();
247                  return new FieldLiteral(new Double(operand1111 % operand16),Datatype.DOUBLE);
248                case LONG : case BIGINT :
249                  double operand17 = ((Long)result2).doubleValue();
250                  return new FieldLiteral(new Double(operand1111 % operand17),Datatype.DOUBLE);
251               case REAL :
252                  double operand18 = ((Float)result2).doubleValue();
253                  return new FieldLiteral(new Double(operand1111 % operand18),Datatype.DOUBLE);
254                case DOUBLE : case FLOAT : case DOUBLEPRECISION :
255                  double operand19 = ((Double)result2).doubleValue();
256                  return new FieldLiteral(new Double(operand1111 % operand19),Datatype.DOUBLE);
257                case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
258                  double operand54 = ((BigDecimal)result2).doubleValue();
259                  return new FieldLiteral(new Double(operand1111 % operand54),Datatype.DOUBLE);
260                default:
261                  throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type2),"MOD"});
262            }
263          case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
264            double bigD = ((BigDecimal)result1).doubleValue();
265            switch(type2){
266               case BYTE :
267                  double c0 = ((Byte)result2).doubleValue();
268                  return new FieldLiteral(new Double(bigD % c0), Datatype.DOUBLE);
269              case SHORT : case SMALLINT :
270                  double c1 = ((Short)result2).doubleValue();
271                  return new FieldLiteral(new Double( bigD % c1 ),Datatype.DOUBLE);
272                case INTEGER : case INT :
273                  double c2 = ((Integer)result2).doubleValue();
274                  return new FieldLiteral(new Double( bigD % c2 ),Datatype.DOUBLE);
275                case LONG : case BIGINT :
276                  double c3 = ((Long)result2).doubleValue();
277                  return new FieldLiteral(new Double( bigD % c3 ),Datatype.DOUBLE);
278                case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
279                  return new FieldLiteral(new Double(bigD % ((BigDecimal)result2).doubleValue()),Datatype.DOUBLE);
280               case REAL :
281                  double c4 = ((Float)result2).doubleValue();
282                  return new FieldLiteral(new Double( bigD % c4 ),Datatype.DOUBLE);
283                case DOUBLE : case FLOAT : case DOUBLEPRECISION :
284                  double c5 = ((Double)result2).doubleValue();
285                  return new FieldLiteral(new Double( bigD % c5 ),Datatype.DOUBLE);
286                default:
287                  throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type2),"MOD"});
288            }
289          default:
290            throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type1),"MOD"});
291      }
292       }*/

293
294    public AbstractRowValueExpression[] getChilds() {
295       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {_parencommanumericvalueexpression0};
296       return childs;
297    }
298
299    public String JavaDoc getType() throws DException {
300       return (String JavaDoc) _SNONRESERVEDWORD1364442551.run(null);
301    }
302
303    public String JavaDoc toString() {
304       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
305       sb.append(" ");
306       sb.append(_SNONRESERVEDWORD1364442551);
307       sb.append(_parencommanumericvalueexpression0);
308       return sb.toString();
309    }
310
311    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
312       modulusexpression tempClass = new modulusexpression();
313       tempClass._parencommanumericvalueexpression0 = (parencommanumericvalueexpression) _parencommanumericvalueexpression0.clone();
314       tempClass._SNONRESERVEDWORD1364442551 = (SNONRESERVEDWORD136444255) _SNONRESERVEDWORD1364442551.clone();
315       return tempClass;
316    }
317
318    public ByteComparison getByteComparison(Object JavaDoc object) throws DException {
319    ByteComparison byteComparison = new ByteComparison(false, new int[] {DOUBLE});
320    byteComparison.setSize(getColumnSize(object));
321    return byteComparison;
322    }
323
324    public _Reference[] checkSemantic(_ServerSession parent) throws DException {
325       _Reference[] ref = super.checkSemantic(parent);
326       if(ref!=null) {
327         return ref;
328        }
329       int type[] = _parencommanumericvalueexpression0.getByteComparison(parent).getDataTypes();
330       if (type[0] == -1 || type[0] <= 15) {
331          if (type[1] == -1 || type[1] <= 15) {
332             return ref;
333          }
334          throw new DException("DSE4108",
335                               new Object JavaDoc[] {StaticClass.getDataTypeName(type[1]),
336                               "MOD"});
337       }
338       throw new DException("DSE4108",
339                            new Object JavaDoc[] {StaticClass.getDataTypeName(type[0]),
340                            "MOD"});
341
342    }
343  public int getColumnSize(Object JavaDoc object) throws DException {
344    return Datatypes.DOUBLESIZE;
345  }
346 }
347
Popular Tags