Top Description Fields Constructors Methods
org.apache.derby.iapi.types

pack-priv abstract Class SQLBinary

extends DataType
implements BitDataValue
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.types.BitDataValue, org.apache.derby.iapi.services.io.StreamStorable, org.apache.derby.iapi.types.ConcatableDataValue, org.apache.derby.iapi.types.VariableSizeDataValue, org.apache.derby.iapi.types.DataValueDescriptor, org.apache.derby.iapi.types.Orderable, org.apache.derby.iapi.services.io.Storable, org.apache.derby.iapi.services.io.Formatable, org.apache.derby.iapi.services.io.TypedFormat, java.io.Externalizable, java.io.Serializable
Known Direct Subclasses
org.apache.derby.iapi.types.SQLBit, org.apache.derby.iapi.types.SQLBlob
Imports
org.apache.derby.iapi.sql.conn.StatementContext, org.apache.derby.shared.common.reference.ContextId, .SQLState, .MessageId, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.context.ContextService, org.apache.derby.iapi.services.io.DerbyIOException, .StoredFormatIds, .FormatIdInputStream, .InputStreamUtil, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.i18n.MessageService, org.apache.derby.iapi.services.cache.ClassSize, java.io.ObjectOutput, .ObjectInput, .IOException, .InputStream, java.sql.Blob, .DataTruncation, .SQLException, .PreparedStatement

SQLBinary is the abstract class for the binary datatypes.

Format : <encoded length><raw data>
Length is encoded to support Cloudscape 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 (Cloudscape 5.x) style or a new Derby style. Derby then uses the next two bits to indicate how the length is encoded.
<encoded length> is one of N styles.


When the value was written from a byte array the Derby encoded byte length format was always used from Derby 10.0 onwards (ie. all open source versions).
When the value was written from a stream (e.g. PreparedStatement.setBinaryStream) then the Cloudscape '5.x format zero' was used by 10.0 and 10.1. The was due to the class RawToBinaryFormatStream always writing four zero bytes for the length before the data.
The Cloudscape '5.x format bits' format I think was never used by Derby.

Field Summary

Modifier and TypeField and Description
pack-priv Blob
private static final int
pack-priv byte[]
private static final int
pack-priv static final byte
pack-priv InputStream
stream

Value as a stream, this stream represents the on-disk format of the value.

pack-priv int
streamValueLength

Length of the value in bytes when this value is set as a stream.

Constructor Summary

AccessConstructor and Description
pack-priv
SQLBinary()

Create a binary value set to NULL

pack-priv
SQLBinary(byte[] val)

pack-priv

Method Summary

Modifier and TypeMethod and Description
public final NumberDataValue

Returns:

A SQLInteger containing the length of the char value
charLength
(NumberDataValue
The result of a previous call to this method, null if not called yet
result
)

Implements org.apache.derby.iapi.types.ConcatableDataValue.charLength.

This method implements the char_length function for bit.

public final void
checkHostVariable(int declaredLength)

Overrides org.apache.derby.iapi.types.DataType.checkHostVariable.

Implements org.apache.derby.iapi.types.DataValueDescriptor.checkHostVariable.

Host variables are rejected if their length is bigger than the declared length, regardless of if the trailing bytes are the pad character.

public final DataValueDescriptor
cloneHolder()

Overrides org.apache.derby.iapi.types.DataType.cloneHolder.

Implements org.apache.derby.iapi.types.DataValueDescriptor.cloneHolder.

Shallow clone a StreamStorable without objectifying.

public DataValueDescriptor
cloneValue(boolean
any streams representing the data value will be materialized if true, the data value will be kept as a stream if possible if false
forceMaterialization
)

Implements org.apache.derby.iapi.types.DataValueDescriptor.cloneValue.

Clone this DataValueDescriptor.

public final boolean
compare(int
Orderable.ORDER_OP_EQUALS means do an = comparison. Orderable.ORDER_OP_LESSTHAN means compare this < other. Orderable.ORDER_OP_LESSOREQUALS means compare this <= other.
op
,
DataValueDescriptor
The DataValueDescriptor to compare this one to.
other
,
boolean
True means to treat nulls as ordered values, that is, treat SQL null as equal to null, and less than all other values. False means to treat nulls as unknown values, that is, the result of any comparison with a null is the UNKNOWN truth value.
orderedNulls
,
boolean
The return value to use if the result of the comparison is the UNKNOWN truth value. In other words, if orderedNulls is false, and a null is involved in the comparison, return unknownRV. This parameter is not used orderedNulls is true.
unknownRV
)

Overrides org.apache.derby.iapi.types.DataType.compare.

Implements org.apache.derby.iapi.types.DataValueDescriptor.compare.

Compare this Orderable with a given Orderable for the purpose of qualification and sorting.

public final int
compare(DataValueDescriptor
The Orderable to compare this one to.
other
)

Implements org.apache.derby.iapi.types.DataValueDescriptor.compare.

Compare this Orderable with a given Orderable for the purpose of index positioning.

private static int
compare(byte[] left, byte[] right)

public final BitDataValue
concatenate(BitDataValue
String on the left hand side of '||'
left
,
BitDataValue
String on the right hand side of '||'
right
,
BitDataValue
The result of a previous call to this method, null if not called yet.
result
)

Implements org.apache.derby.iapi.types.BitDataValue.concatenate.

The SQL concatenation '||' operator.

public final BooleanDataValue

Returns:

A SQL boolean value telling whether the two parameters are equal
equals
(DataValueDescriptor
The value on the left side of the =
left
,
DataValueDescriptor
The value on the right side of the = is not.
right
)

Overrides org.apache.derby.iapi.types.DataType.equals.

Implements org.apache.derby.iapi.types.DataValueDescriptor.equals.

The = operator as called from the language module, as opposed to the storage module.

public int
estimateMemoryUsage()

Implements org.apache.derby.iapi.types.DataValueDescriptor.estimateMemoryUsage.

Estimate the memory usage in bytes of the data value and the overhead of the class.

private int
public final byte[]
getBytes()

Overrides org.apache.derby.iapi.types.DataType.getBytes.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getBytes.

Gets the value in the data value descriptor as a byte array.

public final int
pack-priv abstract int
getMaxMemoryUsage()

Return max memory usage for a SQL Binary

public final InputStream
getStream()

Overrides org.apache.derby.iapi.types.DataType.getStream.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getStream.

Gets the value in the data value descriptor as a stream of bytes.

public final String
getString()

Implements org.apache.derby.iapi.types.DataValueDescriptor.getString.

Used by JDBC -- string should not contain SQL92 formatting.

public final String

Returns:

a trace representation of this SQL DataType.
getTraceString
()

Overrides org.apache.derby.iapi.types.DataType.getTraceString.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getTraceString.

Gets a trace representation for debugging.

pack-priv byte[]
public final BooleanDataValue

Returns:

A SQL boolean value telling whether the first operand is greater than or equal to the second operand
greaterOrEquals
(DataValueDescriptor
The value on the left side of the >=
left
,
DataValueDescriptor
The value on the right side of the >=
right
)

Overrides org.apache.derby.iapi.types.DataType.greaterOrEquals.

Implements org.apache.derby.iapi.types.DataValueDescriptor.greaterOrEquals.

The >= operator as called from the language module, as opposed to the storage module.

public final BooleanDataValue

Returns:

A SQL boolean value telling whether the first operand is greater than the second operand
greaterThan
(DataValueDescriptor
The value on the left side of the operator
left
,
DataValueDescriptor
The value on the right side of the operator
right
)

Overrides org.apache.derby.iapi.types.DataType.greaterThan.

Implements org.apache.derby.iapi.types.DataValueDescriptor.greaterThan.

The > operator as called from the language module, as opposed to the storage module.

public final int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public final boolean
isNull()

Implements org.apache.derby.iapi.services.io.Storable.isNull.

see if the Bit value is null.

public final BooleanDataValue

Returns:

A SQL boolean value telling whether the first operand is less than or equal to the second operand
lessOrEquals
(DataValueDescriptor
The value on the left side of the operator
left
,
DataValueDescriptor
The value on the right side of the operator
right
)

Overrides org.apache.derby.iapi.types.DataType.lessOrEquals.

Implements org.apache.derby.iapi.types.DataValueDescriptor.lessOrEquals.

The <= operator as called from the language module, as opposed to the storage module.

public final BooleanDataValue

Returns:

A SQL boolean value telling whether the first operand is less than the second operand
lessThan
(DataValueDescriptor
The value on the left side of the operator
left
,
DataValueDescriptor
The value on the right side of the operator
right
)

Overrides org.apache.derby.iapi.types.DataType.lessThan.

Implements org.apache.derby.iapi.types.DataValueDescriptor.lessThan.

The < operator as called from the language module, as opposed to the storage module.

public final void
loadStream()

Implements org.apache.derby.iapi.services.io.StreamStorable.loadStream.

Set the value by reading the stream and converting it to an object form.

public final BooleanDataValue

Returns:

A SQL boolean value telling whether the two parameters are not equal
notEquals
(DataValueDescriptor
The value on the left side of the operator
left
,
DataValueDescriptor
The value on the right side of the operator
right
)

Overrides org.apache.derby.iapi.types.DataType.notEquals.

Implements org.apache.derby.iapi.types.DataValueDescriptor.notEquals.

The <> operator as called from the language module, as opposed to the storage module.

pack-priv boolean
private static int
readBinaryLength(ObjectInput in)

Read the encoded length of the value from the on-disk format.

public final void
readExternal(ObjectInput
the stream to read data from in order to restore the object
in
)

Implements java.io.Externalizable.readExternal.

delegated to bit

private void
readFromStream(InputStream in)

Read the value from an input stream.

public final void
restoreToNull()

Implements org.apache.derby.iapi.services.io.Storable.restoreToNull.

Restore this object to its (SQL)null value.

public final InputStream
returnStream()

Implements org.apache.derby.iapi.services.io.StreamStorable.returnStream.

Return the on-disk stream state of the object.

protected final void
setFrom(DataValueDescriptor
The DataValueDescriptor that holds the value to which we want to set this DataValueDescriptor's value.
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setFrom.

Set the value of this DataValueDescriptor based on the value of the specified DataValueDescriptor.

public void
setInto(PreparedStatement ps, int position)

Overrides org.apache.derby.iapi.types.DataType.setInto.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setInto.

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.

public final void
setStream(InputStream
The new stream to use
newStream
)

Implements org.apache.derby.iapi.services.io.StreamStorable.setStream.

Set me to the value represented by this stream.

public final void
setValue(byte[]
The byte value to set this DataValueDescriptor to
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Set the value of this DataValueDescriptor.

public final void
setValue(Blob
The Blob value to set this DataValueDescriptor to
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.BitDataValue.setValue, org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Stuff a BitDataValue with a Blob.

public final void
setValue(InputStream
On disk format of the stream
theStream
,
int
length of the logical value in bytes, or DataValueDescriptor.UNKNOWN_LOGICAL_LENGTH
valueLength
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Set the value from the stream which is in the on-disk format.

public final ConcatableDataValue

Returns:

A ConcatableDataValue containing the result of the substr()
substring
(NumberDataValue
Start of substr
start
,
NumberDataValue
Length of substr
length
,
ConcatableDataValue
The result of a previous call to this method, null if not called yet.
result
,
int
Maximum length of the result
maxLen
)

Implements org.apache.derby.iapi.types.ConcatableDataValue.substring.

The SQL substr() function.

private void
public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv void
truncate(int
the original width in bytes (only used for diagnostics, ignored if warn is false)
sourceWidth
,
int
the desired width in bytes
desiredWidth
,
boolean
whether or not to generate a truncation warning
warn
)

Truncate this value to the desired width by removing bytes at the end of the byte sequence.

private void
writeBlob(ObjectOutput out)

Serialize a blob using the 8.1 encoding.

public final void
writeExternal(ObjectOutput
the stream to write the object to
out
)

Implements java.io.Externalizable.writeExternal.

Write the value out from the byte array (not called if null) using the 8.1 encoding.

private void
writeLength(ObjectOutput out, int len)

Write the length if using the 8.1 encoding.

Inherited from org.apache.derby.iapi.types.DataType:
coalescecomparecomparecompareTodataTypeConversionequalsflipgenericSetObjectgetBooleangetBytegetDategetDoublegetFloatgetIntgetLonggetObjectgetShortgetTimegetTimestampgetTypeNamehasStreamininvalidFormatisNotNullisNullOpnormalizeoutOfRangereadExternalFromArrayrecyclesetBigDecimalsetIntosetObjectsetObjectForCastsetToNullsetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuethrowLangSetMismatchthrowLangSetMismatchtypePrecedencetypeToBigDecimal