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

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

Introduction

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

Prototype

BatchPreparedStatementSetter

Source Link

Usage

From source file:com.exploringspatial.dao.impl.ConflictDaoImpl.java

@Override
public void batchUpdate(List<Conflict> conflicts) {

    jdbcTemplate.batchUpdate(batchUpdateSql, new BatchPreparedStatementSetter() {

        @Override//  w  ww.java  2s.  co  m
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            final DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
            final Conflict instance = conflicts.get(i);
            ps.setLong(1, instance.getGwno());
            ps.setString(2, instance.getEventIdCountry());
            ps.setLong(3, instance.getEventPk());
            ps.setString(4, df.format(instance.getEventDate()));
            ps.setLong(5, instance.getYear());
            ps.setLong(6, instance.getTimePrecision());
            ps.setString(7, instance.getEventType());
            ps.setString(8, instance.getActor1());
            ps.setString(9, instance.getAllyActor1());
            ps.setLong(10, instance.getInter1());
            ps.setString(11, instance.getActor2());
            ps.setString(12, instance.getAllyActor2());
            ps.setLong(13, instance.getInter2());
            ps.setLong(14, instance.getInteraction());
            ps.setString(15, instance.getCountry());
            ps.setString(16, instance.getAdmin1());
            ps.setString(17, instance.getAdmin2());
            ps.setString(18, instance.getAdmin3());
            ps.setString(19, instance.getLocation());
            ps.setDouble(20, instance.getLatitude());
            ps.setDouble(21, instance.getLongitude());
            ps.setLong(22, instance.getGwno());
            ps.setString(23, instance.getSource());
            ps.setString(24, instance.getNotes());
            ps.setLong(25, instance.getFatalities());
        }

        @Override
        public int getBatchSize() {
            return conflicts.size();
        }
    });

}

From source file:shell.framework.organization.department.service.impl.TblSysDepartmentServiceI4JdbcImpl.java

public int assignSysUser(TblSysDepartmentVO departmentVO) {
    String sql = "insert into TBL_SYS_USER_DEPARTMENT values (?,?)";
    final String departmentID = departmentVO.getId();
    String sysUserIds[] = departmentVO.getUser().getId().split("-");
    final List<String> idList = new ArrayList<String>();
    for (String id : sysUserIds) {
        idList.add(id);//from www .j  av a  2  s.  c  om
    }

    int[] deleteNumbers = jdbcBaseDao.batchUpdate(sql, idList, new BatchPreparedStatementSetter() {

        /*
         * (non-Javadoc)
         * @see org.springframework.jdbc.core.BatchPreparedStatementSetter#setValues(java.sql.PreparedStatement, int)
         */
        public void setValues(PreparedStatement ps, int index) throws SQLException {
            String sysUser_id = idList.get(index);
            ps.setString(1, sysUser_id);
            ps.setString(2, departmentID);
        }

        /*
         * (non-Javadoc)
         * @see org.springframework.jdbc.core.BatchPreparedStatementSetter#getBatchSize()
         */
        public int getBatchSize() {
            return idList.size();
        }
    });
    return deleteNumbers.length;
}

From source file:data.DefaultExchanger.java

private int[] batchUpdate(JdbcTemplate jdbcTemplate, final List<JsonNode> nodes) {
    int[] updateCounts = jdbcTemplate.batchUpdate(getInsertSql(), new BatchPreparedStatementSetter() {
        @Override/* ww w  .  j a va  2 s  . co  m*/
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            setPreparedStatement(ps, nodes.get(i));
        }

        @Override
        public int getBatchSize() {
            return nodes.size();
        }
    });
    return updateCounts;
}

From source file:com.carfinance.module.peoplemanage.dao.PeopleManageDao.java

public void peopleroleDoEdit(final long edited_user_id, final long org_id, final String role_ids) {
    this.deleteUserOrgRole(org_id, edited_user_id);
    if (role_ids.length() > 0) {
        final String[] role_id = role_ids.split(",");
        String sql = "insert into user_role (user_id , role_id , org_id) values (?,?,?)";
        try {//from   ww  w. jav a2 s  .com
            this.getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    ps.setLong(1, edited_user_id);
                    ps.setLong(2, Long.valueOf(role_id[i]));
                    ps.setLong(3, org_id);
                }

                public int getBatchSize() {
                    return role_id.length;//??labels.length
                }
            });
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:shell.framework.organization.role.service.impl.TblSysRoleService4JdbcImpl.java

@Override
public int assignURLAuthority(final TblSysRoleVO sysRoleVO) {
    String sql = "insert into TBL_SYS_AUTHORITY values (?,?,?,?) ";
    if (sysRoleVO.getFunction().getId() == null || "".equals(sysRoleVO.getFunction().getId())) {
        return 0;
    }//w  ww. j a v  a  2 s  .c  o m
    String[] functionIDs = sysRoleVO.getFunction().getId().split("-");
    final List<String> functionIdList = Arrays.asList(functionIDs);

    int[] updateNum = jdbcBaseDao.batchUpdate(sql, functionIdList, new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps, int index) throws SQLException {
            String funID = functionIdList.get(index);
            ps.setString(1, sysRoleVO.getRole().getId());
            ps.setString(2, funID);
            ps.setString(3, SystemParam.AUTHORITY_TYPE_URL);
            ps.setInt(4, SystemParam.AUTHORITY_OPER_READ_ONLY); //???? 0-?
        }

        @Override
        public int getBatchSize() {
            return functionIdList.size();
        }
    });
    return updateNum.length;
}

From source file:net.duckling.ddl.service.resource.dao.ResourceDAOImpl.java

@Override
public int updateBid(final int bid, final List<Long> rids) {
    this.getJdbcTemplate().batchUpdate(UPDATE_BID, new BatchPreparedStatementSetter() {
        @Override//  w  w w  .  j  a  v a2s. c om
        public int getBatchSize() {
            return (null != rids && !rids.isEmpty()) ? rids.size() : 0;
        }

        @Override
        public void setValues(PreparedStatement ps, int index) throws SQLException {
            long rid = rids.get(index);
            int i = 0;
            ps.setInt(++i, bid);
            ps.setInt(++i, (int) rid);
        }

    });
    return 1;
}

From source file:gov.nih.nci.cabig.caaers.datamigrator.UserDataMigrator.java

/**
 * Will related a user group to protection group. 
 * @param userName - Username/*w  ww.j a  v  a2s .  c o m*/
 * @param protectionGroupName - protectionGroup name
 * @param groups   - The user groups to associate
 * @param onOracleDB
 */
protected void relateSuperUserGroupsToProtectionElements(final String userName,
        final String protectionGroupName, final List groups, boolean onOracleDB) {
    String pgSQL = "INSERT INTO csm_user_group_role_pg(user_group_role_pg_id, user_id, protection_group_id, role_id,update_date) "
            + "VALUES ((select nextval('csm_user_grou_user_group_r_seq')), "
            + "(select user_id from csm_user where login_name = ?), "
            + "(select protection_group_id from csm_protection_group where protection_group_name = ?), "
            + "(select role_id from csm_role where role_name = ?), " + "now())";
    String oracleSQL = "INSERT INTO csm_user_group_role_pg(user_group_role_pg_id, user_id, protection_group_id, role_id,update_date) "
            + "VALUES (csm_user_grou_user_group_r_seq.nextval, "
            + "(select user_id from csm_user where login_name = ?), "
            + "(select protection_group_id from csm_protection_group where protection_group_name = ?), "
            + "(select role_id from csm_role where role_name = ?), " + "sysdate)";

    String sql = onOracleDB ? oracleSQL : pgSQL;
    getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
        public int getBatchSize() {
            return groups.size();
        }

        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setString(1, userName);
            ps.setString(2, protectionGroupName);
            ps.setString(3, groups.get(i).toString());
        }
    });

}

From source file:com.carfinance.module.peoplemanage.dao.PeopleManageDao.java

public void peopleroleDoAdd(final long edited_user_id, final long org_id, final String[] role_id) {
    String sql = "insert into user_role (user_id , role_id , org_id) values (?,?,?)";
    try {/*from  w  w w  . ja  va 2  s.  c  o  m*/
        this.getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
            public void setValues(PreparedStatement ps, int i) throws SQLException {
                ps.setLong(1, edited_user_id);
                ps.setLong(2, Long.valueOf(role_id[i]));
                ps.setLong(3, org_id);
            }

            public int getBatchSize() {
                return role_id.length;//??labels.length
            }
        });
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:shell.framework.organization.department.service.impl.TblSysDepartmentServiceI4JdbcImpl.java

public int assignSysRole(TblSysDepartmentVO departmentVO) {
    String sql = "insert into TBL_SYS_ROLE_DEPARTMENT values (?,?)";
    final String departmentID = departmentVO.getId();
    String sysRoleIds[] = departmentVO.getRole().getRole().getId().split("-");
    final List<String> idList = Arrays.asList(sysRoleIds);

    int[] deleteNumbers = jdbcBaseDao.batchUpdate(sql, idList, new BatchPreparedStatementSetter() {

        /*//from  w  w w  . j  a v a  2 s  .c  o m
         * (non-Javadoc)
         * @see org.springframework.jdbc.core.BatchPreparedStatementSetter#setValues(java.sql.PreparedStatement, int)
         */
        public void setValues(PreparedStatement ps, int index) throws SQLException {
            String sysRole_id = idList.get(index);
            ps.setString(1, sysRole_id);
            ps.setString(2, departmentID);
        }

        /*
         * (non-Javadoc)
         * @see org.springframework.jdbc.core.BatchPreparedStatementSetter#getBatchSize()
         */
        public int getBatchSize() {
            return idList.size();
        }
    });
    return deleteNumbers.length;
}

From source file:shell.framework.organization.role.service.impl.TblSysRoleService4JdbcImpl.java

@Override
public int unAssignURLAuthority(final TblSysRoleVO sysRoleVO) {
    String sql = "delete from TBL_SYS_AUTHORITY where ROLE_ID=? and FUNCTION_ID=?";
    if (sysRoleVO.getFunction().getId() == null || "".equals(sysRoleVO.getFunction().getId())) {
        return 0;
    }//from  w  w w .  j  a  v  a2 s .  c o  m
    String[] functionIDs = sysRoleVO.getFunction().getId().split("-");
    final List<String> functionIdList = Arrays.asList(functionIDs);

    int[] updateNum = jdbcBaseDao.batchUpdate(sql, functionIdList, new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps, int index) throws SQLException {
            String funID = functionIdList.get(index);
            ps.setString(1, sysRoleVO.getRole().getId());
            ps.setString(2, funID);
        }

        @Override
        public int getBatchSize() {
            return functionIdList.size();
        }
    });
    return updateNum.length;
}