Example usage for org.springframework.jdbc.core.namedparam BeanPropertySqlParameterSource BeanPropertySqlParameterSource

List of usage examples for org.springframework.jdbc.core.namedparam BeanPropertySqlParameterSource BeanPropertySqlParameterSource

Introduction

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

Prototype

public BeanPropertySqlParameterSource(Object object) 

Source Link

Document

Create a new BeanPropertySqlParameterSource for the given bean.

Usage

From source file:org.openlmis.performancetesting.dao.ProductDAO.java

public long insertCategory(ProductCategory productCategory) {
    GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
    template.update(insertCategoryQuery, new BeanPropertySqlParameterSource(productCategory), keyHolder,
            new String[] { "id" });
    long autoGeneratedKey = keyHolder.getKey().longValue();
    productCategory.setId(autoGeneratedKey);
    return autoGeneratedKey;
}

From source file:cz.dasnet.dasik.dao.LearnDaoImpl.java

public void updateLearn(Learn learn) {
    String sql = "UPDATE learns SET user_id = :userId, " + "`trigger` = :trigger, reply = :reply, "
            + "type = :type, channel = :channel, " + "created = :created WHERE id = :id";

    SqlParameterSource learnParameters = new BeanPropertySqlParameterSource(learn);
    update(sql, learnParameters);//  ww w . j  a  v  a2s .co m
}

From source file:com.springdeveloper.data.jdbc.batch.JdbcTasklet.java

/**
 * Execute the {@link #setSql(String) SQL query} provided. If the query
 * starts with "select" (case insensitive) the result is a list of maps,
 * which is logged and added to the step execution exit status. Otherwise
 * the query is executed and the result is an indication, also in the exit
 * status, of the number of rows updated.
 *//*  w ww  .j  av a  2s  . co  m*/
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {

    StepExecution stepExecution = chunkContext.getStepContext().getStepExecution();
    ExitStatus exitStatus = stepExecution.getExitStatus();

    if (sql.trim().toUpperCase().startsWith("SELECT")) {
        logger.debug("Executing: " + sql);
        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql,
                new BeanPropertySqlParameterSource(chunkContext.getStepContext()));
        String msg = "Result: " + result;
        logger.debug(msg);
        stepExecution.setExitStatus(exitStatus.addExitDescription(msg));
    } else {
        logger.debug("Updating : " + sql);
        int updated = jdbcTemplate.update(sql,
                new BeanPropertySqlParameterSource(chunkContext.getStepContext()));
        String msg = "Updated: " + updated + " rows";
        logger.debug(msg);
        stepExecution.setExitStatus(exitStatus.addExitDescription(msg));
    }
    return RepeatStatus.FINISHED;

}

From source file:net.noday.d4c.dao.SubdomainDao.java

public int findCount(Subdomain condition) {
    StringBuffer sql = new StringBuffer("select count(d.id) from domain d where 1=1");
    SqlParameterSource ps = null;/*  www . j a v a  2  s .c  o  m*/
    if (condition != null) {
        ps = new BeanPropertySqlParameterSource(condition);
        sql.append(toConditionSql(condition));
    }
    return namedJdbc.queryForInt(sql.toString(), ps);
}

From source file:cz.dasnet.dasik.dao.UserDaoImpl.java

public void updateUser(User user) {
    String sql = "UPDATE users SET " + "words = :words, words_daily = :wordsDaily, " + "access = :access, "
            + "lastseen = :lastseen, lastseen_action = :lastseenAction, lastseen_nick = :lastseenNick "
            + "WHERE id = :id";
    SqlParameterSource userParameters = new BeanPropertySqlParameterSource(user);
    update(sql, userParameters);/*from   w w  w. j  ava2s .  co m*/
    invalidateUser(user.getMask());
}

From source file:airport.database.services.users.UsersDaoOnlineImpl.java

@Override
public void deleteUser(User user) {
    SqlParameterSource parameterUser = new BeanPropertySqlParameterSource(user);

    jdbcTemplate.update(SQL_QUERY_DELETE_CURRENT_USER, parameterUser);

    if (LOG.isInfoEnabled()) {
        LOG.info("delete user from online. User : " + user);
    }/*from  ww  w. j  av a  2 s  .  com*/
}

From source file:net.turnbig.jdbcx.JdbcxDaoSupport.java

public <T> List<T> queryForListBean(String sql, Object beanParamSource, Class<T> mapResultToClass)
        throws DataAccessException {
    return getNamedParameterJdbcTemplate().query(sql, new BeanPropertySqlParameterSource(beanParamSource),
            getBeanPropsRowMapper(mapResultToClass));
}

From source file:com.rambird.miles.repository.jdbc.JdbcCatgRepositoryImpl.java

@Override
public void save(Category category) throws DataAccessException {
    BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(category);
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    category.setUserName(auth.getName()); //get logged in username

    if (category.isNew()) {
        Number newKey = this.insertMileCatg.executeAndReturnKey(parameterSource);
        category.setCatgid(newKey.intValue());
    } else {// ww w .j a v a 2 s.c o m
        this.namedParameterJdbcTemplate.update(
                "UPDATE category SET catg=:catg, catg_label=:catgLabel, home=:home WHERE catgid=:catgid",
                parameterSource);
    }
}

From source file:airport.database.services.statistics.StatisticsDaoImpl.java

@Override
public void incAmountTakenOffPlane(User user) {
    SqlParameterSource parameterSource = new BeanPropertySqlParameterSource(user);

    jdbcTemplate.update(SQL_QUERY_INC_AMOUNT_TAKEN_OFF_PLANE, parameterSource);
}

From source file:airport.database.services.users.UsersDaoOnlineImpl.java

@Override
public boolean isThere(User user) {
    SqlParameterSource parameterUser = new BeanPropertySqlParameterSource(user);

    int countDispatcher = jdbcTemplate.queryForObject(SQL_QUERY_EXIST_USER, parameterUser, Double.class)
            .intValue();/*from www .ja va  2s. co m*/

    boolean result = countDispatcher > 0;

    if (LOG.isInfoEnabled()) {
        if (result) {
            LOG.info("User is exist. User : " + user);
        } else {
            LOG.info("User isn't exist. User : " + user);
        }
    }

    return result;
}