Search in sources :

Example 1 with UserMetadataServiceException

use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException 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;
}
Also used : UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ColumnListHandler(org.apache.commons.dbutils.handlers.ColumnListHandler) QueryRunner(org.apache.commons.dbutils.QueryRunner)

Example 2 with UserMetadataServiceException

use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException 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());
}
Also used : UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ColumnListHandler(org.apache.commons.dbutils.handlers.ColumnListHandler) QueryRunner(org.apache.commons.dbutils.QueryRunner)

Example 3 with UserMetadataServiceException

use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException 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;
}
Also used : UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ColumnListHandler(org.apache.commons.dbutils.handlers.ColumnListHandler) QueryRunner(org.apache.commons.dbutils.QueryRunner)

Example 4 with UserMetadataServiceException

use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException in project metacat by Netflix.

the class MysqlUserMetadataService method deleteDataMetadatasWithBatch.

private void deleteDataMetadatasWithBatch(final List<String> uris, final boolean removeDataMetadata) {
    try {
        final Connection conn = poolingDataSource.getConnection();
        try {
            final List<List<String>> subLists = Lists.partition(uris, config.getUserMetadataMaxInClauseItems());
            for (List<String> subUris : subLists) {
                _deleteDataMetadatas(conn, subUris, removeDataMetadata);
            }
            conn.commit();
        } catch (SQLException e) {
            conn.rollback();
            throw e;
        } finally {
            conn.close();
        }
    } catch (SQLException e) {
        log.error("Sql exception", e);
        throw new UserMetadataServiceException(String.format("Failed deleting the data metadata for %s", uris), e);
    }
}
Also used : UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) List(java.util.List)

Example 5 with UserMetadataServiceException

use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException in project metacat by Netflix.

the class MySqlTagService method delete.

@Override
public Void delete(final QualifiedName name, final boolean updateUserMetadata) {
    try {
        final Connection conn = getDataSource().getConnection();
        try {
            new QueryRunner().update(conn, SQL_DELETE_TAG_ITEM_TAGS_BY_NAME, name.toString());
            new QueryRunner().update(conn, SQL_DELETE_TAG_ITEM, name.toString());
            if (updateUserMetadata) {
                // Set the tags in user metadata
                final Map<String, Set<String>> data = Maps.newHashMap();
                data.put(NAME_TAGS, Sets.newHashSet());
                userMetadataService.saveDefinitionMetadata(name, "admin", Optional.of(metacatJson.toJsonObject(data)), true);
            }
            conn.commit();
        } catch (SQLException e) {
            conn.rollback();
            throw e;
        } finally {
            conn.close();
        }
    } catch (SQLException e) {
        final String message = String.format("Failed to delete all tags for name %s", name);
        log.error(message, e);
        throw new UserMetadataServiceException(message, e);
    }
    return null;
}
Also used : UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) Set(java.util.Set) SQLException(java.sql.SQLException) Connection(java.sql.Connection) QueryRunner(org.apache.commons.dbutils.QueryRunner)

Aggregations

UserMetadataServiceException (com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException)24 Connection (java.sql.Connection)23 SQLException (java.sql.SQLException)23 QueryRunner (org.apache.commons.dbutils.QueryRunner)15 List (java.util.List)9 QualifiedName (com.netflix.metacat.common.QualifiedName)8 Set (java.util.Set)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Joiner (com.google.common.base.Joiner)5 Preconditions (com.google.common.base.Preconditions)5 Maps (com.google.common.collect.Maps)5 HasDataMetadata (com.netflix.metacat.common.dto.HasDataMetadata)5 HasDefinitionMetadata (com.netflix.metacat.common.dto.HasDefinitionMetadata)5 HasMetadata (com.netflix.metacat.common.dto.HasMetadata)5 MetacatJson (com.netflix.metacat.common.json.MetacatJson)5 MetacatJsonException (com.netflix.metacat.common.json.MetacatJsonException)5 Config (com.netflix.metacat.common.server.properties.Config)5 DBUtil (com.netflix.metacat.common.server.util.DBUtil)5 DataSourceManager (com.netflix.metacat.common.server.util.DataSourceManager)5 PreparedStatement (java.sql.PreparedStatement)5