Top Description Fields Constructors Methods
org.apache.derby.client.am

pack-priv Class CallableLocatorProcedures

extends Object
Class Inheritance
Imports
java.sql.ResultSet, .Types, org.apache.derby.shared.common.error.ExceptionUtil, org.apache.derby.shared.common.reference.SQLState

Contains the necessary methods to call the stored procedure that operate on LOBs identified by locators. An instance of this class will be initialized with a Connection parameter and all calls will be made on that connection.

The class makes sure that each procedure call is only prepared once per instance. Hence, it will keep references to CallableStatement objects for procedures that have been called through this instance. This makes it possible to prepare each procedure call only once per Connection.

Since LOBs can not be parameters to stored procedures, the framework should make sure that calls involving a byte[] or String that does not fit in a VARCHAR (FOR BIT DATA), are split into several calls each operating on a fragment of the LOB.

See Also
{@link ClientConnection#locatorProcedureCall} for an example of how to use this class.

Field Summary

Modifier and TypeField and Description
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private ClientCallableStatement
private final ClientConnection
connection

The connection to be used when calling the stored procedures.

private static final int
private boolean
private static final int
VARCHAR_MAXWIDTH

Max size of byte[] and String parameters to procedures

Constructor Summary

AccessConstructor and Description
pack-priv
CallableLocatorProcedures(ClientConnection
the connection to be used to prepare calls.
conn
)

Create an instance to be used for calling locator-based stored procedures.

Method Summary

Modifier and TypeMethod and Description
pack-priv int

Returns:

locator that identifies the created BLOB.
blobCreateLocator
()

Allocates an empty BLOB on server and returns its locator.

pack-priv byte[]

Returns:

a byte array containing up to forLength consecutive bytes from the BLOB value designated by sourceLocator, starting with the byte at position fromPosition
blobGetBytes
(int
locator that identifies the Blob to operate on
sourceLocator
,
long
the ordinal position of the first byte in the BLOB value to be extracted; the first byte is at position 1
fromPosition
,
int
the number of consecutive bytes to be copied; the value for length must be 0 or greater. Specifying a length that goes beyond the end of the BLOB (i.e., fromPosition + forLength > blob.length()), will result in an error.
forLength
)

Retrieves all or part of the BLOB value that is identified by sourceLocator, as an array of bytes.

pack-priv long

Returns:

length of the BLOB in bytes
blobGetLength
(int
locator that identifies the BLOB
sourceLocator
)

Returns the number of bytes in the BLOB value designated by this sourceLocator.

pack-priv long

Returns:

the position at which the pattern appears, else -1
blobGetPositionFromBytes
(int
locator that identifies the BLOB to be searched.
locator
,
byte[]
the byte array for which to search
searchLiteral
,
long
the position at which to begin searching; the first position is 1
fromPosition
)

Retrieves the byte position at which the specified byte array searchLiteral begins within the BLOB value identified by locator.

private long

Returns:

the position at which the pattern appears, else -1
blobGetPositionFromBytes
(int
locator that identifies the BLOB to be searched.
locator
,
long
the position at which to begin searching; the first position is 1
fromPosition
,
byte[]
the byte array for which to search
searchLiteral
,
int
the offset into the array searchLiteral at which the pattern to search for starts
offset
,
int
the number of bytes from the array of bytes searchLiteral to use for the pattern to search for. It is assumed that this length is smaller than the maximum size of a VARCHAR FOR BIT DATA column. Otherwise, an exception will be thrown.
length
)

Retrieves the byte position at which the specified part of the byte array searchLiteral begins within the BLOB value identified by locator.

pack-priv long

Returns:

the position at which the pattern begins, else -1
blobGetPositionFromLocator
(int
locator that identifies the BLOB to be searched.
locator
,
int
locator designating the BLOB value for which to search
searchLocator
,
long
the position in the BLOB value at which to begin searching; the first position is 1
fromPosition
)

Retrieves the byte position in the BLOB value designated by this locator at which pattern given by searchLocator begins.

pack-priv void
blobReleaseLocator(int
locator that designates the BLOB to be released.
locator
)

This method frees the BLOB and releases the resources that it holds.

pack-priv void
blobSetBytes(int
locator that identifies the Blob to operated on
sourceLocator
,
long
the position in the BLOB value at which to start writing; the first position is 1
fromPosition
,
int
the number of bytes to be written to the BLOB value from the array of bytes bytes. Specifying a length that goes beyond the end of the BLOB (i.e., fromPosition + forLength > blob.length(), will result in an error.
forLength
,
byte[]
the array of bytes to be written
bytes
)

Writes all or part of the given byte array to the BLOB value designated by sourceLocator.

pack-priv void
blobTruncate(int
locator identifying the Blob to be truncated
sourceLocator
,
long
the length, in bytes, to which the BLOB value should be truncated
length
)

Truncates the BLOB value identified by sourceLocator to be length bytes.

pack-priv int

Returns:

locator that identifies the created CLOB.
clobCreateLocator
()

Allocates an empty CLOB on server and returns its locator.

pack-priv long

Returns:

length of the CLOB in characters
clobGetLength
(int
locator that identifies the CLOB
sourceLocator
)

Returns the number of character in the CLOB value designated by this sourceLocator.

pack-priv long

Returns:

the position at which the pattern begins, else -1
clobGetPositionFromLocator
(int
locator that identifies the CLOB to be searched.
locator
,
int
locator designating the CLOB value for which to search
searchLocator
,
long
the position in the CLOB value at which to begin searching; the first position is 1
fromPosition
)

Retrieves the character position in the CLOB value designated by this locator at which substring given by searchLocator begins.

pack-priv long

Returns:

the position at which the pattern appears, else -1
clobGetPositionFromString
(int
locator that identifies the CLOB to be searched.
locator
,
String
the substring for which to search
searchLiteral
,
long
the position at which to begin searching; the first position is 1
fromPosition
)

Retrieves the character position at which the specified substring searchLiteral begins within the CLOB value identified by locator.

private long

Returns:

the position at which the pattern appears, else -1
clobGetPositionFromString
(int
locator that identifies the CLOB to be searched.
locator
,
long
the position at which to begin searching; the first position is 1
fromPosition
,
String
the substring for which to search
searchLiteral
,
int
the offset into the string searchLiteral at which the pattern to search for starts
offset
,
int
the number of characters from the string searchLiteral to use for the pattern to search for. It is assumed that this length is smaller than the maximum size of a VARCHAR column. Otherwise, an exception will be thrown.
length
)

Retrieves the character position at which the specified part of the substring searchLiteral begins within the CLOB value identified by locator.

pack-priv String

Returns:

a string containing up to forLength consecutive characters from the CLOB value designated by sourceLocator, starting with the character at position fromPosition
clobGetSubString
(int
locator that identifies the CLOB to operate on
sourceLocator
,
long
the ordinal position of the first character in the CLOB value to be extracted; the first character is at position 1
fromPosition
,
int
the number of consecutive characters to be copied; the value for length must be 0 or greater. Specifying a length that goes beyond the end of the CLOB (i.e., fromPosition + forLength > clob.length(), will result in an error.
forLength
)

Retrieves all or part of the CLOB value that is identified by sourceLocator, as a String.

pack-priv void
clobReleaseLocator(int
locator that designates the CLOB to be released.
locator
)

This method frees the CLOB and releases the resources that it holds.

pack-priv void
clobSetString(int
locator that identifies the CLOB to operated on
sourceLocator
,
long
the position in the CLOB value at which to start writing; the first position is 1
fromPosition
,
int
the number of characters to be written to the CLOB value from the string string. Specifying a length that goes beyond the end of the CLOB (i.e., fromPosition + forLength > clob.length(), will result in an error.
forLength
,
String
the string to be written
string
)

Writes all or part of the given String to the CLOB value designated by sourceLocator.

pack-priv void
clobTruncate(int
locator identifying the CLOB to be truncated
sourceLocator
,
long
the length, in characters, to which the CLOB value should be truncated
length
)

Truncates the CLOB value identified by sourceLocator to be length characters.

private SqlException

Returns:

If sqle indicates that locator was invalid, an SqlException with SQL state LOB_OBJECT_INVALID. Otherwise, the incoming exception is returned.
handleInvalidLocator
(SqlException
Exception to be checked
sqle
)

If the given exception indicates that locator was not valid, we assume the locator has been garbage-collected due to transaction commit, and wrap the exception in an exception with SQL state LOB_OBJECT_INVALID.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blobCreateLocatorCallback to summary
private ClientCallableStatement blobCreateLocatorCall
blobGetBytesCallback to summary
private ClientCallableStatement blobGetBytesCall
blobGetLengthCallback to summary
private ClientCallableStatement blobGetLengthCall
blobGetPositionFromBytesCallback to summary
private ClientCallableStatement blobGetPositionFromBytesCall
blobGetPositionFromLocatorCallback to summary
private ClientCallableStatement blobGetPositionFromLocatorCall
blobReleaseLocatorCallback to summary
private ClientCallableStatement blobReleaseLocatorCall
blobSetBytesCallback to summary
private ClientCallableStatement blobSetBytesCall
blobTruncateCallback to summary
private ClientCallableStatement blobTruncateCall
clobCreateLocatorCallback to summary
private ClientCallableStatement clobCreateLocatorCall
clobGetLengthCallback to summary
private ClientCallableStatement clobGetLengthCall
clobGetPositionFromLocatorCallback to summary
private ClientCallableStatement clobGetPositionFromLocatorCall
clobGetPositionFromStringCallback to summary
private ClientCallableStatement clobGetPositionFromStringCall
clobGetSubStringCallback to summary
private ClientCallableStatement clobGetSubStringCall
clobReleaseLocatorCallback to summary
private ClientCallableStatement clobReleaseLocatorCall
clobSetStringCallback to summary
private ClientCallableStatement clobSetStringCall
clobTruncateCallback to summary
private ClientCallableStatement clobTruncateCall
connectionback to summary
private final ClientConnection connection

The connection to be used when calling the stored procedures.

INVALID_LOCATORback to summary
private static final int INVALID_LOCATOR
isLocatorSupportAvailableback to summary
private boolean isLocatorSupportAvailable
VARCHAR_MAXWIDTHback to summary
private static final int VARCHAR_MAXWIDTH

Max size of byte[] and String parameters to procedures

Constructor Detail

CallableLocatorProceduresback to summary
pack-priv CallableLocatorProcedures(ClientConnection conn)

Create an instance to be used for calling locator-based stored procedures.

Parameters
conn:ClientConnection

the connection to be used to prepare calls.

Method Detail

blobCreateLocatorback to summary
pack-priv int blobCreateLocator() throws SqlException

Allocates an empty BLOB on server and returns its locator. Any subsequent operations on this BLOB value will be stored in temporary space on the server.

Returns:int

locator that identifies the created BLOB.

blobGetBytesback to summary
pack-priv byte[] blobGetBytes(int sourceLocator, long fromPosition, int forLength) throws SqlException

Retrieves all or part of the BLOB value that is identified by sourceLocator, as an array of bytes. This byte array contains up to forLength consecutive bytes starting at position fromPosition.

If forLength is larger than the maximum length of a VARCHAR FOR BIT DATA, the reading of the BLOB will be split into repeated procedure calls.

Parameters
sourceLocator:int

locator that identifies the Blob to operate on

fromPosition:long

the ordinal position of the first byte in the BLOB value to be extracted; the first byte is at position 1

forLength:int

the number of consecutive bytes to be copied; the value for length must be 0 or greater. Specifying a length that goes beyond the end of the BLOB (i.e., fromPosition + forLength > blob.length()), will result in an error.

Returns:byte[]

a byte array containing up to forLength consecutive bytes from the BLOB value designated by sourceLocator, starting with the byte at position fromPosition

blobGetLengthback to summary
pack-priv long blobGetLength(int sourceLocator) throws SqlException

Returns the number of bytes in the BLOB value designated by this sourceLocator.

Parameters
sourceLocator:int

locator that identifies the BLOB

Returns:long

length of the BLOB in bytes

blobGetPositionFromBytesback to summary
pack-priv long blobGetPositionFromBytes(int locator, byte[] searchLiteral, long fromPosition) throws SqlException

Retrieves the byte position at which the specified byte array searchLiteral begins within the BLOB value identified by locator. The search for searchLiteral begins at position fromPosition.

If searchLiteral is longer than the maximum length of a VARCHAR FOR BIT DATA, it will be split into smaller fragments, and repeated procedure calls will be made to perform the entire search

Parameters
locator:int

locator that identifies the BLOB to be searched.

searchLiteral:byte[]

the byte array for which to search

fromPosition:long

the position at which to begin searching; the first position is 1

Returns:long

the position at which the pattern appears, else -1

blobGetPositionFromBytesback to summary
private long blobGetPositionFromBytes(int locator, long fromPosition, byte[] searchLiteral, int offset, int length) throws SqlException

Retrieves the byte position at which the specified part of the byte array searchLiteral begins within the BLOB value identified by locator. The search for searchLiteral begins at position fromPosition.

This is a helper function used by blobGetPositionFromBytes(int, byte[], long) for each call to the BLOBGETPOSITIONFROMBYTES procedure.

Parameters
locator:int

locator that identifies the BLOB to be searched.

fromPosition:long

the position at which to begin searching; the first position is 1

searchLiteral:byte[]

the byte array for which to search

offset:int

the offset into the array searchLiteral at which the pattern to search for starts

length:int

the number of bytes from the array of bytes searchLiteral to use for the pattern to search for. It is assumed that this length is smaller than the maximum size of a VARCHAR FOR BIT DATA column. Otherwise, an exception will be thrown.

Returns:long

the position at which the pattern appears, else -1

blobGetPositionFromLocatorback to summary
pack-priv long blobGetPositionFromLocator(int locator, int searchLocator, long fromPosition) throws SqlException

Retrieves the byte position in the BLOB value designated by this locator at which pattern given by searchLocator begins. The search begins at position fromPosition.

Parameters
locator:int

locator that identifies the BLOB to be searched.

searchLocator:int

locator designating the BLOB value for which to search

fromPosition:long

the position in the BLOB value at which to begin searching; the first position is 1

Returns:long

the position at which the pattern begins, else -1

blobReleaseLocatorback to summary
pack-priv void blobReleaseLocator(int locator) throws SqlException

This method frees the BLOB and releases the resources that it holds. (E.g., temporary space used to store this BLOB on the server.)

Parameters
locator:int

locator that designates the BLOB to be released.

blobSetBytesback to summary
pack-priv void blobSetBytes(int sourceLocator, long fromPosition, int forLength, byte[] bytes) throws SqlException

Writes all or part of the given byte array to the BLOB value designated by sourceLocator. Writing starts at position fromPosition in the BLOB value; forLength bytes from the given byte array are written. If the end of the Blob value is reached while writing the array of bytes, then the length of the Blob value will be increased to accomodate the extra bytes.

If forLength is larger than the maximum length of a VARCHAR FOR BIT DATA, the writing to the BLOB value will be split into repeated procedure calls.

Parameters
sourceLocator:int

locator that identifies the Blob to operated on

fromPosition:long

the position in the BLOB value at which to start writing; the first position is 1

forLength:int

the number of bytes to be written to the BLOB value from the array of bytes bytes. Specifying a length that goes beyond the end of the BLOB (i.e., fromPosition + forLength > blob.length(), will result in an error.

bytes:byte[]

the array of bytes to be written

blobTruncateback to summary
pack-priv void blobTruncate(int sourceLocator, long length) throws SqlException

Truncates the BLOB value identified by sourceLocator to be length bytes.

Note

If the value specified for length is greater than the length+1 of the BLOB value then an SqlException will be thrown.

Parameters
sourceLocator:int

locator identifying the Blob to be truncated

length:long

the length, in bytes, to which the BLOB value should be truncated

clobCreateLocatorback to summary
pack-priv int clobCreateLocator() throws SqlException

Allocates an empty CLOB on server and returns its locator. Any subsequent operations on this CLOB value will be stored in temporary space on the server.

Returns:int

locator that identifies the created CLOB.

clobGetLengthback to summary
pack-priv long clobGetLength(int sourceLocator) throws SqlException

Returns the number of character in the CLOB value designated by this sourceLocator.

Parameters
sourceLocator:int

locator that identifies the CLOB

Returns:long

length of the CLOB in characters

clobGetPositionFromLocatorback to summary
pack-priv long clobGetPositionFromLocator(int locator, int searchLocator, long fromPosition) throws SqlException

Retrieves the character position in the CLOB value designated by this locator at which substring given by searchLocator begins. The search begins at position fromPosition.

Parameters
locator:int

locator that identifies the CLOB to be searched.

searchLocator:int

locator designating the CLOB value for which to search

fromPosition:long

the position in the CLOB value at which to begin searching; the first position is 1

Returns:long

the position at which the pattern begins, else -1

clobGetPositionFromStringback to summary
pack-priv long clobGetPositionFromString(int locator, String searchLiteral, long fromPosition) throws SqlException

Retrieves the character position at which the specified substring searchLiteral begins within the CLOB value identified by locator. The search for searchLiteral begins at position fromPosition.

If searchLiteral is longer than the maximum length of a VARCHAR, it will be split into smaller fragments, and repeated procedure calls will be made to perform the entire search

Parameters
locator:int

locator that identifies the CLOB to be searched.

searchLiteral:String

the substring for which to search

fromPosition:long

the position at which to begin searching; the first position is 1

Returns:long

the position at which the pattern appears, else -1

clobGetPositionFromStringback to summary
private long clobGetPositionFromString(int locator, long fromPosition, String searchLiteral, int offset, int length) throws SqlException

Retrieves the character position at which the specified part of the substring searchLiteral begins within the CLOB value identified by locator. The search for searchLiteral begins at position fromPosition.

This is a helper function used by clobGetPositionFromString(int, String, long) for each call to the CLOBGETPOSITIONFROMSTRING procedure.

Parameters
locator:int

locator that identifies the CLOB to be searched.

fromPosition:long

the position at which to begin searching; the first position is 1

searchLiteral:String

the substring for which to search

offset:int

the offset into the string searchLiteral at which the pattern to search for starts

length:int

the number of characters from the string searchLiteral to use for the pattern to search for. It is assumed that this length is smaller than the maximum size of a VARCHAR column. Otherwise, an exception will be thrown.

Returns:long

the position at which the pattern appears, else -1

clobGetSubStringback to summary
pack-priv String clobGetSubString(int sourceLocator, long fromPosition, int forLength) throws SqlException

Retrieves all or part of the CLOB value that is identified by sourceLocator, as a String. This String contains up to forLength consecutive characters starting at position fromPosition.

If forLength is larger than the maximum length of a VARCHAR, the reading of the CLOB will be split into repeated procedure calls.

Parameters
sourceLocator:int

locator that identifies the CLOB to operate on

fromPosition:long

the ordinal position of the first character in the CLOB value to be extracted; the first character is at position 1

forLength:int

the number of consecutive characters to be copied; the value for length must be 0 or greater. Specifying a length that goes beyond the end of the CLOB (i.e., fromPosition + forLength > clob.length(), will result in an error.

Returns:String

a string containing up to forLength consecutive characters from the CLOB value designated by sourceLocator, starting with the character at position fromPosition

clobReleaseLocatorback to summary
pack-priv void clobReleaseLocator(int locator) throws SqlException

This method frees the CLOB and releases the resources that it holds. (E.g., temporary space used to store this CLOB on the server.)

Parameters
locator:int

locator that designates the CLOB to be released.

clobSetStringback to summary
pack-priv void clobSetString(int sourceLocator, long fromPosition, int forLength, String string) throws SqlException

Writes all or part of the given String to the CLOB value designated by sourceLocator. Writing starts at position fromPosition in the CLOB value; forLength characters from the given string are written. If the end of the CLOB value is reached while writing the string, then the length of the CLOB value will be increased to accomodate the extra characters.

If forLength is larger than the maximum length of a VARCHAR, the writing to the CLOB value will be split into repeated procedure calls.

Parameters
sourceLocator:int

locator that identifies the CLOB to operated on

fromPosition:long

the position in the CLOB value at which to start writing; the first position is 1

forLength:int

the number of characters to be written to the CLOB value from the string string. Specifying a length that goes beyond the end of the CLOB (i.e., fromPosition + forLength > clob.length(), will result in an error.

string:String

the string to be written

clobTruncateback to summary
pack-priv void clobTruncate(int sourceLocator, long length) throws SqlException

Truncates the CLOB value identified by sourceLocator to be length characters.

Note

If the value specified for length is greater than the length+1 of the CLOB value then an SqlException will be thrown.

Parameters
sourceLocator:int

locator identifying the CLOB to be truncated

length:long

the length, in characters, to which the CLOB value should be truncated

handleInvalidLocatorback to summary
private SqlException handleInvalidLocator(SqlException sqle)

If the given exception indicates that locator was not valid, we assume the locator has been garbage-collected due to transaction commit, and wrap the exception in an exception with SQL state LOB_OBJECT_INVALID.

Parameters
sqle:SqlException

Exception to be checked

Returns:SqlException

If sqle indicates that locator was invalid, an SqlException with SQL state LOB_OBJECT_INVALID. Otherwise, the incoming exception is returned.