java.lang.Object
org.fuin.cqrs4j.AbstractResult<DATA>
org.fuin.cqrs4j.DataResult<DATA>
- Type Parameters:
DATA- Type of data returned in case of success (type =ResultType.OK).
- All Implemented Interfaces:
Serializable,Result<DATA>
Result of a request that contains data in addition to the standard result fields. The type signals if the execution was successful or
not. In case the the result is not
ResultType.OK, the fields code and message should contain unique information to help the user
identifying the cause of the problem.- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProtected default constructor for de-serialization.DataResult(@NotNull Exception exception) Constructor with exception.DataResult(@NotNull ResultType type, String code, String message, DATA data) Constructor without data element name.DataResult(@NotNull ResultType type, String code, String message, DATA data, String dataElement) Constructor with all data. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanstatic <T> DataResult<T>Create an error result without any data.final DATAgetData()Returns the result data.final StringReturns the name of the class contained in the data element.final StringReturns the name of the data attribute.final inthashCode()static DataResult<Void>ok()Create a success result without any data.static <T> DataResult<T>ok(T data) Create a success result with some data.static <T> DataResult<T>Create a success result with some data.final StringtoString()Methods inherited from class org.fuin.cqrs4j.AbstractResult
getCode, getMessage, getType
-
Constructor Details
-
DataResult
protected DataResult()Protected default constructor for de-serialization. -
DataResult
public DataResult(@NotNull @NotNull ResultType type, @Nullable String code, @Nullable String message, @Nullable DATA data) Constructor without data element name.- Parameters:
type- Type.code- Code.message- Message.data- Optional result data.
-
DataResult
public DataResult(@NotNull @NotNull ResultType type, @Nullable String code, @Nullable String message, @Nullable DATA data, String dataElement) Constructor with all data.- Parameters:
type- Type.code- Code.message- Message.data- Optional result data.dataElement- Optional name of the data element.
-
DataResult
Constructor with exception. If the exception is typeMarshalInformationthen it will be used asdatafield, if not data will benull. An exception of typeExceptionShortIdentifablewill be used to fill thecodefield with the identifier value. If it's not aExceptionShortIdentifablethecodefield will be set using the full qualified class name of the exception.- Parameters:
exception- The message for the result is equal to the exception message or the simple name of the exception class if the exception message isnull.
-
-
Method Details
-
getDataClass
Returns the name of the class contained in the data element.- Returns:
- Full qualified class name.
-
getDataElement
Returns the name of the data attribute.- Returns:
- Data element name.
-
getData
Returns the result data.- Returns:
- Response data.
-
hashCode
public final int hashCode() -
equals
-
toString
-
ok
Create a success result without any data.- Returns:
- Result with type
ResultType.OK.
-
ok
Create a success result with some data.- Type Parameters:
T- Type of data.- Parameters:
data- Optional data.- Returns:
- Result with type
ResultType.OK.
-
ok
Create a success result with some data.- Type Parameters:
T- Type of data.- Parameters:
data- Optional data.dataElement- Optional name of the data element.- Returns:
- Result with type
ResultType.OK.
-
error
public static <T> DataResult<T> error(@NotNull @NotNull String code, @NotNull @NotNull String message) Create an error result without any data.- Type Parameters:
T- Not used.- Parameters:
code- Code.message- Message.- Returns:
- Error result with.
-