Module org.firebirdsql.jaybird
Package org.firebirdsql.gds.ng.wire

# Class DefaultBlrCalculator

java.lang.Object
org.firebirdsql.gds.ng.wire.DefaultBlrCalculator

All Implemented Interfaces:
  `BlrCalculator`

public class DefaultBlrCalculator extends Object implements BlrCalculator
Default BLR calculator for the wire protocol.

Most likely this can be used without change for other protocol versions as well, although we may need to investigate the TODOs specified in `calculateBlr(org.firebirdsql.gds.ng.fields.RowDescriptor)`.

Since:
  3.0
Author:
  Mark Rotteveel

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final DefaultBlrCalculator`
  `CALCULATOR_DIALECT_3`
  Cached instance of `DefaultBlrCalculator` for dialect 3 databases.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DefaultBlrCalculator(short dialect)`
  Creates a BLR calculator.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `calculateBatchMessageLength(RowDescriptor rowDescriptor)`
  Calculates the batch message length.
  `byte[]`
  `calculateBlr(RowDescriptor rowDescriptor)`
  Calculates the blr for the row descriptor.
  `byte[]`
  `calculateBlr(RowDescriptor rowDescriptor, RowValue rowValue)`
  Calculates the blr for a specific row value.
  `int`
  `calculateIoLength(FieldDescriptor fieldDescriptor)`
  Calculates the io length for the field descriptor.
  `int`
  `calculateIoLength(FieldDescriptor fieldDescriptor, byte[] fieldData)`
  Calculates the io length for the field descriptor and actual data.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### CALCULATOR_DIALECT_3

    public static final DefaultBlrCalculator CALCULATOR_DIALECT_3
    Cached instance of `DefaultBlrCalculator` for dialect 3 databases.

- ## Constructor Details

  - ### DefaultBlrCalculator

    public DefaultBlrCalculator(short dialect)
    Creates a BLR calculator.
    Parameters:
      `dialect` - dialect, should be `ISCConstants.SQL_DIALECT_V6` (dialect 3) or `ISCConstants.SQL_DIALECT_V5` (dialect 1), but currently `dialect <= 1` is treated as dialect 1 and everything else as dialect 3

- ## Method Details

  - ### calculateBlr

    public byte[] calculateBlr(RowDescriptor rowDescriptor) throws SQLException
    Description copied from interface: `BlrCalculator`
    Calculates the blr for the row descriptor.
    Specified by:
      `calculateBlr` in interface `BlrCalculator`
    Parameters:
      `rowDescriptor` - Row descriptor
    Returns:
      Byte array with the blr
    Throws:
      `SQLException` - When the `RowDescriptor` contains an unsupported field type.

  - ### calculateBlr

    public byte[] calculateBlr(RowDescriptor rowDescriptor, RowValue rowValue) throws SQLException
    Description copied from interface: `BlrCalculator`
    Calculates the blr for a specific row value.

    This allows to optimize for the actual length of the field.

    Specified by:
      `calculateBlr` in interface `BlrCalculator`
    Parameters:
      `rowDescriptor` - Row descriptor
      `rowValue` - Row value
    Returns:
      Byte array with the blr
    Throws:
      `SQLException` - When the `RowValue` contains an unsupported field type.

  - ### calculateIoLength

    public int calculateIoLength(FieldDescriptor fieldDescriptor) throws SQLException
    Description copied from interface: `BlrCalculator`
    Calculates the io length for the field descriptor.

    The return value indicates the length and padding of the type in the buffer

    - < 0 : Type is of specified length * -1 and not padded
    - == 0 : Type is of dynamic length (which is specified in the buffer as an integer) and padded
    - > 0 : Type is of specified length minus 1 (subtracting 1 is required to avoid 0 for types of zero length) and padded
    Specified by:
      `calculateIoLength` in interface `BlrCalculator`
    Parameters:
      `fieldDescriptor` - Field descriptor
    Returns:
      The io length
    Throws:
      `SQLException`

  - ### calculateIoLength

    public int calculateIoLength(FieldDescriptor fieldDescriptor, byte[] fieldData) throws SQLException
    Description copied from interface: `BlrCalculator`
    Calculates the io length for the field descriptor and actual data.

    The return value indicates the length and padding of the type in the buffer

    - < 0 : Type is of specified length * -1 and not padded
    - == 0 : Type is of dynamic length (which is specified in the buffer as an integer) and padded
    - > 0 : Type is of specified length minus 1 (subtracting 1 is required to avoid 0 for types of zero length) and padded

    This allows to optimize for the actual length of the field.

    For `CHAR` (`ISCConstants.SQL_TEXT` the implementation should be consistent with the lengths as given by `BlrCalculator.calculateIoLength(FieldDescriptor)`.

    Specified by:
      `calculateIoLength` in interface `BlrCalculator`
    Parameters:
      `fieldDescriptor` - Field descriptor
      `fieldData` - byte array (can be `null`) with field data.
    Returns:
      The io length
    Throws:
      `SQLException`

  - ### calculateBatchMessageLength

    public int calculateBatchMessageLength(RowDescriptor rowDescriptor) throws SQLException
    Description copied from interface: `BlrCalculator`
    Calculates the batch message length.
    Specified by:
      `calculateBatchMessageLength` in interface `BlrCalculator`
    Parameters:
      `rowDescriptor` - row descriptor
    Returns:
      batch message length
    Throws:
      `SQLException` - when the `RowDescriptor` contains an unsupported field type.