public CacheItemHolder mapRow(ResultSet rs, Connection connection) throws SQLException { URI uri = URI.create(rs.getString("uri")); Vary vary = convertToVary(rs.getString("vary")); Blob blob = rs.getBlob("payload"); Payload payload = null; if (blob != null && !rs.wasNull()) { payload = new InputStreamPayload( new ResultSetInputStream(rs, connection, blob.getBinaryStream()), MIMEType.valueOf(rs.getString("mimetype"))); } Status status = Status.valueOf(rs.getInt("status")); Headers headers = convertToHeaders(rs.getString("headers")); DateTime cacheTime = new DateTime(rs.getTimestamp("cachetime").getTime()); HTTPResponse response = new HTTPResponse(payload, status, headers); return new CacheItemHolder(uri, vary, new CacheItem(rewriteResponse(response), cacheTime)); }
@Override public int size() { Connection connection = getConnection(); PreparedStatement statement = null; ResultSet rs = null; try { statement = connection.prepareStatement("select count(*) from response"); rs = statement.executeQuery(); if (rs.next()) { return rs.getInt(1); } } catch (SQLException e) { throw new DataAccessException("Unable to query for count", e); } finally { JdbcUtil.close(rs); JdbcUtil.close(statement); JdbcUtil.close(connection); } return 0; }