spring-framework / org.springframework.dao.support / DataAccessUtils

DataAccessUtils

abstract class DataAccessUtils

Miscellaneous utility methods for DAO implementations. Useful with any data access technology.

Author
Juergen Hoeller

Since
1.0.2

Constructors

<init>

DataAccessUtils()

Miscellaneous utility methods for DAO implementations. Useful with any data access technology.

Functions

intResult

open static fun intResult(results: MutableCollection<*>): Int

Return a unique int result from the given Collection. Throws an exception if 0 or more than 1 result objects found, of if the unique result object is not convertible to an int.

longResult

open static fun longResult(results: MutableCollection<*>): Long

Return a unique long result from the given Collection. Throws an exception if 0 or more than 1 result objects found, of if the unique result object is not convertible to a long.

nullableSingleResult

open static fun <T : Any> nullableSingleResult(results: MutableCollection<T>): T

Return a single result object from the given Collection.

Throws an exception if 0 or more than 1 element found.

objectResult

open static fun <T : Any> objectResult(results: MutableCollection<*>, requiredType: Class<T>): T

Return a unique result object from the given Collection. Throws an exception if 0 or more than 1 result objects found, of if the unique result object is not convertible to the specified required type.

requiredSingleResult

open static fun <T : Any> requiredSingleResult(results: MutableCollection<T>): T

Return a single result object from the given Collection.

Throws an exception if 0 or more than 1 element found.

requiredUniqueResult

open static fun <T : Any> requiredUniqueResult(results: MutableCollection<T>): T

Return a unique result object from the given Collection.

Throws an exception if 0 or more than 1 instance found.

singleResult

open static fun <T : Any> singleResult(results: MutableCollection<T>): T

Return a single result object from the given Collection.

Returns null if 0 result objects found; throws an exception if more than 1 element found.

translateIfNecessary

open static fun translateIfNecessary(rawException: RuntimeException, pet: PersistenceExceptionTranslator): RuntimeException

Return a translated exception if this is appropriate, otherwise return the given exception as-is.

uniqueResult

open static fun <T : Any> uniqueResult(results: MutableCollection<T>): T

Return a unique result object from the given Collection.

Returns null if 0 result objects found; throws an exception if more than 1 instance found.