Example usage for org.springframework.jdbc.core SingleColumnRowMapper SingleColumnRowMapper

List of usage examples for org.springframework.jdbc.core SingleColumnRowMapper SingleColumnRowMapper

Introduction

In this page you can find the example usage for org.springframework.jdbc.core SingleColumnRowMapper SingleColumnRowMapper.

Prototype

public SingleColumnRowMapper() 

Source Link

Document

Create a new SingleColumnRowMapper for bean-style configuration.

Usage

From source file:org.ohmage.query.impl.UserClassQueries.java

/**
 * Retrieves the list of class identifiers for a user with a given role in
 * that class./*from  w ww.j a va2 s . c o  m*/
 * 
 * @param username The user's username.
 *  
 * @param role The user's class role.
 * 
 * @return The list of class identifiers.
 * 
 * @throws DataAccessException Thrown if there is an error.
 */
public List<String> getClassIdsForUserWithRole(final String username, final Clazz.Role role)
        throws DataAccessException {

    try {
        return getJdbcTemplate().query(SQL_GET_CLASS_IDS_FOR_USER_WITH_ROLE,
                new Object[] { username, role.toString() }, new SingleColumnRowMapper<String>());
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException("Error executing SQL '" + SQL_GET_CLASS_IDS_FOR_USER_WITH_ROLE
                + "' with parameters: " + username + ", " + role.toString(), e);
    }
}

From source file:org.ohmage.query.impl.AuditQueries.java

@Override
public List<Long> getAllAuditsWithClient(String client) throws DataAccessException {
    try {//from  w  w  w . j a va  2s. c om
        return getJdbcTemplate().query(SQL_GET_AUDIT_IDS_WITH_CLIENT, new Object[] { client },
                new SingleColumnRowMapper<Long>());
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException(
                "Error executing SQL '" + SQL_GET_AUDIT_IDS_WITH_CLIENT + "' with parameter: " + client, e);
    }
}

From source file:org.ohmage.query.impl.AuditQueries.java

@Override
public List<Long> getAllAuditsWithDeviceId(String deviceId) throws DataAccessException {
    try {/*from  w w w . j  a  va2s. co m*/
        return getJdbcTemplate().query(SQL_GET_AUDIT_IDS_WITH_DEVICE_ID, new Object[] { deviceId },
                new SingleColumnRowMapper<Long>());
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException(
                "Error executing SQL '" + SQL_GET_AUDIT_IDS_WITH_DEVICE_ID + "' with parameter: " + deviceId,
                e);
    }
}

From source file:org.ohmage.query.impl.AuditQueries.java

public List<Long> getAllAuditsWithResponse(ResponseType responseType, final ErrorCode errorCode)
        throws DataAccessException {
    if (ResponseType.SUCCESS.equals(responseType)) {
        try {//  w w w.  j a v  a  2s .c o  m
            return getJdbcTemplate().query(SQL_GET_AUDIT_IDS_WITH_SUCCESS_RESPONSE,
                    new SingleColumnRowMapper<Long>());
        } catch (org.springframework.dao.DataAccessException e) {
            throw new DataAccessException("Error executing SQL '" + SQL_GET_AUDIT_IDS_WITH_DEVICE_ID + "'.", e);
        }
    } else if (ResponseType.FAILURE.equals(responseType)) {
        if (errorCode == null) {
            try {
                return getJdbcTemplate().query(SQL_GET_AUDIT_IDS_WITH_FAILURE_RESPONSE,
                        new SingleColumnRowMapper<Long>());
            } catch (org.springframework.dao.DataAccessException e) {
                throw new DataAccessException("Error executing SQL '" + SQL_GET_AUDIT_IDS_WITH_DEVICE_ID + "'.",
                        e);
            }
        } else {
            try {
                return getJdbcTemplate().query(SQL_GET_AUDIT_IDS_WITH_FAILURE_RESPONSE_WITH_CODE,
                        new Object[] { errorCode }, new SingleColumnRowMapper<Long>());
            } catch (org.springframework.dao.DataAccessException e) {
                throw new DataAccessException(
                        "Error executing SQL '" + SQL_GET_AUDIT_IDS_WITH_FAILURE_RESPONSE_WITH_CODE + "'.", e);
            }
        }
    } else {
        throw new DataAccessException("Unknown response type: " + responseType.toString());
    }
}

From source file:org.ohmage.query.impl.UserMobilityQueries.java

public String getUserForId(final UUID mobilityId) throws DataAccessException {

    String sql = "SELECT u.username " + "FROM user u, mobility m " + "WHERE u.id = m.user_id "
            + "AND m.uuid = ?";

    try {//from  w  ww  .j a  va2 s.co m
        return getJdbcTemplate().queryForObject(sql, new Object[] { mobilityId.toString() },
                new SingleColumnRowMapper<String>());
    } catch (org.springframework.dao.IncorrectResultSizeDataAccessException e) {
        if (e.getActualSize() == 0) {
            return null;
        } else {
            throw new DataAccessException(
                    "Error executing SQL '" + sql + "' with parameter: " + mobilityId.toString(), e);
        }
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException(
                "Error executing SQL '" + sql + "' with parameter: " + mobilityId.toString(), e);
    }
}

From source file:org.ohmage.query.impl.UserMobilityQueries.java

@Override
public List<String> getIdsForUser(String username) throws DataAccessException {
    try {//from   ww  w.ja  v  a2s  . co m
        return getJdbcTemplate().query(SQL_GET_IDS_FOR_USER, new Object[] { username },
                new SingleColumnRowMapper<String>());
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException(
                "Error executing SQL '" + SQL_GET_IDS_FOR_USER + "' with parameter: " + username, e);
    }
}

From source file:org.ohmage.query.impl.AuditQueries.java

@Override
public List<Long> getAllAuditsOnOrAfterDate(DateTime date) throws DataAccessException {
    try {//  www  .j a  v  a  2  s .c  o  m
        return getJdbcTemplate().query(SQL_GET_AUDIT_IDS_ON_OR_AFTER_DATE, new Object[] { date.getMillis() },
                new SingleColumnRowMapper<Long>());
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException(
                "Error executing SQL '" + SQL_GET_AUDIT_IDS_ON_OR_AFTER_DATE + "' with parameter: " + date, e);
    }
}

From source file:org.ohmage.query.impl.AuditQueries.java

@Override
public List<Long> getAllAuditsOnOrBeforeDate(DateTime date) throws DataAccessException {
    try {// w w  w  .  ja  va 2  s.  c om
        return getJdbcTemplate().query(SQL_GET_AUDIT_IDS_ON_OR_BEFORE_DATE, new Object[] { date.getMillis() },
                new SingleColumnRowMapper<Long>());
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException(
                "Error executing SQL '" + SQL_GET_AUDIT_IDS_ON_OR_BEFORE_DATE + "' with parameter: " + date, e);
    }
}

From source file:org.ohmage.query.impl.UserCampaignQueries.java

/**
 * Retrieves all of the campaign IDs that are associated with a user and
 * the user has a specific role.//from   w ww  .ja va2  s  .  c  om
 * 
 * @param username The username of the user.
 * 
 * @param role The campaign role that the user must have.
 * 
 * @return A List of unique identifiers for all campaigns with which the 
 *          user is associated and has the given role. 
 */
public List<String> getCampaignIdsForUserWithRole(String username, Campaign.Role role)
        throws DataAccessException {
    try {
        return getJdbcTemplate().query(SQL_GET_CAMPAIGN_IDS_FOR_USER_WITH_ROLE,
                new Object[] { username, role.toString() }, new SingleColumnRowMapper<String>());
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException("Error executing SQL '" + SQL_GET_CAMPAIGN_IDS_FOR_USER_WITH_ROLE
                + "' with parameters: " + username + ", " + role, e);
    }
}

From source file:org.ohmage.query.impl.AuditQueries.java

@Override
public List<Long> getAllAuditsOnOrBetweenDates(DateTime startDate, DateTime endDate)
        throws DataAccessException {
    try {/*from w  w  w.  j  a  v  a  2  s .c o m*/
        return getJdbcTemplate().query(SQL_GET_AUDIT_IDS_ON_OR_BETWEEN_DATES,
                new Object[] { startDate.getMillis(), endDate.getMillis() }, new SingleColumnRowMapper<Long>());
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException("Error executing SQL '" + SQL_GET_AUDIT_IDS_ON_OR_BETWEEN_DATES
                + "' with parameters: " + startDate + ", " + endDate, e);
    }
}