java.io.Externalizable
, java.io.Serializable
, java.lang.Comparable
, Formatable
, Storable
, StreamStorable
, TypedFormat
, BitDataValue
, ConcatableDataValue
, DataValueDescriptor
, Orderable
, VariableSizeDataValue
abstract class SQLBinary extends DataType implements BitDataValue
Format :
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.
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.
Modifier and Type | Field | Description |
---|---|---|
(package private) java.sql.Blob |
_blobValue |
|
private static int |
BASE_MEMORY_USAGE |
|
(package private) byte[] |
dataValue |
|
private static int |
LEN_OF_BUFFER_TO_WRITE_BLOB |
|
(package private) static byte |
PAD |
|
(package private) java.io.InputStream |
stream |
Value as a stream, this stream represents the on-disk
format of the value.
|
(package private) int |
streamValueLength |
Length of the value in bytes when this value
is set as a stream.
|
UNKNOWN_LOGICAL_LENGTH
ORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHAN
IGNORE_PRECISION
Constructor | Description |
---|---|
SQLBinary() |
Create a binary value set to NULL
|
SQLBinary(byte[] val) |
|
SQLBinary(java.sql.Blob val) |
Modifier and Type | Method | Description |
---|---|---|
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.
|
DataValueDescriptor |
cloneHolder() |
Shallow clone a StreamStorable without objectifying.
|
DataValueDescriptor |
cloneValue(boolean forceMaterialization) |
Clone this DataValueDescriptor.
|
private static int |
compare(byte[] left,
byte[] right) |
|
boolean |
compare(int op,
DataValueDescriptor other,
boolean orderedNulls,
boolean unknownRV) |
Compare this Orderable with a given Orderable for the purpose of
qualification and sorting.
|
int |
compare(DataValueDescriptor other) |
Compare this Orderable with a given Orderable for the purpose of
index positioning.
|
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.
|
private int |
getBlobLength() |
|
byte[] |
getBytes() |
Gets the value in the data value descriptor as a byte[].
|
int |
getLength() |
length in bytes
|
(package private) abstract int |
getMaxMemoryUsage() |
Return max memory usage for a SQL Binary
|
java.io.InputStream |
getStream() |
Gets the value in the data stream descriptor as an InputStream.
|
java.lang.String |
getString() |
Used by JDBC -- string should not contain
SQL92 formatting.
|
java.lang.String |
getTraceString() |
Gets a trace representation for debugging.
|
(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() |
|
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() |
Set the value by reading the stream and
converting it to an object form.
|
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) |
Read the encoded length of the value from the on-disk format.
|
void |
readExternal(java.io.ObjectInput in) |
delegated to bit
|
private void |
readFromStream(java.io.InputStream in) |
Read the value from an input stream.
|
void |
restoreToNull() |
Restore this object to its (SQL)null value.
|
java.io.InputStream |
returnStream() |
Return the on-disk stream state of the object.
|
protected void |
setFrom(DataValueDescriptor theValue) |
Set the value of this DataValueDescriptor based on the value
of the specified DataValueDescriptor.
|
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) |
Set me to the value represented by this stream.
|
void |
setValue(byte[] theValue) |
Set the value of this DataValueDescriptor.
|
void |
setValue(java.io.InputStream theStream,
int valueLength) |
Set the value from the stream which is in the on-disk format.
|
void |
setValue(java.sql.Blob theValue) |
Set the value of this DataValueDescriptor.
|
ConcatableDataValue |
substring(NumberDataValue start,
NumberDataValue length,
ConcatableDataValue result,
int maxLen) |
The SQL substr() function.
|
private void |
throwStreamingIOException(java.io.IOException ioe) |
|
java.lang.String |
toString() |
|
(package private) void |
truncate(int sourceWidth,
int desiredWidth,
boolean warn) |
Truncate this value to the desired width by removing bytes at the
end of the byte sequence.
|
private void |
writeBlob(java.io.ObjectOutput out) |
Serialize a blob using the 8.1 encoding.
|
void |
writeExternal(java.io.ObjectOutput out) |
Write the value out from the byte array (not called if null)
using the 8.1 encoding.
|
private void |
writeLength(java.io.ObjectOutput out,
int len) |
Write the length if
using the 8.1 encoding.
|
coalesce, compare, compare, compareTo, dataTypeConversion, equals, flip, genericSetObject, getBoolean, getByte, getDate, getDouble, getFloat, getInt, getLong, getObject, getShort, getTime, getTimestamp, getTypeName, hasStream, in, invalidFormat, isNotNull, isNullOp, normalize, outOfRange, readExternalFromArray, recycle, setBigDecimal, setInto, setObject, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatch, typePrecedence, typeToBigDecimal
coalesce, compare, compare, getBoolean, getByte, getDate, getDouble, getFloat, getInt, getLong, getNewNull, getObject, getShort, getTime, getTimestamp, getTypeName, hasStream, in, isNotNull, isNullOp, normalize, readExternalFromArray, recycle, setBigDecimal, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueFromResultSet, typePrecedence, typeToBigDecimal
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getTypeFormatId
setWidth
static final byte PAD
private static final int BASE_MEMORY_USAGE
private static final int LEN_OF_BUFFER_TO_WRITE_BLOB
java.sql.Blob _blobValue
byte[] dataValue
java.io.InputStream stream
int streamValueLength
SQLBinary()
SQLBinary(byte[] val)
SQLBinary(java.sql.Blob val)
public int estimateMemoryUsage()
DataValueDescriptor
estimateMemoryUsage
in interface DataValueDescriptor
abstract int getMaxMemoryUsage()
public final void setValue(byte[] theValue)
DataType
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The byte value to set this DataValueDescriptor topublic final void setValue(java.sql.Blob theValue)
DataType
setValue
in interface BitDataValue
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The Blob value to set this DataValueDescriptor topublic final java.lang.String getString() throws StandardException
getString
in interface DataValueDescriptor
StandardException
- Thrown on errorpublic final java.io.InputStream getStream() throws StandardException
DataType
getStream
in interface DataValueDescriptor
getStream
in class DataType
StandardException
- Thrown on errorDataValueDescriptor.hasStream()
,
StringDataValue.getStreamWithDescriptor()
public final byte[] getBytes() throws StandardException
DataType
getBytes
in interface DataValueDescriptor
getBytes
in class DataType
StandardException
- Thrown on errorbyte[] getValue() throws StandardException
StandardException
public final int getLength() throws StandardException
getLength
in interface DataValueDescriptor
StandardException
- Thrown on errorprivate void throwStreamingIOException(java.io.IOException ioe) throws StandardException
StandardException
public final boolean isNull()
isNull
in interface Storable
Storable.isNull()
public final void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
- io exceptionprivate void writeBlob(java.io.ObjectOutput out) throws java.io.IOException
java.io.IOException
- io exceptionprivate void writeLength(java.io.ObjectOutput out, int len) throws java.io.IOException
java.io.IOException
- io exceptionpublic final void readExternal(java.io.ObjectInput in) throws java.io.IOException
readExternal
in interface java.io.Externalizable
java.io.IOException
- io exceptionjava.lang.ClassNotFoundException
- class not foundprivate static int readBinaryLength(java.io.ObjectInput in) throws java.io.IOException
java.io.IOException
SQLBinary
private void readFromStream(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public final void restoreToNull()
Storable
restoreToNull
in interface Storable
Storable.restoreToNull()
public final boolean compare(int op, DataValueDescriptor other, boolean orderedNulls, boolean unknownRV) throws StandardException
DataValueDescriptor
compare
in interface DataValueDescriptor
compare
in class DataType
op
- Orderable.ORDER_OP_EQUALS means do an = comparison.
Orderable.ORDER_OP_LESSTHAN means compare this < other.
Orderable.ORDER_OP_LESSOREQUALS means compare this <= other.other
- The DataValueDescriptor to compare this one to.orderedNulls
- 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.unknownRV
- 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.StandardException
- thrown on errorpublic final int compare(DataValueDescriptor other) throws StandardException
DataValueDescriptor
compare
in interface DataValueDescriptor
other
- The Orderable to compare this one to.StandardException
- thrown on errorpublic final DataValueDescriptor cloneHolder()
cloneHolder
in interface DataValueDescriptor
cloneHolder
in class DataType
public DataValueDescriptor cloneValue(boolean forceMaterialization)
DataValueDescriptor
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 if
forceMaterialization
is set to false
. An example is if
you need to access the value you just read using cloneValue
after the current transaction has ended, or after the source result set
has been closed.
cloneValue
in interface DataValueDescriptor
forceMaterialization
- any streams representing the data value will
be materialized if true
, the data value will be kept as a
stream if possible if false
DataValueDescriptor
with the same initial
value as this.DataValueDescriptor.cloneValue(boolean)
public final java.io.InputStream returnStream()
StreamStorable
returnStream
in interface StreamStorable
public final void setStream(java.io.InputStream newStream)
setStream
in interface StreamStorable
public final void loadStream() throws StandardException
StreamStorable
loadStream
in interface StreamStorable
StandardException
- on errorboolean objectNull(java.lang.Object o)
public final void setValue(java.io.InputStream theStream, int valueLength)
setValue
in interface DataValueDescriptor
setValue
in class DataType
theStream
- On disk format of the streamvalueLength
- length of the logical value in bytes, or
DataValueDescriptor.UNKNOWN_LOGICAL_LENGTH
protected final void setFrom(DataValueDescriptor theValue) throws StandardException
DataType
setFrom
in class DataType
theValue
- The DataValueDescriptor that holds the value to
which we want to set this DataValueDescriptor's value.StandardException
public final BooleanDataValue equals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
equals
in interface DataValueDescriptor
equals
in class DataType
left
- The value on the left side of the =right
- The value on the right side of the =
is not.StandardException
- Thrown on errorpublic final BooleanDataValue notEquals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
notEquals
in interface DataValueDescriptor
notEquals
in class DataType
left
- The value on the left side of the operatorright
- The value on the right side of the operatorStandardException
- Thrown on errorpublic final BooleanDataValue lessThan(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
lessThan
in interface DataValueDescriptor
lessThan
in class DataType
left
- The value on the left side of the operatorright
- The value on the right side of the operatorStandardException
- Thrown on errorpublic final BooleanDataValue greaterThan(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
greaterThan
in interface DataValueDescriptor
greaterThan
in class DataType
left
- The value on the left side of the operatorright
- The value on the right side of the operatorStandardException
- Thrown on errorpublic final BooleanDataValue lessOrEquals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
lessOrEquals
in interface DataValueDescriptor
lessOrEquals
in class DataType
left
- The value on the left side of the operatorright
- The value on the right side of the operatorStandardException
- Thrown on errorpublic final BooleanDataValue greaterOrEquals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
greaterOrEquals
in interface DataValueDescriptor
greaterOrEquals
in class DataType
left
- The value on the left side of the >=right
- The value on the right side of the >=StandardException
- Thrown on errorpublic final NumberDataValue charLength(NumberDataValue result) throws StandardException
charLength
in interface ConcatableDataValue
result
- The result of a previous call to this method, null
if not called yetStandardException
- Thrown on errorConcatableDataValue.charLength(org.apache.derby.iapi.types.NumberDataValue)
public final BitDataValue concatenate(BitDataValue left, BitDataValue right, BitDataValue result) throws StandardException
BitDataValue
concatenate
in interface BitDataValue
left
- String on the left hand side of '||'right
- String on the right hand side of '||'result
- The result of a previous call to this method,
null if not called yet.StandardException
- Thrown on errorBitDataValue.concatenate(org.apache.derby.iapi.types.BitDataValue, org.apache.derby.iapi.types.BitDataValue, org.apache.derby.iapi.types.BitDataValue)
public final ConcatableDataValue substring(NumberDataValue start, NumberDataValue length, ConcatableDataValue result, int maxLen) throws StandardException
substring
in interface ConcatableDataValue
start
- Start of substrlength
- Length of substrresult
- The result of a previous call to this method,
null if not called yet.maxLen
- Maximum length of the resultStandardException
- Thrown on errorpublic final void checkHostVariable(int declaredLength) throws StandardException
checkHostVariable
in interface DataValueDescriptor
checkHostVariable
in class DataType
StandardException
- Variable is too big.public final java.lang.String toString()
toString
in class java.lang.Object
public final int hashCode()
hashCode
in class java.lang.Object
private static int compare(byte[] left, byte[] right)
public void setInto(java.sql.PreparedStatement ps, int position) throws java.sql.SQLException, StandardException
setInto
in interface DataValueDescriptor
setInto
in class DataType
java.sql.SQLException
- thrown by the PreparedStatement objectStandardException
- thrown by me accessing my value.public final java.lang.String getTraceString() throws StandardException
getTraceString
in interface DataValueDescriptor
getTraceString
in class DataType
StandardException
- if getting the data value fails.DataValueDescriptor.getString()
private int getBlobLength() throws StandardException
StandardException
void truncate(int sourceWidth, int desiredWidth, boolean warn) throws StandardException
sourceWidth
- the original width in bytes (only used for
diagnostics, ignored if warn
is false
)desiredWidth
- the desired width in byteswarn
- whether or not to generate a truncation warningStandardException
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.