use of org.apache.commons.dbutils.handlers.ColumnListHandler in project metacat by Netflix.
the class MysqlUserMetadataService method getDescendantDataUris.
@Override
public List<String> getDescendantDataUris(@Nonnull final String uri) {
List<String> result;
final Connection connection = DBUtil.getReadConnection(poolingDataSource);
try {
final ColumnListHandler<String> handler = new ColumnListHandler<>("uri");
result = new QueryRunner().query(connection, SQL.GET_DESCENDANT_DATA_URIS, handler, uri + "/%");
} catch (SQLException e) {
log.error("Sql exception", e);
throw new UserMetadataServiceException(String.format("Failed to get descendant uris for %s", uri), e);
} finally {
DBUtil.closeReadConnection(connection);
}
return result;
}
use of org.apache.commons.dbutils.handlers.ColumnListHandler in project metacat by Netflix.
the class MysqlUserMetadataService method _deleteDataMetadatas.
@SuppressWarnings("checkstyle:methodname")
private Void _deleteDataMetadatas(final Connection conn, @Nullable final List<String> uris, final boolean removeDataMetadata) 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);
new QueryRunner().update(conn, String.format(SQL.DELETE_DATA_METADATA_DELETE, idParamString), (Object[]) aIds);
if (removeDataMetadata) {
new QueryRunner().update(conn, String.format(SQL.DELETE_DATA_METADATA, idParamString), (Object[]) aIds);
}
}
}
return null;
}
use of org.apache.commons.dbutils.handlers.ColumnListHandler in project metacat by Netflix.
the class MysqlUserMetadataService method getDescendantDefinitionNames.
@Override
public List<QualifiedName> getDescendantDefinitionNames(@Nonnull final QualifiedName name) {
List<String> result;
final Connection connection = DBUtil.getReadConnection(poolingDataSource);
try {
final ColumnListHandler<String> handler = new ColumnListHandler<>("name");
result = new QueryRunner().query(connection, SQL.GET_DESCENDANT_DEFINITION_NAMES, handler, name.toString() + "/%");
} catch (SQLException e) {
log.error("Sql exception", e);
throw new UserMetadataServiceException(String.format("Failed to get descendant names for %s", name), e);
} finally {
DBUtil.closeReadConnection(connection);
}
return result.stream().map(QualifiedName::fromString).collect(Collectors.toList());
}
use of org.apache.commons.dbutils.handlers.ColumnListHandler in project metacat by Netflix.
the class MysqlUserMetadataService method getDeletedDataMetadataUris.
@Override
public List<String> getDeletedDataMetadataUris(final Date deletedPriorTo, final Integer offset, final Integer limit) {
List<String> result;
final Connection connection = DBUtil.getReadConnection(poolingDataSource);
try {
final ColumnListHandler<String> handler = new ColumnListHandler<>("uri");
result = new QueryRunner().query(connection, String.format(SQL.GET_DELETED_DATA_METADATA_URI, offset, limit), handler, deletedPriorTo);
} catch (SQLException e) {
log.error("Sql exception", e);
throw new UserMetadataServiceException(String.format("Failed to get deleted data metadata uris deleted prior to %s", deletedPriorTo), e);
} finally {
DBUtil.closeReadConnection(connection);
}
return result;
}
use of org.apache.commons.dbutils.handlers.ColumnListHandler in project metacat by Netflix.
the class MySqlTagService method list.
/**
* Returns the list of <code>QualifiedName</code> of items that are tagged by the
* given <code>includeTags</code> and do not contain the given <code>excludeTags</code>.
*
* @param includeTags include items that contain tags
* @param excludeTags include items that do not contain tags
* @param sourceName catalog/source name
* @param databaseName database name
* @param tableName table name
* @return list of qualified names of the items
*/
@Override
public List<QualifiedName> list(final Set<String> includeTags, final Set<String> excludeTags, final String sourceName, final String databaseName, final String tableName) {
Set<String> includedNames = Sets.newHashSet();
final Set<String> excludedNames = Sets.newHashSet();
final Connection connection = DBUtil.getReadConnection(getDataSource());
try {
final QueryRunner runner = new QueryRunner();
final String wildCardName = QualifiedName.toWildCardString(sourceName, databaseName, tableName);
//Includes
String query = String.format(QUERY_SEARCH, "in ('" + Joiner.on("','").skipNulls().join(includeTags) + "')");
final Object[] params = { includeTags.size() == 0 ? 1 : 0, wildCardName == null ? 1 : 0, wildCardName };
includedNames.addAll(runner.query(connection, query, new ColumnListHandler<>("name"), params));
if (!excludeTags.isEmpty()) {
//Excludes
query = String.format(QUERY_SEARCH, "in ('" + Joiner.on("','").skipNulls().join(excludeTags) + "')");
final Object[] eParams = { excludeTags.size() == 0 ? 1 : 0, wildCardName == null ? 1 : 0, wildCardName };
excludedNames.addAll(runner.query(connection, query, new ColumnListHandler<>("name"), eParams));
}
} catch (SQLException e) {
final String message = String.format("Failed getting the list of qualified names for tags %s", includeTags);
log.error(message, e);
throw new UserMetadataServiceException(message, e);
} finally {
DBUtil.closeReadConnection(connection);
}
if (!excludeTags.isEmpty()) {
includedNames = Sets.difference(includedNames, excludedNames);
}
return includedNames.stream().map(s -> QualifiedName.fromString(s, false)).collect(Collectors.toList());
}
Aggregations