org.apache.derby.iapi.types
Class SQLSmallint

java.lang.Object
  extended byorg.apache.derby.iapi.types.DataType
      extended byorg.apache.derby.iapi.types.NumberDataType
          extended byorg.apache.derby.iapi.types.SQLSmallint
All Implemented Interfaces:
CloneableObject, DataValueDescriptor, java.io.Externalizable, Formatable, NumberDataValue, Orderable, java.io.Serializable, Storable, TypedFormat

public final class SQLSmallint
extends NumberDataType

SQLSmallint satisfies the DataValueDescriptor interfaces (i.e., OrderableDataType). It implements a smallint column, e.g. for storing a column value; it can be specified when constructed to not allow nulls. Nullability cannot be changed after construction, as it affects the storage size and mechanism.

Because OrderableDataType is a subtype of ValueColumn, SQLSmallint can play a role in either a ValueColumn/Row or a OrderableDataType/Row, interchangeably.

We assume the store has a flag for nullness of the value, and simply return a 0-length array for the stored form when the value is null.

PERFORMANCE: There are likely alot of performance improvements possible for this implementation -- it new's Short more than it probably wants to.

See Also:
Serialized Form

Field Summary
private static int BASE_MEMORY_USAGE
           
private  boolean isnull
           
(package private) static int SMALLINT_LENGTH
           
private  short value
           
 
Fields inherited from class org.apache.derby.iapi.types.NumberDataType
MAXLONG_PLUS_ONE, MINLONG_MINUS_ONE, ZERO_DECIMAL
 
Fields inherited from interface org.apache.derby.iapi.types.NumberDataValue
MAX_DECIMAL_PRECISION_SCALE, MIN_DECIMAL_DIVIDE_SCALE
 
Fields inherited from interface org.apache.derby.iapi.types.Orderable
ORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHAN
 
Constructor Summary
SQLSmallint()
          No-arg constructor, required by Formattable. // This constructor also gets used when we are // allocating space for a short.
SQLSmallint(short val)
           
SQLSmallint(short val, boolean isnull)
           
 
Method Summary
 BooleanDataValue equals(DataValueDescriptor left, DataValueDescriptor right)
          The = operator as called from the language module, as opposed to the storage module.
 int estimateMemoryUsage()
          Estimate the memory usage in bytes of the data value and the overhead of the class.
 boolean getBoolean()
          Gets the value in the data value descriptor as a boolean.
 byte getByte()
          Gets the value in the data value descriptor as a byte.
 DataValueDescriptor getClone()
          Clone this DataValueDescriptor.
 double getDouble()
          Gets the value in the data value descriptor as a double.
 float getFloat()
          Gets the value in the data value descriptor as a float.
 int getInt()
          Gets the value in the data value descriptor as an int.
 int getLength()
          Gets the length of the data value.
 long getLong()
          Gets the value in the data value descriptor as a long.
 DataValueDescriptor getNewNull()
          Get a new null value of the same type as this data value.
 java.lang.Object getObject()
          Gets the value in the data value descriptor as a Java Object.
 short getShort()
          Gets the value in the data value descriptor as a short.
 java.lang.String getString()
          Gets the value in the data value descriptor as a String.
 int getTypeFormatId()
          Return my format identifier.
 java.lang.String getTypeName()
          Get the SQL name of the datatype
 BooleanDataValue greaterOrEquals(DataValueDescriptor left, DataValueDescriptor right)
          The >= operator as called from the language module, as opposed to the storage module.
 BooleanDataValue greaterThan(DataValueDescriptor left, DataValueDescriptor right)
          The > operator as called from the language module, as opposed to the storage module.
 int hashCode()
           
protected  boolean isNegative()
          This method implements the isNegative method.
 boolean isNull()
          always false for non-nullable columns
 BooleanDataValue lessOrEquals(DataValueDescriptor left, DataValueDescriptor right)
          The <= operator as called from the language module, as opposed to the storage module.
 BooleanDataValue lessThan(DataValueDescriptor left, DataValueDescriptor right)
          The < operator as called from the language module, as opposed to the storage module.
 NumberDataValue minus(NumberDataValue result)
          This method implements the unary minus operator for smallint.
 NumberDataValue mod(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result)
          mod(smallint, smallint)
 BooleanDataValue notEquals(DataValueDescriptor left, DataValueDescriptor right)
          The <> operator as called from the language module, as opposed to the storage module.
 void readExternal(java.io.ObjectInput in)
           
 void readExternalFromArray(ArrayInputStream in)
          Read the DataValueDescriptor from the stream.
 void restoreToNull()
          Restore this object to its (SQL)null value.
protected  void setFrom(DataValueDescriptor theValue)
           
 void setInto(java.sql.PreparedStatement ps, int position)
          Set the value into a PreparedStatement.
 void setInto(java.sql.ResultSet rs, int position)
          Set this value into a ResultSet for a subsequent ResultSet.insertRow or ResultSet.updateRow.
 void setValue(boolean theValue)
          Set the value.
 void setValue(byte theValue)
          Common code to handle converting a byte to this value by using the int to this value conversion.
 void setValue(double theValue)
          Set the value of this DataValueDescriptor to the given double value
 void setValue(float theValue)
          Set the value of this DataValueDescriptor to the given double value
 void setValue(int theValue)
          Set the value of this DataValueDescriptor to the given int value
 void setValue(long theValue)
          Set the value of this DataValueDescriptor to the given long value
 void setValue(java.lang.Object theValue)
          Set the value of this DataValueDescriptor to the given value
 void setValue(short theValue)
          Common code to handle converting a short to this value by using the int to this value conversion.
 void setValue(java.lang.String theValue)
          Set the value of this DataValueDescriptor.
 void setValueFromResultSet(java.sql.ResultSet resultSet, int colNumber, boolean isNullable)
          Set the value based on the value for the specified DataValueDescriptor from the specified ResultSet.
 NumberDataValue times(NumberDataValue left, NumberDataValue right, NumberDataValue result)
          This method implements the * operator for "smallint * smallint".
 java.lang.String toString()
           
protected  int typeCompare(DataValueDescriptor arg)
          Compare this (not null) to a non-null value.
 int typePrecedence()
          Each built-in type in JSQL has a precedence.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class org.apache.derby.iapi.types.NumberDataType
absolute, compare, compare, divide, divide, getDecimalValuePrecision, getDecimalValueScale, minus, normalizeDOUBLE, normalizeREAL, normalizeREAL, objectNull, plus, setBigDecimal, setValue, sqrt, typeToBigDecimal
 
Methods inherited from class org.apache.derby.iapi.types.DataType
checkHostVariable, cloneObject, coalesce, dataTypeConversion, equals, flip, genericSetObject, getBytes, getDate, getNationalString, getStream, getTime, getTimestamp, in, invalidFormat, isNotNull, isNullOp, normalize, outOfRange, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatch
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.derby.iapi.types.DataValueDescriptor
checkHostVariable, coalesce, getBytes, getDate, getStream, getTime, getTimestamp, in, isNotNull, isNullOp, normalize, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue
 

Field Detail

SMALLINT_LENGTH

static final int SMALLINT_LENGTH
See Also:
Constant Field Values

BASE_MEMORY_USAGE

private static final int BASE_MEMORY_USAGE

value

private short value

isnull

private boolean isnull
Constructor Detail

SQLSmallint

public SQLSmallint()
No-arg constructor, required by Formattable. // This constructor also gets used when we are // allocating space for a short.


SQLSmallint

public SQLSmallint(short val)

SQLSmallint

public SQLSmallint(short val,
                   boolean isnull)
Method Detail

getInt

public int getInt()
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as an int. Throws an exception if the data value is not an int.

Specified by:
getInt in interface DataValueDescriptor
Overrides:
getInt in class DataType
Returns:
The data value as a int.
See Also:
DataValueDescriptor.getInt()

getByte

public byte getByte()
             throws StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a byte. Throws an exception if the data value is not a byte.

Specified by:
getByte in interface DataValueDescriptor
Overrides:
getByte in class DataType
Returns:
The data value as a byte.
Throws:
StandardException - thrown on failure to convert
See Also:
DataValueDescriptor.getByte()

getShort

public short getShort()
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a short. Throws an exception if the data value is not a short.

Specified by:
getShort in interface DataValueDescriptor
Overrides:
getShort in class DataType
Returns:
The data value as a short.
See Also:
DataValueDescriptor.getShort()

getLong

public long getLong()
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a long. Throws an exception if the data value is not a long.

Specified by:
getLong in interface DataValueDescriptor
Overrides:
getLong in class DataType
Returns:
The data value as a long.
See Also:
DataValueDescriptor.getLong()

getFloat

public float getFloat()
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a float. Throws an exception if the data value is not a float.

Specified by:
getFloat in interface DataValueDescriptor
Overrides:
getFloat in class DataType
Returns:
The data value as a float.
See Also:
DataValueDescriptor.getFloat()

getDouble

public double getDouble()
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a double. Throws an exception if the data value is not a double.

Specified by:
getDouble in interface DataValueDescriptor
Overrides:
getDouble in class DataType
Returns:
The data value as a double.
See Also:
DataValueDescriptor.getDouble()

getBoolean

public boolean getBoolean()
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a boolean. Throws an exception if the data value is not a boolean. For DataValueDescriptor, this is the preferred interface for BIT, but for this no-casting interface, it isn't, because BIT is stored internally as a Bit, not as a Boolean.

Specified by:
getBoolean in interface DataValueDescriptor
Overrides:
getBoolean in class DataType
Returns:
The data value as a boolean.
See Also:
DataValueDescriptor.getBoolean()

getString

public java.lang.String getString()
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a String. Throws an exception if the data value is not a string.

Returns:
The data value as a String.
See Also:
DataValueDescriptor.getString()

getLength

public int getLength()
Description copied from interface: DataValueDescriptor
Gets the length of the data value. The meaning of this is implementation-dependent. For string types, it is the number of characters in the string. For numeric types, it is the number of bytes used to store the number. This is the actual length of this value, not the length of the type it was defined as. For example, a VARCHAR value may be shorter than the declared VARCHAR (maximum) length.

Returns:
The length of the data value
See Also:
DataValueDescriptor.getLength()

getObject

public java.lang.Object getObject()
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a Java Object. The type of the Object will be the Java object type corresponding to the data value's SQL type. JDBC defines a mapping between Java object types and SQL types - we will allow that to be extended through user type definitions. Throws an exception if the data value is not an object (yeah, right).

Specified by:
getObject in interface DataValueDescriptor
Overrides:
getObject in class DataType
Returns:
The data value as a int.
See Also:
DataValueDescriptor.getObject()

getTypeName

public java.lang.String getTypeName()
Description copied from interface: DataValueDescriptor
Get the SQL name of the datatype

Returns:
The SQL name of the datatype

getTypeFormatId

public int getTypeFormatId()
Return my format identifier.

Returns:
The identifier. (A UUID stuffed in an array of 16 bytes).
See Also:
TypedFormat.getTypeFormatId()

isNull

public boolean isNull()
always false for non-nullable columns

Returns:
true if the value is null and false otherwise.
See Also:
Storable.isNull()

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Throws:
java.io.IOException

readExternalFromArray

public void readExternalFromArray(ArrayInputStream in)
                           throws java.io.IOException
Description copied from interface: DataValueDescriptor
Read the DataValueDescriptor from the stream.

Initialize the data value by reading it's values from the ArrayInputStream. This interface is provided as a way to achieve possible performance enhancement when reading an array can be optimized over reading from a generic stream from readExternal().

Parameters:
in - The array stream positioned at the beginning of the byte stream to read from.
Throws:
java.io.IOException - Usual error is if you try to read past limit on the stream.
See Also:
Externalizable.readExternal(java.io.ObjectInput)

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException
Throws:
java.io.IOException

restoreToNull

public void restoreToNull()
Description copied from interface: Storable
Restore this object to its (SQL)null value.

See Also:
Storable.restoreToNull()

typeCompare

protected int typeCompare(DataValueDescriptor arg)
                   throws StandardException
Description copied from class: NumberDataType
Compare this (not null) to a non-null value.

Specified by:
typeCompare in class NumberDataType
Throws:
StandardException - Thrown on error

getClone

public DataValueDescriptor getClone()
Description copied from interface: DataValueDescriptor
Clone this DataValueDescriptor. Results in a new object that has the same value as this but can be modified independently.

Returns:
A clone of the DataValueDescriptor with the same initial value as this.
See Also:
DataValueDescriptor.getClone()

getNewNull

public DataValueDescriptor getNewNull()
Description copied from interface: DataValueDescriptor
Get a new null value of the same type as this data value.

See Also:
DataValueDescriptor.getNewNull()

setValueFromResultSet

public void setValueFromResultSet(java.sql.ResultSet resultSet,
                                  int colNumber,
                                  boolean isNullable)
                           throws java.sql.SQLException
Description copied from interface: DataValueDescriptor
Set the value based on the value for the specified DataValueDescriptor from the specified ResultSet.

Parameters:
resultSet - The specified ResultSet.
colNumber - The 1-based column # into the resultSet.
isNullable - Whether or not the column is nullable (No need to call wasNull() if not)
Returns:
Nothing.
Throws:
java.sql.SQLException - Thrown on error
See Also:
DataValueDescriptor.setValueFromResultSet(java.sql.ResultSet, int, boolean)

setInto

public final void setInto(java.sql.PreparedStatement ps,
                          int position)
                   throws java.sql.SQLException
Set the value into a PreparedStatement.

Specified by:
setInto in interface DataValueDescriptor
Overrides:
setInto in class DataType
Throws:
java.sql.SQLException - Error setting value in PreparedStatement

setInto

public final void setInto(java.sql.ResultSet rs,
                          int position)
                   throws java.sql.SQLException,
                          StandardException
Set this value into a ResultSet for a subsequent ResultSet.insertRow or ResultSet.updateRow. This method will only be called for non-null values.

Specified by:
setInto in interface DataValueDescriptor
Overrides:
setInto in class DataType
Throws:
java.sql.SQLException - thrown by the ResultSet object
StandardException - thrown by me accessing my value.

setValue

public void setValue(java.lang.String theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor.

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The BigDecimal value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException - thrown if string not accepted

setValue

public void setValue(short theValue)
Description copied from class: NumberDataType
Common code to handle converting a short to this value by using the int to this value conversion. Simply calls setValue(int).

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class NumberDataType

setValue

public void setValue(byte theValue)
Description copied from class: NumberDataType
Common code to handle converting a byte to this value by using the int to this value conversion. Simply calls setValue(int).

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class NumberDataType

setValue

public void setValue(int theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given int value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException - if outsideRangeForSmallint

setValue

public void setValue(long theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given long value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException - if outsideRangeForSmallint

setValue

public void setValue(float theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given double value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException - Thrown on error
See Also:
NumberDataValue.setValue(java.lang.Number)

setValue

public void setValue(double theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given double value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException - Thrown on error
See Also:
NumberDataValue.setValue(java.lang.Number)

setValue

public void setValue(boolean theValue)
Description copied from interface: DataValueDescriptor
Set the value.

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - Contains the boolean value to set this to
Returns:
This value
See Also:
NumberDataValue.setValue(java.lang.Number)

setValue

public void setValue(java.lang.Object theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Throws:
StandardException - Thrown on error
See Also:
DataValueDescriptor.setValue(java.lang.Object)

setFrom

protected void setFrom(DataValueDescriptor theValue)
                throws StandardException
Overrides:
setFrom in class DataType
Throws:
StandardException

typePrecedence

public int typePrecedence()
Description copied from interface: DataValueDescriptor
Each built-in type in JSQL has a precedence. This precedence determines how to do type promotion when using binary operators. For example, float has a higher precedence than int, so when adding an int to a float, the result type is float. The precedence for some types is arbitrary. For example, it doesn't matter what the precedence of the boolean type is, since it can't be mixed with other types. But the precedence for the number types is critical. The SQL standard requires that exact numeric types be promoted to approximate numeric when one operator uses both. Also, the precedence is arranged so that one will not lose precision when promoting a type.

Specified by:
typePrecedence in interface DataValueDescriptor
Overrides:
typePrecedence in class DataType
Returns:
The precedence of this type.
See Also:
DataValueDescriptor.typePrecedence()

equals

public BooleanDataValue equals(DataValueDescriptor left,
                               DataValueDescriptor right)
                        throws StandardException
The = operator as called from the language module, as opposed to the storage module.

Specified by:
equals in interface DataValueDescriptor
Overrides:
equals in class DataType
Parameters:
left - The value on the left side of the =
right - The value on the right side of the =
Returns:
A SQL boolean value telling whether the two parameters are equal
Throws:
StandardException - Thrown on error

notEquals

public BooleanDataValue notEquals(DataValueDescriptor left,
                                  DataValueDescriptor right)
                           throws StandardException
The <> operator as called from the language module, as opposed to the storage module.

Specified by:
notEquals in interface DataValueDescriptor
Overrides:
notEquals in class DataType
Parameters:
left - The value on the left side of the <>
right - The value on the right side of the <>
Returns:
A SQL boolean value telling whether the two parameters are not equal
Throws:
StandardException - Thrown on error

lessThan

public BooleanDataValue lessThan(DataValueDescriptor left,
                                 DataValueDescriptor right)
                          throws StandardException
The < operator as called from the language module, as opposed to the storage module.

Specified by:
lessThan in interface DataValueDescriptor
Overrides:
lessThan in class DataType
Parameters:
left - The value on the left side of the <
right - The value on the right side of the < is not.
Returns:
A SQL boolean value telling whether the first operand is less than the second operand
Throws:
StandardException - Thrown on error

greaterThan

public BooleanDataValue greaterThan(DataValueDescriptor left,
                                    DataValueDescriptor right)
                             throws StandardException
The > operator as called from the language module, as opposed to the storage module.

Specified by:
greaterThan in interface DataValueDescriptor
Overrides:
greaterThan in class DataType
Parameters:
left - The value on the left side of the >
right - The value on the right side of the >
Returns:
A SQL boolean value telling whether the first operand is greater than the second operand
Throws:
StandardException - Thrown on error

lessOrEquals

public BooleanDataValue lessOrEquals(DataValueDescriptor left,
                                     DataValueDescriptor right)
                              throws StandardException
The <= operator as called from the language module, as opposed to the storage module.

Specified by:
lessOrEquals in interface DataValueDescriptor
Overrides:
lessOrEquals in class DataType
Parameters:
left - The value on the left side of the <=
right - The value on the right side of the <=
Returns:
A SQL boolean value telling whether the first operand is less than or equal to the second operand
Throws:
StandardException - Thrown on error

greaterOrEquals

public BooleanDataValue greaterOrEquals(DataValueDescriptor left,
                                        DataValueDescriptor right)
                                 throws StandardException
The >= operator as called from the language module, as opposed to the storage module.

Specified by:
greaterOrEquals in interface DataValueDescriptor
Overrides:
greaterOrEquals in class DataType
Parameters:
left - The value on the left side of the >=
right - The value on the right side of the >=
Returns:
A SQL boolean value telling whether the first operand is greater than or equal to the second operand
Throws:
StandardException - Thrown on error

times

public NumberDataValue times(NumberDataValue left,
                             NumberDataValue right,
                             NumberDataValue result)
                      throws StandardException
This method implements the * operator for "smallint * smallint".

Parameters:
left - The first value to be multiplied
right - The second value to be multiplied
result - The result of a previous call to this method, null if not called yet
Returns:
A SQLSmallint containing the result of the multiplication
Throws:
StandardException - Thrown on error

mod

public NumberDataValue mod(NumberDataValue dividend,
                           NumberDataValue divisor,
                           NumberDataValue result)
                    throws StandardException
mod(smallint, smallint)

Specified by:
mod in interface NumberDataValue
Overrides:
mod in class NumberDataType
Throws:
StandardException

minus

public NumberDataValue minus(NumberDataValue result)
                      throws StandardException
This method implements the unary minus operator for smallint.

Parameters:
result - The result of a previous call to this method, null if not called yet
Returns:
A SQLSmalllint containing the result of the division
Throws:
StandardException - Thrown on error

isNegative

protected boolean isNegative()
This method implements the isNegative method.

Specified by:
isNegative in class NumberDataType
Returns:
A boolean. If this.value is negative, return true. For positive values or null, return false.

toString

public java.lang.String toString()

hashCode

public int hashCode()

estimateMemoryUsage

public int estimateMemoryUsage()
Description copied from interface: DataValueDescriptor
Estimate the memory usage in bytes of the data value and the overhead of the class.

Returns:
the estimated memory usage

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.