org.apache.derby.iapi.types
Class SQLBit

java.lang.Object
  extended byorg.apache.derby.iapi.types.DataType
      extended byorg.apache.derby.iapi.types.SQLBinary
          extended byorg.apache.derby.iapi.types.SQLBit
All Implemented Interfaces:
BitDataValue, CloneableObject, ConcatableDataValue, DataValueDescriptor, java.io.Externalizable, Formatable, Orderable, java.io.Serializable, Storable, StreamStorable, TypedFormat, VariableSizeDataValue
Direct Known Subclasses:
SQLVarbit

public class SQLBit
extends SQLBinary

SQLBit satisfies the DataValueDescriptor interfaces (i.e., DataType). It implements a String holder, e.g. for storing a column value; it can be specified when constructed to not allow nulls. Nullability cannot be changed after construction.

Because DataType is a subclass of DataType, SQLBit can play a role in either a DataType/Value or a DataType/KeyRow, interchangeably.

Format :
Length is encoded to support 5.x databases where the length was stored as the number of bits. The first bit of the first byte indicates if the format is an old (5.x) style or a new 8.1 style. 8.1 then uses the next two bits to indicate how the length is encoded.
is one of N styles.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.derby.iapi.types.SQLBinary
dataValue, PAD, stream, streamLength
 
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
 
Fields inherited from interface org.apache.derby.iapi.types.VariableSizeDataValue
IGNORE_PRECISION
 
Constructor Summary
SQLBit()
          no-arg constructor, required by Formattable.
SQLBit(byte[] val)
           
 
Method Summary
 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.
 int getTypeFormatId()
          Return my format identifier.
 java.lang.String getTypeName()
          Get the SQL name of the datatype
 void normalize(DataTypeDescriptor desiredType, DataValueDescriptor source)
          Normalization method - this method may be called when putting a value into a SQLBit, for example, when inserting into a SQLBit column.
 void setValue(java.lang.Object theValue)
          Set the value of this DataValueDescriptor to the given value
 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.
 DataValueDescriptor setWidth(int desiredWidth, int desiredScale, boolean errorOnTrunc)
          Set the width of the to the desired value.
 int typePrecedence()
          Each built-in type in JSQL has a precedence.
 
Methods inherited from class org.apache.derby.iapi.types.SQLBinary
charLength, checkHostVariable, cloneObject, compare, compare, concatenate, equals, estimateMemoryUsage, getBytes, getClone, getLength, getStream, getString, getValue, greaterOrEquals, greaterThan, hashCode, isNull, lessOrEquals, lessThan, loadStream, notEquals, objectNull, readExternal, readExternalFromArray, restoreToNull, returnStream, setFrom, setStream, setValue, setValue, substring, toString, writeExternal
 
Methods inherited from class org.apache.derby.iapi.types.DataType
coalesce, dataTypeConversion, equals, flip, genericSetObject, getBigDecimal, getBoolean, getByte, getDate, getDouble, getFloat, getInt, getLong, getNationalString, getShort, getTime, getTimestamp, in, invalidFormat, isNotNull, isNullOp, outOfRange, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, 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
coalesce, getBigDecimal, getBoolean, getByte, getDate, getDouble, getFloat, getInt, getLong, getShort, getTime, getTimestamp, in, isNotNull, isNullOp, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue
 

Constructor Detail

SQLBit

public SQLBit()
no-arg constructor, required by Formattable.


SQLBit

public SQLBit(byte[] val)
Method Detail

getObject

public java.lang.Object getObject()
                           throws StandardException
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.
Throws:
StandardException - Thrown on error

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()

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)

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()

setValue

public final 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
See Also:
DataValueDescriptor.setValue(java.lang.Object)

normalize

public void normalize(DataTypeDescriptor desiredType,
                      DataValueDescriptor source)
               throws StandardException
Normalization method - this method may be called when putting a value into a SQLBit, for example, when inserting into a SQLBit column. See NormalizeResultSet in execution.

Specified by:
normalize in interface DataValueDescriptor
Overrides:
normalize in class DataType
Parameters:
desiredType - The type to normalize the source column to
source - The value to normalize
Throws:
StandardException - Thrown for null into non-nullable column, and for truncation error

setWidth

public DataValueDescriptor setWidth(int desiredWidth,
                                    int desiredScale,
                                    boolean errorOnTrunc)
                             throws StandardException
Set the width of the to the desired value. Used when CASTing. Ideally we'd recycle normalize(), but the behavior is different (we issue a warning instead of an error, and we aren't interested in nullability).

Parameters:
desiredWidth - the desired length
desiredScale - the desired scale (ignored)
errorOnTrunc - throw error on truncation
Returns:
this with the target width
Throws:
StandardException - Thrown on non-zero truncation if errorOnTrunc is true


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