Search in sources :

Example 1 with H2Dialect

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

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;
}
Also used : H2Dialect(org.apache.ignite.cache.store.jdbc.dialect.H2Dialect) BinaryObject(org.apache.ignite.binary.BinaryObject) UUID(java.util.UUID) Timestamp(java.sql.Timestamp)

Example 3 with H2Dialect

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;
}
Also used : H2Dialect(org.apache.ignite.cache.store.jdbc.dialect.H2Dialect)

Example 4 with H2Dialect

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;
}
Also used : H2Dialect(org.apache.ignite.cache.store.jdbc.dialect.H2Dialect) TestJdbcPojoStoreFactoryWithHangWriteAll(org.apache.ignite.cache.store.jdbc.model.TestJdbcPojoStoreFactoryWithHangWriteAll)

Example 5 with H2Dialect

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();
}
Also used : MySQLDialect(org.apache.ignite.cache.store.jdbc.dialect.MySQLDialect) SQLServerDialect(org.apache.ignite.cache.store.jdbc.dialect.SQLServerDialect) H2Dialect(org.apache.ignite.cache.store.jdbc.dialect.H2Dialect) OracleDialect(org.apache.ignite.cache.store.jdbc.dialect.OracleDialect) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) Connection(java.sql.Connection) BasicJdbcDialect(org.apache.ignite.cache.store.jdbc.dialect.BasicJdbcDialect) DB2Dialect(org.apache.ignite.cache.store.jdbc.dialect.DB2Dialect)

Aggregations

H2Dialect (org.apache.ignite.cache.store.jdbc.dialect.H2Dialect)9 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 Connection (java.sql.Connection)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 JdbcType (org.apache.ignite.cache.store.jdbc.JdbcType)2 JdbcTypeField (org.apache.ignite.cache.store.jdbc.JdbcTypeField)2 Person (org.apache.ignite.examples.model.Person)2 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 UUID (java.util.UUID)1 CacheException (javax.cache.CacheException)1 CacheWriterException (javax.cache.integration.CacheWriterException)1 CacheJdbcPojoStoreFactory (org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory)1 BasicJdbcDialect (org.apache.ignite.cache.store.jdbc.dialect.BasicJdbcDialect)1 DB2Dialect (org.apache.ignite.cache.store.jdbc.dialect.DB2Dialect)1 MySQLDialect (org.apache.ignite.cache.store.jdbc.dialect.MySQLDialect)1 OracleDialect (org.apache.ignite.cache.store.jdbc.dialect.OracleDialect)1 SQLServerDialect (org.apache.ignite.cache.store.jdbc.dialect.SQLServerDialect)1 BinaryTest (org.apache.ignite.cache.store.jdbc.model.BinaryTest)1