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

# Class FieldDescriptor

java.lang.Object
org.firebirdsql.gds.ng.fields.FieldDescriptor

public final class FieldDescriptor extends Object
The class `FieldDescriptor` contains the column metadata of the XSQLVAR server data structure used to describe one column for input or output.

FieldDescriptor is an immutable type, the value of a field is maintained separately in `RowValue`.

Author:
  Mark Rotteveel

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FieldDescriptor(int position, DatatypeCoder datatypeCoder, int type, int subType, int scale, int length, String fieldName, String tableAlias, String originalName, String originalTableName, String ownerName)`
  Constructor for metadata FieldDescriptor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  `int`
  `getCharacterLength()`
  The length in characters of this field.
  `int`
  `getCharacterSetId()`
  Determines the character set id (without collation id).
  `DatatypeCoder`
  `getDatatypeCoder()`
  `IEncodingFactory`
  `getEncodingFactory()`
  `String`
  `getFieldName()`
  `int`
  `getLength()`
  `String`
  `getOriginalName()`
  `String`
  `getOriginalTableName()`
  `String`
  `getOwnerName()`
  `byte`
  `getPaddingByte()`
  Padding to use for fields of this type.
  `int`
  `getPosition()`
  The position of the field in the row or parameter set.
  `int`
  `getScale()`
  `int`
  `getSubType()`
  `String`
  `getTableAlias()`
  `int`
  `getType()`
  `int`
  `hashCode()`
  `boolean`
  `isDbKey()`
  Determines if this is a db-key (RDB$DB_KEY) of a table.
  `boolean`
  `isFbType(int fbType)`
  Check if the type of this field is the specified Firebird data type.
  `boolean`
  `isNullable()`
  `boolean`
  `isVarying()`
  `String`
  `toString()`
  `boolean`
  `typeEquals(FieldDescriptor other)`
  Limited equals that only checks if the data type in the provided field descriptor is the same as this descriptor.

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

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### FieldDescriptor

    public FieldDescriptor(int position, DatatypeCoder datatypeCoder, int type, int subType, int scale, int length, String fieldName, String tableAlias, String originalName, String originalTableName, String ownerName)
    Constructor for metadata FieldDescriptor.
    Parameters:
      `position` - Position of this field (0-based), or `-1` if position is not known (e.g. for test code)
      `datatypeCoder` - Instance of DatatypeCoder to use when decoding column data (note that another instance may be derived internally, which then will be returned by `getDatatypeCoder()`)
      `type` - Column SQL type
      `subType` - Column subtype
      `scale` - Column scale
      `length` - Column defined length
      `fieldName` - Column alias name
      `tableAlias` - Column table alias
      `originalName` - Column original name
      `originalTableName` - Column original table
      `ownerName` - Owner of the column/table

- ## Method Details

  - ### getPosition

    public int getPosition()
    The position of the field in the row or parameter set.

    In general this should be equal to the position of this descriptor in `RowDescriptor`, but in some cases (usually test code), it might be `-1` instead.

    Returns:
      The 0-based position of this field in the row or parameter set (or `-1` if unknown)

  - ### getDatatypeCoder

    public DatatypeCoder getDatatypeCoder()
    Returns:
      The `DatatypeCoder` to use when decoding field data.

  - ### getEncodingFactory

    public IEncodingFactory getEncodingFactory()
    Returns:
      The `IEncodingFactory` for the associated connection.

  - ### getType

    public int getType()
    Returns:
      The Firebird type of this field

  - ### getSubType

    public int getSubType()
    Returns:
      The Firebird subtype of this field

  - ### getScale

    public int getScale()
    Returns:
      The scale of this field

  - ### getLength

    public int getLength()
    Returns:
      The declared (maximum) length of this field

  - ### getFieldName

    public String getFieldName()
    Returns:
      The (aliased) field name

  - ### getTableAlias

    public String getTableAlias()
    Returns:
      The (aliased) table name

  - ### getOriginalName

    public String getOriginalName()
    Returns:
      The original name of the field (e.g. the column name in the table)

  - ### getOriginalTableName

    public String getOriginalTableName()
    Returns:
      The original table name

  - ### getOwnerName

    public String getOwnerName()
    Returns:
      The owner

  - ### isVarying

    public boolean isVarying()
    Returns:
      `true` if the type is variable length (ie `ISCConstants.SQL_VARYING`).

  - ### isFbType

    public boolean isFbType(int fbType)
    Check if the type of this field is the specified Firebird data type.

    This method assumes the not-nullable data type is passed, on checking the nullable bit of `getType()` is set to `0`.

    Parameters:
      `fbType` - One of the `SQL_` data type identifier values
    Returns:
      `true` if the type is the same as the type of this field

  - ### isNullable

    public boolean isNullable()
    Returns:
      `true` if this field is nullable.

  - ### isDbKey

    public boolean isDbKey()
    Determines if this is a db-key (RDB$DB_KEY) of a table.

    NOTE: Technically it could also be a normal `CHAR CHARACTER SET OCTETS` column called `DB_KEY`.

    Returns:
      `true` if the field is a RDB$DB_KEY
    Since:
      4.0

  - ### getCharacterLength

    public int getCharacterLength()
    The length in characters of this field.

    This takes into account the max bytes per character of the character set.

    Returns:
      Character length, or `-1` for non-character types (including blobs)

  - ### getCharacterSetId

    public int getCharacterSetId()
    Determines the character set id (without collation id).
    Returns:
      Character set id for the type, if the type has no character set, than `ISCConstants.CS_dynamic` is returned

  - ### typeEquals

    public boolean typeEquals(FieldDescriptor other)
    Limited equals that only checks if the data type in the provided field descriptor is the same as this descriptor.

    The fields checked are:

    - type
    - subType
    - scale
    - length
    Parameters:
      `other` - Field descriptor to check
    Returns:
      `true` when `other` is not null and has the same type definition as this instance, `false` otherwise.

  - ### getPaddingByte

    public byte getPaddingByte()
    Padding to use for fields of this type.
    Returns:
      padding byte (generally 0x00, or 0x20 for non-binary character data).
    Since:
      5

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### equals

    public boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`