001: /*
002:
003: Derby - Class org.apache.derby.iapi.types.NumberDataValue
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.types;
023:
024: import org.apache.derby.iapi.error.StandardException;
025:
026: public interface NumberDataValue extends DataValueDescriptor {
027: /**
028: * The minimum scale when dividing Decimals
029: */
030: public static final int MIN_DECIMAL_DIVIDE_SCALE = 4;
031: public static final int MAX_DECIMAL_PRECISION_SCALE = 31;
032:
033: /**
034: * The SQL + operator.
035: *
036: * @param addend1 One of the addends
037: * @param addend2 The other addend
038: * @param result The result of the previous call to this method, null
039: * if not called yet.
040: *
041: * @return The sum of the two addends
042: *
043: * @exception StandardException Thrown on error, if result is non-null then its value will be unchanged.
044: */
045: public NumberDataValue plus(NumberDataValue addend1,
046: NumberDataValue addend2, NumberDataValue result)
047: throws StandardException;
048:
049: /**
050: * The SQL - operator.
051: *
052: * @param left The left operand
053: * @param right The right operand
054: * @param result The result of the previous call to this method, null
055: * if not called yet.
056: *
057: * @return left - right
058: *
059: * @exception StandardException Thrown on error, if result is non-null then its value will be unchanged.
060: */
061: public NumberDataValue minus(NumberDataValue left,
062: NumberDataValue right, NumberDataValue result)
063: throws StandardException;
064:
065: /**
066: * The SQL * operator.
067: *
068: * @param left The left operand
069: * @param right The right operand
070: * @param result The result of the previous call to this method, null
071: * if not called yet.
072: *
073: * @return left * right
074: *
075: * @exception StandardException Thrown on error, if result is non-null then its value will be unchanged.
076: */
077: public NumberDataValue times(NumberDataValue left,
078: NumberDataValue right, NumberDataValue result)
079: throws StandardException;
080:
081: /**
082: * The SQL / operator.
083: *
084: * @param dividend The numerator
085: * @param divisor The denominator
086: * @param result The result of the previous call to this method, null
087: * if not called yet.
088: *
089: * @return dividend / divisor
090: *
091: * @exception StandardException Thrown on error, if result is non-null then its value will be unchanged.
092: */
093: public NumberDataValue divide(NumberDataValue dividend,
094: NumberDataValue divisor, NumberDataValue result)
095: throws StandardException;
096:
097: /**
098: * The SQL / operator.
099: *
100: * @param dividend The numerator
101: * @param divisor The denominator
102: * @param result The result of the previous call to this method, null
103: * if not called yet.
104: * @param scale The scale of the result, for decimal type. If pass
105: * in value < 0, can calculate it dynamically.
106: *
107: * @return dividend / divisor
108: *
109: * @exception StandardException Thrown on error, if result is non-null then its value will be unchanged.
110: */
111: public NumberDataValue divide(NumberDataValue dividend,
112: NumberDataValue divisor, NumberDataValue result, int scale)
113: throws StandardException;
114:
115: /**
116: * The SQL mod operator.
117: *
118: * @param dividend The numerator
119: * @param divisor The denominator
120: * @param result The result of the previous call to this method, null
121: * if not called yet.
122: *
123: * @return dividend / divisor
124: *
125: * @exception StandardException Thrown on error, if result is non-null then its value will be unchanged.
126: */
127: public NumberDataValue mod(NumberDataValue dividend,
128: NumberDataValue divisor, NumberDataValue result)
129: throws StandardException;
130:
131: /**
132: * The SQL unary - operator. Negates this NumberDataValue.
133: *
134: * @param result The result of the previous call to this method, null
135: * if not called yet.
136: *
137: * @return - operand
138: *
139: * @exception StandardException Thrown on error, if result is non-null then its value will be unchanged.
140: */
141: public NumberDataValue minus(NumberDataValue result)
142: throws StandardException;
143:
144: /**
145: * The SQL ABSOLUTE operator. Absolute value of this NumberDataValue.
146: *
147: * @param result The result of the previous call to this method, null
148: * if not called yet.
149: *
150: * @exception StandardException Thrown on error, if result is non-null then its value will be unchanged.
151: */
152: public NumberDataValue absolute(NumberDataValue result)
153: throws StandardException;
154:
155: /**
156: * The SQL SQRT operator. Sqrt value of this NumberDataValue.
157: *
158: * @param result The result of the previous call to this method, null
159: * if not call yet.
160: *
161: * @exception StandardException Thrown on error (a negative number), if result is non-null then its value will be unchanged.
162: */
163: public NumberDataValue sqrt(NumberDataValue result)
164: throws StandardException;
165:
166: /**
167: * Set the value of this NumberDataValue to the given value.
168: This is only intended to be called when mapping values from
169: the Java space into the SQL space, e.g. parameters and return
170: types from procedures and functions. Each specific type is only
171: expected to handle the explicit type according the JDBC.
172: <UL>
173: <LI> SMALLINT from java.lang.Integer
174: <LI> INTEGER from java.lang.Integer
175: <LI> LONG from java.lang.Long
176: <LI> FLOAT from java.lang.Float
177: <LI> DOUBLE from java.lang.Double
178: <LI> DECIMAL from java.math.BigDecimal
179: </UL>
180: *
181: * @param theValue An Number containing the value to set this
182: * NumberDataValue to. Null means set the value
183: * to SQL null.
184: *
185: */
186: public void setValue(Number theValue) throws StandardException;
187:
188: /**
189: Return the SQL precision of this specific DECIMAL value.
190: This does not match the return from BigDecimal.precision()
191: added in J2SE 5.0, which represents the precision of the unscaled value.
192: If the value does not represent a SQL DECIMAL then
193: the return is undefined.
194: */
195: public int getDecimalValuePrecision();
196:
197: /**
198: Return the SQL scale of this specific DECIMAL value.
199: This does not match the return from BigDecimal.scale()
200: since in J2SE 5.0 onwards that can return negative scales.
201: If the value does not represent a SQL DECIMAL then
202: the return is undefined.
203: */
204: public int getDecimalValueScale();
205: }
|