Class SQLSmallint
- All Implemented Interfaces:
Externalizable, Serializable, Comparable, Formatable, Storable, TypedFormat, DataValueDescriptor, NumberDataValue, Orderable
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate boolean(package private) static final intprivate shortFields inherited from class NumberDataType
MAXLONG_PLUS_ONE, MINLONG_MINUS_ONEFields inherited from interface DataValueDescriptor
UNKNOWN_LOGICAL_LENGTHFields inherited from interface NumberDataValue
MAX_DECIMAL_PRECISION_SCALE, MIN_DECIMAL_DIVIDE_SCALEFields inherited from interface Orderable
ORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHAN -
Constructor Summary
ConstructorsModifierConstructorDescriptionNo-arg constructor, required by Formattable. // This constructor also gets used when we are // allocating space for a short.SQLSmallint(short val) privateSQLSmallint(short val, boolean isnull) SQLSmallint(Short obj) -
Method Summary
Modifier and TypeMethodDescriptioncloneValue(boolean forceMaterialization) Clone this DataValueDescriptor.equals(DataValueDescriptor left, DataValueDescriptor right) The = operator as called from the language module, as opposed to the storage module.intEstimate the memory usage in bytes of the data value and the overhead of the class.booleanGets the value in the data value descriptor as a boolean.bytegetByte()Gets the value in the data value descriptor as a byte.doubleGets the value in the data value descriptor as a double.floatgetFloat()Gets the value in the data value descriptor as a float.intgetInt()Gets the value in the data value descriptor as a int.intGets the length of the data value.longgetLong()Gets the value in the data value descriptor as a long.Get a new null value of the same type as this data value.Gets the value in the data value descriptor as a int.shortgetShort()Gets the value in the data value descriptor as a short.Gets the value in the data value descriptor as a String.intReturn my format identifier.Get the SQL name of the datatypegreaterOrEquals(DataValueDescriptor left, DataValueDescriptor right) The >= operator as called from the language module, as opposed to the storage module.greaterThan(DataValueDescriptor left, DataValueDescriptor right) The > operator as called from the language module, as opposed to the storage module.inthashCode()protected booleanThis method implements the isNegative method.booleanisNull()always false for non-nullable columnslessOrEquals(DataValueDescriptor left, DataValueDescriptor right) The <= operator as called from the language module, as opposed to the storage module.lessThan(DataValueDescriptor left, DataValueDescriptor right) The < operator as called from the language module, as opposed to the storage module.minus(NumberDataValue result) This method implements the unary minus operator for smallint.mod(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result) mod(smallint, smallint)notEquals(DataValueDescriptor left, DataValueDescriptor right) The <> operator as called from the language module, as opposed to the storage module.voidvoidRestore this object to its (SQL)null value.protected voidsetFrom(DataValueDescriptor theValue) Set the value of this DataValueDescriptor based on the value of the specified DataValueDescriptor.final voidsetInto(PreparedStatement ps, int position) Set the value into a PreparedStatement.final voidSet this value into a ResultSet for a subsequent ResultSet.insertRow or ResultSet.updateRow.voidsetValue(boolean theValue) Set the value.voidsetValue(byte theValue) Common code to handle converting a byte to this value by using the int to this value conversion.voidsetValue(double theValue) Set the value of this DataValueDescriptor to the given double value At DataType level just throws an error lower classes will overridevoidsetValue(float theValue) Set the value of this DataValueDescriptor to the given float value At DataType level just throws an error lower classes will overridevoidsetValue(int theValue) Set the value of this DataValueDescriptor to the given int value At DataType level just throws an error lower classes will overridevoidsetValue(long theValue) Set the value of this DataValueDescriptor to the given long value At DataType level just throws an error lower classes will overridevoidsetValue(short theValue) Common code to handle converting a short to this value by using the int to this value conversion.voidSet the value of this DataValueDescriptor.voidsetValueFromResultSet(ResultSet resultSet, int colNumber, boolean isNullable) Set the value based on the value for the specified DataValueDescriptor from the specified ResultSet.times(NumberDataValue left, NumberDataValue right, NumberDataValue result) This method implements the * operator for "smallint * smallint".toString()protected intCompare this (not null) to a non-null value.intEach built-in type in JSQL has a precedence.voidMethods inherited from class NumberDataType
absolute, compare, compare, divide, divide, minus, normalizeDOUBLE, normalizeREAL, normalizeREAL, objectNull, plus, setBigDecimal, setObject, setValue, sqrt, typeToBigDecimalMethods inherited from class DataType
checkHostVariable, cloneHolder, coalesce, compare, compare, compareTo, dataTypeConversion, equals, flip, genericSetObject, getBytes, getDate, getStream, getTime, getTimestamp, getTraceString, getTypeName, hasStream, in, invalidFormat, isNotNull, isNullOp, normalize, outOfRange, readExternalFromArray, recycle, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatchMethods inherited from interface DataValueDescriptor
checkHostVariable, cloneHolder, coalesce, compare, compare, getBytes, getDate, getStream, getTime, getTimestamp, getTraceString, hasStream, in, isNotNull, isNullOp, normalize, readExternalFromArray, recycle, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue
-
Field Details
-
SMALLINT_LENGTH
static final int SMALLINT_LENGTH- See Also:
-
BASE_MEMORY_USAGE
private static final int BASE_MEMORY_USAGE -
value
private short value -
isnull
private boolean isnull
-
-
Constructor Details
-
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
private SQLSmallint(short val, boolean isnull) -
SQLSmallint
-
-
Method Details
-
getInt
public int getInt()Description copied from class:DataTypeGets the value in the data value descriptor as a int. Throws an exception if the data value is not receivable as a int.- Specified by:
getIntin interfaceDataValueDescriptor- Overrides:
getIntin classDataType- Returns:
- The data value as a int.
- See Also:
-
getByte
Description copied from class:DataTypeGets the value in the data value descriptor as a byte. Throws an exception if the data value is not receivable as a byte.- Specified by:
getBytein interfaceDataValueDescriptor- Overrides:
getBytein classDataType- Returns:
- The data value as a byte.
- Throws:
StandardException- thrown on failure to convert- See Also:
-
getShort
public short getShort()Description copied from class:DataTypeGets the value in the data value descriptor as a short. Throws an exception if the data value is not receivable as a short.- Specified by:
getShortin interfaceDataValueDescriptor- Overrides:
getShortin classDataType- Returns:
- The data value as a short.
- See Also:
-
getLong
public long getLong()Description copied from class:DataTypeGets the value in the data value descriptor as a long. Throws an exception if the data value is not receivable as a long.- Specified by:
getLongin interfaceDataValueDescriptor- Overrides:
getLongin classDataType- Returns:
- The data value as a long.
- See Also:
-
getFloat
public float getFloat()Description copied from class:DataTypeGets the value in the data value descriptor as a float. Throws an exception if the data value is not receivable as a float.- Specified by:
getFloatin interfaceDataValueDescriptor- Overrides:
getFloatin classDataType- Returns:
- The data value as a float.
- See Also:
-
getDouble
public double getDouble()Description copied from class:DataTypeGets the value in the data value descriptor as a double. Throws an exception if the data value is not receivable as a double.- Specified by:
getDoublein interfaceDataValueDescriptor- Overrides:
getDoublein classDataType- Returns:
- The data value as a double.
- See Also:
-
getBoolean
public boolean getBoolean()Description copied from class:DataTypeGets the value in the data value descriptor as a boolean. Throws an exception if the data value is not receivable as a boolean.- Specified by:
getBooleanin interfaceDataValueDescriptor- Overrides:
getBooleanin classDataType- Returns:
- The data value as a boolean.
- See Also:
-
getString
Description copied from interface:DataValueDescriptorGets 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:
-
getLength
public int getLength()Description copied from interface:DataValueDescriptorGets 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:
-
getObject
Description copied from class:DataTypeGets the value in the data value descriptor as a int. Throws an exception if the data value is not receivable as a int.- Specified by:
getObjectin interfaceDataValueDescriptor- Overrides:
getObjectin classDataType- Returns:
- The data value as a int.
- See Also:
-
getTypeName
Description copied from interface:DataValueDescriptorGet 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:
-
isNull
public boolean isNull()always false for non-nullable columns- Returns:
- true if the value is null and false otherwise.
- See Also:
-
writeExternal
- Throws:
IOException
-
readExternal
- Throws:
IOException- See Also:
-
restoreToNull
public void restoreToNull()Description copied from interface:StorableRestore this object to its (SQL)null value.- See Also:
-
typeCompare
Description copied from class:NumberDataTypeCompare this (not null) to a non-null value.- Specified by:
typeComparein classNumberDataType- Throws:
StandardException- Thrown on error
-
cloneValue
Description copied from interface:DataValueDescriptorClone this DataValueDescriptor. Results in a new object that has the same value as this but can be modified independently.Even though the objects can be modified independently regardless of the value of
forceMaterialization, both the clone and the original may be dependent on the store state ifforceMaterializationis set tofalse. An example is if you need to access the value you just read usingcloneValueafter the current transaction has ended, or after the source result set has been closed.- Parameters:
forceMaterialization- any streams representing the data value will be materialized iftrue, the data value will be kept as a stream if possible iffalse- Returns:
- A clone of the
DataValueDescriptorwith the same initial value as this. - See Also:
-
getNewNull
Description copied from interface:DataValueDescriptorGet a new null value of the same type as this data value.- See Also:
-
setValueFromResultSet
public void setValueFromResultSet(ResultSet resultSet, int colNumber, boolean isNullable) throws SQLException Description copied from interface:DataValueDescriptorSet 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)- Throws:
SQLException- Thrown on error- See Also:
-
setInto
Set the value into a PreparedStatement.- Specified by:
setIntoin interfaceDataValueDescriptor- Overrides:
setIntoin classDataType- Throws:
SQLException- Error setting value in PreparedStatement
-
setInto
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:
setIntoin interfaceDataValueDescriptor- Overrides:
setIntoin classDataType- Throws:
SQLException- thrown by the ResultSet objectStandardException- thrown by me accessing my value.
-
setValue
Description copied from class:DataTypeSet the value of this DataValueDescriptor. At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The BigDecimal value to set this DataValueDescriptor to- Throws:
StandardException- thrown if string not accepted
-
setValue
public void setValue(short theValue) Description copied from class:NumberDataTypeCommon code to handle converting a short to this value by using the int to this value conversion. Simply calls setValue(int).- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classNumberDataType- Parameters:
theValue- The value to set this DataValueDescriptor to
-
setValue
public void setValue(byte theValue) Description copied from class:NumberDataTypeCommon code to handle converting a byte to this value by using the int to this value conversion. Simply calls setValue(int).- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classNumberDataType- Parameters:
theValue- The value to set this DataValueDescriptor to
-
setValue
Description copied from class:DataTypeSet the value of this DataValueDescriptor to the given int value At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- if outsideRangeForSmallint
-
setValue
Description copied from class:DataTypeSet the value of this DataValueDescriptor to the given long value At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- if outsideRangeForSmallint
-
setValue
Description copied from class:DataTypeSet the value of this DataValueDescriptor to the given float value At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- Thrown on error- See Also:
-
setValue
Description copied from class:DataTypeSet the value of this DataValueDescriptor to the given double value At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- Thrown on error- See Also:
-
setValue
public void setValue(boolean theValue) Description copied from class:DataTypeSet the value. At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- Contains the boolean value to set this to- See Also:
-
setFrom
Description copied from class:DataTypeSet the value of this DataValueDescriptor based on the value of the specified DataValueDescriptor.- Overrides:
setFromin classDataType- Parameters:
theValue- The DataValueDescriptor that holds the value to which we want to set this DataValueDescriptor's value.- Throws:
StandardException
-
typePrecedence
public int typePrecedence()Description copied from class:DataTypeEach 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:
typePrecedencein interfaceDataValueDescriptor- Overrides:
typePrecedencein classDataType- Returns:
- The precedence of this type.
- See Also:
-
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:
equalsin interfaceDataValueDescriptor- Overrides:
equalsin classDataType- 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:
notEqualsin interfaceDataValueDescriptor- Overrides:
notEqualsin classDataType- Parameters:
left- The value on the left side of the operatorright- The value on the right side of the operator- 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:
lessThanin interfaceDataValueDescriptor- Overrides:
lessThanin classDataType- Parameters:
left- The value on the left side of the operatorright- The value on the right side of the operator 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:
greaterThanin interfaceDataValueDescriptor- Overrides:
greaterThanin classDataType- Parameters:
left- The value on the left side of the operatorright- The value on the right side of the operator- 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:
lessOrEqualsin interfaceDataValueDescriptor- Overrides:
lessOrEqualsin classDataType- Parameters:
left- The value on the left side of the operatorright- The value on the right side of the operator- 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:
greaterOrEqualsin interfaceDataValueDescriptor- Overrides:
greaterOrEqualsin classDataType- Parameters:
left- The value on the left side of the operatorright- The value on the right side of the operator- 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 multipliedright- The second value to be multipliedresult- 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:
modin interfaceNumberDataValue- Overrides:
modin classNumberDataType- Parameters:
dividend- The numeratordivisor- The denominatorresult- The result of the previous call to this method, null if not called yet.- Returns:
- dividend / divisor
- Throws:
StandardException- Thrown on error, if result is non-null then its value will be unchanged.
-
minus
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:
isNegativein classNumberDataType- Returns:
- A boolean. If this.value is negative, return true. For positive values or null, return false.
-
toString
-
hashCode
-
estimateMemoryUsage
public int estimateMemoryUsage()Description copied from interface:DataValueDescriptorEstimate the memory usage in bytes of the data value and the overhead of the class.- Returns:
- the estimated memory usage
-