KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression;
2
3 import java.util.*;
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 randfunction 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.DOUBLE);
23       }
24       try {
25          if (type <= 15) {
26             Random random = new Random();
27             random.setSeed( ( (Number JavaDoc) object).longValue());
28             return new FieldLiteral(new Double JavaDoc(random.nextFloat()), Datatype.DOUBLE);
29          }
30          throw new DException("DSE4108",
31                               new Object JavaDoc[] {StaticClass.getDataTypeName(type),
32                               "RAND"});
33
34          /* switch(type){
35              case BYTE : case TINYINT :
36              case INTEGER : case INT :
37              case REAL :
38              case DOUBLE : case FLOAT : case DOUBLEPRECISION :
39              case LONG : case BIGINT :
40              case SHORT : case SMALLINT :
41              case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
42                Number number=(Number)object;
43                Random random = new Random();
44                random.setSeed(number.longValue());
45              return new FieldLiteral(new Double( random.nextFloat() ),Datatype.DOUBLE);
46               default :
47                  throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type),"RAND"});
48            }*/

49       } catch (Exception JavaDoc e) {
50          throw new DException("DSE419", new Object JavaDoc[] {"RAND"});
51       }
52    }
53
54    /* protected Object getResult(int type,Object object) throws DException {
55        if(object == null)
56          return new FieldLiteral(FieldUtility.NULLBUFFERRANGE,Datatype.DOUBLE);
57         try{
58            Random random = new Random();
59            switch(type){
60              case BYTE : case TINYINT :
61                  Byte byt = (Byte)object;
62                  random.setSeed(byt.longValue());
63                  return new FieldLiteral(new Double( random.nextFloat() ),Datatype.DOUBLE);
64                case INTEGER : case INT :
65                  Integer integer = (Integer)object;
66                  random.setSeed( integer.longValue() );
67                  return new FieldLiteral(new Double( random.nextFloat() ),Datatype.DOUBLE);
68               case REAL :
69                  Float floatV = (Float)object;
70                  random.setSeed( floatV.longValue() );
71                  return new FieldLiteral(new Double( random.nextFloat() ),Datatype.DOUBLE);
72                case DOUBLE : case FLOAT : case DOUBLEPRECISION :
73                  Double doubleV = (Double)object;
74                  random.setSeed( doubleV.longValue() );
75                  return new FieldLiteral(new Double( random.nextFloat() ),Datatype.DOUBLE);
76                case LONG : case BIGINT :
77                  Long longV = (Long)object;
78                  random.setSeed( longV.longValue() );
79                  return new FieldLiteral(new Double( random.nextFloat() ),Datatype.DOUBLE);
80                case SHORT : case SMALLINT :
81                  Short shortV = (Short)object;
82                  random.setSeed( shortV.longValue() );
83                  return new FieldLiteral(new Double( random.nextFloat() ),Datatype.DOUBLE);
84                case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
85                  BigDecimal bigDecimal = (BigDecimal)object;
86                  random.setSeed( bigDecimal.longValue() );
87                  return new FieldLiteral(new Double( random.nextFloat() ),Datatype.DOUBLE);
88               default :
89                  throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type),"RAND"});
90            }
91         } catch( Exception e ){
92            throw new DException("DSE419",new Object[]{"RAND"});
93         }
94      } */

95
96    public AbstractRowValueExpression[] getChilds() {
97       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {_parennumericvalueexpression0};
98       return childs;
99    }
100
101    public String JavaDoc getType() throws DException {
102       return (String JavaDoc) _SNONRESERVEDWORD1364442551.run(null);
103    }
104
105    public String JavaDoc toString() {
106       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
107       sb.append(" ");
108       sb.append(_SNONRESERVEDWORD1364442551);
109       sb.append(_parennumericvalueexpression0);
110       return sb.toString();
111    }
112
113    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
114       randfunction tempClass = new randfunction();
115       tempClass._parennumericvalueexpression0 = (parennumericvalueexpression) _parennumericvalueexpression0.clone();
116       tempClass._SNONRESERVEDWORD1364442551 = (SNONRESERVEDWORD136444255) _SNONRESERVEDWORD1364442551.clone();
117       return tempClass;
118    }
119
120    public ParameterInfo[] getParameterInfo() throws DException {
121      ParameterInfo[] paramInfo = super.getParameterInfo();
122      for (int i = 0; i < paramInfo.length; i++) {
123        if (paramInfo[i].getQuestionMark()) {
124          paramInfo[i].setDataType(Datatypes.DOUBLE);
125          paramInfo[i].setName("RAND Arg");
126        }
127      }
128      return paramInfo;
129    }
130
131
132    public ByteComparison getByteComparison(Object JavaDoc object) throws DException {
133     ByteComparison byteComparison = new ByteComparison(false, new int[] {DOUBLE});
134     byteComparison.setSize(getColumnSize(object));
135     return byteComparison;
136    }
137
138    public _Reference[] checkSemantic(_ServerSession parent) throws DException {
139       _Reference[] ref = super.checkSemantic(parent);
140       if(ref!=null) {
141         return ref;
142        }
143       int type = _parennumericvalueexpression0.getByteComparison(parent).getDataTypes()[0];
144       if (type == -1 || type <= 15) {
145          return ref;
146       }
147       throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "RAND"});
148    }
149   public int getColumnSize(Object JavaDoc object) throws DException {
150          return Datatypes.DOUBLESIZE;
151    }
152
153 }
154
Popular Tags