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

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

Introduction

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

Prototype

public BeanPropertyRowMapper(Class<T> mappedClass) 

Source Link

Document

Create a new BeanPropertyRowMapper , accepting unpopulated properties in the target bean.

Usage

From source file:com.hexin.core.dao.BaseDaoSupport.java

@Override
public <T> List<T> findList(JdbcTemplate jdbcTemplate, String sql, Class<T> dtoClass, Object... args) {

    long startTime = System.currentTimeMillis();
    long endTime;
    long durTime;

    debugSql(sql, args);//from   www.j a v a2s  . co m

    RowMapper<T> rowMapper = new BeanPropertyRowMapper<T>(dtoClass);

    List<T> result = jdbcTemplate.query(sql, rowMapper, args);

    endTime = System.currentTimeMillis();
    durTime = endTime - startTime;
    logger.debug("This jdbc operation costs time: " + durTime);

    return result;
}

From source file:com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesServiceTest.java

/**
 * Test method for {@link com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesService#insertSeverityIfNotExists(biz.futureware.mantis.rpc.soap.client.ObjectRef)}.
 *//*from   ww  w. j ava  2  s  . c  om*/
@Test
public void testInsertSeverityIfNotExists() {
    final ObjectRef item = new ObjectRef(BigInteger.ONE, "item");
    final boolean result = dao.insertSeverityIfNotExists(item);
    assertTrue(result);

    final List<ObjectRef> list = getJdbcTemplate().query("SELECT id, name FROM mantis_enum_severities",
            new BeanPropertyRowMapper<ObjectRef>(ObjectRef.class));

    assertEquals(1, list.size());
    assertEquals(item, list.get(0));

    final boolean result2 = dao.insertSeverityIfNotExists(item);
    assertTrue(result2);
}

From source file:com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesServiceTest.java

/**
 * Test method for {@link com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesService#insertStatusIfNotExists(biz.futureware.mantis.rpc.soap.client.ObjectRef)}.
 *//* ww  w  .jav  a 2 s. c  o  m*/
@Test
public void testInsertStatusIfNotExists() {
    final ObjectRef item = new ObjectRef(BigInteger.ONE, "item");
    final boolean result = dao.insertStatusIfNotExists(item);
    assertTrue(result);

    final List<ObjectRef> list = getJdbcTemplate().query("SELECT id, name FROM mantis_enum_status",
            new BeanPropertyRowMapper<ObjectRef>(ObjectRef.class));

    assertEquals(1, list.size());
    assertEquals(item, list.get(0));

    final boolean result2 = dao.insertStatusIfNotExists(item);
    assertTrue(result2);
}

From source file:com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesServiceTest.java

/**
 * Test method for {@link com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesService#insertResolutionIfNotExists(biz.futureware.mantis.rpc.soap.client.ObjectRef)}.
 *///from   w w  w . j  av  a 2 s  .com
@Test
public void testInsertResolutionIfNotExists() {
    final ObjectRef item = new ObjectRef(BigInteger.ONE, "item");
    final boolean result = dao.insertResolutionIfNotExists(item);
    assertTrue(result);

    final List<ObjectRef> list = getJdbcTemplate().query("SELECT id, name FROM mantis_enum_resolutions",
            new BeanPropertyRowMapper<ObjectRef>(ObjectRef.class));

    assertEquals(1, list.size());
    assertEquals(item, list.get(0));

    final boolean result2 = dao.insertResolutionIfNotExists(item);
    assertTrue(result2);
}

From source file:com.lakeside.data.sqldb.BaseDao.java

/**
 * jdbcTemplate?//from  w w  w.j  ava  2s .c o  m
 * @param <X>?
 * @param paramMap ???,??.
 * @param elementType ??
 * @return 
 */
public <X> List<X> jfind(final String sql, final Map<String, ?> paramMap, final Class<X> elementType) {
    return jdbcTemplate.query(sql, paramMap, new BeanPropertyRowMapper<X>(elementType));
}

From source file:com.github.jrrdev.mantisbtsync.core.jobs.enums.EnumsWritersTest.java

/**
 * Get the items from the database/*  w w w.j a  v a  2 s.  c  o  m*/
 *
 * @param tableName
 *          Name of the target table
 * @return items in the DB
 */
private List<ObjectRef> getItemsFromDb(final String tableName) {
    return getJdbcTemplate().query("SELECT id, name FROM " + tableName,
            new BeanPropertyRowMapper<ObjectRef>(ObjectRef.class));
}

From source file:com.skycloud.management.portal.admin.sysmanage.dao.impl.UserManageDaoImpl.java

@Override
public List<TUserBO> userALL() throws SQLException {
    //      String sql="select u.ID,u.ACCOUNT,u.PWD,u.NAME,u.DEPT_ID,u.ROLE_ID,u.EMAIL,u.PHONE,u.MOBILE," +
    //          "u.FAX,u.POSITION,u.STATE,u.COMMENT,u.CHECK_CODE,u.IS_AUTO_APPROVE," +
    //          "u.CREATOR_USER_ID,u.CREATE_DT,u.LASTUPDATE_DT,c.NAME CREATOR_USER_NAME " +
    //          "from T_SCS_USER u " +
    //          "LEFT JOIN T_SCS_USER c on u.CREATOR_USER_ID=c.ID order by u.ID desc;";
    String sql = "select u.* from T_SCS_USER u where u.DEPT_ID<>1 order by u.ID desc;";
    BeanPropertyRowMapper<TUserBO> userRowMapper = new BeanPropertyRowMapper<TUserBO>(TUserBO.class);
    List<TUserBO> returnList = null;
    try {//w w w .  j  a v a2  s  . c  om
        returnList = this.getJdbcTemplate().query(sql, new RowMapperResultSetExtractor<TUserBO>(userRowMapper));
    } catch (Exception e) {
        throw new SQLException("" + e.getMessage());
    }
    return returnList;
}

From source file:com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesServiceTest.java

/**
 * Test method for {@link com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesService#insertCustomFieldIfNotExists(biz.futureware.mantis.rpc.soap.client.ObjectRef, java.math.BigInteger)}.
 *//*from  w  w  w. j  a  va2 s.c  o m*/
@Test
public void testInsertCustomFieldIfNotExistsProjectNull() {
    final Operation op = insertInto("mantis_enum_custom_field_types").columns("id", "name").values(1, "type_1")
            .build();

    lauchOperation(op);

    final ObjectRef item = new ObjectRef(BigInteger.ONE, "item");
    dao.insertCustomFieldIfNotExists(item, null);

    final List<ObjectRef> list = getJdbcTemplate().query(
            "SELECT cf.id, cf.name" + " FROM mantis_custom_field_table cf",
            new BeanPropertyRowMapper<ObjectRef>(ObjectRef.class));

    assertEquals(1, list.size());
    assertEquals(item, list.get(0));
}

From source file:cu.uci.coj.restapi.controller.RestUserProfileController.java

private boolean ValidateCountry(Integer country_id) {
    String sql = "SELECT * FROM public.country WHERE country_id = ?";
    try {//from w w  w  . j  ava2s.c  om
        Country country = (Country) jdbcTemplate.queryForObject(sql, new Object[] { country_id },
                new BeanPropertyRowMapper(Country.class));
    } catch (Exception e) {
        return false;
    }

    return true;
}

From source file:com.skycloud.management.portal.admin.sysmanage.dao.impl.UserManageDaoImpl.java

@Override
public TUserBO findUserById(final int userId) throws SQLException {
    String sql = "select u.ID,u.ACCOUNT,u.PWD,u.NAME,u.DEPT_ID,u.ROLE_ID,u.EMAIL,u.PHONE,u.MOBILE,"
            + "u.FAX,u.POSITION,u.STATE,u.COMMENT,u.CHECK_CODE,u.IS_AUTO_APPROVE,"
            + "u.CREATOR_USER_ID,u.CREATE_DT,u.LASTUPDATE_DT, r.ROLE_NAME " + "from T_SCS_USER u LEFT JOIN "
            + "T_SCS_ROLE r on u.ROLE_ID=r.ROLE_ID  where u.ID=?;";
    BeanPropertyRowMapper<TUserBO> userRowMapper = new BeanPropertyRowMapper<TUserBO>(TUserBO.class);
    List<TUserBO> returnList = null;
    TUserBO user = null;//from www  .  j a  va2  s  . c o m
    try {
        returnList = this.getJdbcTemplate().query(sql, new PreparedStatementSetter() {
            public void setValues(PreparedStatement ps) throws SQLException {
                ps.setInt(1, userId);
            }
        }, userRowMapper);
    } catch (Exception e) {
        throw new SQLException("" + e.getMessage());
    }
    if (returnList != null && returnList.size() > 0)
        user = returnList.get(0);
    else
        return null;
    user.setDept(deptDao.findDeptById(user.getDeptId()));
    return user;
}