use of org.apache.ignite.cache.store.jdbc.dialect.H2Dialect 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.dialect.H2Dialect in project ignite by apache.
the class CacheJdbcPojoStoreTest method store.
/**
* {@inheritDoc}
*/
@Override
protected CacheJdbcPojoStore<Object, Object> store() {
CacheJdbcPojoStoreFactory<Object, Object> storeFactory = new CacheJdbcPojoStoreFactory<>();
JdbcType[] storeTypes = new JdbcType[7];
storeTypes[0] = new JdbcType();
storeTypes[0].setDatabaseSchema("PUBLIC");
storeTypes[0].setDatabaseTable("ORGANIZATION");
storeTypes[0].setKeyType("org.apache.ignite.cache.store.jdbc.model.OrganizationKey");
storeTypes[0].setKeyFields(new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"));
storeTypes[0].setValueType("org.apache.ignite.cache.store.jdbc.model.Organization");
storeTypes[0].setValueFields(new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"), new JdbcTypeField(Types.VARCHAR, "NAME", String.class, "name"), new JdbcTypeField(Types.VARCHAR, "CITY", String.class, "city"));
storeTypes[1] = new JdbcType();
storeTypes[1].setDatabaseSchema("PUBLIC");
storeTypes[1].setDatabaseTable("PERSON");
storeTypes[1].setKeyType("org.apache.ignite.cache.store.jdbc.model.PersonKey");
storeTypes[1].setKeyFields(new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"));
storeTypes[1].setValueType("org.apache.ignite.cache.store.jdbc.model.Person");
storeTypes[1].setValueFields(new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"), new JdbcTypeField(Types.INTEGER, "ORG_ID", Integer.class, "orgId"), new JdbcTypeField(Types.VARCHAR, "NAME", String.class, "name"));
storeTypes[2] = new JdbcType();
storeTypes[2].setDatabaseSchema("PUBLIC");
storeTypes[2].setDatabaseTable("PERSON_COMPLEX");
storeTypes[2].setKeyType("org.apache.ignite.cache.store.jdbc.model.PersonComplexKey");
storeTypes[2].setKeyFields(new JdbcTypeField(Types.INTEGER, "ID", int.class, "id"), new JdbcTypeField(Types.INTEGER, "ORG_ID", int.class, "orgId"), new JdbcTypeField(Types.INTEGER, "CITY_ID", int.class, "cityId"));
storeTypes[2].setValueType("org.apache.ignite.cache.store.jdbc.model.Person");
storeTypes[2].setValueFields(new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"), new JdbcTypeField(Types.INTEGER, "ORG_ID", Integer.class, "orgId"), new JdbcTypeField(Types.VARCHAR, "NAME", String.class, "name"), new JdbcTypeField(Types.INTEGER, "SALARY", Integer.class, "salary"));
storeTypes[3] = new JdbcType();
storeTypes[3].setDatabaseSchema("PUBLIC");
storeTypes[3].setDatabaseTable("TIMESTAMP_ENTRIES");
storeTypes[3].setKeyType("java.sql.Timestamp");
storeTypes[3].setKeyFields(new JdbcTypeField(Types.TIMESTAMP, "KEY", Timestamp.class, null));
storeTypes[3].setValueType("java.lang.Integer");
storeTypes[3].setValueFields(new JdbcTypeField(Types.INTEGER, "VAL", Integer.class, null));
storeTypes[4] = new JdbcType();
storeTypes[4].setDatabaseSchema("PUBLIC");
storeTypes[4].setDatabaseTable("STRING_ENTRIES");
storeTypes[4].setKeyType("java.lang.String");
storeTypes[4].setKeyFields(new JdbcTypeField(Types.VARCHAR, "KEY", String.class, null));
storeTypes[4].setValueType("java.lang.String");
storeTypes[4].setValueFields(new JdbcTypeField(Types.VARCHAR, "VAL", Integer.class, null));
storeTypes[5] = new JdbcType();
storeTypes[5].setDatabaseSchema("PUBLIC");
storeTypes[5].setDatabaseTable("UUID_ENTRIES");
storeTypes[5].setKeyType("java.util.UUID");
storeTypes[5].setKeyFields(new JdbcTypeField(Types.BINARY, "KEY", UUID.class, null));
storeTypes[5].setValueType("java.util.UUID");
storeTypes[5].setValueFields(new JdbcTypeField(Types.BINARY, "VAL", UUID.class, null));
storeTypes[6] = new JdbcType();
storeTypes[6].setDatabaseSchema("PUBLIC");
storeTypes[6].setDatabaseTable("BINARY_ENTRIES");
storeTypes[6].setKeyType("org.apache.ignite.cache.store.jdbc.model.BinaryTestKey");
storeTypes[6].setKeyFields(new JdbcTypeField(Types.BINARY, "KEY", Integer.class, "id"));
storeTypes[6].setValueType("org.apache.ignite.cache.store.jdbc.model.BinaryTest");
storeTypes[6].setValueFields(new JdbcTypeField(Types.BINARY, "VAL", byte[].class, "bytes"));
storeFactory.setTypes(storeTypes);
storeFactory.setDialect(new H2Dialect());
CacheJdbcPojoStore<Object, Object> store = storeFactory.create();
// H2 DataSource
store.setDataSource(JdbcConnectionPool.create(DFLT_CONN_URL, "sa", ""));
return store;
}
use of org.apache.ignite.cache.store.jdbc.dialect.H2Dialect in project ignite by apache.
the class CacheJdbcPojoWriteBehindStoreWithCoalescingTest method getStoreFactory.
/**
*/
public CacheJdbcPojoStoreFactory getStoreFactory() {
CacheJdbcPojoStoreFactory storeFactory = new CacheJdbcPojoStoreFactory();
storeFactory.setParallelLoadCacheMinimumThreshold(100);
storeFactory.setBatchSize(100);
storeFactory.setMaximumPoolSize(4);
storeFactory.setDataSourceFactory(getDataSourceFactory());
storeFactory.setDialect(new H2Dialect());
storeFactory.setTypes(getJdbcType());
return storeFactory;
}
use of org.apache.ignite.cache.store.jdbc.dialect.H2Dialect in project ignite by apache.
the class CacheJdbcPojoWriteBehindStoreWithCoalescingTest method getStoreFactoryWithHangWriteAll.
/**
*/
public CacheJdbcPojoStoreFactory getStoreFactoryWithHangWriteAll() {
TestJdbcPojoStoreFactoryWithHangWriteAll storeFactory = new TestJdbcPojoStoreFactoryWithHangWriteAll();
storeFactory.setParallelLoadCacheMinimumThreshold(100);
storeFactory.setBatchSize(100);
storeFactory.setMaximumPoolSize(4);
storeFactory.setDataSourceFactory(getDataSourceFactory());
storeFactory.setDialect(new H2Dialect());
storeFactory.setTypes(getJdbcType());
return storeFactory;
}
use of org.apache.ignite.cache.store.jdbc.dialect.H2Dialect in project ignite by apache.
the class CacheAbstractJdbcStore method resolveDialect.
/**
* Perform dialect resolution.
*
* @return The resolved dialect.
* @throws CacheException Indicates problems accessing the metadata.
*/
protected JdbcDialect resolveDialect() throws CacheException {
Connection conn = null;
String dbProductName = null;
try {
conn = openConnection(false);
dbProductName = conn.getMetaData().getDatabaseProductName();
} catch (SQLException e) {
throw new CacheException("Failed access to metadata for detect database dialect.", e);
} finally {
U.closeQuiet(conn);
}
if ("H2".equals(dbProductName))
return new H2Dialect();
if ("MySQL".equals(dbProductName))
return new MySQLDialect();
if (dbProductName.startsWith("Microsoft SQL Server"))
return new SQLServerDialect();
if ("Oracle".equals(dbProductName))
return new OracleDialect();
if (dbProductName.startsWith("DB2/"))
return new DB2Dialect();
U.warn(log, "Failed to resolve dialect (BasicJdbcDialect will be used): " + dbProductName);
return new BasicJdbcDialect();
}
Aggregations