コード例 #1
0
    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));
    }
コード例 #2
0
 @Override
 public Iterator<Key> iterator() {
   Connection connection = getConnection();
   PreparedStatement statement = null;
   ResultSet rs = null;
   List<Key> keys = new ArrayList<Key>();
   try {
     statement = connection.prepareStatement("select uri,vary from response");
     rs = statement.executeQuery();
     while (rs.next()) {
       String uri = rs.getString(1);
       String vary = rs.getString(2);
       keys.add(Key.create(URI.create(uri), mapper.convertToVary(vary)));
     }
   } catch (SQLException ignore) {
   } finally {
     JdbcUtil.close(rs);
     JdbcUtil.close(statement);
     JdbcUtil.close(connection);
   }
   return ImmutableList.copyOf(keys).iterator();
 }