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;
}
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;
}
Aggregations