Java Code Examples for org.springframework.dao.support.DataAccessUtils#singleResult()

The following examples show how to use org.springframework.dao.support.DataAccessUtils#singleResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityDaoImpl.java    From GyJdbc with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public T queryOne(Id id) throws Exception {
    String sql = "SELECT * FROM " + tableName + " WHERE " + primaryKey + " = ?";
    List<T> result = jdbcTemplate.query(sql, rowMapper, id);
    return DataAccessUtils.singleResult(result);
}
 
Example 2
Source File: ComRecipientDaoImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
private <T> T selectRecipients(@VelocityCheck int companyID, RowMapper<T> mapper, String sqlStatement, Object... sqlParameters) throws SQLException {
	List<T> results = selectRecipients(companyID, new RowMapperResultSetExtractor<>(mapper, 1), sqlStatement, sqlParameters);
	return DataAccessUtils.singleResult(results);
}
 
Example 3
Source File: EntityDaoImpl.java    From GyJdbc with Apache License 2.0 4 votes vote down vote up
@Override
public T queryOne(Criteria criteria) throws Exception {
    List<T> result = this.queryWithCriteria(criteria);
    return DataAccessUtils.singleResult(result);
}
 
Example 4
Source File: Result.java    From GyJdbc with Apache License 2.0 4 votes vote down vote up
public E queryOne() throws Exception {
    return DataAccessUtils.singleResult(queryList());
}
 
Example 5
Source File: SqlQuery.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Generic object finder method, used by all other {@code findObject} methods.
 * Object finder methods are like EJB entity bean finders, in that it is
 * considered an error if they return more than one result.
 * @return the result object, or {@code null} if not found. Subclasses may
 * choose to treat this as an error and throw an exception.
 * @see org.springframework.dao.support.DataAccessUtils#singleResult
 */
@Nullable
public T findObject(@Nullable Object[] params, @Nullable Map<?, ?> context) throws DataAccessException {
	List<T> results = execute(params, context);
	return DataAccessUtils.singleResult(results);
}
 
Example 6
Source File: SqlQuery.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Generic object finder method for named parameters.
 * @param paramMap a Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement.
 * Ordering is not significant.
 * @param context contextual information passed to the {@code mapRow}
 * callback method. The JDBC operation itself doesn't rely on this parameter,
 * but it can be useful for creating the objects of the result list.
 * @return a List of objects, one per row of the ResultSet. Normally all these
 * will be of the same class, although it is possible to use different types.
 */
@Nullable
public T findObjectByNamedParam(Map<String, ?> paramMap, @Nullable Map<?, ?> context) throws DataAccessException {
	List<T> results = executeByNamedParam(paramMap, context);
	return DataAccessUtils.singleResult(results);
}
 
Example 7
Source File: SqlQuery.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Generic object finder method, used by all other {@code findObject} methods.
 * Object finder methods are like EJB entity bean finders, in that it is
 * considered an error if they return more than one result.
 * @return the result object, or {@code null} if not found. Subclasses may
 * choose to treat this as an error and throw an exception.
 * @see org.springframework.dao.support.DataAccessUtils#singleResult
 */
@Nullable
public T findObject(@Nullable Object[] params, @Nullable Map<?, ?> context) throws DataAccessException {
	List<T> results = execute(params, context);
	return DataAccessUtils.singleResult(results);
}
 
Example 8
Source File: SqlQuery.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Generic object finder method for named parameters.
 * @param paramMap a Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement.
 * Ordering is not significant.
 * @param context contextual information passed to the {@code mapRow}
 * callback method. The JDBC operation itself doesn't rely on this parameter,
 * but it can be useful for creating the objects of the result list.
 * @return a List of objects, one per row of the ResultSet. Normally all these
 * will be of the same class, although it is possible to use different types.
 */
@Nullable
public T findObjectByNamedParam(Map<String, ?> paramMap, @Nullable Map<?, ?> context) throws DataAccessException {
	List<T> results = executeByNamedParam(paramMap, context);
	return DataAccessUtils.singleResult(results);
}
 
Example 9
Source File: SqlQuery.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generic object finder method, used by all other {@code findObject} methods.
 * Object finder methods are like EJB entity bean finders, in that it is
 * considered an error if they return more than one result.
 * @return the result object, or {@code null} if not found. Subclasses may
 * choose to treat this as an error and throw an exception.
 * @see org.springframework.dao.support.DataAccessUtils#singleResult
 */
public T findObject(Object[] params, Map<?, ?> context) throws DataAccessException {
	List<T> results = execute(params, context);
	return DataAccessUtils.singleResult(results);
}
 
Example 10
Source File: SqlQuery.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generic object finder method for named parameters.
 * @param paramMap Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement.
 * Ordering is not significant.
 * @param context contextual information passed to the {@code mapRow}
 * callback method. The JDBC operation itself doesn't rely on this parameter,
 * but it can be useful for creating the objects of the result list.
 * @return a List of objects, one per row of the ResultSet. Normally all these
 * will be of the same class, although it is possible to use different types.
 */
public T findObjectByNamedParam(Map<String, ?> paramMap, Map<?, ?> context) throws DataAccessException {
	List<T> results = executeByNamedParam(paramMap, context);
	return DataAccessUtils.singleResult(results);
}
 
Example 11
Source File: SqlQuery.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Generic object finder method, used by all other {@code findObject} methods.
 * Object finder methods are like EJB entity bean finders, in that it is
 * considered an error if they return more than one result.
 * @return the result object, or {@code null} if not found. Subclasses may
 * choose to treat this as an error and throw an exception.
 * @see org.springframework.dao.support.DataAccessUtils#singleResult
 */
public T findObject(Object[] params, Map<?, ?> context) throws DataAccessException {
	List<T> results = execute(params, context);
	return DataAccessUtils.singleResult(results);
}
 
Example 12
Source File: SqlQuery.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Generic object finder method for named parameters.
 * @param paramMap Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement.
 * Ordering is not significant.
 * @param context contextual information passed to the {@code mapRow}
 * callback method. The JDBC operation itself doesn't rely on this parameter,
 * but it can be useful for creating the objects of the result list.
 * @return a List of objects, one per row of the ResultSet. Normally all these
 * will be of the same class, although it is possible to use different types.
 */
public T findObjectByNamedParam(Map<String, ?> paramMap, Map<?, ?> context) throws DataAccessException {
	List<T> results = executeByNamedParam(paramMap, context);
	return DataAccessUtils.singleResult(results);
}
 
Example 13
Source File: SqlQuery.java    From effectivejava with Apache License 2.0 2 votes vote down vote up
/**
 * Generic object finder method, used by all other {@code findObject} methods.
 * Object finder methods are like EJB entity bean finders, in that it is
 * considered an error if they return more than one result.
 * @return the result object, or {@code null} if not found. Subclasses may
 * choose to treat this as an error and throw an exception.
 * @see org.springframework.dao.support.DataAccessUtils#singleResult
 */
public T findObject(Object[] params, Map<?, ?> context) throws DataAccessException {
	List<T> results = execute(params, context);
	return DataAccessUtils.singleResult(results);
}
 
Example 14
Source File: SqlQuery.java    From effectivejava with Apache License 2.0 2 votes vote down vote up
/**
 * Generic object finder method for named parameters.
 * @param paramMap Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement.
 * Ordering is not significant.
 * @param context contextual information passed to the {@code mapRow}
 * callback method. The JDBC operation itself doesn't rely on this parameter,
 * but it can be useful for creating the objects of the result list.
 * @return a List of objects, one per row of the ResultSet. Normally all these
 * will be of the same class, although it is possible to use different types.
 */
public T findObjectByNamedParam(Map<String, ?> paramMap, Map<?, ?> context) throws DataAccessException {
	List<T> results = executeByNamedParam(paramMap, context);
	return DataAccessUtils.singleResult(results);
}