use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException 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());
}
use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException in project metacat by Netflix.
the class MySqlTagService method remove.
private void remove(final QualifiedName name, final Set<String> tags, final boolean updateUserMetadata) {
try {
final Connection conn = getDataSource().getConnection();
try {
remove(conn, name, tags, updateUserMetadata);
conn.commit();
} catch (SQLException e) {
conn.rollback();
throw e;
} finally {
conn.close();
}
} catch (SQLException e) {
final String message = String.format("Failed to remove tags for name %s", name);
log.error(message, e);
throw new UserMetadataServiceException(message, e);
}
}
use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException 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 com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException 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 com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException in project metacat by Netflix.
the class MySqlLookupService method setValues.
/**
* Saves the lookup value.
*
* @param name lookup name
* @param values multiple values
* @return returns the lookup with the given name.
*/
@Override
public Lookup setValues(final String name, final Set<String> values) {
Lookup lookup;
try {
final Connection conn = getDataSource().getConnection();
try {
lookup = findOrCreateLookupByName(name, conn);
final Set<String> inserts;
Set<String> deletes = Sets.newHashSet();
final Set<String> lookupValues = lookup.getValues();
if (lookupValues == null || lookupValues.isEmpty()) {
inserts = values;
} else {
inserts = Sets.difference(values, lookupValues).immutableCopy();
deletes = Sets.difference(lookupValues, values).immutableCopy();
}
lookup.setValues(values);
if (!inserts.isEmpty()) {
insertLookupValues(lookup.getId(), inserts, conn);
}
if (!deletes.isEmpty()) {
deleteLookupValues(lookup.getId(), deletes, conn);
}
conn.commit();
} catch (SQLException e) {
conn.rollback();
throw e;
} finally {
conn.close();
}
} catch (SQLException e) {
final String message = String.format("Failed to set the lookup values for name %s", name);
log.error(message, e);
throw new UserMetadataServiceException(message, e);
}
return lookup;
}
Aggregations