public void batchUpdateAcl(List<Auth> authBeans) {
final List<Object[]> deleteParams = new ArrayList<Object[]>();
final List<Object[]> insertParams = new ArrayList<Object[]>();
for (Auth auth : authBeans) {
String resourceID = auth.getResourceID();
String targetID = auth.getTargetID();
String targetType = auth.getType() == null ? AuthTargetType.ROLE.name() : auth.getType().name();
int acl = AuthEnum.formateAclCode(auth.getAcls());
deleteParams.add(new Object[] { targetID, resourceID, targetType });
insertParams.add(new Object[] { targetID, resourceID, targetType, acl });
}
String sql = "DELETE FROM " + TABLE_NAME + " WHERE target=? AND resource=? and targetType=?";
// 批量删除修改后的调用方式
jdbc.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] args = deleteParams.get(i);
ps.setString(1, (String) args[0]);
ps.setString(2, (String) args[1]);
ps.setString(3, (String) args[2]);
}
@Override
public int getBatchSize() {
return 0;
}
});
sql = "INSERT INTO " + TABLE_NAME + " (target, resource, targetType, acl) VALUES(?,?,?,?)";
// 批量插入修改后的调用方式
jdbc.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] args = insertParams.get(i);
ps.setString(1, (String) args[0]);
ps.setString(2, (String) args[1]);
ps.setString(3, (String) args[2]);
ps.setString(4, (String) args[3]);
}
@Override
public int getBatchSize() {
return 0;
}
});
}