/** * Closes a {@link ResultSet}, {@link Statement} and {@link Connection} (if not null) and logs (but does not * rethrow) any resulting {@link SQLException}. This is useful for cleaning up after a database query. * * @param resultSet * {@link ResultSet} to close * @param statement * {@link Statement} to close * @param connection * {@link Connection} to close */ public static void quietClose(ResultSet resultSet, Statement statement, Connection connection) { quietClose(resultSet); quietClose(statement); quietClose(connection); }
/** * Closes a {@link ResultSet}, {@link Statement} and {@link Connection} (if not null) and logs (but does not * rethrow) any resulting {@link SQLException}. This is useful for cleaning up after a database query. * * @param resultSet * {@link ResultSet} to close * @param statement * {@link Statement} to close * @param connection * {@link Connection} to close */ public static void quietClose(ResultSet resultSet, Statement statement, Connection connection) { quietClose(resultSet); quietClose(statement); quietClose(connection); }
/** * Closes a {@link ResultSet}, {@link Statement} and {@link Connection} (if not null) and logs (but does not * rethrow) any resulting {@link SQLException}. This is useful for cleaning up after a database query. * * @param resultSet * {@link ResultSet} to close * @param statement * {@link Statement} to close * @param connection * {@link Connection} to close */ public static void quietClose(ResultSet resultSet, Statement statement, Connection connection) { quietClose(resultSet); quietClose(statement); quietClose(connection); }
/** * Closes a {@link ResultSet}, {@link Statement} and {@link Connection} (if not null) and logs (but does not * rethrow) any resulting {@link SQLException}. This is useful for cleaning up after a database query. * * @param resultSet * {@link ResultSet} to close * @param statement * {@link Statement} to close * @param connection * {@link Connection} to close */ public static void quietClose(ResultSet resultSet, Statement statement, Connection connection) { quietClose(resultSet); quietClose(statement); quietClose(connection); }
@Override public void close() { IOUtils.quietClose(resultSet, statement, connection); endOfData(); }
@Override public void close() { IOUtils.quietClose(resultSet, statement, connection); endOfData(); }
@Override public void close() { IOUtils.quietClose(resultSet, statement, connection); endOfData(); }
@Override public final void storeMapping(long longID, String stringID) throws TasteException { Connection conn = null; 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); } }
@Override public final void storeMapping(long longID, String stringID) throws TasteException { Connection conn = null; 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); } }
@Override public final void storeMapping(long longID, String stringID) throws TasteException { Connection conn = null; 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); } }
@Override public final String toStringID(long longID) throws TasteException { Connection conn = null; 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); } }
private List<Preference> readProbePreferences(Path dir) throws IOException { List<Preference> preferences = new LinkedList<Preference>(); FileSystem fs = dir.getFileSystem(getConf()); for (FileStatus seqFile : fs.globStatus(new Path(dir, "part-*"))) { Path path = seqFile.getPath(); InputStream in = null; try { in = fs.open(path); BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8"))); String line; while ((line = reader.readLine()) != null) { String[] tokens = TasteHadoopUtils.splitPrefTokens(line); long userID = Long.parseLong(tokens[0]); long itemID = Long.parseLong(tokens[1]); float value = Float.parseFloat(tokens[2]); preferences.add(new GenericPreference(userID, itemID, value)); } } finally { IOUtils.quietClose(in); } } return preferences; } }
@Override public final String toStringID(long longID) throws TasteException { Connection conn = null; 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); } }
@Override public final String toStringID(long longID) throws TasteException { Connection conn = null; 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); } }
writer.write(String.valueOf(rmse)); } finally { IOUtils.quietClose(writer);
IOUtils.quietClose(reader); return endOfData();
private Matrix readMatrix(Path dir) throws IOException { Matrix matrix = new SparseMatrix(new int[] { Integer.MAX_VALUE, Integer.MAX_VALUE }); FileSystem fs = dir.getFileSystem(getConf()); for (FileStatus seqFile : fs.globStatus(new Path(dir, "part-*"))) { Path path = seqFile.getPath(); SequenceFile.Reader reader = null; try { reader = new SequenceFile.Reader(fs, path, getConf()); IntWritable key = new IntWritable(); VectorWritable value = new VectorWritable(); while (reader.next(key, value)) { int row = key.get(); Iterator<Vector.Element> elementsIterator = value.get().iterateNonZero(); while (elementsIterator.hasNext()) { Vector.Element element = elementsIterator.next(); matrix.set(row, element.index(), element.get()); } } } finally { IOUtils.quietClose(reader); } } return matrix; }
writer.write("RMSE: " + rmse + ", MAE: " + mae + "\n"); } finally { IOUtils.quietClose(writer);