Пример #1
0
 private HTTPResponse getImpl(Connection connection, final Key key) {
   PreparedStatement statement = null;
   try {
     statement = connection.prepareStatement("select * from response where uri = ? and vary = ?");
     statement.setString(1, key.getURI().toString());
     statement.setString(2, key.getVary().toJSON());
     ResultSet rs = statement.executeQuery();
     if (rs.next()) {
       CacheItemHolder holder = mapper.mapRow(rs, connection);
       return holder.getCacheItem().getResponse();
     }
   } catch (SQLException e) {
     throw new DataAccessException(e);
   } finally {
     JdbcUtil.close(statement);
   }
   return null;
 }
Пример #2
0
 @Override
 public CacheItem get(HTTPRequest request) {
   Connection connection = getConnection();
   PreparedStatement statement = null;
   try {
     statement = connection.prepareStatement("select * from response where uri = ?");
     statement.setString(1, request.getRequestURI().toString());
     ResultSet rs = statement.executeQuery();
     while (rs.next()) {
       CacheItemHolder holder = mapper.mapRow(rs, connection);
       if (holder.getVary().matches(request)) {
         return holder.getCacheItem();
       }
     }
   } catch (SQLException e) {
     throw new DataAccessException(e);
   } finally {
     JdbcUtil.close(statement);
   }
   return null;
 }
Пример #3
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();
 }