繁体   English   中英

带有Postgresql的Apache Ignite缓存

[英]Apache Ignite Cache with Postgresql

我正在寻找几天以了解Postgressql的缓存,这是POST类

public class Post implements Serializable {
private static final long serialVersionUID = 0L;
private String id;
private String title;
private String description;
private LocalDate creationDate;
private String author;
// rest of the setter and getter are omitted
}

这是我根本看不懂的代码

@Override
public Post load(String key) throws CacheLoaderException {
    Map<String, Object> inputParam = new HashMap<>();
    inputParam.put("id", key);
    return jdbcTemplate.queryForObject("SELECT * FROM POSTS WHERE id=?", inputParam, new RowMapper<Post>() {
        @Override
        //WHAT THE mapRow method does? Is there another way to do some thing?
        public Post mapRow(ResultSet rs, int i) throws SQLException {
            return new Post(rs.getString(1), rs.getString(2), rs.getString(3), rs.getDate(4), rs.getString(5));
        }
    });

}

这是完整的代码: 链接

这些代码摘自Apache Ignite的“高性能内存计算”一书。 谢谢...

在这里,您尝试处理下一个SQL请求:

“选择*从ID ==的帖子?”

例如,表“ POSTS”有5个条目。 每个POST条目都包含5个字段。 在数据库中执行此SQL命令时,将获得5行。 每行将按一定顺序包含这5个字段(取决于表的创建方式)。

在您的示例中,您将使用jdbcTemplate.queryForObject方法。 它需要实现RowMapper对象,该对象将从“ SELECT * FROM POSTS WHERE id =?”开始的行继续进行。

你可以在这里读到它:

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/RowMapper.html#mapRow-java.sql.ResultSet-int-

这个怎么运作:

例如“ SELECT * FROM POSTS WHERE id =?” 应该为某些ID返回1或更多行。 每行将显示为ResultSet对象(您可以将其视为具有5个字段的行)。 在将每个ResultSet(行)返回给用户之前,应将其转换为POST对象。

public Post mapRow(ResultSet rs, int i) throws SQLException {
    return new Post(rs.getString(1), rs.getString(2), rs.getString(3), rs.getDate(4), rs.getString(5));
}

这段代码只是说,您获得具有5个字段(字符串,字符串,字符串,日期,字符串)的行,并使用这5个字段构建POST对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM