Module org.firebirdsql.jaybird
Package org.firebirdsql.gds

# Class MessageTemplate

java.lang.Object
org.firebirdsql.gds.MessageTemplate

@NullMarked public abstract sealed class MessageTemplate extends Object
Message template for Firebird and Jaybird parameterized error messages.

Since:
  6

## Method Summary

Modifier and Type
Method
Description
`final void`
`appendErrorInfoSuffix(StringBuilder messageBuffer)`
Appends the SQLstate and error code to `messageBuffer`.
`abstract void`
`appendMessage(StringBuilder messageBuffer, List<? extends @Nullable Object> parameters)`
Appends the message, formatted using `parameters`, to `messageBuffer`.
`abstract int`
`errorCode()`
`static MessageTemplate`
`of(int errorCode)`
Returns a message template for the specified error code.
`abstract @Nullable String`
`sqlState()`
`final String`
`toMessage(List<? extends @Nullable Object> parameters)`
Renders the message, formatted using `parameters`.
`abstract MessageTemplate`
`withDefaultSqlState(String defaultSqlState)`
Returns a copy of this template with `sqlState` set to `defaultSqlState` if the SQLstate of this template is `null`, otherwise returns this template.
`abstract MessageTemplate`
`withSqlState(String sqlState)`
Returns a copy of this template with `sqlState` set, or this template if it already has `sqlState` as its SQLstate value.

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

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

## Method Details

### of

public static MessageTemplate of(int errorCode)
Returns a message template for the specified error code.

Parameters:
  `errorCode` - error code
Returns:
  message template; if there is no error defined for `errorCode`, a message template is returned with a "not found" message and SQLstate `null`.

### errorCode

public abstract int errorCode()

Returns:
  error code of this message

### sqlState

public abstract @Nullable String sqlState()

Returns:
  SQLstate (can be `null`)

### withDefaultSqlState

public abstract MessageTemplate withDefaultSqlState(String defaultSqlState)
Returns a copy of this template with `sqlState` set to `defaultSqlState` if the SQLstate of this template is `null`, otherwise returns this template.

Parameters:
  `defaultSqlState` - default SQLstate to apply if this template has `sqlState == null`
Returns:
  this template if `sqlState` is non-`null`, otherwise a copy with the `sqlState` set to `defaultSqlState`
Throws:
  `NullPointerException` - if `defaultSqlState` is `null` and `sqlState` of this instance is also `null`
  `IllegalArgumentException` - if `defaultSqlState` is not 5 characters long

### withSqlState

public abstract MessageTemplate withSqlState(String sqlState)
Returns a copy of this template with `sqlState` set, or this template if it already has `sqlState` as its SQLstate value.

Parameters:
  `sqlState` - new SQLstate value (not `null`)
Returns:
  this template if it already has `sqlState` as its value, otherwise a copy with `sqlState` set
Throws:
  `NullPointerException` - if `sqlState` is `null`
  `IllegalArgumentException` - if `sqlState` is not 5 characters long

### toMessage

public final String toMessage(List<? extends @Nullable Object> parameters)
Renders the message, formatted using `parameters`.

Parameters:
  `parameters` - parameters
Returns:
  formatted message
See Also:
  - `appendMessage(StringBuilder, List)`

### appendMessage

public abstract void appendMessage(StringBuilder messageBuffer, List<? extends @Nullable Object> parameters)
Appends the message, formatted using `parameters`, to `messageBuffer`.

Parameters that are missing or `null` are rendered as `(null)`. Excess parameters are concatenated to the end of the message, unless the `errorCode` is `ISCConstants.isc_formatted_exception`.

Parameters:
  `messageBuffer` - string builder to append to
  `parameters` - parameters to use for formatting (never `null`, may be empty)
See Also:
  - `appendErrorInfoSuffix(StringBuilder)`

### appendErrorInfoSuffix

public final void appendErrorInfoSuffix(StringBuilder messageBuffer)
Appends the SQLstate and error code to `messageBuffer`.

Parameters:
  `messageBuffer` - string builder to append to
See Also:
  - `appendMessage(StringBuilder, List)`