Class DataResult<DATA>

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>

public final class DataResult<DATA> extends AbstractResult<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 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

      public DataResult(@NotNull @NotNull Exception exception)
      Constructor with exception. If the exception is type MarshalInformation then it will be used as data field, if not data will be null. An exception of type ExceptionShortIdentifable will be used to fill the code field with the identifier value. If it's not a ExceptionShortIdentifable the code field 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 is null.
  • Method Details

    • getDataClass

      public final String getDataClass()
      Returns the name of the class contained in the data element.
      Returns:
      Full qualified class name.
    • getDataElement

      public final String getDataElement()
      Returns the name of the data attribute.
      Returns:
      Data element name.
    • getData

      @Nullable public final DATA getData()
      Returns the result data.
      Returns:
      Response data.
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • ok

      public static DataResult<Void> ok()
      Create a success result without any data.
      Returns:
      Result with type ResultType.OK.
    • ok

      public static <T> DataResult<T> ok(@Nullable T data)
      Create a success result with some data.
      Type Parameters:
      T - Type of data.
      Parameters:
      data - Optional data.
      Returns:
      Result with type ResultType.OK.
    • ok

      public static <T> DataResult<T> ok(@Nullable T data, String dataElement)
      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.