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.example.dfa.demo.service.DfaDemoServiceImpl.java

@Override
public NextEventDTO processWorkflowEvent(NextEventDTO nextEvent) {
    SqlParameterSource inParams = new BeanPropertySqlParameterSource(nextEvent);
    processWorkflowEventSpaCall.execute(inParams);
    NextEventDTO result = jdbcTemplate.queryForObject(
            "SELECT dws.DFA_WORKFLOW_ID,dws.DFA_STATE_ID FROM dfa.DFA_WORKFLOW JOIN dfa.DFA_WORKFLOW_STATE dws ON dws.DFA_WORKFLOW_ID = IF(SUB_STATE, dfa.DFA_WORKFLOW.SPAWN_DFA_WORKFLOW_ID, dfa.DFA_WORKFLOW.DFA_WORKFLOW_ID) AND dws.IS_CURRENT = 1 WHERE dfa.DFA_WORKFLOW.DFA_WORKFLOW_ID = ?",
            new BeanPropertyRowMapper<NextEventDTO>(NextEventDTO.class), nextEvent.getDfaWorkflowId());
    return result;
}

From source file:com.krawler.workflow.module.dao.DataObjectOperationDAOImpl.java

@Override
public List getAllDataObjects(String objName, Class classObj) {
    List results = null;//w  w w. j  a v  a  2 s . c  o m
    StringBuilder query = new StringBuilder("SELECT * FROM ");
    query.append(getTableName(objName));
    try {
        results = getJdbcTemplate().query(query.toString(), new BeanPropertyRowMapper(classObj));
    } catch (DataAccessException e) {
        LOG.warn("Can not fetch all records", e);
    }

    return results;
}

From source file:org.snaker.engine.access.spring.SpringJdbcAccess.java

@Override
public <T> List<T> queryList(Page<T> page, Class<T> T, String sql, Object... args) {
    String countSQL = "select count(1) from (" + sql + ") c ";
    String querySQL = sql;/*w w w .  j  av  a2  s.c om*/
    if (page.isOrderBySetted()) {
        querySQL = sql + StringHelper.buildPageOrder(page.getOrder(), page.getOrderBy());
    }
    //???pageSize
    if (page.getPageSize() != Page.NON_PAGE) {
        querySQL = getDialect().getPageSql(querySQL, page.getPageNo(), page.getPageSize());
    }
    if (log.isDebugEnabled()) {
        log.debug("countSQL=\n" + countSQL);
        log.debug("querySQL=\n" + querySQL);
    }

    List<T> tasks = null;
    long count = 0L;
    try {
        count = template.queryForLong(countSQL, args);
        tasks = template.query(querySQL, args, new BeanPropertyRowMapper<T>(T));
        if (tasks == null)
            tasks = Collections.emptyList();
        page.setResult(tasks);
        page.setTotalCount(ClassHelper.castLong(count));
        return page.getResult();
    } catch (RuntimeException e) {
        log.error("" + e.getMessage());
        return Collections.emptyList();
    }
}

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

@Override
public <T> T findUnique(String sql, Class<T> dtoClass, Object... args) {

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

    debugSql(sql, args);// w w w.  jav  a2  s .  c om

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

    List<T> list = jdbcTemplate.query(sql, rowMapper, args);
    if (list.isEmpty()) {
        return null;
    }

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

    return list.get(0);
}

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

/**
 * Test method for {@link com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesService#insertUserIfNotExists(biz.futureware.mantis.rpc.soap.client.AccountData, java.math.BigInteger)}.
 *///from  w w  w.java 2 s .  co m
@Test
public void testInsertUserIfNotExists() {
    final Operation op = insertInto("mantis_project_table").columns("id", "name").values(1, "project_1")
            .build();

    lauchOperation(op);

    final AccountData item = new AccountData();
    item.setId(BigInteger.valueOf(1));
    item.setName("new_user_1");

    dao.insertUserIfNotExists(item, BigInteger.ONE);

    final List<AccountData> list = getJdbcTemplate()
            .query("SELECT usr.id, usr.name" + " FROM mantis_user_table usr"
                    + " INNER JOIN mantis_project_user_list_table pul ON pul.user_id = usr.id"
                    + " WHERE pul.project_id = 1", new BeanPropertyRowMapper<AccountData>(AccountData.class));

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

    dao.insertUserIfNotExists(item, BigInteger.ONE);
}

From source file:konditer.client.dao.CustomerDao.java

@Override
public Customer getCustomer(int customerId) {
    String SQL_QUERY = "SELECT CUSTOMER_ID, " + "DISCOUNT_ID, " + "CUSTOMER_LAST_NAME, "
            + "CUSTOMER_FIRST_NAME, " + "CUSTOMER_PARENT_NAME, " + "CUSTOMER_DATE_BORN, " + "CUSTOMER_INFO, "
            + "TIMESTAMP " + "FROM customers " + "WHERE CUSTOMER_ID = ?";
    Customer customer = (Customer) jdbcTemplate.queryForObject(SQL_QUERY, new Object[] { customerId },
            new BeanPropertyRowMapper(Customer.class));
    return customer;
}

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

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

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

    debugSql(sql, args);//ww w  . j av a  2 s .  c  o  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.krawler.workflow.module.dao.DataObjectOperationDAOImpl.java

@Override
public Object getDataObjectById(Object dataObject, String pKeyName) {
    Object result = null;// w  ww . j a  v  a2 s  .  com
    StringBuilder query = new StringBuilder("SELECT * FROM ");
    query.append(getTableName(dataObject.getClass().getSimpleName()));
    query.append(" where ");
    query.append(pKeyName);
    query.append(" = ?");

    try {
        Object id = BeanUtils.getProperty(dataObject, pKeyName);
        result = getJdbcTemplate().queryForObject(query.toString(), new Object[] { id },
                new BeanPropertyRowMapper(dataObject.getClass()));
    } catch (DataAccessException e) {
        LOG.warn("Can not fetch all records", e);
    } catch (Exception e) {
        LOG.warn("Can not fetch all records", e);
    }

    return result;
}

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

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

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

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

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

From source file:au.org.ala.layers.dao.UserDataDAOImpl.java

@Override
public List<Ud_header> list(String user_id) {

    String sql = "SELECT * FROM Ud_header WHERE user_id = ?";

    List<Ud_header> ud_headers = (List<Ud_header>) jdbcTemplate.queryForObject(sql,
            new BeanPropertyRowMapper(Ud_header.class), new Object[] { user_id });

    return ud_headers;
}