use of org.apache.commons.dbutils.handlers.ColumnListHandler in project metacat by Netflix.
the class MysqlUserMetadataService method _softDeleteDataMetadatas.
@SuppressWarnings("checkstyle:methodname")
private Void _softDeleteDataMetadatas(final Connection conn, final String userId, @Nullable final List<String> uris) throws SQLException {
if (uris != null && !uris.isEmpty()) {
final List<String> paramVariables = uris.stream().map(s -> "?").collect(Collectors.toList());
final String[] aUris = uris.stream().toArray(String[]::new);
final String paramString = Joiner.on(",").skipNulls().join(paramVariables);
final ColumnListHandler<Long> handler = new ColumnListHandler<>("id");
final List<Long> ids = new QueryRunner().query(conn, String.format(SQL.GET_DATA_METADATA_IDS, paramString), handler, (Object[]) aUris);
if (!ids.isEmpty()) {
final List<String> idParamVariables = ids.stream().map(s -> "?").collect(Collectors.toList());
final Long[] aIds = ids.stream().toArray(Long[]::new);
final String idParamString = Joiner.on(",").skipNulls().join(idParamVariables);
final List<Long> dupIds = new QueryRunner().query(conn, String.format(SQL.GET_DATA_METADATA_DELETE_BY_IDS, idParamString), handler, (Object[]) aIds);
if (!dupIds.isEmpty()) {
ids.removeAll(dupIds);
}
final List<Object[]> deleteDataMetadatas = Lists.newArrayList();
ids.forEach(id -> deleteDataMetadatas.add(new Object[] { id, userId }));
new QueryRunner().batch(conn, SQL.SOFT_DELETE_DATA_METADATA, deleteDataMetadatas.toArray(new Object[deleteDataMetadatas.size()][2]));
}
}
return null;
}
Aggregations