Class SQLChar
- java.lang.Object
-
- org.apache.derby.iapi.types.DataType
-
- org.apache.derby.iapi.types.SQLChar
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable,java.lang.Comparable,Formatable,Storable,StreamStorable,TypedFormat,ConcatableDataValue,DataValueDescriptor,Orderable,StringDataValue,VariableSizeDataValue
- Direct Known Subclasses:
CollatorSQLChar,SQLVarchar
public class SQLChar extends DataType implements StringDataValue, StreamStorable
The SQLChar represents a CHAR value with UCS_BASIC collation. SQLChar may be used directly by any code when it is guaranteed that the required collation is UCS_BASIC, e.g. system columns.The state may be in char[], a String, a Clob, or an unread stream, depending on how the datatype was created.
Stream notes:
When the datatype comes from the database layer and the length of the bytes necessary to store the datatype on disk exceeds the size of a page of the container holding the data then the store returns a stream rather than reading all the bytes into a char[] or String. The hope is that the usual usage case is that data never need be expanded in the derby layer, and that client can just be given a stream that can be read a char at a time through the jdbc layer. Even though SQLchar's can't ever be this big, this code is shared by all the various character datatypes including SQLClob which is expected to usually larger than a page.
The state can also be a stream in the case of insert/update where the client has used a jdbc interface to set the value as a stream rather than char[]. In this case the hope is that the usual usage case is that stream never need be read until it is passed to store, read once, and inserted into the database.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.sql.Clob_clobValueThe value as a user-created Clob(package private) char[][]arg_passerprivate static intBASE_MEMORY_USAGEprivate static char[]BLANKSStatic array that can be used for blank padding.protected static StreamHeaderGeneratorCHAR_HEADER_GENERATORStream header generator for CHAR, VARCHAR and LONG VARCHAR.private java.text.CollationKeycKeyprivate static intGROWBY_FOR_CHARwhen 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 LocaleFinderlocaleFinderprivate static charPADThe pad character (space).private char[]rawDataprivate intrawLengthprotected static intRETURN_SPACE_THRESHOLDthreshold, that decides when we return space back to the VM see getString() where it is used(package private) java.io.InputStreamstreamThe value as a stream in the on-disk format.private java.lang.StringvalueFields of the class-
Fields inherited from interface org.apache.derby.iapi.types.DataValueDescriptor
UNKNOWN_LOGICAL_LENGTH
-
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.StringDataValue
BOTH, COLLATION_DERIVATION_EXPLICIT, COLLATION_DERIVATION_IMPLICIT, COLLATION_DERIVATION_NONE, COLLATION_TYPE_TERRITORY_BASED, COLLATION_TYPE_TERRITORY_BASED_IDENTICAL, COLLATION_TYPE_TERRITORY_BASED_PRIMARY, COLLATION_TYPE_TERRITORY_BASED_SECONDARY, COLLATION_TYPE_TERRITORY_BASED_TERTIARY, COLLATION_TYPE_UCS_BASIC, LEADING, TRAILING
-
Fields inherited from interface org.apache.derby.iapi.types.VariableSizeDataValue
IGNORE_PRECISION
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringDataValueansiTrim(int trimType, StringDataValue trimChar, StringDataValue result)The SQL Ansi trim function.private static voidappendBlanks(char[] ca, int offset, int howMany)Private/Protected methods of This class:NumberDataValuecharLength(NumberDataValue result)This method implements the char_length function for char.DataValueDescriptorcloneHolder()Shallow clone a StreamStorable without objectifying.DataValueDescriptorcloneValue(boolean forceMaterialization)Clone this DataValueDescriptor.booleancompare(int op, DataValueDescriptor other, boolean orderedNulls, boolean unknownRV)Compare this Orderable with a given Orderable for the purpose of qualification and sorting.intcompare(DataValueDescriptor other)Compare this Orderable with a given Orderable for the purpose of index positioning.StringDataValueconcatenate(StringDataValue leftOperand, StringDataValue rightOperand, StringDataValue result)The SQL concatenation '||' operator.private voidcopyState(java.lang.String otherValue, char[] otherRawData, int otherRawLength, java.text.CollationKey otherCKey, java.io.InputStream otherStream, java.sql.Clob otherClobValue, LocaleFinder otherLocaleFinder)protected voidcopyState(SQLChar other)BooleanDataValueequals(DataValueDescriptor left, DataValueDescriptor right)The = operator as called from the language module, as opposed to the storage module.intestimateMemoryUsage()Estimate the memory usage in bytes of the data value and the overhead of the class.private voidformatJDBCDate(java.util.Calendar cal, java.lang.StringBuffer sb)private voidformatJDBCTime(java.util.Calendar cal, java.lang.StringBuffer sb)booleangetBoolean()Get Boolean from a SQLChar.bytegetByte()Get Byte from a SQLChar.char[]getCharArray()Get a char array.private intgetClobLength()protected java.text.CollationKeygetCollationKey()This method gets called for the collation sensitive char classes ie CollatorSQLChar, CollatorSQLVarchar, CollatorSQLLongvarchar, CollatorSQLClob.protected java.text.RuleBasedCollatorgetCollatorForCollation()java.sql.DategetDate(java.util.Calendar cal)Get date from a SQLChar.static java.sql.DategetDate(java.util.Calendar cal, java.lang.String str, LocaleFinder localeFinder)Static function to Get date from a string.doublegetDouble()Get double from a SQLChar.floatgetFloat()Get float from a SQLChar.intgetInt()Get int from a SQLChar.intgetLength()Gets the length of the data value.private java.util.LocalegetLocale()protected LocaleFindergetLocaleFinder()longgetLong()Get long from a SQLChar.DataValueDescriptorgetNewNull()Get a new null value of the same type as this data value.protected StringDataValuegetNewVarchar()Get a SQLVarchar for a built-in string function.java.lang.ObjectgetObject()Gets the value in the data value descriptor as a int.char[]getRawDataAndZeroIt()This is a special accessor used when we wrap passwords in VARCHARs.shortgetShort()Get Short from a SQLChar.java.io.InputStreamgetStream()Gets the value in the data stream descriptor as an InputStream.StreamHeaderGeneratorgetStreamHeaderGenerator()Returns the default stream header generator for the string data types.CharacterStreamDescriptorgetStreamWithDescriptor()Returns a descriptor for the input stream for this character data value.java.lang.StringgetString()If possible, use getCharArray() if you don't really need a string.java.sql.TimegetTime(java.util.Calendar cal)Get time from a SQLChar.static java.sql.TimegetTime(java.util.Calendar cal, java.lang.String str, LocaleFinder localeFinder)Static function to Get Time from a string.java.sql.TimestampgetTimestamp(java.util.Calendar cal)Get Timestamp from a SQLChar.static java.sql.TimestampgetTimestamp(java.util.Calendar cal, java.lang.String str, LocaleFinder localeFinder)Static function to Get Timestamp from a string.java.lang.StringgetTraceString()Gets a trace representation for debugging.intgetTypeFormatId()Return my format identifier.java.lang.StringgetTypeName()Get the SQL name of the datatypeprivate intgetUTF8Length(java.lang.String string, int start, int end)Get the number of bytes needed to represent a string in modified UTF-8, which is the encoding used bywriteExternal()andwriteUTF().StringDataValuegetValue(java.text.RuleBasedCollator collatorForComparison)Gets either SQLChar/SQLVarchar/SQLLongvarchar/SQLClob(base classes) or CollatorSQLChar/CollatorSQLVarchar/CollatorSQLLongvarch/CollatorSQLClob (subclasses).BooleanDataValuegreaterOrEquals(DataValueDescriptor left, DataValueDescriptor right)The >= operator as called from the language module, as opposed to the storage module.BooleanDataValuegreaterThan(DataValueDescriptor left, DataValueDescriptor right)The > operator as called from the language module, as opposed to the storage module.protected intgrowBy()returns the reasonable minimum amount by which the array can grow .inthashCode()(package private) inthashCodeForCollation()Hash code implementation for collator sensitive subclasses.protected voidhasNonBlankChars(java.lang.String source, int start, int end)booleanisNull()see if the String value is null.BooleanDataValuelessOrEquals(DataValueDescriptor left, DataValueDescriptor right)The <= operator as called from the language module, as opposed to the storage module.BooleanDataValuelessThan(DataValueDescriptor left, DataValueDescriptor right)The < operator as called from the language module, as opposed to the storage module.BooleanDataValuelike(DataValueDescriptor pattern)This method implements the like function for char (with no escape value).BooleanDataValuelike(DataValueDescriptor pattern, DataValueDescriptor escape)This method implements the like function for char with an escape value.voidloadStream()Set the value by reading the stream and converting it to an object form.NumberDataValuelocate(StringDataValue searchFrom, NumberDataValue start, NumberDataValue result)This method implements the locate function for char.StringDataValuelower(StringDataValue result)Convert the string to lower case.protected voidnormalize(DataTypeDescriptor desiredType, java.lang.String sourceValue)voidnormalize(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.BooleanDataValuenotEquals(DataValueDescriptor left, DataValueDescriptor right)The <> operator as called from the language module, as opposed to the storage module.private intrawGetClobLength()voidreadExternal(java.io.ObjectInput in)protected voidreadExternal(java.io.ObjectInput in, int utflen, int knownStrLen)Restores the data value from the source stream, materializing the value in memory.protected voidreadExternalClobFromArray(ArrayInputStream in, int charLen)Reads a CLOB from the source stream and materializes the value in a character array.voidreadExternalFromArray(ArrayInputStream in)Reads in a string from the specified data input stream.private voidresetForMaterialization()Resets state after materializing value from an array.voidrestoreToNull()Restore this object to its (SQL)null value.java.io.InputStreamreturnStream()Public Methods of StreamStorable interface:voidsetBigDecimal(java.math.BigDecimal bigDecimal)Only to be called when an application through JDBC is setting a SQLChar to a java.math.BigDecimal.protected voidsetFrom(DataValueDescriptor theValue)Set the value of this DataValueDescriptor based on the value of the specified DataValueDescriptor.voidsetInto(java.sql.PreparedStatement ps, int position)Set the value into a PreparedStatement.protected voidsetLocaleFinder(LocaleFinder localeFinder)voidsetObjectForCast(java.lang.Object theValue, boolean instanceOfResultType, java.lang.String resultTypeClassName)Allow any Java type to be cast to a character type using Object.toString.voidsetStream(java.io.InputStream newStream)Set this value to the on-disk format stream.voidsetStreamHeaderFormat(java.lang.Boolean inSoftUpgradeMode)Sets the mode for the database being accessed.voidsetValue(boolean theValue)Set the value.voidsetValue(byte theValue)Set the value of this DataValueDescriptor to the given byte value At DataType level just throws an error lower classes will overridevoidsetValue(byte[] theValue)Set the value of this DataValueDescriptor.voidsetValue(double theValue)Set the value of this DataValueDescriptor to the given double value At DataType level just throws an error lower classes will overridevoidsetValue(float theValue)Set the value of this DataValueDescriptor to the given float value At DataType level just throws an error lower classes will overridevoidsetValue(int theValue)Set the value of this DataValueDescriptor to the given int value At DataType level just throws an error lower classes will overridevoidsetValue(long theValue)Set the value of this DataValueDescriptor to the given long value At DataType level just throws an error lower classes will overridevoidsetValue(short theValue)Set the value of this DataValueDescriptor to the given short value At DataType level just throws an error lower classes will overridevoidsetValue(java.io.InputStream theStream, int valueLength)Set the value from the stream which is in the on-disk format.voidsetValue(java.lang.String theValue)Set the value of this DataValueDescriptor.voidsetValue(java.sql.Clob theValue)Set the value of this DataValueDescriptor.voidsetValue(java.sql.Date theValue, java.util.Calendar cal)Set the value of this DataValueDescriptor.voidsetValue(java.sql.Time theValue, java.util.Calendar cal)Set the value of this DataValueDescriptor.voidsetValue(java.sql.Timestamp theValue, java.util.Calendar cal)Set the value of this DataValueDescriptor.voidsetValueFromResultSet(java.sql.ResultSet resultSet, int colNumber, boolean isNullable)Set the value based on the value for the specified DataValueDescriptor from the specified ResultSet.voidsetWidth(int desiredWidth, int desiredScale, boolean errorOnTrunc)Set the width of the to the desired value.protected static intstringCompare(char[] op1, int leftlen, char[] op2, int rightlen)Compare two Strings using standard SQL semantics.protected static intstringCompare(java.lang.String op1, java.lang.String op2)Compare two Strings using standard SQL semantics.protected intstringCompare(SQLChar char1, SQLChar char2)Compare two SQLChars.ConcatableDataValuesubstring(NumberDataValue start, NumberDataValue length, ConcatableDataValue result, int maxLen)The SQL substr() function.protected voidthrowStreamingIOException(java.io.IOException ioe)Wraps anIOExceptionin aStandardExceptionthen throws the wrapping exception.java.lang.StringtoString()private java.lang.StringtrimInternal(int trimType, char trimChar, java.lang.String source)This function public for testing purposes.inttypePrecedence()Each built-in type in JSQL has a precedence.inttypeToBigDecimal()CHAR/VARCHAR/LONG VARCHAR implementation.StringDataValueupper(StringDataValue result)Convert the string to upper case.protected voidwriteClobUTF(java.io.ObjectOutput out)Writes the header and the user data for a CLOB to the destination stream.voidwriteExternal(java.io.ObjectOutput out)Writes a non-Clob data value to the modified UTF-8 format used by Derby.private static voidwriteUTF(java.io.ObjectOutput out, int c)Write a single character to a stream in the modified UTF-8 format.private voidwriteUTF(java.io.ObjectOutput out, int strLen, boolean isRaw, java.io.Reader characterReader)Writes the user data value to a stream in the modified UTF-8 format.voidzeroRawData()Zero out the wrapped char[] so that it can't be memory-sniffed.-
Methods inherited from class org.apache.derby.iapi.types.DataType
checkHostVariable, coalesce, compare, compare, compareTo, dataTypeConversion, equals, flip, genericSetObject, getBytes, getTypeName, hasStream, in, invalidFormat, isNotNull, isNullOp, outOfRange, recycle, setInto, setObject, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatch
-
-
-
-
Field Detail
-
PAD
private static final char PAD
The pad character (space).- See Also:
- Constant Field Values
-
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
-
BASE_MEMORY_USAGE
private static final int BASE_MEMORY_USAGE
-
BLANKS
private static final char[] BLANKS
Static array that can be used for blank padding.
-
CHAR_HEADER_GENERATOR
protected static final StreamHeaderGenerator CHAR_HEADER_GENERATOR
Stream header generator for CHAR, VARCHAR and LONG VARCHAR. Currently, only one header format is used for these data types.
-
value
private java.lang.String value
Fields of the class
-
rawData
private char[] rawData
-
rawLength
private int rawLength
-
cKey
private java.text.CollationKey cKey
-
_clobValue
protected java.sql.Clob _clobValue
The value as a user-created Clob
-
stream
java.io.InputStream stream
The value as a stream in the on-disk format.
-
localeFinder
private LocaleFinder localeFinder
-
arg_passer
char[][] arg_passer
-
-
Constructor Detail
-
SQLChar
public SQLChar()
no-arg constructor, required by Formattable.
-
SQLChar
public SQLChar(java.lang.String val)
-
SQLChar
public SQLChar(java.sql.Clob val)
-
SQLChar
public SQLChar(char[] val)
This is a special constructor used when we need to represent a password as a VARCHAR (see DERBY-866). If you need a general-purpose constructor for char[] values and you want to re-use this constructor, make sure to keep track of the following:
- A password should never be turned into a String. This is because Java garbage collection makes it easy to sniff memory for String passwords. For more information, see this blog.
- It must be possible to 0 out the char[] array wrapped inside this SQLChar. This reduces the vulnerability that someone could sniff the char[] password after Derby has processed it.
-
-
Method Detail
-
appendBlanks
private static void appendBlanks(char[] ca, int offset, int howMany)Private/Protected methods of This class:
-
getRawDataAndZeroIt
public char[] getRawDataAndZeroIt()
This is a special accessor used when we wrap passwords in VARCHARs. This accessor copies the wrapped char[] and then fills it with 0s so that the password can't be memory-sniffed. For more information, see the comment on the SQLChar( char[] ) constructor.
-
zeroRawData
public void zeroRawData()
Zero out the wrapped char[] so that it can't be memory-sniffed. This helps us protect passwords. See the comment on the SQLChar( char[] ) constructor.
-
getBoolean
public boolean getBoolean() throws StandardExceptionGet Boolean from a SQLChar.Return false for only "0" or "false" for false. No case insensitivity. Everything else is true.
The above matches JCC and the client driver.
- Specified by:
getBooleanin interfaceDataValueDescriptor- Overrides:
getBooleanin classDataType- Returns:
- The data value as a boolean.
- Throws:
StandardException- Thrown on error- See Also:
DataValueDescriptor.getBoolean()
-
getByte
public byte getByte() throws StandardExceptionGet Byte from a SQLChar.Uses java standard Byte.parseByte() to perform coercion.
- Specified by:
getBytein interfaceDataValueDescriptor- Overrides:
getBytein classDataType- Returns:
- The data value as a byte.
- Throws:
StandardException- thrown on failure to convert- See Also:
DataValueDescriptor.getByte()
-
getShort
public short getShort() throws StandardExceptionGet Short from a SQLChar.Uses java standard Short.parseShort() to perform coercion.
- Specified by:
getShortin interfaceDataValueDescriptor- Overrides:
getShortin classDataType- Returns:
- The data value as a short.
- Throws:
StandardException- thrown on failure to convert- See Also:
DataValueDescriptor.getShort()
-
getInt
public int getInt() throws StandardExceptionGet int from a SQLChar.Uses java standard Short.parseInt() to perform coercion.
- Specified by:
getIntin interfaceDataValueDescriptor- Overrides:
getIntin classDataType- Returns:
- The data value as a int.
- Throws:
StandardException- thrown on failure to convert- See Also:
DataValueDescriptor.getInt()
-
getLong
public long getLong() throws StandardExceptionGet long from a SQLChar.Uses java standard Short.parseLong() to perform coercion.
- Specified by:
getLongin interfaceDataValueDescriptor- Overrides:
getLongin classDataType- Returns:
- The data value as a long.
- Throws:
StandardException- thrown on failure to convert- See Also:
DataValueDescriptor.getLong()
-
getFloat
public float getFloat() throws StandardExceptionGet float from a SQLChar.Uses java standard Float.floatValue() to perform coercion.
- Specified by:
getFloatin interfaceDataValueDescriptor- Overrides:
getFloatin classDataType- Returns:
- The data value as a float.
- Throws:
StandardException- thrown on failure to convert- See Also:
DataValueDescriptor.getFloat()
-
getDouble
public double getDouble() throws StandardExceptionGet double from a SQLChar.Uses java standard Double.doubleValue() to perform coercion.
- Specified by:
getDoublein interfaceDataValueDescriptor- Overrides:
getDoublein classDataType- Returns:
- The data value as a double.
- Throws:
StandardException- thrown on failure to convert- See Also:
DataValueDescriptor.getDouble()
-
getDate
public java.sql.Date getDate(java.util.Calendar cal) throws StandardExceptionGet date from a SQLChar.- Specified by:
getDatein interfaceDataValueDescriptor- Overrides:
getDatein classDataType- 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 StandardExceptionStatic function to Get date from a string.- Throws:
StandardException- thrown on failure to convert- See Also:
DataValueDescriptor.getDate(java.util.Calendar)
-
getTime
public java.sql.Time getTime(java.util.Calendar cal) throws StandardExceptionGet time from a SQLChar.- Specified by:
getTimein interfaceDataValueDescriptor- Overrides:
getTimein classDataType- 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 StandardExceptionStatic function to Get Time from a string.- Throws:
StandardException- thrown on failure to convert- See Also:
DataValueDescriptor.getTime(java.util.Calendar)
-
getTimestamp
public java.sql.Timestamp getTimestamp(java.util.Calendar cal) throws StandardExceptionGet Timestamp from a SQLChar.- Specified by:
getTimestampin interfaceDataValueDescriptor- Overrides:
getTimestampin classDataType- 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 StandardExceptionStatic function to Get Timestamp from a string.- Throws:
StandardException- thrown on failure to convert- See Also:
DataValueDescriptor.getTimestamp(java.util.Calendar)
-
returnStream
public java.io.InputStream returnStream()
Public Methods of StreamStorable interface:- Specified by:
returnStreamin interfaceStreamStorable
-
setStream
public void setStream(java.io.InputStream newStream)
Set this value to the on-disk format stream.- Specified by:
setStreamin interfaceStreamStorable
-
loadStream
public void loadStream() throws StandardExceptionDescription copied from interface:StreamStorableSet the value by reading the stream and converting it to an object form.- Specified by:
loadStreamin interfaceStreamStorable- Throws:
StandardException- on error
-
getObject
public java.lang.Object getObject() throws StandardExceptionDescription copied from class:DataTypeGets the value in the data value descriptor as a int. Throws an exception if the data value is not receivable as a int.- Specified by:
getObjectin interfaceDataValueDescriptor- Overrides:
getObjectin classDataType- Returns:
- The data value as a int.
- Throws:
StandardException- Thrown on error
-
getStream
public java.io.InputStream getStream() throws StandardExceptionDescription copied from class:DataTypeGets the value in the data stream descriptor as an InputStream. Throws an exception if the data value is not receivable as a stream.- Specified by:
getStreamin interfaceDataValueDescriptor- Overrides:
getStreamin classDataType- Returns:
- The data value as an InputStream.
- Throws:
StandardException- Thrown on error- See Also:
DataValueDescriptor.hasStream(),StringDataValue.getStreamWithDescriptor()
-
getStreamWithDescriptor
public CharacterStreamDescriptor getStreamWithDescriptor() throws StandardException
Returns a descriptor for the input stream for this character data value.- Specified by:
getStreamWithDescriptorin interfaceStringDataValue- Returns:
- Nothing, throws exception.
- Throws:
StandardException- if the value isn't represented by a stream- See Also:
SQLClob.getStreamWithDescriptor()
-
typeToBigDecimal
public int typeToBigDecimal() throws StandardExceptionCHAR/VARCHAR/LONG VARCHAR implementation. Convert to a BigDecimal using getString.- Specified by:
typeToBigDecimalin interfaceDataValueDescriptor- Overrides:
typeToBigDecimalin classDataType- Returns:
- Types.CHAR for String conversion through getString Types.DECIMAL for BigDecimal through getObject or Types.BIGINT for long conversion through getLong
- Throws:
StandardException- Conversion is not possible
-
getLength
public int getLength() throws StandardExceptionDescription copied from interface:DataValueDescriptorGets 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:
getLengthin interfaceDataValueDescriptor- Returns:
- The length of the data value
- Throws:
StandardException- Thrown on error
-
throwStreamingIOException
protected void throwStreamingIOException(java.io.IOException ioe) throws StandardExceptionWraps anIOExceptionin aStandardExceptionthen throws the wrapping exception.- Parameters:
ioe- theIOExceptionto wrap- Throws:
StandardException- the wrapping exception
-
getTypeName
public java.lang.String getTypeName()
Description copied from interface:DataValueDescriptorGet the SQL name of the datatype- Specified by:
getTypeNamein interfaceDataValueDescriptor- Returns:
- The SQL name of the datatype
-
getString
public java.lang.String getString() throws StandardExceptionIf 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:
getStringin interfaceDataValueDescriptor- Returns:
- The data value as a String.
- Throws:
StandardException- Thrown on error
-
getCharArray
public char[] getCharArray() throws StandardExceptionGet 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:
getCharArrayin interfaceStringDataValue- Throws:
StandardException- Thrown on error
-
getTypeFormatId
public int getTypeFormatId()
Return my format identifier.- Specified by:
getTypeFormatIdin interfaceTypedFormat- 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:
isNullin interfaceStorable- 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.IOExceptionWrites a non-Clob data value to the modified UTF-8 format used by Derby. 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
writeShortmethod 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:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException- if an I/O error occurs.- Since:
- JDK1.0
- See Also:
DataInputStream
-
writeUTF
private final void writeUTF(java.io.ObjectOutput out, int strLen, boolean isRaw, java.io.Reader characterReader) throws java.io.IOExceptionWrites the user data value to a stream in the modified UTF-8 format.- Parameters:
out- destination streamstrLen- string length of the valueisRaw-trueif the source israwData,falseif the source isvaluecharacterReader- Reader from _clobValue if it exists- Throws:
java.io.IOException- if writing to the destination stream fails
-
writeUTF
private static void writeUTF(java.io.ObjectOutput out, int c) throws java.io.IOExceptionWrite a single character to a stream in the modified UTF-8 format.- Parameters:
out- the destination streamc- the character to write- Throws:
java.io.IOException- if writing to the destination stream fails
-
writeClobUTF
protected final void writeClobUTF(java.io.ObjectOutput out) throws java.io.IOExceptionWrites the header and the user data for a CLOB to the destination stream.- Parameters:
out- destination stream- Throws:
java.io.IOException- if writing to the destination stream fails
-
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:
readExternalFromArrayin interfaceDataValueDescriptor- Overrides:
readExternalFromArrayin classDataType- Parameters:
in- a data input stream.- 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)
-
readExternalClobFromArray
protected void readExternalClobFromArray(ArrayInputStream in, int charLen) throws java.io.IOException
Reads a CLOB from the source stream and materializes the value in a character array.- Parameters:
in- source streamcharLen- the char length of the value, or0if unknown- Throws:
java.io.IOException- if reading from the source fails
-
resetForMaterialization
private void resetForMaterialization()
Resets state after materializing value from an array.
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
readExternal
protected void readExternal(java.io.ObjectInput in, int utflen, int knownStrLen) throws java.io.IOExceptionRestores the data value from the source stream, materializing the value in memory.- Parameters:
in- the source streamutflen- the byte length, or0if unknownknownStrLen- the char length, or0if unknown- Throws:
java.io.UTFDataFormatException- if an encoding error is detectedjava.io.IOException- if reading the stream fails
-
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:StorableRestore this object to its (SQL)null value.- Specified by:
restoreToNullin interfaceStorable- See Also:
Storable.restoreToNull()
-
compare
public boolean compare(int op, DataValueDescriptor other, boolean orderedNulls, boolean unknownRV) throws StandardExceptionDescription copied from interface:DataValueDescriptorCompare 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:
comparein interfaceDataValueDescriptor- Overrides:
comparein classDataType- Parameters:
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.- Returns:
- true if the comparison is true (duh!)
- Throws:
StandardException- thrown on error
-
compare
public int compare(DataValueDescriptor other) throws StandardException
Description copied from interface:DataValueDescriptorCompare 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 greater than all other values.- Specified by:
comparein interfaceDataValueDescriptor- 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
-
cloneHolder
public DataValueDescriptor cloneHolder()
Shallow clone a StreamStorable without objectifying. This is used to avoid unnecessary objectifying of a stream object. The only difference of this method from cloneValue is this method does not objectify a stream.- Specified by:
cloneHolderin interfaceDataValueDescriptor- Overrides:
cloneHolderin classDataType- Returns:
- A shallow clone.
-
cloneValue
public DataValueDescriptor cloneValue(boolean forceMaterialization)
Description copied from interface:DataValueDescriptorClone this DataValueDescriptor. Results in a new object that has the same value as this but can be modified independently.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 ifforceMaterializationis set tofalse. An example is if you need to access the value you just read usingcloneValueafter the current transaction has ended, or after the source result set has been closed.- Specified by:
cloneValuein interfaceDataValueDescriptor- Parameters:
forceMaterialization- any streams representing the data value will be materialized iftrue, the data value will be kept as a stream if possible iffalse- Returns:
- A clone of the
DataValueDescriptorwith the same initial value as this. - See Also:
DataValueDescriptor.cloneValue(boolean)
-
getNewNull
public DataValueDescriptor getNewNull()
Description copied from interface:DataValueDescriptorGet a new null value of the same type as this data value.- Specified by:
getNewNullin interfaceDataValueDescriptor- See Also:
DataValueDescriptor.getNewNull()
-
getValue
public StringDataValue getValue(java.text.RuleBasedCollator collatorForComparison)
Description copied from interface:StringDataValueGets either SQLChar/SQLVarchar/SQLLongvarchar/SQLClob(base classes) or CollatorSQLChar/CollatorSQLVarchar/CollatorSQLLongvarch/CollatorSQLClob (subclasses). Whether this method returns the base class or the subclass depends on the value of the RuleBasedCollator. If RuleBasedCollator is null, then the object returned would be baseclass otherwise it would be subcalss.- Specified by:
getValuein interfaceStringDataValue- See Also:
StringDataValue.getValue(RuleBasedCollator)
-
setValueFromResultSet
public final void setValueFromResultSet(java.sql.ResultSet resultSet, int colNumber, boolean isNullable) throws java.sql.SQLExceptionDescription copied from interface:DataValueDescriptorSet the value based on the value for the specified DataValueDescriptor from the specified ResultSet.- Specified by:
setValueFromResultSetin interfaceDataValueDescriptor- 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)- 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, StandardExceptionSet the value into a PreparedStatement.- Specified by:
setIntoin interfaceDataValueDescriptor- Overrides:
setIntoin classDataType- Throws:
java.sql.SQLException- thrown by the PreparedStatement objectStandardException- thrown by me accessing my value.
-
setValue
public void setValue(java.sql.Clob theValue)
Description copied from class:DataTypeSet the value of this DataValueDescriptor. At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Specified by:
setValuein interfaceStringDataValue- Overrides:
setValuein classDataType- Parameters:
theValue- The Clob value to set this DataValueDescriptor to
-
setValue
public void setValue(java.lang.String theValue)
Description copied from class:DataTypeSet the value of this DataValueDescriptor. At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The BigDecimal value to set this DataValueDescriptor to
-
setValue
public void setValue(boolean theValue) throws StandardExceptionDescription copied from class:DataTypeSet the value. At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- Contains the boolean value to set this to- Throws:
StandardException
-
setValue
public void setValue(int theValue) throws StandardExceptionDescription copied from class:DataTypeSet the value of this DataValueDescriptor to the given int value At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- Thrown on error
-
setValue
public void setValue(double theValue) throws StandardExceptionDescription copied from class:DataTypeSet the value of this DataValueDescriptor to the given double value At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- Thrown on error
-
setValue
public void setValue(float theValue) throws StandardExceptionDescription copied from class:DataTypeSet the value of this DataValueDescriptor to the given float value At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- Thrown on error
-
setValue
public void setValue(short theValue) throws StandardExceptionDescription copied from class:DataTypeSet the value of this DataValueDescriptor to the given short value At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- Thrown on error
-
setValue
public void setValue(long theValue) throws StandardExceptionDescription copied from class:DataTypeSet the value of this DataValueDescriptor to the given long value At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- Thrown on error
-
setValue
public void setValue(byte theValue) throws StandardExceptionDescription copied from class:DataTypeSet the value of this DataValueDescriptor to the given byte value At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- Thrown on error
-
setValue
public void setValue(byte[] theValue) throws StandardExceptionDescription copied from class:DataTypeSet the value of this DataValueDescriptor. At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The byte value to set this DataValueDescriptor to- Throws:
StandardException
-
setBigDecimal
public void setBigDecimal(java.math.BigDecimal bigDecimal) throws StandardExceptionOnly to be called when an application through JDBC is setting a SQLChar to a java.math.BigDecimal.- Specified by:
setBigDecimalin interfaceDataValueDescriptor- Overrides:
setBigDecimalin classDataType- Parameters:
bigDecimal- required to be a BigDecimal or null.- Throws:
StandardException
-
setValue
public void setValue(java.sql.Date theValue, java.util.Calendar cal) throws StandardExceptionDescription copied from class:DataTypeSet the value of this DataValueDescriptor. At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The Date value to set this DataValueDescriptor tocal- The time zone from the calendar is used to construct the database date value- Throws:
StandardException- Thrown on error
-
setValue
public void setValue(java.sql.Time theValue, java.util.Calendar cal) throws StandardExceptionDescription copied from class:DataTypeSet the value of this DataValueDescriptor. At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The Time value to set this DataValueDescriptor tocal- The time zone from the calendar is used to construct the database time value- Throws:
StandardException- Thrown on error
-
setValue
public void setValue(java.sql.Timestamp theValue, java.util.Calendar cal) throws StandardExceptionDescription copied from class:DataTypeSet the value of this DataValueDescriptor. At DataType level just throws an error lower classes will override- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The Timestamp value to set this DataValueDescriptor tocal- The time zone from the calendar is used to construct the database timestamp value- 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 final void setValue(java.io.InputStream theStream, int valueLength)Set the value from the stream which is in the on-disk format.- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theStream- On disk format of the streamvalueLength- length of the logical value in characters, orDataValueDescriptor.UNKNOWN_LOGICAL_LENGTH
-
setObjectForCast
public void setObjectForCast(java.lang.Object theValue, boolean instanceOfResultType, java.lang.String resultTypeClassName) throws StandardExceptionAllow any Java type to be cast to a character type using Object.toString.- Specified by:
setObjectForCastin interfaceDataValueDescriptor- Overrides:
setObjectForCastin classDataType- Parameters:
theValue- The new valueinstanceOfResultType- Whether or not the new value is an instanceof the result type.resultTypeClassName- The class name of the resulting (declared) type (for error messages only).- Throws:
StandardException- thrown on failure- See Also:
DataValueDescriptor.setObjectForCast(java.lang.Object, boolean, java.lang.String)
-
setFrom
protected void setFrom(DataValueDescriptor theValue) throws StandardException
Description copied from class:DataTypeSet the value of this DataValueDescriptor based on the value of the specified DataValueDescriptor.- Overrides:
setFromin classDataType- Parameters:
theValue- The DataValueDescriptor that holds the value to which we want to set this DataValueDescriptor's value.- Throws:
StandardException
-
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:
normalizein interfaceDataValueDescriptor- Overrides:
normalizein classDataType- Parameters:
desiredType- The type to normalize the source column tosource- The value to normalize- 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 void setWidth(int desiredWidth, int desiredScale, boolean errorOnTrunc) throws StandardExceptionSet 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:
setWidthin interfaceVariableSizeDataValue- Parameters:
desiredWidth- the desired lengthdesiredScale- the desired scale (ignored)errorOnTrunc- throw an error on truncation- Throws:
StandardException- Thrown when errorOnTrunc is true and when a shrink will truncate non-white spaces.
-
getUTF8Length
private int getUTF8Length(java.lang.String string, int start, int end) throws StandardExceptionGet the number of bytes needed to represent a string in modified UTF-8, which is the encoding used bywriteExternal()andwriteUTF().- Parameters:
string- the string whose length to calculatestart- start index (inclusive)end- end index (exclusive)- Throws:
StandardException
-
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:
equalsin interfaceDataValueDescriptor- Overrides:
equalsin classDataType- 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:
notEqualsin interfaceDataValueDescriptor- Overrides:
notEqualsin classDataType- Parameters:
left- The value on the left side of the operatorright- The value on the right side of the operator- 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:
lessThanin interfaceDataValueDescriptor- Overrides:
lessThanin classDataType- Parameters:
left- The value on the left side of the operatorright- The value on the right side of the operator- 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:
greaterThanin interfaceDataValueDescriptor- Overrides:
greaterThanin classDataType- Parameters:
left- The value on the left side of the operatorright- The value on the right side of the operator- 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:
lessOrEqualsin interfaceDataValueDescriptor- Overrides:
lessOrEqualsin classDataType- Parameters:
left- The value on the left side of the operatorright- The value on the right side of the operator- 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:
greaterOrEqualsin interfaceDataValueDescriptor- Overrides:
greaterOrEqualsin classDataType- Parameters:
left- The value on the left side of the operatorright- The value on the right side of the operator- 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:
charLengthin interfaceConcatableDataValue- 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:StringDataValueThe SQL concatenation '||' operator.- Specified by:
concatenatein interfaceStringDataValue- 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:
likein interfaceStringDataValue- 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:
likein interfaceStringDataValue- Parameters:
pattern- The pattern to useescape- 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:
locatein interfaceStringDataValue- Parameters:
searchFrom- - The string to search fromstart- - The position to search from in string searchFromresult- - 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:
substringin interfaceConcatableDataValue- Parameters:
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 result- Returns:
- A ConcatableDataValue containing the result of the substr()
- Throws:
StandardException- Thrown on error
-
trimInternal
private java.lang.String trimInternal(int trimType, char trimChar, java.lang.String source)This function public for testing purposes.- Parameters:
trimType- Type of trim (LEADING, TRAILING, or BOTH)trimChar- Character to trimsource- String from which to trim trimChar- Returns:
- A String containing the result of the trim.
-
ansiTrim
public StringDataValue ansiTrim(int trimType, StringDataValue trimChar, StringDataValue result) throws StandardException
Description copied from interface:StringDataValueThe SQL Ansi trim function.- Specified by:
ansiTrimin interfaceStringDataValue- Parameters:
trimType- Type of trim (LEADING, TRAILING, or BOTH)trimChar- Character to trim from this SQLChar (may be null)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
-
upper
public StringDataValue upper(StringDataValue result) throws StandardException
Description copied from interface:StringDataValueConvert the string to upper case.- Specified by:
upperin interfaceStringDataValue- 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:StringDataValueConvert the string to lower case.- Specified by:
lowerin interfaceStringDataValue- 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 class:DataTypeEach 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:
typePrecedencein interfaceDataValueDescriptor- Overrides:
typePrecedencein classDataType- 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 Stringop2- 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.- 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 Stringop2- The second String- Returns:
- -1 - op1 < op2 0 - op1 == op2 1 - op1 > op2
-
getCollationKey
protected java.text.CollationKey getCollationKey() throws StandardExceptionThis method gets called for the collation sensitive char classes ie CollatorSQLChar, CollatorSQLVarchar, CollatorSQLLongvarchar, CollatorSQLClob. These collation sensitive chars need to have the collation key in order to do string comparison. And the collation key is obtained using the Collator object that these classes already have.- Returns:
- CollationKey obtained using Collator on the string
- Throws:
StandardException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
hashCodeForCollation
int hashCodeForCollation()
Hash code implementation for collator sensitive subclasses.
-
getNewVarchar
protected StringDataValue getNewVarchar() throws StandardException
Get a SQLVarchar for a built-in string function.- Returns:
- a SQLVarchar.
- Throws:
StandardException- Thrown on error
-
setLocaleFinder
protected void setLocaleFinder(LocaleFinder localeFinder)
-
getLocale
private java.util.Locale getLocale() throws StandardException- Throws:
StandardException- Thrown on error
-
getCollatorForCollation
protected java.text.RuleBasedCollator getCollatorForCollation() throws StandardException- Throws:
StandardException
-
getLocaleFinder
protected LocaleFinder getLocaleFinder()
-
estimateMemoryUsage
public int estimateMemoryUsage()
Description copied from interface:DataValueDescriptorEstimate the memory usage in bytes of the data value and the overhead of the class.- Specified by:
estimateMemoryUsagein interfaceDataValueDescriptor- Returns:
- the estimated memory usage
-
copyState
protected void copyState(SQLChar other)
-
copyState
private void copyState(java.lang.String otherValue, char[] otherRawData, int otherRawLength, java.text.CollationKey otherCKey, java.io.InputStream otherStream, java.sql.Clob otherClobValue, LocaleFinder otherLocaleFinder)
-
getTraceString
public java.lang.String getTraceString() throws StandardExceptionGets a trace representation for debugging.- Specified by:
getTraceStringin interfaceDataValueDescriptor- Overrides:
getTraceStringin classDataType- Returns:
- a trace representation of this SQL Type.
- Throws:
StandardException- if getting the data value fails.- See Also:
DataValueDescriptor.getString()
-
getStreamHeaderGenerator
public StreamHeaderGenerator getStreamHeaderGenerator()
Returns the default stream header generator for the string data types.- Specified by:
getStreamHeaderGeneratorin interfaceStringDataValue- Returns:
- A stream header generator.
- See Also:
StringDataValue.setStreamHeaderFormat(java.lang.Boolean)
-
setStreamHeaderFormat
public void setStreamHeaderFormat(java.lang.Boolean inSoftUpgradeMode)
Sets the mode for the database being accessed.- Specified by:
setStreamHeaderFormatin interfaceStringDataValue- Parameters:
inSoftUpgradeMode-trueif the database is being accessed in soft upgrade mode,falseif not, andnullif unknown
-
getClobLength
private int getClobLength() throws StandardException- Throws:
StandardException
-
rawGetClobLength
private int rawGetClobLength() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
-