KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.expression.
2     numericvalueexpression;
3
4 import java.math.*;
5
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.field.*;
12 import com.daffodilwoods.database.resource.*;
13 import com.daffodilwoods.daffodildb.server.sql99.common.ColumnDetails;
14 import com.daffodilwoods.database.utility.P;
15 import java.sql.Timestamp JavaDoc;
16 import com.daffodilwoods.daffodildb.utils.field.FieldTimeStamp;
17 import java.util.Calendar JavaDoc;
18 import java.util.GregorianCalendar JavaDoc;
19 import java.util.Date JavaDoc;
20 import com.daffodilwoods.daffodildb.utils.DBDate;
21
22 public class numericvalueexpressionSplussign_1537298301term
23     extends AbstractTerm
24     implements numericvalueexpression, Datatypes,
25     _sortspecificationAndselectSubList {
26   public term _term0;
27   public Splussign_1537298301 _Splussign_15372983011;
28   public numericvalueexpression _numericvalueexpression2;
29   GregorianCalendar JavaDoc calendar = new GregorianCalendar JavaDoc();
30 int dtype=-1;
31   public _Reference[] checkSemantic(_ServerSession parent) throws DException {
32
33     _Reference[] refs = super.checkSemantic(parent);
34     if (refs == null || refs.length == 0) { // check put by Kaushik on 14/07/2004 for 'invalid column' problem in DDL
35
ByteComparison bc1 = _numericvalueexpression2.getByteComparison(parent);
36       ByteComparison bc2 = _term0.getByteComparison(parent);
37       int type1 = bc1.getDataTypes()[0];
38       int type2 = bc2.getDataTypes()[0];
39
40       /*following change are made by Sandeep Kadiyan to solve bug 12077 corrospond
41        change made in Check Class*/

42
43       if (! ( (type1 == Datatypes.CHAR || type1 == Datatypes.VARCHAR ||
44                type1 == Datatypes.LONGVARCHAR || type1 == Datatypes.CHARACTER) &&
45              (type2 == Datatypes.CHAR || type2 == Datatypes.VARCHAR ||
46               type2 == Datatypes.LONGVARCHAR || type2 == Datatypes.CHARACTER))) {
47         Check.checkForDatatypeForArthmeticOperations(type1, type2);
48       }
49
50     }
51
52     setAppropriateDatatypeAndCheck(parent);
53     return refs;
54   }
55
56   private void setAppropriateDatatypeAndCheck(Object JavaDoc object) throws DException {
57     int dataType1 = 0;
58     int dataType2 = 0;
59     ColumnDetails[] cd = _term0.getColumnDetails();
60     ColumnDetails[] Rcd = _numericvalueexpression2.getColumnDetails();
61     switch (cd.length) {
62       case 0: // for subquery
63
switch (Rcd.length) {
64           case 0: //for subquery
65
dataType1 = getDataTypeForByte(childs[0].getByteComparison(object));
66             dataType2 = getDataTypeForByte(childs[1].getByteComparison(object));
67             break;
68           default: //Handle subquery
69
dataType1 = dataType2 = getDataTypeForByte(childs[1].
70                 getByteComparison(object));
71             Rcd[0].setDatatype(dataType2);
72         }
73         break;
74       default:
75         switch (Rcd.length) {
76           case 0: //Handle subquery
77
dataType2 = dataType1 = getDataTypeForByte(childs[0].
78                 getByteComparison(object));
79             cd[0].setDatatype(dataType1); //Datatypes.BIGDECIMAL
80
break;
81           default:
82             if (cd[0].getQuestion()) {
83               switch (Rcd[0].getDatatype()) {
84                 case -1:
85                   cd[0].setDatatype(15); //BigDecimal
86
Rcd[0].setDatatype(15); //Bigdecimal
87
dataType1 = 15;
88                   dataType2 = 15;
89                   break;
90                 case BYTE:
91                 case TINYINT:
92                 case SHORT:
93                 case SMALLINT:
94                 case INTEGER:
95                 case INT:
96                 case LONG:
97                 case BIGINT:
98                 case BIGDECIMAL:
99                 case DEC:
100                 case DECIMAL:
101                 case NUMERIC:
102                 case REAL:
103                 case DOUBLE:
104                 case FLOAT:
105                 case DOUBLEPRECISION:
106                   cd[0].setDatatype(15);
107                   dataType1 = dataType2 = 15;
108                   break;
109                 case CHARACTER:
110                 case VARCHAR:
111                 case CHAR:
112                 case CHARACTERVARYING:
113                   cd[0].setDatatype(16);
114                   dataType1 = dataType2 = 16;
115                   break;
116                 case DATE:
117                 case TIMESTAMP:
118                 case TIME:
119                   cd[0].setDatatype(5);
120                   dataType1 = dataType2 = 5;
121               }
122
123             }
124             else {
125               if (Rcd[0].getQuestion()) {
126                 switch (cd[0].getDatatype()) {
127                   case -1:
128                     cd[0].setDatatype(15); //BigDecimal
129
Rcd[0].setDatatype(15); //Bigdecimal
130
dataType1 = 15;
131                     dataType2 = 15;
132                     break;
133                   case BYTE:
134                   case TINYINT:
135                   case SHORT:
136                   case SMALLINT:
137                   case INTEGER:
138                   case INT:
139                   case LONG:
140                   case BIGINT:
141                   case BIGDECIMAL:
142                   case DEC:
143                   case DECIMAL:
144                   case NUMERIC:
145                   case REAL:
146                   case DOUBLE:
147                   case FLOAT:
148                   case DOUBLEPRECISION:
149                     Rcd[0].setDatatype(15);
150                     dataType2 = dataType1 = 15;
151                     break;
152                   case CHARACTER:
153                   case VARCHAR:
154                   case CHAR:
155                   case CHARACTERVARYING:
156                     Rcd[0].setDatatype(16);
157                     dataType2 = dataType1 = 16;
158                     break;
159                   case DATE:
160                   case TIMESTAMP:
161                   case TIME:
162                     Rcd[0].setDatatype(5);
163                     dataType1 = 5;
164                     dataType2 = Rcd[0].getDatatype();
165                 }
166               }
167               else {
168                 dataType1 = getDataTypeForByte(childs[0].getByteComparison(
169                     object));
170                 dataType2 = getDataTypeForByte(childs[1].getByteComparison(
171                     object));
172
173               }
174             }
175         }
176     }
177     if (GeneralPurposeStaticClass.isCharacterType(dataType1) &&
178         GeneralPurposeStaticClass.isCharacterType(dataType2))
179       dtype = 17;
180
181    else
182 dtype = GeneralPurposeStaticClass.getDataTypeForArithmetic(dataType1,
183           dataType2);
184   }
185
186   public int getDataType(Object JavaDoc object) throws DException {
187     try {
188       return super.getDataType(object, "PLUS");
189     }
190     catch (DException ex) {
191       throw ex;
192     }
193   }
194
195   public AbstractRowValueExpression[] getChilds() {
196     AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {
197         (AbstractRowValueExpression) (_numericvalueexpression2),
198         (AbstractRowValueExpression) (_term0)};
199     return childs;
200   }
201
202   public String JavaDoc toString() {
203     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
204     sb.append(" ");
205     sb.append(_numericvalueexpression2);
206     sb.append(" ");
207     sb.append(_Splussign_15372983011);
208     sb.append(" ");
209     sb.append(_term0);
210     return sb.toString();
211   }
212
213   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
214     numericvalueexpressionSplussign_1537298301term tempClass = new
215         numericvalueexpressionSplussign_1537298301term();
216     tempClass._term0 = (term) _term0.clone();
217     tempClass._Splussign_15372983011 = (Splussign_1537298301)
218         _Splussign_15372983011.clone();
219     tempClass._numericvalueexpression2 = (numericvalueexpression)
220         _numericvalueexpression2.clone();
221     return tempClass;
222   }
223
224   public FieldBase getObject(int type1, int type2, Object JavaDoc result1,
225                              Object JavaDoc result2) throws DException {
226     switch (type1) {
227       case BYTE:
228       case TINYINT:
229         byte operand0 = ( (Byte JavaDoc) result1).byteValue();
230         switch (type2) {
231           case BYTE:
232           case TINYINT:
233             byte s11 = ( (Byte JavaDoc) result2).byteValue();
234             return new FieldLiteral(new Short JavaDoc( (short) (operand0 + s11)), SHORT);
235           case SHORT:
236           case SMALLINT:
237             short s1 = ( (Short JavaDoc) result2).shortValue();
238             return new FieldLiteral(new Integer JavaDoc( (int) (operand0 + s1)),
239                                     INTEGER);
240           case INTEGER:
241           case INT:
242             int s2 = ( (Integer JavaDoc) result2).intValue();
243             return new FieldLiteral(new Long JavaDoc( (operand0 + s2)), LONG);
244           case LONG:
245           case BIGINT:
246             long s3 = ( (Long JavaDoc) result2).longValue();
247             return new FieldLiteral(new BigDecimal("" + (operand0 + s3)),
248                                     BIGDECIMAL);
249           case BIGDECIMAL:
250           case DEC:
251           case DECIMAL:
252           case NUMERIC:
253             BigDecimal bbb = new BigDecimal(operand0 + "");
254             return new FieldLiteral(bbb.add( (BigDecimal) result2), BIGDECIMAL);
255           case REAL:
256             float s4 = ( (Float JavaDoc) result2).floatValue();
257             return new FieldLiteral(new Float JavaDoc(operand0 + s4), FLOAT);
258           case DOUBLE:
259           case FLOAT:
260           case DOUBLEPRECISION:
261             double s5 = ( (Double JavaDoc) result2).doubleValue();
262             return new FieldLiteral(new Double JavaDoc(operand0 + s5), DOUBLE);
263           case CHARACTER:
264           case VARCHAR:
265           case CHAR:
266           case CHARACTERVARYING:
267             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER", "BYTE"});
268             /* Done by vibha */
269           case DATE:
270             long dateInMls = ( (Date JavaDoc) result2).getTime();
271             return calculateDateSum(dateInMls, result1);
272           case TIMESTAMP:
273             long timeStampInMls = ( (Timestamp JavaDoc) result2).getTime();
274             return calculateTimeStampSum(timeStampInMls, result1);
275           case TIME:
276             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
277                                  "BYTE"});
278         }
279         break;
280       case SHORT:
281       case SMALLINT:
282         short operand = ( (Short JavaDoc) result1).shortValue();
283         switch (type2) {
284           case BYTE:
285           case TINYINT:
286             byte s11 = ( (Byte JavaDoc) result2).byteValue();
287             return new FieldLiteral(new Integer JavaDoc( (int) (operand + s11)),
288                                     INTEGER);
289           case SHORT:
290           case SMALLINT:
291             short s1 = ( (Short JavaDoc) result2).shortValue();
292             return new FieldLiteral(new Integer JavaDoc( (int) (operand + s1)), INTEGER);
293           case INTEGER:
294           case INT:
295             int s2 = ( (Integer JavaDoc) result2).intValue();
296             return new FieldLiteral(new Long JavaDoc( (long) (operand + s2)), LONG);
297           case LONG:
298           case BIGINT:
299             long s3 = ( (Long JavaDoc) result2).longValue();
300             return new FieldLiteral(new BigDecimal( (double) (operand + s3)),
301                                     BIGDECIMAL);
302           case BIGDECIMAL:
303           case DEC:
304           case DECIMAL:
305           case NUMERIC:
306             double b1 = ( (Short JavaDoc) result1).doubleValue();
307             return new FieldLiteral( ( (BigDecimal) result2).add(new BigDecimal(
308                 b1)), BIGDECIMAL);
309           case REAL:
310             float s4 = ( (Float JavaDoc) result2).floatValue();
311             return new FieldLiteral(new Double JavaDoc( (double) (operand + s4)),
312                                     DOUBLE);
313           case DOUBLE:
314           case FLOAT:
315           case DOUBLEPRECISION:
316             double s5 = ( (Double JavaDoc) result2).doubleValue();
317             return new FieldLiteral(new BigDecimal(operand + s5), BIGDECIMAL);
318           case CHARACTER:
319           case VARCHAR:
320           case CHAR:
321           case CHARACTERVARYING:
322             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER", "SHORT"});
323
324             /* Done by vibha */
325           case DATE:
326             long dateInMls = ( (Date JavaDoc) result2).getTime();
327             return calculateDateSum(dateInMls, result1);
328           case TIMESTAMP:
329             long timeStampInMls = ( (Timestamp JavaDoc) result2).getTime();
330             return calculateTimeStampSum(timeStampInMls, result1);
331           case TIME:
332             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
333                                  "BYTE"});
334         }
335         break;
336       case INTEGER:
337       case INT:
338         int operand1 = ( (Integer JavaDoc) result1).intValue();
339         switch (type2) {
340           case BYTE:
341           case TINYINT:
342             byte s11 = ( (Byte JavaDoc) result2).byteValue();
343             return new FieldLiteral(new Long JavaDoc( (operand1 + s11)), LONG);
344           case SHORT:
345           case SMALLINT:
346             short s6 = ( (Short JavaDoc) result2).shortValue();
347             return new FieldLiteral(new Long JavaDoc( (long) operand1 + s6), LONG);
348           case INTEGER:
349           case INT:
350             int operand2 = ( (Integer JavaDoc) result2).intValue();
351             return new FieldLiteral(new Long JavaDoc( (long) operand1 + operand2), LONG);
352           case LONG:
353           case BIGINT:
354             long operand3 = ( (Long JavaDoc) result2).longValue();
355             return new FieldLiteral(new Double JavaDoc( (double) operand1 + operand3),
356                                     DOUBLE);
357           case BIGDECIMAL:
358           case DEC:
359           case DECIMAL:
360           case NUMERIC:
361             double b2 = ( (Integer JavaDoc) result1).doubleValue();
362             return new FieldLiteral( ( (BigDecimal) result2).add(new BigDecimal(
363                 b2)), BIGDECIMAL);
364           case REAL:
365             float operand4 = ( (Float JavaDoc) result2).floatValue();
366             return new FieldLiteral(new Double JavaDoc(operand1 + operand4), DOUBLE);
367           case DOUBLE:
368           case FLOAT:
369           case DOUBLEPRECISION:
370             double operand5 = ( (Double JavaDoc) result2).doubleValue();
371             return new FieldLiteral(new BigDecimal(operand1 + operand5),
372                                     BIGDECIMAL);
373           case CHARACTER:
374           case VARCHAR:
375           case CHAR:
376           case CHARACTERVARYING:
377             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER", "INT"});
378             /* Done by vibha */
379           case DATE:
380             long dateInMls = ( (Date JavaDoc) result2).getTime();
381             return calculateDateSum(dateInMls, result1);
382           case TIMESTAMP:
383             long timeStampInMls = ( (Timestamp JavaDoc) result2).getTime();
384             return calculateTimeStampSum(timeStampInMls, result1);
385           case TIME:
386             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
387                                  "BYTE"});
388
389         }
390         break;
391       case LONG:
392       case BIGINT:
393         long operand11 = ( (Long JavaDoc) result1).longValue();
394         switch (type2) {
395           case BYTE:
396           case TINYINT:
397             byte s11 = ( (Byte JavaDoc) result2).byteValue();
398             return new FieldLiteral(new BigDecimal("" + (operand11 + s11)),
399                                     BIGDECIMAL);
400           case SHORT:
401           case SMALLINT:
402             short s7 = ( (Short JavaDoc) result2).shortValue();
403             return new FieldLiteral(new Double JavaDoc( (double) operand11 + s7),
404                                     DOUBLE);
405           case INTEGER:
406           case INT:
407             int operand6 = ( (Integer JavaDoc) result2).intValue();
408             return new FieldLiteral(new Double JavaDoc( (double) operand11 + operand6),
409                                     DOUBLE);
410           case LONG:
411           case BIGINT:
412             long operand7 = ( (Long JavaDoc) result2).longValue();
413             return new FieldLiteral(new Double JavaDoc( (double) operand11 + operand7),
414                                     DOUBLE);
415           case BIGDECIMAL:
416           case DEC:
417           case DECIMAL:
418           case NUMERIC:
419             double b3 = ( (Long JavaDoc) result1).doubleValue();
420             return new FieldLiteral( ( (BigDecimal) result2).add(new BigDecimal(
421                 b3)), BIGDECIMAL);
422           case REAL:
423             float operand8 = ( (Float JavaDoc) result2).floatValue();
424             return new FieldLiteral(new Double JavaDoc( (double) operand11 + operand8),
425                                     DOUBLE);
426           case DOUBLE:
427           case FLOAT:
428           case DOUBLEPRECISION:
429             double operand9 = ( (Double JavaDoc) result2).doubleValue();
430             return new FieldLiteral(new BigDecimal(operand11 + operand9),
431                                     BIGDECIMAL);
432           case CHARACTER:
433           case VARCHAR:
434           case CHAR:
435           case CHARACTERVARYING:
436             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER", "LONG"});
437             /* Done by vibha */
438           case DATE:
439             long dateInMls = ( (Date JavaDoc) result2).getTime();
440             return calculateDateSum(dateInMls, result1);
441           case TIMESTAMP:
442             long timeStampInMls = ( (Timestamp JavaDoc) result2).getTime();
443             return calculateTimeStampSum(timeStampInMls, result1);
444           case TIME:
445             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
446                                  "BYTE"});
447
448         }
449         break;
450       case BIGDECIMAL:
451       case DEC:
452       case DECIMAL:
453       case NUMERIC:
454         switch (type2) {
455           case SHORT:
456           case SMALLINT:
457             double d1 = ( (Number JavaDoc) result2).doubleValue();
458             return new FieldLiteral( ( (BigDecimal) result1).add(new BigDecimal(
459                 d1)), BIGDECIMAL);
460           case BYTE:
461           case TINYINT:
462             double s11 = ( (Byte JavaDoc) result2).doubleValue();
463             return new FieldLiteral( ( (BigDecimal) result1).add(new BigDecimal(
464                 s11)), BIGDECIMAL);
465           case INTEGER:
466           case INT:
467             double s12 = ( (Integer JavaDoc) result2).doubleValue();
468             return new FieldLiteral( ( (BigDecimal) result1).add(new BigDecimal(
469                 s12)), BIGDECIMAL);
470           case DOUBLE:
471           case FLOAT:
472           case DOUBLEPRECISION:
473             double s13 = ( (Double JavaDoc) result2).doubleValue();
474             return new FieldLiteral( ( (BigDecimal) result1).add(new BigDecimal(
475                 s13)), BIGDECIMAL);
476           case REAL:
477             double s14 = ( (Float JavaDoc) result2).doubleValue();
478             return new FieldLiteral( ( (BigDecimal) result1).add(new BigDecimal(
479                 s14)), BIGDECIMAL);
480           case LONG:
481           case BIGINT:
482             double s15 = ( (Long JavaDoc) result2).doubleValue();
483             return new FieldLiteral( ( (BigDecimal) result1).add(new BigDecimal(
484                 s15)), BIGDECIMAL);
485           case BIGDECIMAL:
486           case DEC:
487           case DECIMAL:
488           case NUMERIC:
489             return new FieldLiteral( ( (BigDecimal) result1).add( (BigDecimal)
490                 result2), BIGDECIMAL);
491           case CHARACTER:
492           case VARCHAR:
493           case CHAR:
494           case CHARACTERVARYING:
495             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER",
496                                  "BIGDECIMAL"});
497             /* Done by vibha */
498           case DATE:
499             long dateInMls = ( (Date JavaDoc) result2).getTime();
500             return calculateDateSum(dateInMls, result1);
501           case TIMESTAMP:
502             long timeStampInMls = ( (Timestamp JavaDoc) result2).getTime();
503             return calculateTimeStampSum(timeStampInMls, result1);
504           case TIME:
505             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
506                                  "BYTE"});
507
508         }
509         break;
510       case REAL:
511         float operand111 = ( (Float JavaDoc) result1).floatValue();
512         switch (type2) {
513           case SHORT:
514           case SMALLINT:
515             short s8 = ( (Short JavaDoc) result2).shortValue();
516             return new FieldLiteral(new Double JavaDoc( (double) operand111 + s8),
517                                     DOUBLE);
518           case BYTE:
519           case TINYINT:
520             byte s11 = ( (Byte JavaDoc) result2).byteValue();
521             return new FieldLiteral(new Double JavaDoc( (double) operand111 + s11),
522                                     DOUBLE);
523           case INTEGER:
524           case INT:
525             int operand12 = ( (Integer JavaDoc) result2).intValue();
526             return new FieldLiteral(new Double JavaDoc(operand111 + operand12), DOUBLE);
527           case LONG:
528           case BIGINT:
529             long operand13 = ( (Long JavaDoc) result2).longValue();
530             return new FieldLiteral(new Double JavaDoc(operand111 + operand13), DOUBLE);
531           case BIGDECIMAL:
532           case DEC:
533           case DECIMAL:
534           case NUMERIC:
535             double b4 = ( (Float JavaDoc) result1).doubleValue();
536             return new FieldLiteral( ( (BigDecimal) result2).add(new BigDecimal(
537                 b4)), BIGDECIMAL);
538           case REAL:
539             float operand14 = ( (Float JavaDoc) result2).floatValue();
540             return new FieldLiteral(new Double JavaDoc(operand111 + operand14), DOUBLE);
541           case DOUBLE:
542           case FLOAT:
543           case DOUBLEPRECISION:
544             double operand15 = ( (Double JavaDoc) result2).doubleValue();
545             return new FieldLiteral(new BigDecimal(operand111 + operand15),
546                                     BIGDECIMAL);
547           case CHARACTER:
548           case VARCHAR:
549           case CHAR:
550           case CHARACTERVARYING:
551             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER", "FLOAT"});
552             /* Done by vibha */
553           case DATE:
554             long dateInMls = ( (Date JavaDoc) result2).getTime();
555             return calculateDateSum(dateInMls, result1);
556           case TIMESTAMP:
557             long timeStampInMls = ( (Timestamp JavaDoc) result2).getTime();
558             return calculateTimeStampSum(timeStampInMls, result1);
559           case TIME:
560             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
561                                  "BYTE"});
562
563         }
564         break;
565       case DOUBLE:
566       case FLOAT:
567       case DOUBLEPRECISION:
568         double operand1111 = ( (Double JavaDoc) result1).doubleValue();
569         switch (type2) {
570           case SHORT:
571           case SMALLINT:
572             short s9 = ( (Short JavaDoc) result2).shortValue();
573             return new FieldLiteral(new BigDecimal(operand1111 + s9),
574                                     BIGDECIMAL);
575           case BYTE:
576           case TINYINT:
577             byte s11 = ( (Byte JavaDoc) result2).byteValue();
578             return new FieldLiteral(new BigDecimal(operand1111 + s11),
579                                     BIGDECIMAL);
580           case INTEGER:
581           case INT:
582             int operand16 = ( (Integer JavaDoc) result2).intValue();
583             return new FieldLiteral(new BigDecimal(operand1111 + operand16),
584                                     BIGDECIMAL);
585           case LONG:
586           case BIGINT:
587             long operand17 = ( (Long JavaDoc) result2).longValue();
588             return new FieldLiteral(new BigDecimal(operand1111 + operand17),
589                                     BIGDECIMAL);
590           case BIGDECIMAL:
591           case DEC:
592           case DECIMAL:
593           case NUMERIC:
594             double b5 = ( (Double JavaDoc) result1).doubleValue();
595             return new FieldLiteral( ( (BigDecimal) result2).add(new BigDecimal(
596                 b5)), BIGDECIMAL);
597           case REAL:
598             float operand18 = ( (Float JavaDoc) result2).floatValue();
599             return new FieldLiteral(new BigDecimal(operand1111 + operand18),
600                                     BIGDECIMAL);
601           case DOUBLE:
602           case FLOAT:
603           case DOUBLEPRECISION:
604             double operand19 = ( (Double JavaDoc) result2).doubleValue();
605             return new FieldLiteral(new BigDecimal(operand1111 + operand19),
606                                     BIGDECIMAL);
607           case CHARACTER:
608           case VARCHAR:
609           case CHAR:
610           case CHARACTERVARYING:
611             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER", "DOUBLE"});
612
613             /* Done by vibha */
614           case DATE:
615             long dateInMls = ( (Date JavaDoc) result2).getTime();
616             return calculateDateSum(dateInMls, result1);
617           case TIMESTAMP:
618             long timeStampInMls = ( (Timestamp JavaDoc) result2).getTime();
619             return calculateTimeStampSum(timeStampInMls, result1);
620           case TIME:
621             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
622                                  "BYTE"});
623
624         }
625         break;
626       case CHARACTER:
627       case VARCHAR:
628       case CHAR:
629       case CHARACTERVARYING:
630         switch (type2) {
631           case SHORT:
632           case SMALLINT:
633             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER", "SHORT"});
634           case INTEGER:
635           case INT:
636             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER", "INT"});
637           case LONG:
638           case BIGINT:
639             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER", "LONG"});
640           case BIGDECIMAL:
641           case DEC:
642           case DECIMAL:
643           case NUMERIC:
644             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER",
645                                  "BIGDECIMAL"});
646           case REAL:
647             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER", "FLOAT"});
648           case DOUBLE:
649           case FLOAT:
650           case DOUBLEPRECISION:
651             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER", "DOUBLE"});
652           case DATE:
653           case TIME:
654           case TIMESTAMP:
655             throw new DException("DSE87", new Object JavaDoc[] {"CHARACTER",
656                                  "DATE/TIME/TIMESTAMP"});
657           case CHARACTER:
658           case VARCHAR:
659           case CHAR:
660           case CHARACTERVARYING:
661             return new FieldStringLiteral( (result1.toString() +
662                                             result2.toString()), CHARACTER);
663         }
664         break;
665       case TIMESTAMP:
666         switch (type2) {
667           case SHORT:
668           case SMALLINT:
669           case INTEGER:
670           case INT:
671           case BYTE:
672           case LONG:
673           case BIGINT:
674           case BIGDECIMAL:
675           case DEC:
676           case DECIMAL:
677           case NUMERIC:
678           case REAL:
679           case DOUBLE:
680           case FLOAT:
681           case DOUBLEPRECISION:
682             long timeStampInMls = ( (Timestamp JavaDoc) result1).getTime();
683
684             return calculateTimeStampSum(timeStampInMls, result2);
685           case DATE:
686           case TIME:
687           case TIMESTAMP:
688             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
689                                  "DATE/TIME/TIMESTAMP"});
690         }
691
692       case DATE:
693         switch (type2) {
694           case SHORT:
695           case SMALLINT:
696           case INTEGER:
697           case INT:
698           case BYTE:
699           case LONG:
700           case BIGINT:
701           case BIGDECIMAL:
702           case DEC:
703           case DECIMAL:
704           case NUMERIC:
705           case REAL:
706           case DOUBLE:
707           case FLOAT:
708           case DOUBLEPRECISION:
709
710             long dateInMls = ( (Date JavaDoc) result1).getTime();
711             return calculateDateSum(dateInMls, result2);
712
713         }
714       case TIME:
715         switch (type2) {
716           case SHORT:
717           case SMALLINT:
718             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
719                                  "SHORT"});
720           case INTEGER:
721           case INT:
722             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
723                                  "INT"});
724           case LONG:
725           case BIGINT:
726             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
727                                  "LONG"});
728           case BIGDECIMAL:
729           case DEC:
730           case DECIMAL:
731           case NUMERIC:
732             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
733                                  "BIGDECIMAL"});
734           case REAL:
735             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
736                                  "FLOAT"});
737           case DOUBLE:
738           case FLOAT:
739           case DOUBLEPRECISION:
740             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
741                                  "DOUBLE"});
742           case DATE:
743           case TIME:
744           case TIMESTAMP:
745             throw new DException("DSE87", new Object JavaDoc[] {"DATE/TIME/TIMESTAMP",
746                                  "DATE/TIME/TIMESTAMP"});
747         }
748
749
750     }
751     throw new DException("DSE35",
752                          new Object JavaDoc[] {StaticClass.getDataTypeName(type1),
753                          StaticClass.getDataTypeName(type2)});
754
755   }
756
757     ColumnDetails columnDetail ;
758   public ColumnDetails[] getColumnDetails() throws DException {
759     ColumnDetails cd[] = super.getColumnDetails();
760     if (cd.length == 1)
761       return cd;
762
763     columnDetail = new ColumnDetails();
764     String JavaDoc str = toString();
765     columnDetail.setColumn(new String JavaDoc[] {str});
766     columnDetail.setType(FUNCTIONAL);
767     columnDetail.setObject(this);
768     columnDetail.setExpression(str);
769
770     return new ColumnDetails[] {
771         columnDetail};
772   }
773
774   public ColumnDetails[] getChildColumnDetails() throws DException {
775     return columnDetails;
776   }
777
778   /* Method overridden by Kaushik to solve Bug no. 11993 */
779
780   public ParameterInfo[] getParameterInfo() throws DException {
781     ParameterInfo[] parameterInfo = super.getParameterInfo();
782     for (int i = 0; i < parameterInfo.length; i++) {
783       if (parameterInfo[i].getQuestionMark()) {
784         for (int j = 0; j < columnDetails.length; j++)
785           if (columnDetails[j].getQuestion())
786             parameterInfo[i].setDataType(columnDetails[j].getDatatype()); //BIGDECIMAL
787
}
788     }
789     return parameterInfo;
790   }
791
792   /* Done by vibha to support Timestamp + no of days */
793   private FieldTimeStampLiteral calculateTimeStampSum(long result1,
794       Object JavaDoc result2) {
795     calendar.setTimeInMillis(result1);
796     calendar.add(Calendar.DATE, ( (Number JavaDoc) result2).intValue());
797     return new FieldTimeStampLiteral(new Timestamp JavaDoc(calendar.getTimeInMillis()));
798   }
799
800   /* Done by vibha to support Date + no of days */
801   private FieldDateLiteral calculateDateSum(long result1, Object JavaDoc result2) {
802     calendar.setTimeInMillis(result1);
803     calendar.add(Calendar.DATE, ( (Number JavaDoc) result2).intValue());
804     return new FieldDateLiteral(new DBDate(calendar.getTimeInMillis()));
805   }
806
807   public int getAppropriateDataType(Object JavaDoc object) throws DException{
808     try {
809       if (dtype == -1) {
810         setAppropriateDatatypeAndCheck(object);
811       }
812     }
813     catch (DException ex) {
814       return 0;
815     }
816     return dtype;
817
818   }
819
820 }
821
Popular Tags