Search in sources :

Example 21 with BatchPreparedStatementSetter

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

the class FileDiffDao method update.

public int[] update(final FileDiff[] fileDiffs) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "UPDATE " + TABLE_NAME + " SET " + "rid = ?, " + "diff_type = ?, " + "src = ?, " + "parameters = ?, " + "state = ?, " + "create_time = ? " + "WHERE did = ?";
    return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setLong(1, fileDiffs[i].getRuleId());
            ps.setInt(2, fileDiffs[i].getDiffType().getValue());
            ps.setString(3, fileDiffs[i].getSrc());
            ps.setString(4, fileDiffs[i].getParametersJsonString());
            ps.setInt(5, fileDiffs[i].getState().getValue());
            ps.setLong(6, fileDiffs[i].getCreateTime());
            ps.setLong(7, fileDiffs[i].getDiffId());
        }

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

Example 22 with BatchPreparedStatementSetter

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

the class CmdletDao method batchDelete.

public int[] batchDelete(final List<Long> cids) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    final String sql = "DELETE FROM " + TABLE_NAME + " WHERE cid = ?";
    return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setLong(1, cids.get(i));
        }

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

Example 23 with BatchPreparedStatementSetter

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

the class SmallFileDao method batchInsertUpdate.

public int[] batchInsertUpdate(final CompactFileState[] fileStates) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "REPLACE INTO small_file (path, container_file_path, offset, length)" + " VALUES (?,?,?,?)";
    return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setString(1, fileStates[i].getPath());
            ps.setString(2, fileStates[i].getFileContainerInfo().getContainerFilePath());
            ps.setLong(3, fileStates[i].getFileContainerInfo().getOffset());
            ps.setLong(4, fileStates[i].getFileContainerInfo().getLength());
        }

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

Example 24 with BatchPreparedStatementSetter

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

the class StorageHistoryDao method insertStorageHistTable.

public void insertStorageHistTable(final StorageCapacity[] storages, final long interval) throws SQLException {
    if (storages.length == 0) {
        return;
    }
    final Long curr = System.currentTimeMillis();
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "INSERT INTO storage_hist (type, time_stamp, capacity, free) VALUES (?,?,?,?);";
    jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setString(1, storages[i].getType() + "-" + interval);
            if (storages[i].getTimeStamp() == null) {
                ps.setLong(2, curr);
            } else {
                ps.setLong(2, storages[i].getTimeStamp());
            }
            ps.setLong(3, storages[i].getCapacity());
            ps.setLong(4, storages[i].getFree());
        }

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

Example 25 with BatchPreparedStatementSetter

use of org.springframework.jdbc.core.BatchPreparedStatementSetter in project spring-framework by spring-projects.

the class NamedParameterJdbcTemplate method batchUpdate.

@Override
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) {
    if (batchArgs.length == 0) {
        return new int[0];
    }
    ParsedSql parsedSql = getParsedSql(sql);
    PreparedStatementCreatorFactory pscf = getPreparedStatementCreatorFactory(parsedSql, batchArgs[0]);
    return getJdbcOperations().batchUpdate(pscf.getSql(), new BatchPreparedStatementSetter() {

        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null);
            pscf.newPreparedStatementSetter(values).setValues(ps);
        }

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

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