org.apache.derby.iapi.types
Class SQLChar

java.lang.Object
  extended byorg.apache.derby.iapi.types.DataType
      extended byorg.apache.derby.iapi.types.SQLChar
All Implemented Interfaces:
CloneableObject, ConcatableDataValue, DataValueDescriptor, java.io.Externalizable, Formatable, Orderable, java.io.Serializable, Storable, StreamStorable, StringDataValue, TypedFormat, VariableSizeDataValue
Direct Known Subclasses:
SQLNationalChar, SQLVarchar

public class SQLChar
extends DataType
implements StringDataValue, StreamStorable

SQLChar satisfies the DataValueDescriptor interfaces (i.e., OrderableDataType). It implements an 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 OrderableDataType is a subclass of DataType, SQLChar can play a role in either a DataType/ValueRow or a OrderableDataType/KeyRow, interchangeably.

See Also:
Serialized Form

Field Summary
(package private)  char[][] arg_passer
           
private static int BASE_MEMORY_USAGE
           
private static char[] BLANKS
          Static array that can be used for blank padding.
private  java.text.CollationKey cKey
           
private static int GROWBY_FOR_CHAR
          when we know that the array needs to grow by at least one byte, it is not performant to grow by just one byte instead this amount is used to provide a reasonable growby size.
private  int[] intArray
           
private  int intLength
           
private  LocaleFinder localeFinder
           
private  char[] rawData
           
private  int rawLength
           
protected static int RETURN_SPACE_THRESHOLD
          threshold, that decides when we return space back to the VM see getString() where it is used
protected  java.io.InputStream stream
           
private  java.lang.String value
           
 
Fields inherited from interface org.apache.derby.iapi.types.StringDataValue
BOTH, LEADING, TRAILING
 
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
SQLChar()
          no-arg constructor, required by Formattable.
SQLChar(java.lang.String val)
           
 
Method Summary
static void appendBlanks(char[] ca, int offset, int howMany)
           
 NumberDataValue charLength(NumberDataValue result)
          This method implements the char_length function for char.
 java.lang.Object cloneObject()
          From CloneableObject Shallow clone a StreamStorable without objectifying.
 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.
 StringDataValue concatenate(StringDataValue leftOperand, StringDataValue rightOperand, StringDataValue result)
          The SQL concatenation '||' operator.
protected  void copyState(SQLChar other)
           
 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  void formatJDBCDate(java.util.Calendar cal, java.lang.StringBuffer sb)
           
private  void formatJDBCTime(java.util.Calendar cal, java.lang.StringBuffer sb)
           
 boolean getBoolean()
          Gets the value in the data value descriptor as a boolean.
 byte getByte()
          Gets the value in the data value descriptor as a byte.
 char[] getCharArray()
          Get a char array.
 DataValueDescriptor getClone()
          Clone this DataValueDescriptor.
protected  java.text.CollationKey getCollationKey()
           
 java.sql.Date getDate(java.util.Calendar cal)
          Gets the value in the data value descriptor as a java.sql.Date.
static java.sql.Date getDate(java.util.Calendar cal, java.lang.String str, LocaleFinder localeFinder)
           
protected  java.text.DateFormat getDateFormat()
           
protected  java.text.DateFormat getDateFormat(java.util.Calendar cal)
           
 double getDouble()
          Gets the value in the data value descriptor as a double.
 float getFloat()
          Gets the value in the data value descriptor as a float.
 int getInt()
          Gets the value in the data value descriptor as an int.
private  int[] getIntArray()
           
private  int getIntLength()
           
 int getLength()
          Gets the length of the data value.
private  java.util.Locale getLocale()
           
protected  LocaleFinder getLocaleFinder()
           
 long getLong()
          Gets the value in the data value descriptor as a long.
 DataValueDescriptor getNewNull()
          Get a new null value of the same type as this data value.
protected  StringDataValue getNewVarchar()
          Get a SQLVarchar for a built-in string function.
 java.lang.Object getObject()
          Gets the value in the data value descriptor as a Java Object.
 short getShort()
          Gets the value in the data value descriptor as a short.
 java.io.InputStream getStream()
          Gets the value in the data value descriptor as a Java InputStream.
 java.lang.String getString()
          If possible, use getCharArray() if you don't really need a string.
 java.sql.Time getTime(java.util.Calendar cal)
          Gets the value in the data value descriptor as a java.sql.Time.
static java.sql.Time getTime(java.util.Calendar cal, java.lang.String str, LocaleFinder localeFinder)
           
protected  java.text.DateFormat getTimeFormat()
           
protected  java.text.DateFormat getTimeFormat(java.util.Calendar cal)
           
 java.sql.Timestamp getTimestamp(java.util.Calendar cal)
          Gets the value in the data value descriptor as a java.sql.Timestamp.
static java.sql.Timestamp getTimestamp(java.util.Calendar cal, java.lang.String str, LocaleFinder localeFinder)
           
protected  java.text.DateFormat getTimestampFormat()
           
protected  java.text.DateFormat getTimestampFormat(java.util.Calendar cal)
           
 int getTypeFormatId()
          Return my format identifier.
 java.lang.String getTypeName()
          Get the SQL name of the datatype
 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.
protected  int growBy()
          returns the reasonable minimum amount by which the array can grow .
 int hashCode()
           
protected  void hasNonBlankChars(java.lang.String source, int start, int end)
           
protected  boolean isNationalString()
          Return whether or not this is a national character datatype.
 boolean isNull()
          see if the String 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.
 BooleanDataValue like(DataValueDescriptor pattern)
          This method implements the like function for char (with no escape value).
 BooleanDataValue like(DataValueDescriptor pattern, DataValueDescriptor escape)
          This method implements the like function for char with an escape value.
 void loadStream()
          sets the stream state for the object.
 NumberDataValue locate(StringDataValue searchFrom, NumberDataValue start, NumberDataValue result)
          This method implements the locate function for char.
 StringDataValue lower(StringDataValue result)
          Convert the string to lower case.
protected  java.sql.Date nationalGetDate(java.util.Calendar cal)
          This implements getDate() for the national types.
protected  java.sql.Time nationalGetTime(java.util.Calendar cal)
          This implements getTime() for the national types.
protected  java.sql.Timestamp nationalGetTimestamp(java.util.Calendar cal)
          This implements getTimestamp() for the national types.
protected  int nationalHashCode()
          Implementation of hashCode() for the national character types, put here to make it accessible to all the national types.
 void normalize(DataTypeDescriptor desiredType, DataValueDescriptor source)
          Normalization method - this method may be called when putting a value into a SQLChar, for example, when inserting into a SQLChar column.
protected  void normalize(DataTypeDescriptor desiredType, java.lang.String sourceValue)
           
 BooleanDataValue notEquals(DataValueDescriptor left, DataValueDescriptor right)
          The <> operator as called from the language module, as opposed to the storage module.
 void readExternal(java.io.ObjectInput in)
           
 void readExternalFromArray(ArrayInputStream in)
          Reads in a string from the specified data input stream.
 void restoreToNull()
          Restore this object to its (SQL)null value.
 java.io.InputStream returnStream()
          Return the stream state of the object.
private  void setAsToNationalString(java.lang.Object theValue)
           
 void setBigDecimal(java.lang.Number bigDecimal)
          Only to be called when an application through JDBC is setting a SQLChar to a java.math.BigDecimal.
private  java.text.DateFormat setDateFormatCalendar(java.text.DateFormat df, java.util.Calendar cal)
           
protected  void setFrom(DataValueDescriptor theValue)
           
 void setInto(java.sql.PreparedStatement ps, int position)
          Set the value into a PreparedStatement.
protected  void setLocaleFinder(LocaleFinder localeFinder)
           
 void setStream(java.io.InputStream newStream)
          sets the stream state for the object.
 void setValue(boolean theValue)
          Set the value.
 void setValue(byte theValue)
          Set the value of this DataValueDescriptor to the given byte value
 void setValue(byte[] theValue)
          Set the value of this DataValueDescriptor.
 void setValue(java.sql.Date theValue, java.util.Calendar cal)
          Set the value of this DataValueDescriptor.
 void setValue(double theValue)
          Set the value of this DataValueDescriptor to the given double value
 void setValue(float theValue)
          Set the value of this DataValueDescriptor to the given double value
 void setValue(java.io.InputStream theStream, int streamLength)
          Set the value to be the contents of the stream.
 void setValue(int theValue)
          Set the value of this DataValueDescriptor to the given int value
 void setValue(long theValue)
          Set the value of this DataValueDescriptor to the given long value
 void setValue(java.lang.Object theValue)
          Set the value of this DataValueDescriptor to the given value
 void setValue(short theValue)
          Set the value of this DataValueDescriptor to the given short value
 void setValue(java.lang.String theValue)
          Set the value of this DataValueDescriptor.
 void setValue(java.sql.Time theValue, java.util.Calendar cal)
          Set the value of this DataValueDescriptor.
 void setValue(java.sql.Timestamp theValue, java.util.Calendar cal)
          Set the value of this DataValueDescriptor.
 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.
protected  int stringCollatorCompare(SQLChar str2)
          Compare a localized string with this one.
protected static int stringCompare(char[] op1, int leftlen, char[] op2, int rightlen)
          Compare two Strings using standard SQL semantics.
protected  int stringCompare(SQLChar char1, SQLChar char2)
          Compare two SQLChars.
protected static int stringCompare(java.lang.String op1, java.lang.String op2)
          Compare two Strings using standard SQL semantics.
 ConcatableDataValue substring(NumberDataValue start, NumberDataValue length, ConcatableDataValue result, int maxLen)
          The SQL substr() function.
 java.lang.String toString()
           
 StringDataValue trim(int trimType, StringDataValue result)
          The SQL trim(), ltrim() and rtrim() functions.
 int typePrecedence()
          Each built-in type in JSQL has a precedence.
 int typeToBigDecimal()
          CHAR/VARCHAR/LONG VARCHAR implementation.
 StringDataValue upper(StringDataValue result)
          Convert the string to upper case.
 void writeExternal(java.io.ObjectOutput out)
          The maximum stored size is based upon the UTF format used to stored the String.
 XMLDataValue XMLParse(XMLDataValue result, boolean preserveWS)
           
 
Methods inherited from class org.apache.derby.iapi.types.DataType
checkHostVariable, coalesce, dataTypeConversion, equals, flip, genericSetObject, getBytes, getNationalString, in, invalidFormat, isNotNull, isNullOp, outOfRange, setInto, setObjectForCast, setToNull, 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
checkHostVariable, coalesce, getBytes, in, isNotNull, isNullOp, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue
 

Field Detail

RETURN_SPACE_THRESHOLD

protected static final int RETURN_SPACE_THRESHOLD
threshold, that decides when we return space back to the VM see getString() where it is used

See Also:
Constant Field Values

GROWBY_FOR_CHAR

private static final int GROWBY_FOR_CHAR
when we know that the array needs to grow by at least one byte, it is not performant to grow by just one byte instead this amount is used to provide a reasonable growby size.

See Also:
Constant Field Values

BLANKS

private static final char[] BLANKS
Static array that can be used for blank padding.


arg_passer

char[][] arg_passer

value

private java.lang.String value

rawData

private char[] rawData

rawLength

private int rawLength

cKey

private java.text.CollationKey cKey

stream

protected java.io.InputStream stream

intArray

private int[] intArray

intLength

private int intLength

localeFinder

private LocaleFinder localeFinder

BASE_MEMORY_USAGE

private static final int BASE_MEMORY_USAGE
Constructor Detail

SQLChar

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


SQLChar

public SQLChar(java.lang.String val)
Method Detail

appendBlanks

public static void appendBlanks(char[] ca,
                                int offset,
                                int howMany)

getBoolean

public boolean getBoolean()
                   throws StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a boolean. Throws an exception if the data value is not a boolean. For DataValueDescriptor, this is the preferred interface for BIT, but for this no-casting interface, it isn't, because BIT is stored internally as a Bit, not as a Boolean.

Specified by:
getBoolean in interface DataValueDescriptor
Overrides:
getBoolean in class DataType
Returns:
The data value as a boolean.
Throws:
StandardException - Thrown on error
See Also:
DataValueDescriptor.getBoolean()

getByte

public byte getByte()
             throws StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a byte. Throws an exception if the data value is not a byte.

Specified by:
getByte in interface DataValueDescriptor
Overrides:
getByte in class DataType
Returns:
The data value as a byte.
Throws:
StandardException - thrown on failure to convert
See Also:
DataValueDescriptor.getByte()

getShort

public short getShort()
               throws StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a short. Throws an exception if the data value is not a short.

Specified by:
getShort in interface DataValueDescriptor
Overrides:
getShort in class DataType
Returns:
The data value as a short.
Throws:
StandardException - thrown on failure to convert
See Also:
DataValueDescriptor.getShort()

getInt

public int getInt()
           throws StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as an int. Throws an exception if the data value is not an int.

Specified by:
getInt in interface DataValueDescriptor
Overrides:
getInt in class DataType
Returns:
The data value as a int.
Throws:
StandardException - thrown on failure to convert
See Also:
DataValueDescriptor.getInt()

getLong

public long getLong()
             throws StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a long. Throws an exception if the data value is not a long.

Specified by:
getLong in interface DataValueDescriptor
Overrides:
getLong in class DataType
Returns:
The data value as a long.
Throws:
StandardException - thrown on failure to convert
See Also:
DataValueDescriptor.getLong()

getFloat

public float getFloat()
               throws StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a float. Throws an exception if the data value is not a float.

Specified by:
getFloat in interface DataValueDescriptor
Overrides:
getFloat in class DataType
Returns:
The data value as a float.
Throws:
StandardException - thrown on failure to convert
See Also:
DataValueDescriptor.getFloat()

getDouble

public double getDouble()
                 throws StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a double. Throws an exception if the data value is not a double.

Specified by:
getDouble in interface DataValueDescriptor
Overrides:
getDouble in class DataType
Returns:
The data value as a double.
Throws:
StandardException - thrown on failure to convert
See Also:
DataValueDescriptor.getDouble()

typeToBigDecimal

public int typeToBigDecimal()
                     throws StandardException
CHAR/VARCHAR/LONG VARCHAR implementation. Convert to a BigDecimal using getString.

Specified by:
typeToBigDecimal in interface DataValueDescriptor
Overrides:
typeToBigDecimal in class DataType
Throws:
StandardException

getDate

public java.sql.Date getDate(java.util.Calendar cal)
                      throws StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a java.sql.Date. Throws an exception if the data value is not a Date.

Specified by:
getDate in interface DataValueDescriptor
Overrides:
getDate in class DataType
Parameters:
cal - calendar for object creation
Returns:
The data value as a java.sql.Date.
Throws:
StandardException - thrown on failure to convert
See Also:
DataValueDescriptor.getDate(java.util.Calendar)

getDate

public static java.sql.Date getDate(java.util.Calendar cal,
                                    java.lang.String str,
                                    LocaleFinder localeFinder)
                             throws StandardException
Throws:
StandardException

getTime

public java.sql.Time getTime(java.util.Calendar cal)
                      throws StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a java.sql.Time. Throws an exception if the data value is not a Time.

Specified by:
getTime in interface DataValueDescriptor
Overrides:
getTime in class DataType
Parameters:
cal - calendar for object creation
Returns:
The data value as a java.sql.Time.
Throws:
StandardException - thrown on failure to convert
See Also:
DataValueDescriptor.getTime(java.util.Calendar)

getTime

public static java.sql.Time getTime(java.util.Calendar cal,
                                    java.lang.String str,
                                    LocaleFinder localeFinder)
                             throws StandardException
Throws:
StandardException - thrown on failure to convert

getTimestamp

public java.sql.Timestamp getTimestamp(java.util.Calendar cal)
                                throws StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a java.sql.Timestamp. Throws an exception if the data value is not a Timestamp.

Specified by:
getTimestamp in interface DataValueDescriptor
Overrides:
getTimestamp in class DataType
Parameters:
cal - calendar for object creation
Returns:
The data value as a java.sql.Timestamp.
Throws:
StandardException - thrown on failure to convert
See Also:
DataValueDescriptor.getTimestamp(java.util.Calendar)

getTimestamp

public static java.sql.Timestamp getTimestamp(java.util.Calendar cal,
                                              java.lang.String str,
                                              LocaleFinder localeFinder)
                                       throws StandardException
Throws:
StandardException - thrown on failure to convert
See Also:
DataValueDescriptor.getTimestamp(java.util.Calendar)

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

getStream

public java.io.InputStream getStream()
                              throws StandardException
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
Returns:
The data value as an InputStream.
Throws:
StandardException - Thrown on error

getLength

public int getLength()
              throws StandardException
Description copied from interface: DataValueDescriptor
Gets 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.

Specified by:
getLength in interface DataValueDescriptor
Returns:
The length of the data value
Throws:
StandardException - Thrown on error

getTypeName

public java.lang.String getTypeName()
Description copied from interface: DataValueDescriptor
Get the SQL name of the datatype

Specified by:
getTypeName in interface DataValueDescriptor
Returns:
The SQL name of the datatype

getString

public java.lang.String getString()
                           throws StandardException
If possible, use getCharArray() if you don't really need a string. getString() will cause an extra char array to be allocated when it calls the the String() constructor (the first time through), so may be cheaper to use getCharArray().

Specified by:
getString in interface DataValueDescriptor
Returns:
The data value as a String.
Throws:
StandardException - Thrown on error

getCharArray

public char[] getCharArray()
                    throws StandardException
Get a char array. Typically, this is a simple getter that is cheaper than getString() because we always need to create a char array when doing I/O. Use this instead of getString() where reasonable.

WARNING: may return a character array that has spare characters at the end. MUST be used in conjunction with getLength() to be safe.

Specified by:
getCharArray in interface StringDataValue
Throws:
StandardException - Thrown on error

returnStream

public java.io.InputStream returnStream()
Description copied from interface: StreamStorable
Return the stream state of the object.

Specified by:
returnStream in interface StreamStorable

setStream

public void setStream(java.io.InputStream newStream)
Description copied from interface: StreamStorable
sets the stream state for the object.

Specified by:
setStream in interface StreamStorable

loadStream

public void loadStream()
                throws StandardException
Description copied from interface: StreamStorable
sets the stream state for the object.

Specified by:
loadStream in interface StreamStorable
Throws:
StandardException - on error

getTypeFormatId

public int getTypeFormatId()
Return my format identifier.

Specified by:
getTypeFormatId in interface TypedFormat
Returns:
The identifier. (A UUID stuffed in an array of 16 bytes).
See Also:
TypedFormat.getTypeFormatId()

isNull

public boolean isNull()
see if the String value is null.

Specified by:
isNull in interface Storable
Returns:
true if the value is null and false otherwise.
See Also:
Storable.isNull()

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
The maximum stored size is based upon the UTF format used to stored the String. The format consists of a two byte length field and a maximum number of three bytes for each character.
This puts an upper limit on the length of a stored String. The maximum stored length is 65535, these leads to the worse case of a maximum string length of 21844 ((65535 - 2) / 3).
Strings with stored length longer than 64K is handled with the following format: (1) 2 byte length: will be assigned 0. (2) UTF formated string data. (3) terminate the string with the following 3 bytes: first byte is: +---+---+---+---+---+---+---+---+ | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | +---+---+---+---+---+---+---+---+ second byte is: +---+---+---+---+---+---+---+---+ | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +---+---+---+---+---+---+---+---+ third byte is: +---+---+---+---+---+---+---+---+ | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +---+---+---+---+---+---+---+---+ The UTF format: Writes a string to the underlying output stream using UTF-8 encoding in a machine-independent manner.

First, two bytes are written to the output stream as if by the writeShort method giving the number of bytes to follow. This value is the number of bytes actually written out, not the length of the string. Following the length, each character of the string is output, in sequence, using the UTF-8 encoding for the character.

Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException - if an I/O error occurs.
java.io.IOException - thrown by writeUTF
Since:
JDK1.0
See Also:
DataInputStream

readExternalFromArray

public void readExternalFromArray(ArrayInputStream in)
                           throws java.io.IOException
Reads in a string from the specified data input stream. The string has been encoded using a modified UTF-8 format.

The first two bytes are read as if by readUnsignedShort. This value gives the number of following bytes that are in the encoded string, not the length of the resulting string. The following bytes are then interpreted as bytes encoding characters in the UTF-8 format and are converted into characters.

This method blocks until all the bytes are read, the end of the stream is detected, or an exception is thrown.

Specified by:
readExternalFromArray in interface DataValueDescriptor
Parameters:
in - a data input stream.
Returns:
a Unicode string.
Throws:
java.io.EOFException - if the input stream reaches the end before all the bytes.
java.io.IOException - if an I/O error occurs.
java.io.UTFDataFormatException - if the bytes do not represent a valid UTF-8 encoding of a Unicode string.
See Also:
DataInputStream.readUnsignedShort(), Externalizable.readExternal(java.io.ObjectInput)

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException

growBy

protected int growBy()
returns the reasonable minimum amount by which the array can grow . See readExternal. when we know that the array needs to grow by at least one byte, it is not performant to grow by just one byte instead this amount is used to provide a resonable growby size.

Returns:
minimum reasonable growby size

restoreToNull

public void restoreToNull()
Description copied from interface: Storable
Restore this object to its (SQL)null value.

Specified by:
restoreToNull in interface Storable
See Also:
Storable.restoreToNull()

compare

public boolean compare(int op,
                       DataValueDescriptor other,
                       boolean orderedNulls,
                       boolean unknownRV)
                throws 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
Throws:
StandardException - thrown on error

compare

public int compare(DataValueDescriptor other)
            throws 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
Parameters:
other - The Orderable to compare this one to.
Returns:
<0 - this Orderable is less than other. 0 - this Orderable equals other. >0 - this Orderable is greater than other. The code should not explicitly look for -1, or 1.
Throws:
StandardException - thrown on error

cloneObject

public 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
Returns:
clone of me as an Object

getClone

public 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
Returns:
A clone of the DataValueDescriptor with the same initial value as this.
See Also:
DataValueDescriptor.getClone()

getNewNull

public DataValueDescriptor getNewNull()
Description copied from interface: DataValueDescriptor
Get a new null value of the same type as this data value.

Specified by:
getNewNull in interface DataValueDescriptor
See Also:
DataValueDescriptor.getNewNull()

setValueFromResultSet

public final 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.

Specified by:
setValueFromResultSet in interface DataValueDescriptor
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)

setInto

public final void setInto(java.sql.PreparedStatement ps,
                          int position)
                   throws java.sql.SQLException,
                          StandardException
Set the value into a PreparedStatement.

Specified by:
setInto in interface DataValueDescriptor
Overrides:
setInto in class DataType
Throws:
java.sql.SQLException
StandardException

setValue

public void setValue(java.lang.String theValue)
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor.

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The BigDecimal value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor

setValue

public void setValue(boolean theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value.

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - Contains the boolean value to set this to
Returns:
This value
Throws:
StandardException

setValue

public void setValue(int theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given int value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException - Thrown on error

setValue

public void setValue(double theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given double value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException - Thrown on error

setValue

public void setValue(float theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given double value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException - Thrown on error

setValue

public void setValue(short theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given short value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException - Thrown on error

setValue

public void setValue(long theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given long value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException - Thrown on error

setValue

public void setValue(byte theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given byte value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException - Thrown on error

setValue

public void setValue(byte[] theValue)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor.

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The byte value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException

setBigDecimal

public void setBigDecimal(java.lang.Number bigDecimal)
                   throws StandardException
Only to be called when an application through JDBC is setting a SQLChar to a java.math.BigDecimal.

Specified by:
setBigDecimal in interface DataValueDescriptor
Overrides:
setBigDecimal in class DataType
Throws:
StandardException

setValue

public void setValue(java.sql.Date theValue,
                     java.util.Calendar cal)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor.

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The Date value to set this DataValueDescriptor to
cal - The time zone from the calendar is used to construct the database date value
Returns:
This DataValueDescriptor
Throws:
StandardException - Thrown on error

setValue

public void setValue(java.sql.Time theValue,
                     java.util.Calendar cal)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor.

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The Time value to set this DataValueDescriptor to
cal - The time zone from the calendar is used to construct the database time value
Returns:
This DataValueDescriptor
Throws:
StandardException - Thrown on error

setValue

public void setValue(java.sql.Timestamp theValue,
                     java.util.Calendar cal)
              throws StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor.

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The Timestamp value to set this DataValueDescriptor to
cal - The time zone from the calendar is used to construct the database timestamp value
Returns:
This DataValueDescriptor
Throws:
StandardException - Thrown on error

formatJDBCDate

private void formatJDBCDate(java.util.Calendar cal,
                            java.lang.StringBuffer sb)

formatJDBCTime

private void formatJDBCTime(java.util.Calendar cal,
                            java.lang.StringBuffer sb)

setValue

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

setValue

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

setFrom

protected void setFrom(DataValueDescriptor theValue)
                throws StandardException
Overrides:
setFrom in class DataType
Throws:
StandardException

setAsToNationalString

private void setAsToNationalString(java.lang.Object theValue)

normalize

public void normalize(DataTypeDescriptor desiredType,
                      DataValueDescriptor source)
               throws StandardException
Normalization method - this method may be called when putting a value into a SQLChar, for example, when inserting into a SQLChar 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
Returns:
The normalized SQLChar
Throws:
StandardException - Thrown for null into non-nullable column, and for truncation error

normalize

protected void normalize(DataTypeDescriptor desiredType,
                         java.lang.String sourceValue)
                  throws StandardException
Throws:
StandardException

hasNonBlankChars

protected final void hasNonBlankChars(java.lang.String source,
                                      int start,
                                      int end)
                               throws StandardException
Throws:
StandardException

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

Specified by:
setWidth in interface VariableSizeDataValue
Parameters:
desiredWidth - the desired length
desiredScale - the desired scale (ignored)
errorOnTrunc - throw an error on truncation
Returns:
this with the new width
Throws:
StandardException - Thrown when errorOnTrunc is true and when a shrink will truncate non-white spaces.

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:
equals in interface DataValueDescriptor
Overrides:
equals in class DataType
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:
notEquals in interface DataValueDescriptor
Overrides:
notEquals in class DataType
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 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:
lessThan in interface DataValueDescriptor
Overrides:
lessThan in class DataType
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 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:
greaterThan in interface DataValueDescriptor
Overrides:
greaterThan in class DataType
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 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:
lessOrEquals in interface DataValueDescriptor
Overrides:
lessOrEquals in class DataType
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 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:
greaterOrEquals in interface DataValueDescriptor
Overrides:
greaterOrEquals in class DataType
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 first operand is greater than or equal to the second operand
Throws:
StandardException - Thrown on error

charLength

public NumberDataValue charLength(NumberDataValue result)
                           throws StandardException
This method implements the char_length function for char.

Specified by:
charLength in interface ConcatableDataValue
Parameters:
result - The result of a previous call to this method, null if not called yet
Returns:
A SQLInteger containing the length of the char value
Throws:
StandardException - Thrown on error
See Also:
ConcatableDataValue.charLength(NumberDataValue)

concatenate

public StringDataValue concatenate(StringDataValue leftOperand,
                                   StringDataValue rightOperand,
                                   StringDataValue result)
                            throws StandardException
Description copied from interface: StringDataValue
The SQL concatenation '||' operator.

Specified by:
concatenate in interface StringDataValue
Parameters:
leftOperand - String on the left hand side of '||'
rightOperand - String on the right hand side of '||'
result - The result of a previous call to this method, null if not called yet.
Returns:
A ConcatableDataValue containing the result of the '||'
Throws:
StandardException - Thrown on error
See Also:
StringDataValue.concatenate(org.apache.derby.iapi.types.StringDataValue, org.apache.derby.iapi.types.StringDataValue, org.apache.derby.iapi.types.StringDataValue)

like

public BooleanDataValue like(DataValueDescriptor pattern)
                      throws StandardException
This method implements the like function for char (with no escape value).

Specified by:
like in interface StringDataValue
Parameters:
pattern - The pattern to use
Returns:
A SQL boolean value telling whether the first operand is like the second operand
Throws:
StandardException - Thrown on error

like

public BooleanDataValue like(DataValueDescriptor pattern,
                             DataValueDescriptor escape)
                      throws StandardException
This method implements the like function for char with an escape value.

Specified by:
like in interface StringDataValue
Parameters:
pattern - The pattern to use
escape - the escape character
Returns:
A SQL boolean value telling whether the first operand is like the second operand
Throws:
StandardException - Thrown on error

locate

public NumberDataValue locate(StringDataValue searchFrom,
                              NumberDataValue start,
                              NumberDataValue result)
                       throws StandardException
This method implements the locate function for char.

Specified by:
locate in interface StringDataValue
Parameters:
searchFrom - - The string to search from
start - - The position to search from in string searchFrom
result - - The object to return Note: use getString() to get the string to search for.
Returns:
The position in searchFrom the fist occurrence of this.value. 0 is returned if searchFrom does not contain this.value.
Throws:
StandardException - Thrown on error

substring

public ConcatableDataValue substring(NumberDataValue start,
                                     NumberDataValue length,
                                     ConcatableDataValue result,
                                     int maxLen)
                              throws StandardException
The SQL substr() function.

Specified by:
substring in interface ConcatableDataValue
Parameters:
start - Start of substr
length - Length of substr
result - The result of a previous call to this method, null if not called yet.
maxLen - Maximum length of the result
Returns:
A ConcatableDataValue containing the result of the substr()
Throws:
StandardException - Thrown on error

trim

public StringDataValue trim(int trimType,
                            StringDataValue result)
                     throws StandardException
The SQL trim(), ltrim() and rtrim() functions.

Specified by:
trim in interface StringDataValue
Parameters:
trimType - Type of trim
result - The result of a previous call to this method, null if not called yet.
Returns:
A StringDataValue containing the result of the trim()
Throws:
StandardException - Thrown on error

upper

public StringDataValue upper(StringDataValue result)
                      throws StandardException
Description copied from interface: StringDataValue
Convert the string to upper case.

Specified by:
upper in interface StringDataValue
Parameters:
result - The result (reusable - allocate if null).
Returns:
The string converted to upper case.
Throws:
StandardException - Thrown on error
See Also:
StringDataValue.upper(org.apache.derby.iapi.types.StringDataValue)

lower

public StringDataValue lower(StringDataValue result)
                      throws StandardException
Description copied from interface: StringDataValue
Convert the string to lower case.

Specified by:
lower in interface StringDataValue
Parameters:
result - The result (reusable - allocate if null).
Returns:
The string converted to lower case.
Throws:
StandardException - Thrown on error
See Also:
StringDataValue.lower(org.apache.derby.iapi.types.StringDataValue)

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

stringCompare

protected static int stringCompare(java.lang.String op1,
                                   java.lang.String op2)
Compare two Strings using standard SQL semantics.

Parameters:
op1 - The first String
op2 - The second String
Returns:
-1 - op1 < op2 0 - op1 == op2 1 - op1 > op2

stringCompare

protected int stringCompare(SQLChar char1,
                            SQLChar char2)
                     throws StandardException
Compare two SQLChars. This method will be overriden in the National char wrappers so that the appropriate comparison is done.

Throws:
StandardException - Thrown on error

stringCompare

protected static int stringCompare(char[] op1,
                                   int leftlen,
                                   char[] op2,
                                   int rightlen)
Compare two Strings using standard SQL semantics.

Parameters:
op1 - The first String
op2 - The second String
Returns:
-1 - op1 < op2 0 - op1 == op2 1 - op1 > op2

stringCollatorCompare

protected int stringCollatorCompare(SQLChar str2)
                             throws StandardException
Compare a localized string with this one.

Parameters:
str2 - The other string
Returns:
-1 - this < str2 0 - this == str2 1 - this > str2
Throws:
StandardException

getCollationKey

protected java.text.CollationKey getCollationKey()
                                          throws StandardException
Throws:
StandardException

toString

public java.lang.String toString()

hashCode

public int hashCode()

nationalHashCode

protected int nationalHashCode()
Implementation of hashCode() for the national character types, put here to make it accessible to all the national types.


getIntArray

private int[] getIntArray()
                   throws StandardException
Throws:
StandardException

getIntLength

private int getIntLength()

getNewVarchar

protected StringDataValue getNewVarchar()
                                 throws StandardException
Get a SQLVarchar for a built-in string function. (Could be either a SQLVarchar or SQLNationalVarchar.)

Returns:
a SQLVarchar or SQLNationalVarchar.
Throws:
StandardException - Thrown on error

isNationalString

protected boolean isNationalString()
Return whether or not this is a national character datatype.


nationalGetDate

protected java.sql.Date nationalGetDate(java.util.Calendar cal)
                                 throws StandardException
This implements getDate() for the national types. It lives here so it can be shared between all the national types.

Throws:
StandardException - thrown on failure to convert

nationalGetTime

protected java.sql.Time nationalGetTime(java.util.Calendar cal)
                                 throws StandardException
This implements getTime() for the national types. It lives here so it can be shared between all the national types.

Throws:
StandardException - thrown on failure to convert

nationalGetTimestamp

protected java.sql.Timestamp nationalGetTimestamp(java.util.Calendar cal)
                                           throws StandardException
This implements getTimestamp() for the national types. It lives here so it can be shared between all the national types.

Throws:
StandardException - thrown on failure to convert

setLocaleFinder

protected void setLocaleFinder(LocaleFinder localeFinder)

getLocale

private java.util.Locale getLocale()
                            throws StandardException
Throws:
StandardException - Thrown on error

getLocaleFinder

protected LocaleFinder getLocaleFinder()

getDateFormat

protected java.text.DateFormat getDateFormat()
                                      throws StandardException
Throws:
StandardException

getTimeFormat

protected java.text.DateFormat getTimeFormat()
                                      throws StandardException
Throws:
StandardException

getTimestampFormat

protected java.text.DateFormat getTimestampFormat()
                                           throws StandardException
Throws:
StandardException

getDateFormat

protected java.text.DateFormat getDateFormat(java.util.Calendar cal)
                                      throws StandardException
Throws:
StandardException

getTimeFormat

protected java.text.DateFormat getTimeFormat(java.util.Calendar cal)
                                      throws StandardException
Throws:
StandardException

getTimestampFormat

protected java.text.DateFormat getTimestampFormat(java.util.Calendar cal)
                                           throws StandardException
Throws:
StandardException

setDateFormatCalendar

private java.text.DateFormat setDateFormatCalendar(java.text.DateFormat df,
                                                   java.util.Calendar cal)

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
Returns:
the estimated memory usage

copyState

protected void copyState(SQLChar other)

XMLParse

public XMLDataValue XMLParse(XMLDataValue result,
                             boolean preserveWS)
                      throws StandardException
Specified by:
XMLParse in interface StringDataValue
Throws:
StandardException

Built on Tue 2006-10-10 19:23:47+0200, from revision exported

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