use of org.apache.commons.dbutils.QueryRunner in project metacat by Netflix.
the class MySqlTagService method rename.
@Override
public Void rename(final QualifiedName name, final String newTableName) {
try {
final Connection conn = getDataSource().getConnection();
try {
final QualifiedName newName = QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), newTableName);
new QueryRunner().update(conn, SQL_UPDATE_TAG_ITEM, newName.toString(), name.toString());
conn.commit();
} catch (Exception e) {
conn.rollback();
throw e;
} finally {
conn.close();
}
} catch (SQLException e) {
final String message = String.format("Failed to rename item name %s", name);
log.error(message, e);
throw new UserMetadataServiceException(message, e);
}
return null;
}
use of org.apache.commons.dbutils.QueryRunner in project metacat by Netflix.
the class MySqlTagService method search.
/**
* Returns the list of <code>QualifiedName</code> of items that have tags containing the given tag text.
*
* @param tag partial text of a tag
* @param sourceName source/catalog name
* @param databaseName database name
* @param tableName table name
* @return list of qualified names of the items
*/
@Override
public List<QualifiedName> search(final String tag, final String sourceName, final String databaseName, final String tableName) {
final Connection connection = DBUtil.getReadConnection(getDataSource());
try {
final String wildCardName = QualifiedName.toWildCardString(sourceName, databaseName, tableName);
//Includes
final String query = String.format(QUERY_SEARCH, "like ?");
final Object[] params = { tag == null ? 1 : 0, tag + "%", wildCardName == null ? 1 : 0, wildCardName };
return new QueryRunner().query(connection, query, new ColumnListHandler<>("name"), params);
} catch (SQLException e) {
final String message = String.format("Failed getting the list of qualified names for tag %s", tag);
log.error(message, e);
throw new UserMetadataServiceException(message, e);
} finally {
DBUtil.closeReadConnection(connection);
}
}
use of org.apache.commons.dbutils.QueryRunner in project metacat by Netflix.
the class MySqlTagService method remove.
private void remove(final Connection conn, final QualifiedName name, final Set<String> tags, final boolean updateUserMetadata) throws SQLException {
new QueryRunner().update(conn, String.format(SQL_DELETE_TAG_ITEM_TAGS_BY_NAME_TAGS, "'" + Joiner.on("','").skipNulls().join(tags) + "'"), name.toString());
if (updateUserMetadata) {
final TagItem tagItem = get(name);
tagItem.getValues().removeAll(tags);
final Map<String, Set<String>> data = Maps.newHashMap();
data.put(NAME_TAGS, tagItem.getValues());
userMetadataService.saveDefinitionMetadata(name, "admin", Optional.of(metacatJson.toJsonObject(data)), true);
}
}
use of org.apache.commons.dbutils.QueryRunner in project metacat by Netflix.
the class MySqlLookupService method insertLookupValues.
private void insertLookupValues(final Long id, final Set<String> inserts, final Connection conn) throws SQLException {
final Object[][] params = new Object[inserts.size()][];
final Iterator<String> iter = inserts.iterator();
int index = 0;
while (iter.hasNext()) {
params[index++] = ImmutableList.of(id, iter.next()).toArray();
}
new QueryRunner().batch(conn, SQL_INSERT_LOOKUP_VALUES, params);
}
use of org.apache.commons.dbutils.QueryRunner in project metacat by Netflix.
the class MySqlLookupService method findOrCreateLookupByName.
private Lookup findOrCreateLookupByName(final String name, final Connection conn) throws SQLException {
Lookup lookup = get(name);
if (lookup == null) {
final Object[] params = { name, STRING_TYPE, config.getLookupServiceUserAdmin(), config.getLookupServiceUserAdmin() };
final Long lookupId = new QueryRunner().insert(conn, SQL_INSERT_LOOKUP, new ScalarHandler<>(1), params);
lookup = new Lookup();
lookup.setName(name);
lookup.setId(lookupId);
}
return lookup;
}
Aggregations