This class is not thread-safe.
- Author:
- Mark Rotteveel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the cause of the current exception.static SQLException
Creates a connection closed error (JaybirdErrorCodes.jb_connectionClosed
).exception
(int errorCode) The (next) exception is an exception.static FbExceptionBuilder
forException
(int errorCode) Creates an exception builder with the specified error code.static FbExceptionBuilder
forNonTransientConnectionException
(int errorCode) Creates an exception builder for non-transient connection exceptions with the specified error code.static FbExceptionBuilder
forNonTransientException
(int errorCode) Creates an exception builder for non-transient exceptions with the specified error code.static FbExceptionBuilder
forTimeoutException
(int errorCode) Creates an exception builder for timeout exceptions with the specified error code.static FbExceptionBuilder
forTransientException
(int errorCode) Creates an exception builder for transient exceptions with the specified error code.static FbExceptionBuilder
forWarning
(int errorCode) Creates an exception builder for a warning with the specified error code.static SQLException
Creates an I/O write error (ISCConstants.isc_net_read_err
).static SQLException
Creates an I/O write error (ISCConstants.isc_net_write_err
).boolean
isEmpty()
messageParameter
(int parameter) Adds an integer message parameter for the exception message.messageParameter
(int param1, int param2) Adds two integer message parameters for the exception message.messageParameter
(@Nullable Object parameter) Adds an object message parameter for the exception message (applyingString.valueOf(parameter)
).messageParameter
(@Nullable Object... params) Adds object message parameters for the exception message (applyingString.valueOf(parameter)
).messageParameter
(@Nullable Object param1, @Nullable Object param2) Adds two object message parameters for the exception message (applyingString.valueOf(parameter)
).nonTransientConnectionException
(int errorCode) Force the next exception to be aSQLNonTransientConnectionException
.nonTransientException
(int errorCode) Force the next exception to be aSQLNonTransientException
.Sets the SQL state.timeoutException
(int errorCode) Force the next exception to be aSQLTimeoutException
.static SQLException
toException
(int errorCode) Creates aSQLException
(or subclass) with the specified error code.Converts the builder to a single SQLException instance with a single exception message.<T extends SQLException>
TtoFlatSQLException
(Class<T> type) Converts the builder to the appropriate SQLException instance and casts to the specified type T.static SQLException
toNonTransientConnectionException
(int errorCode) Creates aSQLException
(or subclass) for non-transient connection exceptions with the specified error code.static SQLException
toNonTransientException
(int errorCode) Creates aSQLException
(or subclass) for non-transient exceptions with the specified error code.Converts the builder to the appropriate SQLException instance (optionally with a chain of additional exceptions).<T extends SQLException>
TtoSQLException
(Class<T> type) Converts the builder to the appropriate SQLException instance (optionally with a chain of additional exceptions) and casts to the specified type T.toString()
static SQLException
toTimeoutException
(int errorCode) Creates aSQLException
(or subclass) for timeout exceptions with the specified error code.static SQLException
toTransientException
(int errorCode) Creates aSQLException
(or subclass) for transient exceptions with the specified error code.static SQLWarning
toWarning
(int errorCode) Creates aSQLWarning
with the specified error code.transientException
(int errorCode) Force the next exception to be aSQLTransientException
.warning
(int errorCode) The (next) exception is a warning.
-
Constructor Details
-
FbExceptionBuilder
public FbExceptionBuilder()
-
-
Method Details
-
exception
The (next) exception is an exception.This method and related methods can be called multiple times. This builder might produce a chained exception, but could also merge exceptions depending on the error code and other rules internal to this builder.
- Parameters:
errorCode
- Firebird error code- Returns:
- this FbExceptionBuilder
- See Also:
-
forException
Creates an exception builder with the specified error code.Equivalent to calling:
new FbExceptionBuilder().exception(errorCode);
- Parameters:
errorCode
- Firebird error code- Returns:
- FbExceptionBuilder initialized with the specified error code
-
toException
Creates aSQLException
(or subclass) with the specified error code.Equivalent to calling
FbExceptionBuilder.forException(errorCode).toSQLException()
.- Parameters:
errorCode
- Firebird error code- Returns:
- exception with message, vendor code and SQLSTATE derived from
errorCode
- Since:
- 6
-
forTimeoutException
Creates an exception builder for timeout exceptions with the specified error code.Equivalent to calling:
new FbExceptionBuilder().timeoutException(errorCode);
- Parameters:
errorCode
- Firebird error code- Returns:
- FbExceptionBuilder initialized with the specified error code
- Since:
- 6
-
toTimeoutException
Creates aSQLException
(or subclass) for timeout exceptions with the specified error code.Equivalent to calling
FbExceptionBuilder.forTimeoutException(errorCode).toSQLException()
.- Parameters:
errorCode
- Firebird error code- Returns:
- exception with message, vendor code and SQLSTATE derived from
errorCode
- Since:
- 6
-
forNonTransientException
Creates an exception builder for non-transient exceptions with the specified error code.Equivalent to calling:
new FbExceptionBuilder().nonTransientException(errorCode);
- Parameters:
errorCode
- Firebird error code- Returns:
- FbExceptionBuilder initialized with the specified error code
- Since:
- 6
-
toNonTransientException
Creates aSQLException
(or subclass) for non-transient exceptions with the specified error code.Equivalent to calling
FbExceptionBuilder.forNonTransientException(errorCode).toSQLException()
.- Parameters:
errorCode
- Firebird error code- Returns:
- exception with message, vendor code and SQLSTATE derived from
errorCode
- Since:
- 6
-
forNonTransientConnectionException
Creates an exception builder for non-transient connection exceptions with the specified error code.Equivalent to calling:
new FbExceptionBuilder().nonTransientConnectionException(errorCode);
- Parameters:
errorCode
- Firebird error code- Returns:
- FbExceptionBuilder initialized with the specified error code
- Since:
- 6
-
toNonTransientConnectionException
Creates aSQLException
(or subclass) for non-transient connection exceptions with the specified error code.Equivalent to calling
FbExceptionBuilder.forNonTransientConnectionException(errorCode).toSQLException()
.- Parameters:
errorCode
- Firebird error code- Returns:
- exception with message, vendor code and SQLSTATE derived from
errorCode
- Since:
- 6
-
forTransientException
Creates an exception builder for transient exceptions with the specified error code.- Parameters:
errorCode
- Firebird error code- Returns:
- FbExceptionBuilder initialized with the specified error code
- Since:
- 6
-
toTransientException
Creates aSQLException
(or subclass) for transient exceptions with the specified error code.Equivalent to calling
FbExceptionBuilder.forTransientException(errorCode).toSQLException()
.- Parameters:
errorCode
- Firebird error code- Returns:
- exception with message, vendor code and SQLSTATE derived from
errorCode
- Since:
- 6
-
forWarning
Creates an exception builder for a warning with the specified error code.Equivalent to calling:
new FbExceptionBuilder().warning(errorCode);
- Parameters:
errorCode
- Firebird error code- Returns:
- FbExceptionBuilder initialized with the specified error code
-
toWarning
Creates aSQLWarning
with the specified error code.Equivalent to calling
FbExceptionBuilder.forWarning(errorCode).toSQLException(SQLWarning.class)
.- Parameters:
errorCode
- Firebird error code- Returns:
- exception with message, vendor code and SQLSTATE derived from
errorCode
- Since:
- 6
-
ioWriteError
Creates an I/O write error (ISCConstants.isc_net_write_err
).- Parameters:
e
- exception cause- Returns:
- SQLException instance
- Since:
- 6
-
ioReadError
Creates an I/O write error (ISCConstants.isc_net_read_err
).- Parameters:
e
- exception cause- Returns:
- SQLException instance
- Since:
- 6
-
connectionClosed
Creates a connection closed error (JaybirdErrorCodes.jb_connectionClosed
).- Returns:
- SQLException instance
- Since:
- 6
-
warning
The (next) exception is a warning.- Parameters:
errorCode
- Firebird error code- Returns:
- this FbExceptionBuilder
- See Also:
-
timeoutException
Force the next exception to be aSQLTimeoutException
.- Parameters:
errorCode
- Firebird error code- Returns:
- this FbExceptionBuilder
- See Also:
-
nonTransientException
Force the next exception to be aSQLNonTransientException
.- Parameters:
errorCode
- Firebird error code- Returns:
- this FbExceptionBuilder
- See Also:
-
nonTransientConnectionException
Force the next exception to be aSQLNonTransientConnectionException
.- Parameters:
errorCode
- Firebird error code- Returns:
- this FbExceptionBuilder
- See Also:
-
transientException
Force the next exception to be aSQLTransientException
.- Parameters:
errorCode
- Firebird error code- Returns:
- this FbExceptionBuilder
- See Also:
-
messageParameter
Adds an integer message parameter for the exception message.- Parameters:
parameter
- message parameter- Returns:
- this FbExceptionBuilder
-
messageParameter
Adds two integer message parameters for the exception message.- Parameters:
param1
- message parameterparam2
- message parameter- Returns:
- this FbExceptionBuilder
- Since:
- 5
-
messageParameter
Adds an object message parameter for the exception message (applyingString.valueOf(parameter)
).- Parameters:
parameter
- message parameter- Returns:
- this FbExceptionBuilder
- Since:
- 5
-
messageParameter
Adds two object message parameters for the exception message (applyingString.valueOf(parameter)
).- Parameters:
param1
- message parameterparam2
- message parameter- Returns:
- this FbExceptionBuilder
- Since:
- 5
-
messageParameter
Adds object message parameters for the exception message (applyingString.valueOf(parameter)
).- Parameters:
params
- message parameters- Returns:
- this FbExceptionBuilder
- Since:
- 5
-
sqlState
Sets the SQL state. Overriding the value derived from the Firebird error code.SQL State is usually derived from the errorCode. Use of this method is optional.
- Parameters:
sqlState
- SQL State value- Returns:
- this FbExceptionBuilder
-
cause
Sets the cause of the current exception.- Parameters:
cause
- Throwable with the cause- Returns:
- this FbExceptionBuilder
-
toSQLException
Converts the builder to the appropriate SQLException instance (optionally with a chain of additional exceptions).When returning exception information from the status vector, it is advisable to use
toFlatSQLException()
as this applies some heuristics to get more specific error codes and flattens the message into a single exception.If
isEmpty()
returnsfalse
, then this will throw anIllegalStateException
.- Returns:
- SQLException object
- See Also:
-
toFlatSQLException
Converts the builder to a single SQLException instance with a single exception message.This method attempts to assign the most specific error code and SQL state to the returned exception.
The cause of the returned exception is set to an instance of
FBSQLExceptionInfo
which contains the separate items obtained from the status vector. These items are chained together using the SQLException chain.If
isEmpty()
returnsfalse
, then this will throw anIllegalStateException
.- Returns:
- SQLException object
- See Also:
-
toSQLException
Converts the builder to the appropriate SQLException instance (optionally with a chain of additional exceptions) and casts to the specified type T.- Type Parameters:
T
- Expected exception type- Parameters:
type
- Class of type T- Returns:
- SQLException of type T
- Throws:
ClassCastException
- If the first exception created with this builder is not of the specified type- See Also:
-
toFlatSQLException
Converts the builder to the appropriate SQLException instance and casts to the specified type T.- Type Parameters:
T
- Expected exception type- Parameters:
type
- Class of type T- Returns:
- SQLException of type T
- Throws:
ClassCastException
- If the first exception created with this builder is not of the specified type- See Also:
-
isEmpty
public boolean isEmpty()- Returns:
true
if this builder contains exception information,false
otherwise
-
toString
-