org.springframework.jdbc.core.BatchPreparedStatementSetter Java Examples

The following examples show how to use org.springframework.jdbc.core.BatchPreparedStatementSetter. 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 File: GroupOperationDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
protected void delete(final List<GroupOperationModel> groupOperations) {
    ValueCheckers.notNullOrEmpty(groupOperations, "group operations");
    DataConfig.jdbcTemplate().batchUpdate("delete from service_group_operation where group_id =? and operation = ?",
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    GroupOperationModel groupOperation = groupOperations.get(i);
                    ps.setLong(1, groupOperation.getGroupId());
                    ps.setString(2, groupOperation.getOperation());
                }

                @Override
                public int getBatchSize() {
                    return groupOperations.size();
                }
            });
}
 
Example #2
Source File: RouteRuleGroupDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
protected void release(final List<RouteRuleGroupModel> models) {
    checkReleaseArgument(models);
    DataConfig.jdbcTemplate().batchUpdate("update service_route_rule_group set weight = unreleased_weight where route_rule_id=? and group_id=?",
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    RouteRuleGroupModel model = models.get(i);
                    ps.setLong(1, model.getRouteRuleId());
                    ps.setLong(2, model.getGroupId());
                }

                @Override
                public int getBatchSize() {
                    return models.size();
                }
            });
}
 
Example #3
Source File: JdbcClient.java    From plumdo-work with 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 #4
Source File: RouteRuleGroupDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
protected void insertOrUpdate(final List<RouteRuleGroupModel> models) {
    checkInsertOrUpdateArgument(models);
    DataConfig.jdbcTemplate().batchUpdate("insert into service_route_rule_group (route_rule_id, group_id, unreleased_weight) values (?,?,?)"
            + " on duplicate key update unreleased_weight=?", new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            RouteRuleGroupModel model = models.get(i);
            ps.setLong(1, model.getRouteRuleId());
            ps.setLong(2, model.getGroupId());
            Integer unreleasedWeight = model.getUnreleasedWeight();
            if (unreleasedWeight == null) {
                ps.setString(3, null);
                ps.setString(4, null);
            } else {
                ps.setInt(3, unreleasedWeight);
                ps.setInt(4, unreleasedWeight);
            }
        }

        @Override
        public int getBatchSize() {
            return models.size();
        }
    });
}
 
Example #5
Source File: RouteRuleGroupDao.java    From artemis with 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_route_rule_group 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 #6
Source File: ServiceInstanceLogDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
protected void insert(final List<ServiceInstanceLogModel> logs) {
    if (CollectionUtils.isEmpty(logs)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate(
            "insert into service_instance_log (service_id, instance_id, ip, machine_name, metadata, port, protocol, region_id, zone_id, healthy_check_url, url, group_id, operation, operator_id, token) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public int getBatchSize() {
                    return logs.size();
                }

                @Override
                public void setValues(final PreparedStatement ps, final int index) throws SQLException {
                    final ServiceInstanceLogModel log = logs.get(index);
                    Object[] params = new Object[] {log.getServiceId(), log.getInstanceId(),
                            log.getIp(), log.getMachineName(), log.getMetadata(), log.getPort(), log.getProtocol(), log.getRegionId(), log.getZoneId(), log.getHealthCheckUrl(), log.getUrl(), log.getGroupId(),
                            log.getOperation(), log.getOperatorId(), log.getToken()};
                    for (int i = 0; i < params.length; i++) {
                        ps.setObject(i + 1, params[i]);
                    }
                }
            });
}
 
Example #7
Source File: RouteRuleGroupDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
protected void insert(final List<RouteRuleGroupModel> models) {
    checkInsertOrUpdateArgument(models);
    DataConfig.jdbcTemplate().batchUpdate("insert ignore into service_route_rule_group (route_rule_id, group_id, unreleased_weight) values (?,?,?)", new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            RouteRuleGroupModel model = models.get(i);
            ps.setLong(1, model.getRouteRuleId());
            ps.setLong(2, model.getGroupId());
            Integer unreleasedWeight = model.getUnreleasedWeight();
            if (unreleasedWeight == null) {
                ps.setString(3, null);
            } else {
                ps.setInt(3, unreleasedWeight);
            }
        }

        @Override
        public int getBatchSize() {
            return models.size();
        }
    });
}
 
Example #8
Source File: GroupInstanceDao.java    From artemis with 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_group_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 #9
Source File: GroupInstanceDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
protected void deleteByFilters(final List<GroupInstanceModel> filters){
    checkInsertOrUpdateArgument(filters);
    DataConfig.jdbcTemplate().batchUpdate("delete from service_group_instance where group_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 GroupInstanceModel filter = filters.get(i);
            ps.setLong(1, filter.getGroupId());
            ps.setString(2, filter.getInstanceId());
        }
    });
}
 
Example #10
Source File: GroupInstanceDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
protected void insert(final List<GroupInstanceModel> models) {
    checkInsertOrUpdateArgument(models);
    DataConfig.jdbcTemplate().batchUpdate("insert ignore into service_group_instance (group_id, instance_id) values (?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    GroupInstanceModel model = models.get(i);
                    ps.setLong(1, model.getGroupId());
                    ps.setString(2, model.getInstanceId());
                }

                @Override
                public int getBatchSize() {
                    return models.size();
                }
            });
}
 
Example #11
Source File: InstanceDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
public void delete(final Long... ids) {
    if ((ids == null) || (ids.length == 0)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate("delete from instance where id = ?", new BatchPreparedStatementSetter() {
        @Override
        public int getBatchSize() {
            return ids.length;
        }

        @Override
        public void setValues(final PreparedStatement ps, final int i) throws SQLException {
            final Long id = ids[i];
            if (id == null) {
                ps.setLong(1, 0L);
            } else {
                ps.setLong(1, id);
            }
        }
    });
}
 
Example #12
Source File: ServerLogDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
public void insert(final List<ServerLogModel> logs) {
    if (CollectionUtils.isEmpty(logs)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate(
            "insert into server_log (region_id, server_id, operation, operator_id, token, extensions, complete) values (?,?,?,?,?,?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public int getBatchSize() {
                    return logs.size();
                }

                @Override
                public void setValues(final PreparedStatement ps, final int index) throws SQLException {
                    final ServerLogModel log = logs.get(index);
                    ps.setString(1, log.getRegionId());
                    ps.setString(2, log.getServerId());
                    ps.setString(3, log.getOperation());
                    ps.setString(4, log.getOperatorId());
                    ps.setString(5, log.getToken());
                    ps.setString(6, log.getExtensions());
                    ps.setBoolean(7, log.isComplete());
                }
            });
}
 
Example #13
Source File: InstanceDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
public void destroyServers(final List<ServerKey> serverKeys) {
    if (CollectionUtils.isEmpty(serverKeys)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate("delete from instance where region_id=? and instance_id=?",
            new BatchPreparedStatementSetter() {
                @Override
                public int getBatchSize() {
                    return serverKeys.size();
                }

                @Override
                public void setValues(final PreparedStatement ps, final int index) throws SQLException {
                    ServerKey serverKey = serverKeys.get(index);
                    ps.setString(1, serverKey.getRegionId());
                    ps.setString(2, serverKey.getServerId());
                }
            });
}
 
Example #14
Source File: InstanceDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
public void insert(final List<InstanceModel> instances) {
    if (CollectionUtils.isEmpty(instances)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate("insert into instance (region_id, service_id, instance_id, operation, operator_id, token) values (?,?,?,?,?,?)"
            + " on duplicate key update operator_id=?, token=?", new BatchPreparedStatementSetter() {
                @Override
                public int getBatchSize() {
                    return instances.size();
                }

                @Override
                public void setValues(final PreparedStatement ps, final int index) throws SQLException {
                    final InstanceModel instance = instances.get(index);
                    ps.setString(1, instance.getRegionId());
                    ps.setString(2, instance.getServiceId());
                    ps.setString(3, instance.getInstanceId());
                    ps.setString(4, instance.getOperation());
                    ps.setString(5, instance.getOperatorId());
                    ps.setString(6, instance.getToken());
                    ps.setString(7, instance.getOperatorId());
                    ps.setString(8, instance.getToken());
                }
            });
}
 
Example #15
Source File: GroupInstanceLogDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
protected void insert(final List<GroupInstanceLogModel> logs) {
    if (CollectionUtils.isEmpty(logs)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate(
            "insert into service_group_instance_log (group_id, instance_id, operation, operator_id, token, reason) values (?,?,?,?,?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public int getBatchSize() {
                    return logs.size();
                }

                @Override
                public void setValues(final PreparedStatement ps, final int index) throws SQLException {
                    final GroupInstanceLogModel log = logs.get(index);
                    ps.setLong(1, log.getGroupId());
                    ps.setString(2, log.getInstanceId());
                    ps.setString(3, log.getOperation());
                    ps.setString(4, log.getOperatorId());
                    ps.setString(5, log.getToken());
                    ps.setString(6, log.getReason());
                }
            });
}
 
Example #16
Source File: GroupOperationDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
protected void insertOrUpdate(final List<GroupOperationModel> models) {
    checkInsertOrUpdateArgument(models);
    DataConfig.jdbcTemplate().batchUpdate("insert ignore into service_group_operation (group_id, operation) values (?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    GroupOperationModel groupOperation = models.get(i);
                    ps.setLong(1, groupOperation.getGroupId());
                    ps.setString(2, groupOperation.getOperation());
                }

                @Override
                public int getBatchSize() {
                    return models.size();
                }
            });
}
 
Example #17
Source File: GroupTagDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
public void insertOrUpdate(final List<GroupTagModel> models) {
    checkInsertOrUpdateArgument(models);
    DataConfig.jdbcTemplate().batchUpdate("insert into service_group_tag (group_id, tag, value) values (?,?,?) on duplicate key update value = ?",
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    GroupTagModel model = models.get(i);
                    ps.setLong(1, model.getGroupId());
                    ps.setString(2, model.getTag());
                    ps.setString(3, model.getValue());
                    ps.setString(4, model.getValue());
                }

                @Override
                public int getBatchSize() {
                    return models.size();
                }
            });
}
 
Example #18
Source File: RouteRuleLogDao.java    From artemis with 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());
                }
            });
}
 
Example #19
Source File: GroupDao.java    From artemis with 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 #20
Source File: GroupDao.java    From artemis with 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 #21
Source File: GroupDao.java    From artemis with 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 #22
Source File: InstanceLogDao.java    From artemis with Apache License 2.0 6 votes vote down vote up
public void insert(final List<InstanceLogModel> logs) {
    if (CollectionUtils.isEmpty(logs)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate(
            "insert into instance_log (region_id, service_id, instance_id, operation, operator_id, token, extensions, complete) values (?,?,?,?,?,?,?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public int getBatchSize() {
                    return logs.size();
                }

                @Override
                public void setValues(final PreparedStatement ps, final int index) throws SQLException {
                    final InstanceLogModel log = logs.get(index);
                    ps.setString(1, log.getRegionId());
                    ps.setString(2, log.getServiceId());
                    ps.setString(3, log.getInstanceId());
                    ps.setString(4, log.getOperation());
                    ps.setString(5, log.getOperatorId());
                    ps.setString(6, log.getToken());
                    ps.setString(7, log.getExtensions());
                    ps.setBoolean(8, log.isComplete());
                }
            });
}
 
Example #23
Source File: GroupOperationLogDao.java    From artemis with 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 #24
Source File: GroupTagLogDao.java    From artemis with 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 #25
Source File: ServiceInstanceDao.java    From artemis with 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 #26
Source File: ServiceInstanceDao.java    From artemis with 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 #27
Source File: ServiceInstanceDao.java    From artemis with 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 #28
Source File: RouteRuleDao.java    From artemis with 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 #29
Source File: RouteRuleDao.java    From artemis with 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 #30
Source File: RouteRuleDao.java    From artemis with 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);
            }
        }
    });
}