KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > BaseExpressionActivation


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.BaseExpressionActivation
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.execute;
23
24 import org.apache.derby.iapi.error.StandardException;
25
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27
28 import org.apache.derby.iapi.types.DataValueDescriptor;
29 import org.apache.derby.catalog.types.UserDefinedTypeIdImpl;
30
31 import org.apache.derby.iapi.services.context.ContextManager;
32 import org.apache.derby.iapi.services.context.Context;
33
34 import org.apache.derby.iapi.jdbc.ConnectionContext;
35
36 import org.apache.derby.iapi.types.DataValueFactory;
37 import org.apache.derby.iapi.types.TypeId;
38
39 import org.apache.derby.iapi.sql.execute.ExecutionContext;
40 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
41
42 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
43 import org.apache.derby.iapi.store.access.TransactionController;
44 import org.apache.derby.iapi.reference.Attribute;
45
46 import org.apache.derby.iapi.sql.ResultSet;
47
48 import java.sql.Connection JavaDoc;
49 import java.sql.SQLException JavaDoc;
50
51 /**
52  * BaseExpressionActivation
53  *
54  * Support needed by Expression evaluators (Filters) and by
55  * ResultSet materializers (Activations)
56  */

57 public abstract class BaseExpressionActivation
58 {
59
60     
61     //
62
// constructors
63
//
64
BaseExpressionActivation()
65     {
66         super();
67     }
68
69
70     /**
71      * Get the minimum value of 4 input values. If less than 4 values, input
72      * NULL. If more than 4 input values, call this multiple times to
73      * accumulate results. Also have judge's type as parameter to have a base
74      * upon which the comparison is based. An example use is for code
75      * generation in bug 3858.
76      *
77      * @param v1 1st value
78      * @param v2 2nd value
79      * @param v3 3rd value
80      * @param v4 4th value
81      * @param judgeTypeFormatId type format id of the judge
82      * @param judgeUserJDBCTypeId JDBC type id if judge is user type;
83      * -1 if not user type
84      *
85      * @return The minimum value of the 4.
86      */

87     public static DataValueDescriptor minValue(DataValueDescriptor v1,
88                                               DataValueDescriptor v2,
89                                               DataValueDescriptor v3,
90                                               DataValueDescriptor v4,
91                                               int judgeTypeFormatId,
92                                               int judgeUserJDBCTypeId)
93                                         throws StandardException
94     {
95         DataValueDescriptor judge;
96         if (judgeUserJDBCTypeId == -1)
97             judge = (DataValueDescriptor) new TypeId(judgeTypeFormatId, null).getNull();
98         else
99             judge = (DataValueDescriptor) new TypeId(judgeTypeFormatId, new UserDefinedTypeIdImpl()).getNull();
100             
101         DataValueDescriptor minVal = v1;
102         if (v2 != null && judge.lessThan(v2, minVal).equals(true))
103             minVal = v2;
104         if (v3 != null && judge.lessThan(v3, minVal).equals(true))
105             minVal = v3;
106         if (v4 != null && judge.lessThan(v4, minVal).equals(true))
107             minVal = v4;
108         return minVal;
109     }
110
111
112     /**
113      * Get the maximum value of 4 input values. If less than 4 values, input
114      * NULL. If more than 4 input values, call this multiple times to
115      * accumulate results. Also have judge's type as parameter to have a base
116      * upon which the comparison is based. An example use is for code
117      * generation in bug 3858.
118      *
119      * @param v1 1st value
120      * @param v2 2nd value
121      * @param v3 3rd value
122      * @param v4 4th value
123      * @param judgeTypeFormatId type format id of the judge
124      * @param judgeUserJDBCTypeId JDBC type id if judge is user type;
125      * -1 if not user type
126      *
127      * @return The maximum value of the 4.
128      */

129     public static DataValueDescriptor maxValue(DataValueDescriptor v1,
130                                               DataValueDescriptor v2,
131                                               DataValueDescriptor v3,
132                                               DataValueDescriptor v4,
133                                               int judgeTypeFormatId,
134                                               int judgeUserJDBCTypeId)
135                                         throws StandardException
136     {
137         DataValueDescriptor judge;
138         if (judgeUserJDBCTypeId == -1)
139             judge = new TypeId(judgeTypeFormatId, null).getNull();
140         else
141             judge = new TypeId(judgeTypeFormatId, new UserDefinedTypeIdImpl()).getNull();
142
143         DataValueDescriptor maxVal = v1;
144         if (v2 != null && judge.greaterThan(v2, maxVal).equals(true))
145             maxVal = v2;
146         if (v3 != null && judge.greaterThan(v3, maxVal).equals(true))
147             maxVal = v3;
148         if (v4 != null && judge.greaterThan(v4, maxVal).equals(true))
149             maxVal = v4;
150         return maxVal;
151     }
152
153 }
154
Popular Tags