Java Code Examples for org.apache.ignite.configuration.CacheConfiguration#setReadThrough()

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setReadThrough() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteTxCacheWriteSynchronizationModesMultithreadedTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param name Cache name.
 * @param syncMode Write synchronization mode.
 * @param backups Number of backups.
 * @param store If {@code true} configures cache store.
 * @return Cache configuration.
 */
private CacheConfiguration<Object, Object> cacheConfiguration(@NotNull String name,
    CacheWriteSynchronizationMode syncMode,
    int backups,
    boolean store) {
    CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfg.setName(name);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(syncMode);
    ccfg.setBackups(backups);

    if (store) {
        ccfg.setCacheStoreFactory(new TestStoreFactory());
        ccfg.setReadThrough(true);
        ccfg.setWriteThrough(true);
    }

    return ccfg;
}
 
Example 2
Source File: IgniteCacheStoreSessionWriteBehindAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param igniteInstanceName Ignite instance name.
 * @return Cache configuration.
 * @throws Exception In case of error.
 */
@Override @SuppressWarnings("unchecked")
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg0 = super.cacheConfiguration(igniteInstanceName);

    ccfg0.setReadThrough(true);
    ccfg0.setWriteThrough(true);
    ccfg0.setWriteBehindBatchSize(10);
    ccfg0.setWriteBehindFlushSize(10);
    ccfg0.setWriteBehindFlushFrequency(600);
    ccfg0.setWriteBehindEnabled(true);

    ccfg0.setCacheStoreFactory(singletonFactory(new TestStore()));

    return ccfg0;
}
 
Example 3
Source File: IgniteCacheReadFromBackupTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
private void checkGetFromBackupStoreReadThroughDisabled(List<CacheConfiguration<Object, Object>> cacheCfgs) throws Exception {
    for (CacheConfiguration<Object, Object> ccfg : cacheCfgs) {
        ccfg.setCacheStoreFactory(new TestStoreFactory());
        ccfg.setReadThrough(false);

        boolean near = (ccfg.getNearConfiguration() != null);

        log.info("Test cache [mode=" + ccfg.getCacheMode() +
            ", atomicity=" + ccfg.getAtomicityMode() +
            ", backups=" + ccfg.getBackups() +
            ", near=" + near + "]");

        ignite(0).createCache(ccfg);

        awaitPartitionMapExchange();

        try {
            checkLocalRead(NODES, ccfg);
        }
        finally {
            ignite(0).destroyCache(ccfg.getName());
        }
    }
}
 
Example 4
Source File: GridCacheMarshallingNodeJoinSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<Integer, TestObject> cacheCfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    cacheCfg.setCacheMode(CacheMode.PARTITIONED);
    cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    cacheCfg.setRebalanceMode(CacheRebalanceMode.SYNC);
    cacheCfg.setCacheStoreFactory(new StoreFactory());
    cacheCfg.setReadThrough(true);
    cacheCfg.setLoadPreviousValue(true);

    cfg.setCacheConfiguration(cacheCfg);

    return cfg;
}
 
Example 5
Source File: IgnteCacheClientWriteBehindStoreAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);

    ccfg.setWriteBehindEnabled(true);
    ccfg.setWriteBehindBatchSize(10);

    if (getTestIgniteInstanceName(2).equals(igniteInstanceName)) {
        ccfg.setCacheStoreFactory(null);
        ccfg.setWriteThrough(false);
        ccfg.setReadThrough(false);
        ccfg.setWriteBehindEnabled(false);
    }

    return ccfg;
}
 
Example 6
Source File: TxRecoveryStoreEnabledTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    cfg.setCommunicationSpi(new TestCommunicationSpi());

    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setName(CACHE_NAME);
    ccfg.setNearConfiguration(null);
    ccfg.setCacheMode(CacheMode.PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setCacheStoreFactory(new TestCacheStoreFactory());
    ccfg.setReadThrough(true);
    ccfg.setWriteThrough(true);
    ccfg.setWriteBehindEnabled(false);

    cfg.setCacheConfiguration(ccfg);

    cfg.setFailureHandler(new StopNodeFailureHandler());

    return cfg;
}
 
Example 7
Source File: GridCacheAbstractTransformWriteThroughSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    GridCacheGenericTestStore<String, Integer> store = new GridCacheGenericTestStore<>();

    stores.add(store);

    CacheConfiguration cacheCfg = defaultCacheConfiguration();

    cacheCfg.setCacheMode(PARTITIONED);
    cacheCfg.setBackups(1);
    cacheCfg.setCacheStoreFactory(singletonFactory(store));
    cacheCfg.setReadThrough(true);
    cacheCfg.setWriteThrough(true);
    cacheCfg.setLoadPreviousValue(true);
    cacheCfg.setAtomicityMode(TRANSACTIONAL);
    cacheCfg.setNearConfiguration(new NearCacheConfiguration());

    cfg.setCacheConfiguration(cacheCfg);

    return cfg;
}
 
Example 8
Source File: GridNearCacheStoreUpdateTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Cache configuration.
 */
protected CacheConfiguration<String, String> cacheConfiguration() {
    CacheConfiguration<String, String> cfg = new CacheConfiguration<>(CACHE_NAME);

    cfg.setCacheStoreFactory(new StoreFactory());

    cfg.setReadThrough(true);
    cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

    return cfg;
}
 
Example 9
Source File: CacheStoreTxPutAllMultiNodeTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Cache configuration.
 */
protected CacheConfiguration<Integer, String> cacheConfiguration() {
    CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>(CACHE_NAME);

    cfg.setCacheStoreFactory(new CacheStoreTxPutAllMultiNodeTest.StoreFactory());

    cfg.setReadThrough(true);
    cfg.setWriteThrough(true);
    cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);

    return cfg;
}
 
Example 10
Source File: IgniteTxPreloadAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration cfg = super.cacheConfiguration(igniteInstanceName);

    cfg.setRebalanceMode(ASYNC);
    cfg.setWriteSynchronizationMode(FULL_SYNC);
    cfg.setCacheStoreFactory(null);
    cfg.setReadThrough(false);
    cfg.setWriteThrough(false);

    return cfg;
}
 
Example 11
Source File: GridCacheAtomicLocalMetricsNoStoreSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);

    ccfg.setReadThrough(false);
    ccfg.setWriteThrough(false);
    ccfg.setCacheStoreFactory(null);

    return ccfg;
}
 
Example 12
Source File: CacheAutoStoreExample.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Configure cache with store.
 */
private static CacheConfiguration<Long, Person> cacheConfiguration() {
    CacheConfiguration<Long, Person> cfg = new CacheConfiguration<>(CACHE_NAME);

    CacheJdbcPojoStoreExampleFactory storeFactory = new CacheJdbcPojoStoreExampleFactory();

    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);

    cfg.setCacheStoreFactory(storeFactory);

    // Set atomicity as transaction, since we are showing transactions in the example.
    cfg.setAtomicityMode(TRANSACTIONAL);

    cfg.setReadThrough(true);
    cfg.setWriteThrough(true);

    return cfg;
}
 
Example 13
Source File: IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration cfg = super.cacheConfiguration(igniteInstanceName);

    cfg.setCacheStoreFactory(null);
    cfg.setReadThrough(false);
    cfg.setWriteThrough(false);

    return cfg;
}
 
Example 14
Source File: IgniteGetNonPlainKeyReadThroughSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setCacheMode(CacheMode.PARTITIONED);

    ccfg.setReadThrough(true);

    ccfg.setCacheStoreFactory(storeFactory);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 15
Source File: GridCacheBasicStoreMultithreadedAbstractTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected final IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    c.setDiscoverySpi(disco);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(cacheMode());
    cc.setWriteSynchronizationMode(FULL_SYNC);

    cc.setCacheStoreFactory(singletonFactory(store));
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);

    c.setCacheConfiguration(cc);

    return c;
}
 
Example 16
Source File: CacheStoreSample.java    From ignite-book-code-samples with GNU General Public License v3.0 4 votes vote down vote up
private static void jdbcStoreExample() throws Exception{
    //let's make a dynamic cache on the fly which is distributed across all running nodes.
    //the same configuration you would probably set in configuration xml format
    IgniteConfiguration cfg = new IgniteConfiguration();

    CacheConfiguration configuration = new CacheConfiguration();
    configuration.setName("dynamicCache");
    configuration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);

    configuration.setCacheStoreFactory(FactoryBuilder.factoryOf(PostgresDBStore.class));
    configuration.setReadThrough(true);
    configuration.setWriteThrough(true);

    configuration.setWriteBehindEnabled(true);

    log("Start. PersistenceStore example.");
    cfg.setCacheConfiguration(configuration);

    try (Ignite ignite = Ignition.start(cfg)) {
        //create cache if it doesn't exist
        int count = 10;
        try (IgniteCache<String, Post> igniteCache = ignite.getOrCreateCache(configuration)) {
            try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                //let us clear

                for (int i = 1; i <= count; i++)
                    igniteCache.put("_" + i, new Post("_" + i, "title-" + i, "description-" + i, LocalDate.now().plus(i, ChronoUnit.DAYS), "author-" + i));

                tx.commit();

                for (int i = 1; i < count; i += 2) {
                    igniteCache.clear("_" + i);
                    log("Clear every odd key: " + i);
                }

                for (long i = 1; i <= count; i++)
                    log("Local peek at [key=_" + i + ", val=" + igniteCache.localPeek("_" + i) + ']');

                for (long i = 1; i <= count; i++)
                    log("Got [key=_" + i + ", val=" + igniteCache.get("_" + i) + ']');

                tx.commit();
            }
        }

        log("PersistenceStore example finished.");
        //ignite.destroyCache("dynamicCache");
        Thread.sleep(Integer.MAX_VALUE);
    }
}
 
Example 17
Source File: GridCacheWriteBehindStoreLoadTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings({"unchecked"})
@Override protected final IgniteConfiguration getConfiguration() throws Exception {
    IgniteConfiguration c = super.getConfiguration();

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    c.setDiscoverySpi(disco);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(cacheMode());
    cc.setWriteSynchronizationMode(FULL_SYNC);

    cc.setCacheStoreFactory(singletonFactory(store));
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);

    cc.setWriteBehindEnabled(true);
    cc.setWriteBehindFlushFrequency(WRITE_FROM_BEHIND_FLUSH_FREQUENCY);

    c.setCacheConfiguration(cc);

    return c;
}
 
Example 18
Source File: GridCacheWriteBehindStoreAbstractTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected IgniteConfiguration getConfiguration() throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    IgniteConfiguration c = super.getConfiguration();

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    c.setDiscoverySpi(disco);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(cacheMode());
    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cc.setAtomicityMode(TRANSACTIONAL);

    cc.setCacheStoreFactory(singletonFactory(store));
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);

    cc.setWriteBehindEnabled(true);
    cc.setWriteBehindFlushFrequency(WRITE_FROM_BEHIND_FLUSH_FREQUENCY);

    c.setCacheConfiguration(cc);

    return c;
}
 
Example 19
Source File: IgniteCacheNoWriteThroughAbstractTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);

    ccfg.setReadThrough(true);

    ccfg.setWriteThrough(false);

    ccfg.setLoadPreviousValue(true);

    return ccfg;
}
 
Example 20
Source File: CacheJdbcPojoWriteBehindStoreWithCoalescingTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/** */
public CacheConfiguration getCacheConfiguration() {
    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setName("TEST_CACHE");

    ccfg.setCacheMode(REPLICATED);

    ccfg.setAtomicityMode(ATOMIC);

    ccfg.setPartitionLossPolicy(READ_WRITE_SAFE);

    ccfg.setReadThrough(true);

    ccfg.setWriteThrough(true);

    ccfg.setWriteBehindEnabled(true);

    ccfg.setWriteBehindBatchSize(1000);

    QueryEntity queryEntity = new QueryEntity();

    queryEntity.setKeyType("java.lang.Integer");

    queryEntity.setValueType("org.apache.ignite.cache.store.jdbc.model.TestPojo");

    queryEntity.setTableName("TEST_CACHE");

    queryEntity.setKeyFieldName("value3");

    Set<String> keyFiles = new HashSet<>();

    keyFiles.add("value3");

    queryEntity.setKeyFields(keyFiles);

    LinkedHashMap<String, String> fields = new LinkedHashMap<>();

    fields.put("value1", "java.lang.String");

    fields.put("value2", "java.lang.Integer");

    fields.put("value3", "java.sql.Date");

    queryEntity.setFields(fields);

    Map<String, String> aliases = new HashMap<>();

    aliases.put("value1", "VALUE1");

    aliases.put("value2", "VALUE2");

    aliases.put("value3", "VALUE3");

    queryEntity.setAliases(aliases);

    ArrayList<QueryEntity> queryEntities = new ArrayList<>();

    queryEntities.add(queryEntity);

    ccfg.setQueryEntities(queryEntities);

    return ccfg;
}