java.lang.Object
org.apache.derby.iapi.types.DataType
org.apache.derby.iapi.types.SQLBinary
- All Implemented Interfaces:
- BitDataValue, CloneableObject, ConcatableDataValue, DataValueDescriptor, java.io.Externalizable, org.apache.derby.iapi.services.io.Formatable, Orderable, java.io.Serializable, org.apache.derby.iapi.services.io.Storable, org.apache.derby.iapi.services.io.StreamStorable, org.apache.derby.iapi.services.io.TypedFormat, VariableSizeDataValue
- Direct Known Subclasses:
- SQLBit, SQLBlob
- public abstract class SQLBinary
- extends DataType
- implements BitDataValue
SQLBinary 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.
- (5.x format) 4 byte Java format integer value 0 - either is 0 bytes/bits or an unknown number of bytes.
- (5.x format) 4 byte Java format integer value >0 (positive) - number of bits in , number of bytes in
is the minimum number of bytes required to store the number of bits.
- (8.1 format) 1 byte encoded length (0 <= L <= 31) - number of bytes of - encoded = 0x80 & L
- (8.1 format) 3 byte encoded length (32 <= L < 64k) - number of bytes of - encoded = 0xA0
- (8.1 format) 5 byte encoded length (64k <= L < 2G) - number of bytes of - encoded = 0xC0
- (future) to be determined L >= 2G - encoded 0xE0
(0xE0 is an esacape to allow any number of arbitary encodings in the future).
|
Constructor Summary |
(package private) |
SQLBinary()
no-arg constructor, required by Formattable. |
(package private) |
SQLBinary(byte[] val)
|
|
Method Summary |
NumberDataValue |
charLength(NumberDataValue result)
This method implements the char_length function for bit. |
void |
checkHostVariable(int declaredLength)
Host variables are rejected if their length is
bigger than the declared length, regardless of
if the trailing bytes are the pad character. |
java.lang.Object |
cloneObject()
From CloneableObject
Shallow clone a StreamStorable without objectifying. |
private static int |
compare(byte[] left,
byte[] right)
|
int |
compare(DataValueDescriptor other)
Compare this Orderable with a given Orderable for the purpose of
index positioning. |
boolean |
compare(int op,
DataValueDescriptor other,
boolean orderedNulls,
boolean unknownRV)
Compare this Orderable with a given Orderable for the purpose of
qualification and sorting. |
BitDataValue |
concatenate(BitDataValue left,
BitDataValue right,
BitDataValue result)
The SQL concatenation '||' operator. |
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. |
byte[] |
getBytes()
Gets the value in the data value descriptor as a byte array. |
DataValueDescriptor |
getClone()
Clone this DataValueDescriptor. |
int |
getLength()
length in bytes |
java.io.InputStream |
getStream()
Gets the value in the data value descriptor as a Java InputStream. |
java.lang.String |
getString()
Used by JDBC -- string should not contain
SQL92 formatting. |
(package private) byte[] |
getValue()
|
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()
Get a value that represents this Object, as uniquely as
possible within the confines of an int. |
boolean |
isNull()
see if the Bit value is null. |
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. |
void |
loadStream()
sets the stream state for the object. |
BooleanDataValue |
notEquals(DataValueDescriptor left,
DataValueDescriptor right)
The <> operator as called from the language module, as opposed to
the storage module. |
(package private) boolean |
objectNull(java.lang.Object o)
|
private static int |
readBinaryLength(java.io.ObjectInput in)
|
void |
readExternal(java.io.ObjectInput in)
delegated to bit |
void |
readExternalFromArray(org.apache.derby.iapi.services.io.ArrayInputStream in)
Read the DataValueDescriptor from the stream. |
private void |
readFromStream(java.io.InputStream in)
|
void |
restoreToNull()
Restore this object to its (SQL)null value. |
java.io.InputStream |
returnStream()
Return the stream state of the object. |
protected void |
setFrom(DataValueDescriptor theValue)
|
void |
setInto(java.sql.PreparedStatement ps,
int position)
Adding this method to ensure that super class' setInto method doesn't get called
that leads to the violation of JDBC spec( untyped nulls ) when batching is turned on. |
void |
setStream(java.io.InputStream newStream)
sets the stream state for the object. |
void |
setValue(byte[] theValue)
Set the value of this DataValueDescriptor. |
void |
setValue(java.io.InputStream theStream,
int streamLength)
Set the value to be the contents of the stream. |
ConcatableDataValue |
substring(NumberDataValue start,
NumberDataValue length,
ConcatableDataValue result,
int maxLen)
The SQL substr() function. |
java.lang.String |
toString()
Convert this Object to a human-readable String. |
void |
writeExternal(java.io.ObjectOutput out)
Write the value out from the byte array (not called if null)
using the 8.1 encoding. |
| Methods inherited from class org.apache.derby.iapi.types.DataType |
coalesce, dataTypeConversion, equals, flip, genericSetObject, getBoolean, getByte, getDate, getDouble, getFloat, getInt, getLong, getNationalString, getObject, getShort, getTime, getTimestamp, in, invalidFormat, isNotNull, isNullOp, normalize, outOfRange, setBigDecimal, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatch, typePrecedence, typeToBigDecimal |
| Methods inherited from interface org.apache.derby.iapi.types.DataValueDescriptor |
coalesce, getBoolean, getByte, getDate, getDouble, getFloat, getInt, getLong, getNewNull, getObject, getShort, getTime, getTimestamp, getTypeName, in, isNotNull, isNullOp, normalize, setBigDecimal, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueFromResultSet, typePrecedence, typeToBigDecimal |
PAD
static final byte PAD
- See Also:
- Constant Field Values
BASE_MEMORY_USAGE
private static final int BASE_MEMORY_USAGE
dataValue
byte[] dataValue
stream
java.io.InputStream stream
streamLength
int streamLength
- Length of the stream in units relevant to the type,
in this case bytes.
SQLBinary
SQLBinary()
- no-arg constructor, required by Formattable.
SQLBinary
SQLBinary(byte[] val)
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.
- Specified by:
estimateMemoryUsage in interface DataValueDescriptor
setValue
public final void setValue(byte[] theValue)
- Description copied from interface:
DataValueDescriptor
- Set the value of this DataValueDescriptor.
- Specified by:
setValue in interface DataValueDescriptor- Overrides:
setValue in class DataType
getString
public final java.lang.String getString()
throws org.apache.derby.iapi.error.StandardException
- Used by JDBC -- string should not contain
SQL92 formatting.
- Specified by:
getString in interface DataValueDescriptor
getStream
public final java.io.InputStream getStream()
- Description copied from interface:
DataValueDescriptor
- Gets the value in the data value descriptor as a Java InputStream.
Only data types that implements StreamStorable will have stream states.
- Specified by:
getStream in interface DataValueDescriptor- Overrides:
getStream in class DataType
getBytes
public final byte[] getBytes()
throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
DataValueDescriptor
- Gets the value in the data value descriptor as a byte array.
Throws an exception if the data value is not a byte array.
- Specified by:
getBytes in interface DataValueDescriptor- Overrides:
getBytes in class DataType
getValue
byte[] getValue()
throws org.apache.derby.iapi.error.StandardException
getLength
public final int getLength()
throws org.apache.derby.iapi.error.StandardException
- length in bytes
- Specified by:
getLength in interface DataValueDescriptor
isNull
public final boolean isNull()
- see if the Bit value is null.
- Specified by:
isNull in interface org.apache.derby.iapi.services.io.Storable
writeExternal
public final void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
- Write the value out from the byte array (not called if null)
using the 8.1 encoding.
- Specified by:
writeExternal in interface java.io.Externalizable
readExternal
public final void readExternal(java.io.ObjectInput in)
throws java.io.IOException
- delegated to bit
- Specified by:
readExternal in interface java.io.Externalizable
readExternalFromArray
public final void readExternalFromArray(org.apache.derby.iapi.services.io.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().
- Specified by:
readExternalFromArray in interface DataValueDescriptor
readBinaryLength
private static int readBinaryLength(java.io.ObjectInput in)
throws java.io.IOException
readFromStream
private void readFromStream(java.io.InputStream in)
throws java.io.IOException
restoreToNull
public final void restoreToNull()
- Description copied from interface:
org.apache.derby.iapi.services.io.Storable
- Restore this object to its (SQL)null value.
- Specified by:
restoreToNull in interface org.apache.derby.iapi.services.io.Storable
compare
public final boolean compare(int op,
DataValueDescriptor other,
boolean orderedNulls,
boolean unknownRV)
throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
DataValueDescriptor
- Compare this Orderable with a given Orderable for the purpose of
qualification and sorting. The caller gets to determine how nulls
should be treated - they can either be ordered values or unknown
values.
- Specified by:
compare in interface DataValueDescriptor- Overrides:
compare in class DataType
compare
public final int compare(DataValueDescriptor other)
throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
DataValueDescriptor
- Compare this Orderable with a given Orderable for the purpose of
index positioning. This method treats nulls as ordered values -
that is, it treats SQL null as equal to null and less than all
other values.
- Specified by:
compare in interface DataValueDescriptor
cloneObject
public final java.lang.Object cloneObject()
- From CloneableObject
Shallow clone a StreamStorable without objectifying. This is used to avoid
unnecessary objectifying of a stream object. The only difference of this method
from getClone is this method does not objectify a stream. beetle 4896
- Specified by:
cloneObject in interface CloneableObject- Overrides:
cloneObject in class DataType
getClone
public final 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.
- Specified by:
getClone in interface DataValueDescriptor
returnStream
public final java.io.InputStream returnStream()
- Description copied from interface:
org.apache.derby.iapi.services.io.StreamStorable
- Return the stream state of the object.
- Specified by:
returnStream in interface org.apache.derby.iapi.services.io.StreamStorable
setStream
public final void setStream(java.io.InputStream newStream)
- Description copied from interface:
org.apache.derby.iapi.services.io.StreamStorable
- sets the stream state for the object.
- Specified by:
setStream in interface org.apache.derby.iapi.services.io.StreamStorable
loadStream
public final void loadStream()
throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
org.apache.derby.iapi.services.io.StreamStorable
- sets the stream state for the object.
- Specified by:
loadStream in interface org.apache.derby.iapi.services.io.StreamStorable
objectNull
boolean objectNull(java.lang.Object o)
setValue
public final void setValue(java.io.InputStream theStream,
int streamLength)
- Description copied from interface:
DataValueDescriptor
- Set the value to be the contents of the stream.
The reading of the stream may be delayed until execution time.
The format of the stream is required to be the format of this type.
- Specified by:
setValue in interface DataValueDescriptor- Overrides:
setValue in class DataType
setFrom
protected final void setFrom(DataValueDescriptor theValue)
throws org.apache.derby.iapi.error.StandardException
- Overrides:
setFrom in class DataType
equals
public final BooleanDataValue equals(DataValueDescriptor left,
DataValueDescriptor right)
throws org.apache.derby.iapi.error.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
notEquals
public final BooleanDataValue notEquals(DataValueDescriptor left,
DataValueDescriptor right)
throws org.apache.derby.iapi.error.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
lessThan
public final BooleanDataValue lessThan(DataValueDescriptor left,
DataValueDescriptor right)
throws org.apache.derby.iapi.error.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
greaterThan
public final BooleanDataValue greaterThan(DataValueDescriptor left,
DataValueDescriptor right)
throws org.apache.derby.iapi.error.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
lessOrEquals
public final BooleanDataValue lessOrEquals(DataValueDescriptor left,
DataValueDescriptor right)
throws org.apache.derby.iapi.error.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
greaterOrEquals
public final BooleanDataValue greaterOrEquals(DataValueDescriptor left,
DataValueDescriptor right)
throws org.apache.derby.iapi.error.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
charLength
public final NumberDataValue charLength(NumberDataValue result)
throws org.apache.derby.iapi.error.StandardException
- This method implements the char_length function for bit.
- Specified by:
charLength in interface ConcatableDataValue
concatenate
public final BitDataValue concatenate(BitDataValue left,
BitDataValue right,
BitDataValue result)
throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
BitDataValue
- The SQL concatenation '||' operator.
- Specified by:
concatenate in interface BitDataValue
substring
public final ConcatableDataValue substring(NumberDataValue start,
NumberDataValue length,
ConcatableDataValue result,
int maxLen)
throws org.apache.derby.iapi.error.StandardException
- The SQL substr() function.
- Specified by:
substring in interface ConcatableDataValue
checkHostVariable
public final void checkHostVariable(int declaredLength)
throws org.apache.derby.iapi.error.StandardException
- Host variables are rejected if their length is
bigger than the declared length, regardless of
if the trailing bytes are the pad character.
- Specified by:
checkHostVariable in interface DataValueDescriptor- Overrides:
checkHostVariable in class DataType
toString
public final java.lang.String toString()
- Description copied from class:
java.lang.Object
- Convert this Object to a human-readable String.
There are no limits placed on how long this String
should be or what it should contain. We suggest you
make it as intuitive as possible to be able to place
it into System.out.println() 55
and such.
It is typical, but not required, to ensure that this method
never completes abruptly with a java.lang.RuntimeException.
This method will be called when performing string
concatenation with this object. If the result is
null, string concatenation will instead
use "null".
The default implementation returns
getClass().getName() + "@" +
Integer.toHexString(hashCode()).
hashCode
public final int hashCode()
- Description copied from class:
java.lang.Object
- Get a value that represents this Object, as uniquely as
possible within the confines of an int.
There are some requirements on this method which
subclasses must follow:
- Semantic equality implies identical hashcodes. In other
words, if
a.equals(b) is true, then
a.hashCode() == b.hashCode() must be as well.
However, the reverse is not necessarily true, and two
objects may have the same hashcode without being equal.
- It must be consistent. Whichever value o.hashCode()
returns on the first invocation must be the value
returned on all later invocations as long as the object
exists. Notice, however, that the result of hashCode may
change between separate executions of a Virtual Machine,
because it is not invoked on the same object.
Notice that since hashCode is used in
java.util.Hashtable and other hashing classes,
a poor implementation will degrade the performance of hashing
(so don't blindly implement it as returning a constant!). Also,
if calculating the hash is time-consuming, a class may consider
caching the results.
The default implementation returns
System.identityHashCode(this)
compare
private static int compare(byte[] left,
byte[] right)
setInto
public void setInto(java.sql.PreparedStatement ps,
int position)
throws java.sql.SQLException,
org.apache.derby.iapi.error.StandardException
- Adding this method to ensure that super class' setInto method doesn't get called
that leads to the violation of JDBC spec( untyped nulls ) when batching is turned on.
- Specified by:
setInto in interface DataValueDescriptor- Overrides:
setInto in class DataType