Search in sources :

Example 6 with BatchPreparedStatementSetter

use of org.springframework.jdbc.core.BatchPreparedStatementSetter in project SSM by Intel-bigdata.

the class FileDiffDao method batchUpdate.

public int[] batchUpdate(final List<Long> dids, final FileDiffState state) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    final String sql = "UPDATE " + TABLE_NAME + " SET state = ? " + "WHERE did = ?";
    return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setShort(1, (short) state.getValue());
            ps.setLong(2, dids.get(i));
        }

        @Override
        public int getBatchSize() {
            return dids.size();
        }
    });
}
Also used : SQLException(java.sql.SQLException) BatchPreparedStatementSetter(org.springframework.jdbc.core.BatchPreparedStatementSetter) PreparedStatement(java.sql.PreparedStatement) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 7 with BatchPreparedStatementSetter

use of org.springframework.jdbc.core.BatchPreparedStatementSetter in project SSM by Intel-bigdata.

the class CmdletDao method update.

public int[] update(final List<CmdletInfo> cmdletInfos) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "UPDATE " + TABLE_NAME + " SET  state = ?, state_changed_time = ? WHERE cid = ?";
    return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setInt(1, cmdletInfos.get(i).getState().getValue());
            ps.setLong(2, cmdletInfos.get(i).getStateChangedTime());
            ps.setLong(3, cmdletInfos.get(i).getCid());
        }

        public int getBatchSize() {
            return cmdletInfos.size();
        }
    });
}
Also used : SQLException(java.sql.SQLException) BatchPreparedStatementSetter(org.springframework.jdbc.core.BatchPreparedStatementSetter) PreparedStatement(java.sql.PreparedStatement) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 8 with BatchPreparedStatementSetter

use of org.springframework.jdbc.core.BatchPreparedStatementSetter in project SSM by Intel-bigdata.

the class CmdletDao method replace.

public int[] replace(final CmdletInfo[] cmdletInfos) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "REPLACE INTO " + TABLE_NAME + "(cid, " + "rid, " + "aids, " + "state, " + "parameters, " + "generate_time, " + "state_changed_time)" + " VALUES(?, ?, ?, ?, ?, ?, ?)";
    return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setLong(1, cmdletInfos[i].getCid());
            ps.setLong(2, cmdletInfos[i].getRid());
            ps.setString(3, StringUtils.join(cmdletInfos[i].getAidsString(), ","));
            ps.setLong(4, cmdletInfos[i].getState().getValue());
            ps.setString(5, cmdletInfos[i].getParameters());
            ps.setLong(6, cmdletInfos[i].getGenerateTime());
            ps.setLong(7, cmdletInfos[i].getStateChangedTime());
        }

        public int getBatchSize() {
            return cmdletInfos.length;
        }
    });
}
Also used : SQLException(java.sql.SQLException) BatchPreparedStatementSetter(org.springframework.jdbc.core.BatchPreparedStatementSetter) PreparedStatement(java.sql.PreparedStatement) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 9 with BatchPreparedStatementSetter

use of org.springframework.jdbc.core.BatchPreparedStatementSetter in project SSM by Intel-bigdata.

the class ActionDao method replace.

public int[] replace(final ActionInfo[] actionInfos) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "REPLACE INTO " + TABLE_NAME + "(aid, " + "cid, " + "action_name, " + "args, " + "result, " + "log, " + "successful, " + "create_time, " + "finished, " + "finish_time, " + "exec_host, " + "progress)" + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setLong(1, actionInfos[i].getActionId());
            ps.setLong(2, actionInfos[i].getCmdletId());
            ps.setString(3, actionInfos[i].getActionName());
            ps.setString(4, actionInfos[i].getArgsJsonString());
            ps.setString(5, actionInfos[i].getResult());
            ps.setString(6, actionInfos[i].getLog());
            ps.setBoolean(7, actionInfos[i].isSuccessful());
            ps.setLong(8, actionInfos[i].getCreateTime());
            ps.setBoolean(9, actionInfos[i].isFinished());
            ps.setLong(10, actionInfos[i].getFinishTime());
            ps.setString(11, actionInfos[i].getExecHost());
            ps.setFloat(12, actionInfos[i].getProgress());
        }

        public int getBatchSize() {
            return actionInfos.length;
        }
    });
}
Also used : SQLException(java.sql.SQLException) BatchPreparedStatementSetter(org.springframework.jdbc.core.BatchPreparedStatementSetter) PreparedStatement(java.sql.PreparedStatement) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 10 with BatchPreparedStatementSetter

use of org.springframework.jdbc.core.BatchPreparedStatementSetter in project SSM by Intel-bigdata.

the class XattrDao method insertXattrList.

public synchronized boolean insertXattrList(final Long fid, final List<XAttribute> attributes) throws SQLException {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "INSERT INTO xattr (fid, namespace, name, value) VALUES (?, ?, ?, ?)";
    int[] i = jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setLong(1, fid);
            ps.setString(2, attributes.get(i).getNameSpace());
            ps.setString(3, attributes.get(i).getName());
            ps.setBytes(4, attributes.get(i).getValue());
        }

        public int getBatchSize() {
            return attributes.size();
        }
    });
    return i.length == attributes.size();
}
Also used : SQLException(java.sql.SQLException) BatchPreparedStatementSetter(org.springframework.jdbc.core.BatchPreparedStatementSetter) PreparedStatement(java.sql.PreparedStatement) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Aggregations

PreparedStatement (java.sql.PreparedStatement)28 BatchPreparedStatementSetter (org.springframework.jdbc.core.BatchPreparedStatementSetter)28 SQLException (java.sql.SQLException)22 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)18 TransactionStatus (org.springframework.transaction.TransactionStatus)6 ArrayList (java.util.ArrayList)5 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)5 List (java.util.List)4 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)4 TransactionCallback (org.springframework.transaction.support.TransactionCallback)2 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)2 ModifyWordbook (zjp.translateit.dto.ModifyWordbook)2 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)1 DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)1 DbDataMedia (com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia)1 DbMediaSource (com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource)1 NamedThreadFactory (com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory)1 Query (com.baidu.unbiz.common.genericdao.operator.Query)1 BaseObject (com.github.knightliao.apollo.db.bo.BaseObject)1 EmailRecipient (com.serotonin.m2m2.vo.mailingList.EmailRecipient)1