简体   繁体   English

带有Postgresql的Apache Ignite缓存

[英]Apache Ignite Cache with Postgresql

I am looking for days to understand the cache with postgressql Here is the POST class 我正在寻找几天以了解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
}

Here is the code that I could not understand at all 这是我根本看不懂的代码

@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));
        }
    });

}

Here is the full code : link 这是完整的代码: 链接

These codes are taken from High Performance in-memory computing with Apache Ignite book. 这些代码摘自Apache Ignite的“高性能内存计算”一书。 thank you... 谢谢...

Here you try to process next SQL request: 在这里,您尝试处理下一个SQL请求:

"SELECT * FROM POSTS WHERE id=?" “选择*从ID ==的帖子?”

For example table "POSTS" have 5 entries. 例如,表“ POSTS”有5个条目。 Every POST entry contains 5 fields. 每个POST条目都包含5个字段。 When you execute this SQL command in the database you will get 5 rows. 在数据库中执行此SQL命令时,将获得5行。 Every row will contain this 5 fields in some order (depends on how the table was created). 每行将按一定顺序包含这5个字段(取决于表的创建方式)。

In your example you are going to use jdbcTemplate.queryForObject method. 在您的示例中,您将使用jdbcTemplate.queryForObject方法。 It required to implement the RowMapper object that will proceed the rows from "SELECT * FROM POSTS WHERE id=?". 它需要实现RowMapper对象,该对象将从“ SELECT * FROM POSTS WHERE id =?”开始的行继续进行。

You can read about it here: 你可以在这里读到它:

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

How it works: 这个怎么运作:

For example "SELECT * FROM POSTS WHERE id=?" 例如“ SELECT * FROM POSTS WHERE id =?” should return 1 or more rows for some id. 应该为某些ID返回1或更多行。 Every row will be presented as ResultSet object (you can look at it as on row with 5 fields). 每行将显示为ResultSet对象(您可以将其视为具有5个字段的行)。 Every ResultSet (row) should be transformed into POST object before it will be returned to the user. 在将每个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));
}

This code just says that you get the row with 5 fields (string, string, string, date, string) and build the POST object using this 5 fields. 这段代码只是说,您获得具有5个字段(字符串,字符串,字符串,日期,字符串)的行,并使用这5个字段构建POST对象。

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

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