org.apache.derby.iapi.types
Class ClobStreamHeaderGenerator

java.lang.Object
  extended by org.apache.derby.iapi.types.ClobStreamHeaderGenerator
All Implemented Interfaces:
StreamHeaderGenerator

public final class ClobStreamHeaderGenerator
extends java.lang.Object
implements StreamHeaderGenerator

Generates stream headers for Clob data values.

THREAD SAFETY NOTE: This class is considered thread safe, even though it strictly speaking isn't. However, with the assumption that an instance of this class cannot be shared across databases with different versions, the only bad thing that can happen is that the mode is obtained several times.


Field Summary
private  StringDataValue callbackDVD
          Reference to "owning" DVD, used to update it with information about which header format should be used.
private static CharStreamHeaderGenerator CHARHDRGEN
          Header generator for the pre 10.5 header format.
private  java.lang.Boolean isPreDerbyTenFive
          true if the database version is prior to 10.5, false if the version is 10.5 or newer.
private static byte MAGIC_BYTE
          Magic byte for the 10.5 stream header format.
private static byte[] UNKNOWN_LENGTH
          Bytes for a 10.5 unknown length header.
 
Fields inherited from interface org.apache.derby.iapi.types.StreamHeaderGenerator
DERBY_EOF_MARKER
 
Constructor Summary
ClobStreamHeaderGenerator(boolean isPreDerbyTenFive)
          Creates a new generator using the specified header format.
ClobStreamHeaderGenerator(StringDataValue dvd)
          Creates a new generator that will use the context manager to determine which header format to use based on the database version.
 
Method Summary
private  void determineHeaderFormat()
          Determines which header format to use.
 boolean expectsCharCount()
          Tells if the header encodes a character or byte count.
 int generateInto(byte[] buf, int offset, long valueLength)
          Generates the header for the specified length and writes it into the provided buffer, starting at the specified offset.
 int generateInto(java.io.ObjectOutput out, long valueLength)
          Generates the header for the specified length.
 int getMaxHeaderLength()
          Returns the maximum header length.
 int writeEOF(byte[] buffer, int offset, long valueLength)
          Writes a Derby-specific end-of-stream marker to the buffer for a stream of the specified character length, if required.
 int writeEOF(java.io.ObjectOutput out, long valueLength)
          Writes a Derby-specific end-of-stream marker to the destination stream for the specified character length, if required.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAGIC_BYTE

private static final byte MAGIC_BYTE
Magic byte for the 10.5 stream header format.

See Also:
Constant Field Values

UNKNOWN_LENGTH

private static final byte[] UNKNOWN_LENGTH
Bytes for a 10.5 unknown length header.


CHARHDRGEN

private static final CharStreamHeaderGenerator CHARHDRGEN
Header generator for the pre 10.5 header format. This format is used for Clobs as well if the database version is pre 10.5.


callbackDVD

private final StringDataValue callbackDVD
Reference to "owning" DVD, used to update it with information about which header format should be used. This is currently only determined by consulting the data dictionary about the version.

This is an optimization to avoid having to consult the data dictionary on every request to generate a header when a data value descriptor is reused.


isPreDerbyTenFive

private java.lang.Boolean isPreDerbyTenFive
true if the database version is prior to 10.5, false if the version is 10.5 or newer. If null, the version will be determined by obtaining the database context through the context service.

Constructor Detail

ClobStreamHeaderGenerator

public ClobStreamHeaderGenerator(StringDataValue dvd)
Creates a new generator that will use the context manager to determine which header format to use based on the database version.

Parameters:
dvd - the owning data value descriptor

ClobStreamHeaderGenerator

public ClobStreamHeaderGenerator(boolean isPreDerbyTenFive)
Creates a new generator using the specified header format.

Parameters:
isPreDerbyTenFive - true if the database version is prior to 10.5, false if the version is 10.5 or newer
Method Detail

expectsCharCount

public boolean expectsCharCount()
Tells if the header encodes a character or byte count.

Currently the header expects a character count if the header format is 10.5 (or newer), and a byte count if we are accessing a database created by a version prior to 10.5.

Specified by:
expectsCharCount in interface StreamHeaderGenerator
Returns:
false if a byte count is expected (prior to 10.5), true if a character count is expected (10.5 and newer).

generateInto

public int generateInto(byte[] buf,
                        int offset,
                        long valueLength)
Generates the header for the specified length and writes it into the provided buffer, starting at the specified offset.

Specified by:
generateInto in interface StreamHeaderGenerator
Parameters:
buf - the buffer to write into
offset - starting offset in the buffer
valueLength - the length to encode in the header
Returns:
The number of bytes written into the buffer.

generateInto

public int generateInto(java.io.ObjectOutput out,
                        long valueLength)
                 throws java.io.IOException
Generates the header for the specified length.

Specified by:
generateInto in interface StreamHeaderGenerator
Parameters:
out - the destination stream
valueLength - the length to encode in the header
Returns:
The number of bytes written to the destination stream.
Throws:
java.io.IOException - if writing to the destination stream fails

writeEOF

public int writeEOF(byte[] buffer,
                    int offset,
                    long valueLength)
Writes a Derby-specific end-of-stream marker to the buffer for a stream of the specified character length, if required.

Specified by:
writeEOF in interface StreamHeaderGenerator
Parameters:
buffer - the buffer to write into
offset - starting offset in the buffer
valueLength - the length of the stream
Returns:
Number of bytes written (zero or more).

writeEOF

public int writeEOF(java.io.ObjectOutput out,
                    long valueLength)
             throws java.io.IOException
Writes a Derby-specific end-of-stream marker to the destination stream for the specified character length, if required.

Specified by:
writeEOF in interface StreamHeaderGenerator
Parameters:
out - the destination stream
valueLength - the length of the stream
Returns:
Number of bytes written (zero or more).
Throws:
java.io.IOException - if writing to the destination stream fails

getMaxHeaderLength

public int getMaxHeaderLength()
Returns the maximum header length.

Specified by:
getMaxHeaderLength in interface StreamHeaderGenerator
Returns:
Maximum header length in bytes.

determineHeaderFormat

private void determineHeaderFormat()
Determines which header format to use.

Implementation note: The header format is determined by consulting the data dictionary throught the context service. If there is no context, the operation will fail.

Throws:
java.lang.IllegalStateException - if there is no context

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.