public abstract class DataAccessUtils
extends java.lang.Object
Constructor and Description |
---|
DataAccessUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
intResult(java.util.Collection<?> results)
Return a unique int result from the given Collection.
|
static long |
longResult(java.util.Collection<?> results)
Return a unique long result from the given Collection.
|
static <T> T |
objectResult(java.util.Collection<?> results,
java.lang.Class<T> requiredType)
Return a unique result object from the given Collection.
|
static <T> T |
requiredSingleResult(java.util.Collection<T> results)
Return a single result object from the given Collection.
|
static <T> T |
requiredUniqueResult(java.util.Collection<T> results)
Return a unique result object from the given Collection.
|
static <T> T |
singleResult(java.util.Collection<T> results)
Return a single result object from the given Collection.
|
static java.lang.RuntimeException |
translateIfNecessary(java.lang.RuntimeException rawException,
PersistenceExceptionTranslator pet)
Return a translated exception if this is appropriate,
otherwise return the input exception.
|
static <T> T |
uniqueResult(java.util.Collection<T> results)
Return a unique result object from the given Collection.
|
@Nullable public static <T> T singleResult(@Nullable java.util.Collection<T> results) throws IncorrectResultSizeDataAccessException
Returns null
if 0 result objects found;
throws an exception if more than 1 element found.
results
- the result Collection (can be null
)null
if noneIncorrectResultSizeDataAccessException
- if more than one
element has been found in the given Collection@Nullable public static <T> T requiredSingleResult(@Nullable java.util.Collection<T> results) throws IncorrectResultSizeDataAccessException
Throws an exception if 0 or more than 1 element found.
results
- the result Collection (can be null
)IncorrectResultSizeDataAccessException
- if more than one
element has been found in the given CollectionEmptyResultDataAccessException
- if no element at all
has been found in the given Collection@Nullable public static <T> T uniqueResult(@Nullable java.util.Collection<T> results) throws IncorrectResultSizeDataAccessException
Returns null
if 0 result objects found;
throws an exception if more than 1 instance found.
results
- the result Collection (can be null
)null
if noneIncorrectResultSizeDataAccessException
- if more than one
result object has been found in the given CollectionCollectionUtils.hasUniqueObject(java.util.Collection<?>)
public static <T> T requiredUniqueResult(@Nullable java.util.Collection<T> results) throws IncorrectResultSizeDataAccessException
Throws an exception if 0 or more than 1 instance found.
results
- the result Collection (can be null
)IncorrectResultSizeDataAccessException
- if more than one
result object has been found in the given CollectionEmptyResultDataAccessException
- if no result object at all
has been found in the given CollectionCollectionUtils.hasUniqueObject(java.util.Collection<?>)
public static <T> T objectResult(@Nullable java.util.Collection<?> results, @Nullable java.lang.Class<T> requiredType) throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException
results
- the result Collection (can be null
)IncorrectResultSizeDataAccessException
- if more than one
result object has been found in the given CollectionEmptyResultDataAccessException
- if no result object
at all has been found in the given CollectionTypeMismatchDataAccessException
- if the unique object does
not match the specified required typepublic static int intResult(@Nullable java.util.Collection<?> results) throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException
results
- the result Collection (can be null
)IncorrectResultSizeDataAccessException
- if more than one
result object has been found in the given CollectionEmptyResultDataAccessException
- if no result object
at all has been found in the given CollectionTypeMismatchDataAccessException
- if the unique object
in the collection is not convertible to an intpublic static long longResult(@Nullable java.util.Collection<?> results) throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException
results
- the result Collection (can be null
)IncorrectResultSizeDataAccessException
- if more than one
result object has been found in the given CollectionEmptyResultDataAccessException
- if no result object
at all has been found in the given CollectionTypeMismatchDataAccessException
- if the unique object
in the collection is not convertible to a longpublic static java.lang.RuntimeException translateIfNecessary(java.lang.RuntimeException rawException, PersistenceExceptionTranslator pet)
rawException
- exception we may wish to translatepet
- PersistenceExceptionTranslator to use to perform the translation