Java Code Examples for org.springframework.jdbc.core.BatchPreparedStatementSetter

The following examples show how to use org.springframework.jdbc.core.BatchPreparedStatementSetter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: NamedParameterJdbcTemplate.java    License: MIT License 6 votes vote down vote up
@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;
				}
			});
}
 
Example 2
public static int[] executeBatchUpdateWithNamedParameters(
		final ParsedSql parsedSql, final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) {

	if (batchArgs.length == 0) {
		return new int[0];
	}

	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]);
	return jdbcOperations.batchUpdate(
			sqlToUse,
			new BatchPreparedStatementSetter() {
				@Override
				public void setValues(PreparedStatement ps, int i) throws SQLException {
					Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null);
					int[] columnTypes = NamedParameterUtils.buildSqlTypeArray(parsedSql, batchArgs[i]);
					setStatementParameters(values, ps, columnTypes);
				}
				@Override
				public int getBatchSize() {
					return batchArgs.length;
				}
			});
}
 
Example 3
Source Project: spring-analysis-note   Source File: AbstractJdbcInsert.java    License: MIT License 6 votes vote down vote up
/**
 * Delegate method to execute the batch insert.
 */
private int[] executeBatchInternal(final List<List<Object>> batchValues) {
	if (logger.isDebugEnabled()) {
		logger.debug("Executing statement " + getInsertString() + " with batch of size: " + batchValues.size());
	}
	return getJdbcTemplate().batchUpdate(getInsertString(),
			new BatchPreparedStatementSetter() {
				@Override
				public void setValues(PreparedStatement ps, int i) throws SQLException {
					setParameterValues(ps, batchValues.get(i), getInsertTypes());
				}
				@Override
				public int getBatchSize() {
					return batchValues.size();
				}
			});
}
 
Example 4
@Override
public void lockCustomers(int companyId, List<Integer> ids) {
	UUID uuid = UUID.randomUUID();
	String deleteTemp = "delete from cust_temporary_tbl where uuid=?";
	String insertCustomerId = "INSERT INTO cust_temporary_tbl (uuid, customer_id) VALUES (?,?)";

	getJdbcTemplate().batchUpdate(insertCustomerId, new BatchPreparedStatementSetter() {
		@Override
		public void setValues(PreparedStatement ps, int i) throws SQLException {
			ps.setString(1,uuid.toString());
			ps.setInt(2, ids.get(i));
		}

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

	String selForUpd = "SELECT * FROM " + getCustomerTableName(companyId) + " WHERE customer_id IN (select customer_id from cust_temporary_tbl where uuid=? ) FOR UPDATE";
	select(logger, selForUpd, uuid.toString());
	update(logger, deleteTemp, uuid.toString());
}
 
Example 5
Source Project: spring-boot   Source File: JdbcBookRepository.java    License: MIT License 6 votes vote down vote up
@Override
public int[] batchUpdate(List<Book> books) {

    return this.jdbcTemplate.batchUpdate(
            "update books set price = ? where id = ?",
            new BatchPreparedStatementSetter() {

                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    ps.setBigDecimal(1, books.get(i).getPrice());
                    ps.setLong(2, books.get(i).getId());
                }

                public int getBatchSize() {
                    return books.size();
                }

            });

}
 
Example 6
Source Project: spring-boot   Source File: JdbcBookRepository.java    License: MIT License 6 votes vote down vote up
@Override
public int[] batchInsert(List<Book> books) {

    return this.jdbcTemplate.batchUpdate(
            "insert into books (name, price) values(?,?)",
            new BatchPreparedStatementSetter() {

                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    ps.setString(1, books.get(i).getName());
                    ps.setBigDecimal(2, books.get(i).getPrice());
                }

                public int getBatchSize() {
                    return books.size();
                }

            });
}
 
Example 7
Source Project: java-technology-stack   Source File: NamedParameterJdbcTemplate.java    License: MIT License 6 votes vote down vote up
@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;
				}
			});
}
 
Example 8
public static int[] executeBatchUpdateWithNamedParameters(
		final ParsedSql parsedSql, final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) {

	if (batchArgs.length == 0) {
		return new int[0];
	}

	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]);
	return jdbcOperations.batchUpdate(
			sqlToUse,
			new BatchPreparedStatementSetter() {
				@Override
				public void setValues(PreparedStatement ps, int i) throws SQLException {
					Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null);
					int[] columnTypes = NamedParameterUtils.buildSqlTypeArray(parsedSql, batchArgs[i]);
					setStatementParameters(values, ps, columnTypes);
				}
				@Override
				public int getBatchSize() {
					return batchArgs.length;
				}
			});
}
 
Example 9
Source Project: java-technology-stack   Source File: AbstractJdbcInsert.java    License: MIT License 6 votes vote down vote up
/**
 * Delegate method to execute the batch insert.
 */
private int[] executeBatchInternal(final List<List<Object>> batchValues) {
	if (logger.isDebugEnabled()) {
		logger.debug("Executing statement " + getInsertString() + " with batch of size: " + batchValues.size());
	}
	return getJdbcTemplate().batchUpdate(getInsertString(),
			new BatchPreparedStatementSetter() {
				@Override
				public void setValues(PreparedStatement ps, int i) throws SQLException {
					setParameterValues(ps, batchValues.get(i), getInsertTypes());
				}
				@Override
				public int getBatchSize() {
					return batchValues.size();
				}
			});
}
 
Example 10
Source Project: qconfig   Source File: PropertiesEntryLogDaoImpl.java    License: MIT License 6 votes vote down vote up
@Override
public void batchInsert(final List<PropertiesEntryDiff> entries) {
    jdbcTemplate.batchUpdate(INSERT_SQL, new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            PropertiesEntryDiff entry = entries.get(i);
            ps.setString(1, entry.getGroupId());
            ps.setString(2, entry.getDataId());
            ps.setString(3, entry.getProfile());
            ps.setString(4, entry.getKey());
            ps.setLong(5, entry.getVersion());
            ps.setString(6, entry.getValue());
            ps.setLong(7, entry.getLastVersion());
            ps.setString(8, entry.getLastValue());
            ps.setString(9, entry.getComment());
            ps.setInt(10, entry.getType().getCode());
            ps.setString(11, entry.getOperator());
        }
        @Override
        public int getBatchSize() {
            return entries.size();
        }
    });
}
 
Example 11
Source Project: qconfig   Source File: FilePushHistoryDaoImpl.java    License: MIT License 6 votes vote down vote up
@Override
public void batchInsert(final List<FilePushHistory> filePushHistories) {
    jdbcTemplate.batchUpdate(INSERT_SQL, new BatchPreparedStatementSetter() {

        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            FilePushHistory filePushHistory = filePushHistories.get(i);
            ps.setString(1, filePushHistory.getGroup());
            ps.setString(2, filePushHistory.getProfile());
            ps.setString(3, filePushHistory.getDataId());
            ps.setInt(4, filePushHistory.getVersion());
            ps.setString(5, filePushHistory.getMD5());
            ps.setString(6, filePushHistory.getIP());
            ps.setInt(7, filePushHistory.getPort());
            ps.setInt(8, filePushHistory.getStatus().code());
            ps.setInt(9, filePushHistory.getType().code());
            ps.setString(10, filePushHistory.getOperator());
        }

        @Override
        public int getBatchSize() {
            return filePushHistories.size();
        }
    });
}
 
Example 12
Source Project: qconfig   Source File: ApplicationUserDaoImpl.java    License: MIT License 6 votes vote down vote up
@Override
public void batchAdd(final List<String> rtxId, final String addCode, final AccessRoleType type) {
    jdbcTemplate.batchUpdate(ADD_USER_FOR_APP, new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement preparedStatement, int i) throws SQLException {
            preparedStatement.setString(1, addCode);
            preparedStatement.setString(3, rtxId.get(i));
            preparedStatement.setInt(2, type.code());
        }

        @Override
        public int getBatchSize() {
            return rtxId.size();
        }
    });
}
 
Example 13
void saveValue(final SchedulerConfiguration schedulerConfiguration) {

            final List<SchedulerConfigurationValue> values = this.mapSchedulerConfigurationValues(schedulerConfiguration);
            this.mapSchedulerConfigurationValues(schedulerConfiguration);

            final String sql = String.format(INSERT_VALUES, this.tableName);
            this.jdbcTemplate.batchUpdate(
                    sql,
                    new BatchPreparedStatementSetter() {
                        @Override
                        public void setValues(final PreparedStatement preparedStatement, final int i) throws SQLException {
                            final SchedulerConfigurationValue value = values.get(i);
                            preparedStatement.setLong(1, value.getSchedulerConfigurationid());
                            preparedStatement.setString(2, value.getType());
                            preparedStatement.setString(3, value.getValue());
                        }

                        @Override
                        public int getBatchSize() {
                            return values.size();
                        }
                    }
            );
        }
 
Example 14
Source Project: qconfig   Source File: ProfileDaoImpl.java    License: MIT License 6 votes vote down vote up
@Override
public void batchCreate(final String group, final List<String> profiles, final String operator) {
    jdbcTemplate.batchUpdate(CREATE_SQL, new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            String profile = profiles.get(i);
            ps.setString(1, group);
            ps.setString(2, profile);
            ps.setString(3, operator);
        }

        @Override
        public int getBatchSize() {
            return profiles.size();
        }
    });
}
 
Example 15
Source Project: poli   Source File: UserDao.java    License: MIT License 6 votes vote down vote up
public void insertUserAttributes(long userId, List<UserAttribute> userAttributes) {
    String sql = "INSERT INTO p_user_attribute(user_id, attr_key, attr_value) VALUES(?, ?, ?)";
    jt.batchUpdate(sql, new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setLong(1, userId);
            ps.setString(2, userAttributes.get(i).getAttrKey());
            ps.setString(3, userAttributes.get(i).getAttrValue());
        }

        @Override
        public int getBatchSize() {
            return userAttributes.size();
        }
    });
}
 
Example 16
public static int[] executeBatchUpdateWithNamedParameters(final ParsedSql parsedSql,
		final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) {
	if (batchArgs.length <= 0) {
		return new int[] {0};
	}
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]);
	return jdbcOperations.batchUpdate(
			sqlToUse,
			new BatchPreparedStatementSetter() {

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

				@Override
				public int getBatchSize() {
					return batchArgs.length;
				}
			});
}
 
Example 17
Source Project: lams   Source File: AbstractJdbcInsert.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Delegate method to execute the batch insert.
 */
private int[] executeBatchInternal(final List<List<Object>> batchValues) {
	if (logger.isDebugEnabled()) {
		logger.debug("Executing statement " + getInsertString() + " with batch of size: " + batchValues.size());
	}
	return getJdbcTemplate().batchUpdate(getInsertString(),
			new BatchPreparedStatementSetter() {
				@Override
				public void setValues(PreparedStatement ps, int i) throws SQLException {
					setParameterValues(ps, batchValues.get(i), getInsertTypes());
				}
				@Override
				public int getBatchSize() {
					return batchValues.size();
				}
			});
}
 
Example 18
Source Project: plumdo-work   Source File: JdbcClient.java    License: Apache License 2.0 6 votes vote down vote up
public int[] batchUpdate(String sql, final Object[] keys, final List<ObjectMap> entityList) {
    log.debug("批量操作,SQL语句:{}", sql);
    return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement preparedStatement, int i) throws SQLException {
            ObjectMap map = entityList.get(i);
            List<Object> params = new ArrayList<>();
            for (int j = 0; j < keys.length; j++) {
                Object value = map.get(keys[j]);
                preparedStatement.setObject(j + 1, value);
                params.add(value);
            }
            log.debug("批量操作,参数:{}", params);
        }

        @Override
        public int getBatchSize() {
            return entityList.size();
        }
    });
}
 
Example 19
Source Project: artemis   Source File: RouteRuleDao.java    License: Apache License 2.0 6 votes vote down vote up
protected void delete(final List<Long> ids) {
    ValueCheckers.notNullOrEmpty(ids, "ids");
    DataConfig.jdbcTemplate().batchUpdate("update service_route_rule set deleted = true where id = ?", new BatchPreparedStatementSetter() {
        @Override
        public int getBatchSize() {
            return ids.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int i) throws SQLException {
            final Long id = ids.get(i);
            if (id == null) {
                ps.setLong(1, 0L);
            } else {
                ps.setLong(1, id);
            }
        }
    });
}
 
Example 20
Source Project: artemis   Source File: RouteRuleDao.java    License: Apache License 2.0 6 votes vote down vote up
protected void insertOrUpdate(final List<RouteRuleModel> models) {
    checkInsertOrUpdateArgument(models);
    DataConfig.jdbcTemplate().batchUpdate("insert into service_route_rule (service_id, name, description, status, strategy) values (?,?,?,?,?)"
            + " on duplicate key update description=?, status=?, strategy=?, deleted=false", new BatchPreparedStatementSetter() {

        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            RouteRuleModel model = models.get(i);
            Object[] params = new Object[]{model.getServiceId(), model.getName(), model.getDescription(), model.getStatus(), model.getStrategy(),
            model.getDescription(), model.getStatus(), model.getStrategy()};

            for (int index= 0; index < params.length; index++) {
                ps.setObject(index + 1, params[index]);
            }
        }

        @Override
        public int getBatchSize() {
            return models.size();
        }
    });
}
 
Example 21
Source Project: artemis   Source File: RouteRuleDao.java    License: Apache License 2.0 6 votes vote down vote up
protected void insert(final List<RouteRuleModel> models) {
    checkInsertOrUpdateArgument(models);
    DataConfig.jdbcTemplate().batchUpdate("insert into service_route_rule (service_id, name, description, status, strategy) values (?,?,?,?,?)"
            + " on duplicate key update deleted=false", new BatchPreparedStatementSetter() {

        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            RouteRuleModel model = models.get(i);
            ps.setString(1, model.getServiceId());
            ps.setString(2, model.getName());
            ps.setString(3, model.getDescription());
            ps.setString(4, model.getStatus());
            ps.setString(5, model.getStrategy());
        }

        @Override
        public int getBatchSize() {
            return models.size();
        }
    });
}
 
Example 22
Source Project: artemis   Source File: ServiceInstanceDao.java    License: Apache License 2.0 6 votes vote down vote up
protected void delete(final List<Long> ids) {
    ValueCheckers.notNullOrEmpty(ids, "ids");
    DataConfig.jdbcTemplate().batchUpdate("delete from service_instance where id = ?", new BatchPreparedStatementSetter() {
        @Override
        public int getBatchSize() {
            return ids.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int i) throws SQLException {
            final Long id = ids.get(i);
            if (id == null) {
                ps.setLong(1, 0L);
            } else {
                ps.setLong(1, id);
            }
        }
    });
}
 
Example 23
Source Project: artemis   Source File: ServiceInstanceDao.java    License: Apache License 2.0 6 votes vote down vote up
protected void deleteByFilters(final List<ServiceInstanceModel> filters) {
    checkInsertOrUpdateArgument(filters);
    DataConfig.jdbcTemplate().batchUpdate("delete from service_instance where service_id = ? and instance_id=?", new BatchPreparedStatementSetter() {
        @Override
        public int getBatchSize() {
            return filters.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int i) throws SQLException {
            final ServiceInstanceModel filter = filters.get(i);
            ps.setString(1, filter.getServiceId());
            ps.setString(2, filter.getInstanceId());
        }
    });
}
 
Example 24
Source Project: artemis   Source File: ServiceInstanceDao.java    License: Apache License 2.0 6 votes vote down vote up
protected void insertOrUpdate(final List<ServiceInstanceModel> models) {
    checkInsertOrUpdateArgument(models);
    DataConfig.jdbcTemplate().batchUpdate("insert into service_instance (service_id, instance_id, ip, machine_name, metadata, port, protocol, region_id, zone_id, healthy_check_url, url, description, group_id) values (?,?,?,?,?,?,?,?,?,?,?,?,?) on duplicate key " +
                    "update  ip=?, machine_name=?, metadata=?, port=?, protocol=?, region_id=?, zone_id=?, healthy_check_url=?, url=?, description=?, group_id=?",
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    ServiceInstanceModel model = models.get(i);
                    Object[] params = new Object[] {model.getServiceId(), model.getInstanceId(),
                            model.getIp(), model.getMachineName(), model.getMetadata(), model.getPort(), model.getProtocol(),model.getRegionId(), model.getZoneId(), model.getHealthCheckUrl(), model.getUrl(), model.getDescription(),model.getGroupId(),
                            model.getIp(), model.getMachineName(), model.getMetadata(), model.getPort(), model.getProtocol(),model.getRegionId(), model.getZoneId(), model.getHealthCheckUrl(), model.getUrl(), model.getDescription(), model.getGroupId()};
                    for (int index = 0; index < params.length; index++) {
                        ps.setObject(index + 1, params[index]);
                    }
                }

                @Override
                public int getBatchSize() {
                    return models.size();
                }
            });
}
 
Example 25
Source Project: artemis   Source File: GroupTagLogDao.java    License: Apache License 2.0 6 votes vote down vote up
public void insert(final List<GroupTagLogModel> logs) {
    if (CollectionUtils.isEmpty(logs)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate(
            "insert into service_group_tag_log (group_id, operation, tag, value, operator_id, token, extensions) values (?,?,?,?,?,?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public int getBatchSize() {
                    return logs.size();
                }

                @Override
                public void setValues(final PreparedStatement ps, final int index) throws SQLException {
                    final GroupTagLogModel log = logs.get(index);
                    ps.setLong(1, log.getGroupId());
                    ps.setString(2, log.getOperation());
                    ps.setString(3, log.getTag());
                    ps.setString(4, log.getValue());
                    ps.setString(5, log.getOperatorId());
                    ps.setString(6, log.getToken());
                    ps.setString(7, log.getExtensions());
                }
            });
}
 
Example 26
Source Project: artemis   Source File: GroupOperationLogDao.java    License: Apache License 2.0 6 votes vote down vote up
public void insert(final List<GroupOperationLogModel> logs) {
    if (CollectionUtils.isEmpty(logs)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate(
            "insert into service_group_operation_log (group_id, operation, complete, operator_id, token, extensions, reason) values (?,?,?,?,?,?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public int getBatchSize() {
                    return logs.size();
                }

                @Override
                public void setValues(final PreparedStatement ps, final int index) throws SQLException {
                    final GroupOperationLogModel log = logs.get(index);
                    ps.setLong(1, log.getGroupId());
                    ps.setString(2, log.getOperation());
                    ps.setBoolean(3, log.isComplete());
                    ps.setString(4, log.getOperatorId());
                    ps.setString(5, log.getToken());
                    ps.setString(6, log.getExtensions());
                    ps.setString(7, log.getReason());
                }
            });
}
 
Example 27
Source Project: artemis   Source File: GroupDao.java    License: Apache License 2.0 6 votes vote down vote up
protected void delete(final List<Long> ids) {
    ValueCheckers.notNullOrEmpty(ids, "ids");
    DataConfig.jdbcTemplate().batchUpdate("update service_group set deleted = true where id = ?", new BatchPreparedStatementSetter() {
        @Override
        public int getBatchSize() {
            return ids.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int i) throws SQLException {
            final Long id = ids.get(i);
            if (id == null) {
                ps.setLong(1, 0L);
            } else {
                ps.setLong(1, id);
            }
        }
    });
}
 
Example 28
Source Project: artemis   Source File: GroupDao.java    License: Apache License 2.0 6 votes vote down vote up
protected void insertOrUpdate(final List<GroupModel> models) {
    checkInsertOrUpdateArgument(models);
    DataConfig.jdbcTemplate().batchUpdate("insert into service_group (service_id, region_id, zone_id, name, app_id, description,status) values (?,?,?,?,?,?,?)"
            + " on duplicate key update app_id=?, description=?, status=?, deleted=false", new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            GroupModel model = models.get(i);
            ps.setString(1, model.getServiceId());
            ps.setString(2, model.getRegionId());
            ps.setString(3, model.getZoneId());
            ps.setString(4, model.getName());
            ps.setString(5, model.getAppId());
            ps.setString(6, model.getDescription());
            ps.setString(7, model.getStatus());
            ps.setString(8, model.getAppId());
            ps.setString(9, model.getDescription());
            ps.setString(10, model.getStatus());
        }

        @Override
        public int getBatchSize() {
            return models.size();
        }
    });
}
 
Example 29
Source Project: artemis   Source File: GroupDao.java    License: Apache License 2.0 6 votes vote down vote up
protected void insert(final List<GroupModel> models) {
    checkInsertOrUpdateArgument(models);
    DataConfig.jdbcTemplate().batchUpdate("insert into service_group (service_id, region_id, zone_id, name, app_id, description,status) values (?,?,?,?,?,?,?)"
            + " on duplicate key update deleted=false", new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            GroupModel model = models.get(i);
            ps.setString(1, model.getServiceId());
            ps.setString(2, model.getRegionId());
            ps.setString(3, model.getZoneId());
            ps.setString(4, model.getName());
            ps.setString(5, model.getAppId());
            ps.setString(6, model.getDescription());
            ps.setString(7, model.getStatus());
        }

        @Override
        public int getBatchSize() {
            return models.size();
        }
    });
}
 
Example 30
Source Project: artemis   Source File: RouteRuleLogDao.java    License: Apache License 2.0 6 votes vote down vote up
public void insert(final List<RouteRuleLogModel> logs) {
    if (CollectionUtils.isEmpty(logs)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate(
            "insert into service_route_rule_log (service_id, name, status, operation, operator_id, token, extensions, reason) values (?,?,?,?,?,?,?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public int getBatchSize() {
                    return logs.size();
                }

                @Override
                public void setValues(final PreparedStatement ps, final int index) throws SQLException {
                    final RouteRuleLogModel log = logs.get(index);
                    ps.setString(1, log.getServiceId());
                    ps.setString(2, log.getName());
                    ps.setString(3, log.getStatus());
                    ps.setString(4, log.getOperation());
                    ps.setString(5, log.getOperatorId());
                    ps.setString(6, log.getToken());
                    ps.setString(7, log.getExtensions());
                    ps.setString(8, log.getReason());
                }
            });
}