Search code examples
javaxmlcachingannotationsignite

Ignite Cache Setup via XML and Annotation


I followed the example in the Ignite documentation for how to configure Ignite to act as a cache with a Postgres database.

I have been able to implement the person example and have had success configuring caches for other simple tables that map to simple POJOS. At this point I have 3 questions:

  1. I have only been using an xml configuration on my server to define caches and their types. Is it possible to configure theses caches with annotations either partially or in whole? I have seen else where that caches and their types can be configured with annotations but I am not certain if annotations can be used to define the data source for my connection to postgres. If the data source cannot be configured via annotations is it possible to configure the data source in the xml? I know I can configure them in my java code but would prefer to either use annotations or the XML, however the XML seems very verbose.

  2. I have some nested tables where each row corresponds to two or more objects, one with the others nested inside (single layer). Is there documentation of how to set up caches for these objects?

  3. Its it possible to use other non built in objects as the cache key?


Solution

    1. It is not possible to configure cache via annotations probably because cache configurations are rich to describe it in such way. You could use Java configuration[1] or create a cache dynamically by calling Ignite#getOrCreateCache. Java and XML configurations are equal in terms of features. A data source could be configured via Java[3] as well via XML[2].
    2. In this case you could create your own CacheStore implementation to retrieve data from multiple tables.
    3. As keys you could you primitive types, POJOs, or binary objects.

    [1] https://ignite.apache.org/docs/latest/configuring-caches/configuration-overview

    [2] https://ignite.apache.org/docs/latest/persistence/external-storage#cachejdbcpojostore

    [3]https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java