Example usage for org.apache.mahout.common IOUtils quietClose

List of usage examples for org.apache.mahout.common IOUtils quietClose

Introduction

In this page you can find the example usage for org.apache.mahout.common IOUtils quietClose.

Prototype

public static void quietClose(ResultSet resultSet, Statement statement, Connection connection) 

Source Link

Document

Closes a ResultSet , Statement and Connection (if not null) and logs (but does not rethrow) any resulting SQLException .

Usage

From source file:edu.uci.ics.sourcerer.ml.db.AbstractJDBCUserSimilarity.java

License:Open Source License

@Override
public double userSimilarity(long userID1, long userID2) throws TasteException {

    if (userID1 == userID2) {
        return 1.0;
    }/*from w  w  w.ja v  a2 s  . com*/
    // Order as smaller - larger
    if (userID1 > userID2) {
        long temp = userID1;
        userID1 = userID2;
        userID2 = temp;
    }

    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = dataSource.getConnection();
        stmt = conn.prepareStatement(getUserUserSimilaritySQL, ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_READ_ONLY);
        stmt.setFetchDirection(ResultSet.FETCH_FORWARD);
        stmt.setFetchSize(getFetchSize());
        stmt.setLong(1, userID1);
        stmt.setLong(2, userID2);

        log.debug("Executing SQL query: {}", getUserUserSimilaritySQL);
        rs = stmt.executeQuery();

        if (rs.next()) {
            return rs.getDouble(1);
        } else {
            throw new NoSuchItemException();
        }

    } catch (SQLException sqle) {
        log.warn("Exception while retrieving user", sqle);
        throw new TasteException(sqle);
    } finally {
        IOUtils.quietClose(rs, stmt, conn);
    }
}

From source file:org.gpfvic.mahout.cf.taste.impl.common.jdbc.EachRowIterator.java

License:Apache License

@Override
public void close() {
    IOUtils.quietClose(resultSet, statement, connection);
    endOfData();
}

From source file:org.gpfvic.mahout.cf.taste.impl.model.AbstractJDBCIDMigrator.java

License:Apache License

@Override
public final void storeMapping(long longID, String stringID) throws TasteException {
    Connection conn = null;//from w  w w  .j  a va 2  s.c  o  m
    PreparedStatement stmt = null;
    try {
        conn = dataSource.getConnection();
        stmt = conn.prepareStatement(storeMappingSQL);
        stmt.setLong(1, longID);
        stmt.setString(2, stringID);
        stmt.executeUpdate();
    } catch (SQLException sqle) {
        throw new TasteException(sqle);
    } finally {
        IOUtils.quietClose(null, stmt, conn);
    }
}

From source file:org.gpfvic.mahout.cf.taste.impl.model.AbstractJDBCIDMigrator.java

License:Apache License

@Override
public final String toStringID(long longID) throws TasteException {
    Connection conn = null;//from   w  ww  .  j  a v a  2  s  .  c  om
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        conn = dataSource.getConnection();
        stmt = conn.prepareStatement(getStringIDSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        stmt.setFetchDirection(ResultSet.FETCH_FORWARD);
        stmt.setFetchSize(1);
        stmt.setLong(1, longID);
        rs = stmt.executeQuery();
        if (rs.next()) {
            return rs.getString(1);
        } else {
            return null;
        }
    } catch (SQLException sqle) {
        throw new TasteException(sqle);
    } finally {
        IOUtils.quietClose(rs, stmt, conn);
    }
}

From source file:org.plista.kornakapi.core.storage.MySqlStorage.java

License:Apache License

@Override
public FastIDSet getCandidates(String label) throws IOException {
    Connection conn = null;//from w  w w  .jav a 2  s  .  co  m
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {

        FastIDSet candidates = new FastIDSet();

        conn = dataSource.getConnection();
        stmt = conn.prepareStatement(GET_CANDIDATES_QUERY, ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_READ_ONLY);
        stmt.setFetchDirection(ResultSet.FETCH_FORWARD);
        stmt.setFetchSize(1000);
        stmt.setString(1, label);

        rs = stmt.executeQuery();

        while (rs.next()) {
            candidates.add(rs.getLong(1));
        }

        return candidates;

    } catch (SQLException e) {
        throw new IOException(e);
    } finally {
        IOUtils.quietClose(rs, stmt, conn);
    }
}

From source file:org.plista.kornakapi.core.storage.MySqlStorage.java

License:Apache License

public LinkedList<String> getAllLabels() throws IOException {
    Connection conn = null;/*  ww w.j  a v a  2 s .  co  m*/
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {

        LinkedList<String> candidates = new LinkedList<String>();

        conn = dataSource.getConnection();
        stmt = conn.prepareStatement(GET_LABELS, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        stmt.setFetchDirection(ResultSet.FETCH_FORWARD);
        stmt.setFetchSize(1000);
        rs = stmt.executeQuery();

        while (rs.next()) {
            candidates.add(rs.getString(1));
        }

        return candidates;

    } catch (SQLException e) {
        throw new IOException(e);
    } finally {
        IOUtils.quietClose(rs, stmt, conn);
    }
}

From source file:org.plista.kornakapi.core.storage.MySqlStorage.java

License:Apache License

public String getItemsLabel(long itemid) throws IOException {
    Connection conn = null;/*from w ww .ja v a  2 s  . c o m*/
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {

        conn = dataSource.getConnection();
        stmt = conn.prepareStatement(GET_ITEMSLABEL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        stmt.setLong(1, itemid);
        stmt.setFetchDirection(ResultSet.FETCH_FORWARD);
        stmt.setFetchSize(10);
        rs = stmt.executeQuery();
        String label = null;
        if (rs.next()) {
            label = rs.getString(1);
        }

        return label;

    } catch (SQLException e) {
        throw new IOException(e);
    } finally {
        IOUtils.quietClose(rs, stmt, conn);
    }
}