Search in sources :

Example 1 with CacheJdbcPojoStoreFactory

use of org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory in project ignite by apache.

the class CacheBinaryAutoStoreExample method cacheConfiguration.

/**
     * Configure cache with store.
     */
private static CacheConfiguration<Long, Person> cacheConfiguration() {
    CacheJdbcPojoStoreFactory<Long, Person> storeFactory = new CacheJdbcPojoStoreFactory<>();
    storeFactory.setDataSourceBean("h2-example-db");
    storeFactory.setDialect(new H2Dialect());
    JdbcType jdbcType = new JdbcType();
    jdbcType.setCacheName(CACHE_NAME);
    jdbcType.setDatabaseSchema("PUBLIC");
    jdbcType.setDatabaseTable("PERSON");
    jdbcType.setKeyType("java.lang.Long");
    jdbcType.setKeyFields(new JdbcTypeField(Types.BIGINT, "ID", Long.class, "id"));
    jdbcType.setValueType("org.apache.ignite.examples.model.Person");
    jdbcType.setValueFields(new JdbcTypeField(Types.BIGINT, "ID", Long.class, "id"), new JdbcTypeField(Types.VARCHAR, "FIRST_NAME", String.class, "firstName"), new JdbcTypeField(Types.VARCHAR, "LAST_NAME", String.class, "lastName"));
    storeFactory.setTypes(jdbcType);
    CacheConfiguration<Long, Person> cfg = new CacheConfiguration<>(CACHE_NAME);
    cfg.setCacheStoreFactory(storeFactory);
    // Set atomicity as transaction, since we are showing transactions in the example.
    cfg.setAtomicityMode(TRANSACTIONAL);
    // This option will allow to start remote nodes without having user classes in classpath.
    cfg.setStoreKeepBinary(true);
    cfg.setReadThrough(true);
    cfg.setWriteThrough(true);
    return cfg;
}
Also used : CacheJdbcPojoStoreFactory(org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory) H2Dialect(org.apache.ignite.cache.store.jdbc.dialect.H2Dialect) JdbcType(org.apache.ignite.cache.store.jdbc.JdbcType) JdbcTypeField(org.apache.ignite.cache.store.jdbc.JdbcTypeField) Person(org.apache.ignite.examples.model.Person) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 2 with CacheJdbcPojoStoreFactory

use of org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory in project ignite by apache.

the class VisorCacheJdbcType method list.

/**
     * @param factory Store factory to extract JDBC types info.
     * @return Data transfer object for cache type metadata configurations.
     */
public static List<VisorCacheJdbcType> list(Factory factory) {
    List<VisorCacheJdbcType> res = new ArrayList<>();
    if (factory != null || factory instanceof CacheJdbcPojoStoreFactory) {
        CacheJdbcPojoStoreFactory jdbcFactory = (CacheJdbcPojoStoreFactory) factory;
        JdbcType[] jdbcTypes = jdbcFactory.getTypes();
        if (!F.isEmpty(jdbcTypes)) {
            for (JdbcType jdbcType : jdbcTypes) res.add(new VisorCacheJdbcType(jdbcType));
        }
    }
    return res;
}
Also used : CacheJdbcPojoStoreFactory(org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory) ArrayList(java.util.ArrayList) JdbcType(org.apache.ignite.cache.store.jdbc.JdbcType)

Aggregations

CacheJdbcPojoStoreFactory (org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory)2 JdbcType (org.apache.ignite.cache.store.jdbc.JdbcType)2 ArrayList (java.util.ArrayList)1 JdbcTypeField (org.apache.ignite.cache.store.jdbc.JdbcTypeField)1 H2Dialect (org.apache.ignite.cache.store.jdbc.dialect.H2Dialect)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 Person (org.apache.ignite.examples.model.Person)1