Search in sources :

Example 6 with TapException

use of cascading.tap.TapException in project SpyGlass by ParallelAI.

the class JDBCTap method executeUpdate.

/**
     * Method executeUpdate allows for ad-hoc update statements to be sent to the remote RDBMS. The number of
     * rows updated will be returned, if applicable.
     *
     * @param updateString of type String
     * @return int
     */
public int executeUpdate(String updateString) {
    Connection connection = null;
    int result;
    try {
        connection = createConnection();
        try {
            LOG.info("executing update: {}", updateString);
            Statement statement = connection.createStatement();
            result = statement.executeUpdate(updateString);
            connection.commit();
            statement.close();
        } catch (SQLException exception) {
            throw new TapException("unable to execute update statement: " + updateString, exception);
        }
    } finally {
        try {
            if (connection != null)
                connection.close();
        } catch (SQLException exception) {
            // ignore
            LOG.warn("ignoring connection close exception", exception);
        }
    }
    return result;
}
Also used : TapException(cascading.tap.TapException)

Example 7 with TapException

use of cascading.tap.TapException in project SpyGlass by ParallelAI.

the class JDBCTap method executeQuery.

/**
     * Method executeQuery allows for ad-hoc queries to be sent to the remove RDBMS. A value
     * of -1 for returnResults will return a List of all results from the query, a value of 0 will return an empty List.
     *
     * @param queryString   of type String
     * @param returnResults of type int
     * @return List
     */
public List<Object[]> executeQuery(String queryString, int returnResults) {
    Connection connection = null;
    List<Object[]> result = Collections.emptyList();
    try {
        connection = createConnection();
        try {
            LOG.info("executing query: {}", queryString);
            Statement statement = connection.createStatement();
            // we don't care about results
            ResultSet resultSet = statement.executeQuery(queryString);
            if (returnResults != 0)
                result = copyResultSet(resultSet, returnResults == -1 ? Integer.MAX_VALUE : returnResults);
            connection.commit();
            statement.close();
        } catch (SQLException exception) {
            throw new TapException("unable to execute query statement: " + queryString, exception);
        }
    } finally {
        try {
            if (connection != null)
                connection.close();
        } catch (SQLException exception) {
            // ignore
            LOG.warn("ignoring connection close exception", exception);
        }
    }
    return result;
}
Also used : TapException(cascading.tap.TapException)

Example 8 with TapException

use of cascading.tap.TapException in project SpyGlass by ParallelAI.

the class JDBCTapCollector method close.

@Override
public void close() {
    try {
        LOG.info("closing tap collector for: {}", tap);
        writer.close(reporter);
    } catch (IOException exception) {
        LOG.warn("exception closing: {}", exception);
        throw new TapException("exception closing JDBCTapCollector", exception);
    } finally {
        super.close();
    }
}
Also used : TapException(cascading.tap.TapException) IOException(java.io.IOException)

Aggregations

TapException (cascading.tap.TapException)8 IOException (java.io.IOException)3 Credentials (org.apache.hadoop.security.Credentials)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 Token (org.apache.hadoop.security.token.Token)1