Class ServicesUtil

java.lang.Object
de.hybris.platform.servicelayer.util.ServicesUtil

public class ServicesUtil extends Object
Utilities for handling e.g. exceptions in DAO classes in a common way, parameters etc.
  • Constructor Details

    • ServicesUtil

      public ServicesUtil()
  • Method Details

    • validateIfSingleResult

      public static void validateIfSingleResult(Collection<? extends Object> resultToCheck, String unknownIdException, String ambiguousIdException)
      Checks if collection contains only a single object.
      Parameters:
      resultToCheck - collection to check
      unknownIdException - message for exception thrown if collection is empty or is null
      ambiguousIdException - message for exception thrown if collection has more than one object
      Throws:
      UnknownIdentifierException - if collection is empty or is null
      AmbiguousIdentifierException - if collection has more than one object
    • validateIfSingleResult

      public static void validateIfSingleResult(Collection<? extends Object> resultToCheck, Class clazz, String qualifier, Object qualifierValue)
      Checks if collection contains only a single object and generates proper exception messages out of passed type and qualifier.
      Parameters:
      resultToCheck - collection to check
      clazz - result must contain elements which are assignable from this clazz
      qualifier - unique qualifier used for search
      qualifierValue - for qualifier
      Throws:
      UnknownIdentifierException - if collection is empty or is null
      AmbiguousIdentifierException - if collection has more than one object
      IllegalStateException - if element in collection is NOT of the given type
    • validateIfAnyResult

      public static void validateIfAnyResult(Collection resultToCheck, String unknownIdException)
      Checks if collection contains any objects.
      Parameters:
      resultToCheck - collection to check
      unknownIdException - message for exception thrown if collection is empty or is null
      Throws:
      UnknownIdentifierException - if collection is empty or is null
    • validateParameterNotNull

      public static void validateParameterNotNull(Object parameter, String nullMessage)
      Validates if parameter passed to method is not null
      Parameters:
      parameter - to check
      nullMessage - message for exception thrown if parameter is null
      Throws:
      IllegalArgumentException - if parameter is null
    • validateParameterNotNullStandardMessage

      public static void validateParameterNotNullStandardMessage(String parameter, Object parameterValue)
      Validates if parameter value passed to method is not null.
      Parameters:
      parameter - name of parameter used for exception message
      parameterValue - value to check for null
      Throws:
      IllegalArgumentException - if parameter is null