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

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setIndexedTypes() . 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: GridCacheCrossCacheQuerySelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new cache configuration.
 *
 * @param name Cache name.
 * @param mode Cache mode.
 * @param clsK Key class.
 * @param clsV Value class.
 * @return Cache configuration.
 */
private static CacheConfiguration createCache(String name, CacheMode mode, Class<?> clsK, Class<?> clsV) {
    CacheConfiguration<?,?> cc = defaultCacheConfiguration();

    cc.setName(name);
    cc.setCacheMode(mode);
    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cc.setRebalanceMode(SYNC);
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setIndexedTypes(clsK, clsV);

    if ((mode != CacheMode.PARTITIONED) && (mode != CacheMode.REPLICATED))
        throw new IllegalStateException("mode: " + mode);

    return cc;
}
 
Example 2
Source File: IgniteQueryDedicatedPoolTest.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)
        .setGridLogger(testLog);

    CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfg.setIndexedTypes(Integer.class, Integer.class);
    ccfg.setIndexedTypes(Byte.class, Byte.class);
    ccfg.setSqlFunctionClasses(IgniteQueryDedicatedPoolTest.class);
    ccfg.setName(CACHE_NAME);

    cfg.setCacheConfiguration(ccfg);
    cfg.setIndexingSpi(new TestIndexingSpi());

    if (nonNull(qryPoolSize))
        cfg.setQueryThreadPoolSize(qryPoolSize);

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

    CacheConfiguration<?,?> cache = defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setIndexedTypes(
        Integer.class, Person.class
    );

    cfg.setCacheConfiguration(cache);

    return cfg;
}
 
Example 4
Source File: IgniteCacheDistributedQueryCancelSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
@Test
public void testQueryResponseFailCode() throws Exception {
    try (Ignite client = startClientGrid("client")) {

        CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
        cfg.setSqlFunctionClasses(Functions.class);
        cfg.setIndexedTypes(Integer.class, Integer.class);
        cfg.setName("test");

        IgniteCache<Integer, Integer> cache = client.getOrCreateCache(cfg);

        cache.put(1, 1);

        QueryCursor<List<?>> qry = cache.query(new SqlFieldsQuery("select fail() from Integer"));

        try {
            qry.getAll();

            fail();
        }
        catch (Exception e) {
            assertTrue(e instanceof CacheException);
        }
    }
}
 
Example 5
Source File: IgniteCacheOffheapEvictQueryTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<?,?> cacheCfg = defaultCacheConfiguration();

    cacheCfg.setCacheMode(PARTITIONED);
    cacheCfg.setAtomicityMode(TRANSACTIONAL);
    cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cacheCfg.setBackups(0);
    cacheCfg.setEvictionPolicy(null);
    cacheCfg.setNearConfiguration(null);

    cacheCfg.setIndexedTypes(
        Integer.class, Integer.class
    );

    cfg.setCacheConfiguration(cacheCfg);

    return cfg;
}
 
Example 6
Source File: JdbcThinAutoCloseServerCursorTest.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 {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration cache = defaultCacheConfiguration();

    cache.setName(CACHE_NAME);
    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setIndexedTypes(Integer.class, Person.class);

    cfg.setCacheConfiguration(cache);

    return cfg;
}
 
Example 7
Source File: TextQueryExample.java    From ignite-book-code-samples with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This is an entry point of TextQueryExample, the ignite configuration lies upon resources directory as
 * example-ignite.xml.
 *
 * @param args Command line arguments, none required.
 */
public static void main(String[] args) throws Exception {

    //The ignite configuration lies below resources directory as example-ignite.xml.
    try (Ignite ignite = Ignition.start("example-ignite.xml")) {

        logger.info("Text. Sql query example.");

        CacheConfiguration<Long, Company> employeeCacheCfg = new CacheConfiguration<>(COMPANY_CACHE_NAME);

        employeeCacheCfg.setCacheMode(CacheMode.PARTITIONED);
        employeeCacheCfg.setIndexedTypes(Long.class, Company.class);

        try (
                IgniteCache<Long, Company> employeeCache = ignite.createCache(employeeCacheCfg)
        ) {
            if (args.length <= 0) {
                logger.error("Usages! java -jar .\\target\\cache-store-runnable.jar scanquery|textquery");
                System.exit(0);
            }
            initialize();

            if (args[0].equalsIgnoreCase(SCAN_QUERY)) {
                scanQuery();
                log("Scan query example finished.");
            } else if (args[0].equalsIgnoreCase(TEXT_QUERY)) {
                textQuery();
                log("Text query example finished.");
            }

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

    CacheConfiguration<?, ?> cache = GridAbstractTest.defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(0);
    cache.setIndexedTypes(Integer.class, Integer.class);

    cfg.setCacheConfiguration(cache);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(IP_FINDER);

    cfg.setDiscoverySpi(disco);

    cfg.setCommunicationSpi(new TcpCommunicationSpi() {
        /** {@inheritDoc} */
        @Override public void sendMessage(ClusterNode node, Message msg,
            IgniteInClosure<IgniteException> ackC) {
            if (GridIoMessage.class.isAssignableFrom(msg.getClass())) {
                Message gridMsg = ((GridIoMessage)msg).message();

                if (gridMsg instanceof GridQueryCancelRequest)
                    throw new RuntimeException("Fake network error");
            }

            super.sendMessage(node, msg, ackC);
        }
    });

    return cfg;
}
 
Example 9
Source File: JdbcThinNoDefaultSchemaTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param name Cache name.
 * @return Cache configuration.
 * @throws Exception In case of error.
 */
@SuppressWarnings("unchecked")
private CacheConfiguration cacheConfiguration(@NotNull String name) throws Exception {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setIndexedTypes(Integer.class, Integer.class);

    cfg.setName(name);

    return cfg;
}
 
Example 10
Source File: IgniteBinaryObjectQueryArgumentsTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cacheName Cache name.
 * @param key Key type.
 * @param val Value type
 * @return Configuration.
 */
@SuppressWarnings("unchecked")
private CacheConfiguration getCacheConfiguration(final String cacheName, final Class<?> key, final Class<?> val) {
    CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    cfg.setName(cacheName);

    cfg.setIndexedTypes(key, val);

    return cfg;
}
 
Example 11
Source File: DemoRandomCacheLoadService.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Configure cacheCountry.
 */
private static <K, V> CacheConfiguration<K, V> cacheRandom() {
    CacheConfiguration<K, V> ccfg = new CacheConfiguration<>(RANDOM_CACHE_NAME);

    ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
    ccfg.setQueryDetailMetricsSize(10);
    ccfg.setStatisticsEnabled(true);
    ccfg.setIndexedTypes(Integer.class, Integer.class);

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

    CacheConfiguration<Integer, Value> cc = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    cc.setCopyOnRead(true);
    cc.setIndexedTypes(Integer.class, Value.class);
    cc.setSqlFunctionClasses(TestSQLFunctions.class);

    cfg.setCacheConfiguration(cc);

    return cfg;
}
 
Example 13
Source File: GridCacheQuerySqlFieldInlineSizeSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testGroupIndex() throws Exception {
    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setIndexedTypes(Integer.class, TestValueGroupIndex.class);

    assertEquals(1, ccfg.getQueryEntities().size());

    QueryEntity ent = (QueryEntity)ccfg.getQueryEntities().iterator().next();

    assertEquals(1, ent.getIndexes().size());

    QueryIndex idx = ent.getIndexes().iterator().next();

    assertEquals(10, idx.getInlineSize());
}
 
Example 14
Source File: IgniteDbAbstractTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    DataStorageConfiguration dbCfg = new DataStorageConfiguration();

    if (client)
        cfg.setClientMode(true);

    dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4);

    if (isLargePage())
        dbCfg.setPageSize(16 * 1024);

    dbCfg.setWalMode(WALMode.LOG_ONLY);

    dbCfg.setDefaultDataRegionConfiguration(
        new DataRegionConfiguration()
            .setPersistenceEnabled(true)
            .setMaxSize(DataStorageConfiguration.DFLT_DATA_REGION_INITIAL_SIZE)
    );

    configure(dbCfg);

    cfg.setDataStorageConfiguration(dbCfg);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    if (indexingEnabled())
        ccfg.setIndexedTypes(Integer.class, DbValue.class);

    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setRebalanceMode(SYNC);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));

    CacheConfiguration ccfg2 = new CacheConfiguration("non-primitive");

    if (indexingEnabled())
        ccfg2.setIndexedTypes(DbKey.class, DbValue.class);

    ccfg2.setAtomicityMode(TRANSACTIONAL);
    ccfg2.setWriteSynchronizationMode(FULL_SYNC);
    ccfg2.setRebalanceMode(SYNC);
    ccfg2.setAffinity(new RendezvousAffinityFunction(false, 32));

    CacheConfiguration ccfg3 = new CacheConfiguration("large");

    if (indexingEnabled())
        ccfg3.setIndexedTypes(Integer.class, LargeDbValue.class);

    ccfg3.setAtomicityMode(TRANSACTIONAL);
    ccfg3.setWriteSynchronizationMode(FULL_SYNC);
    ccfg3.setRebalanceMode(SYNC);
    ccfg3.setAffinity(new RendezvousAffinityFunction(false, 32));

    CacheConfiguration ccfg4 = new CacheConfiguration("tiny");

    ccfg4.setAtomicityMode(TRANSACTIONAL);
    ccfg4.setWriteSynchronizationMode(FULL_SYNC);
    ccfg4.setRebalanceMode(SYNC);
    ccfg4.setAffinity(new RendezvousAffinityFunction(1, null));

    CacheConfiguration ccfg5 = new CacheConfiguration("atomic");

    if (indexingEnabled())
        ccfg5.setIndexedTypes(DbKey.class, DbValue.class);

    ccfg5.setAtomicityMode(ATOMIC);
    ccfg5.setWriteSynchronizationMode(FULL_SYNC);
    ccfg5.setRebalanceMode(SYNC);
    ccfg5.setAffinity(new RendezvousAffinityFunction(false, 32));

    if (!client)
        cfg.setCacheConfiguration(ccfg, ccfg2, ccfg3, ccfg4, ccfg5);

    cfg.setMarshaller(null);

    configure(cfg);

    return cfg;
}
 
Example 15
Source File: SqlQueryEmployees.java    From ignite-book-code-samples with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This is an entry point of SqlQueryEmployees, the ignite configuration lies upon resources directory as
 * example-ignite.xml.
 *
 * @param args Command line arguments, none required.
 */
public static void main(String[] args) throws Exception {

    //The ignite configuration lies below resources directory as example-ignite.xml.
    Ignite ignite = Ignition.start("example-ignite.xml");

    logger.info("Start. Sql query example.");

    CacheConfiguration<Integer, Department> deptCacheCfg = new CacheConfiguration<>(DEPARTMENT_CACHE_NAME);

    deptCacheCfg.setCacheMode(CacheMode.REPLICATED);
    deptCacheCfg.setIndexedTypes(Integer.class, Department.class);

    CacheConfiguration<EmployeeKey, Employee> employeeCacheCfg = new CacheConfiguration<>(EMPLOYEE_CACHE_NAME);

    employeeCacheCfg.setCacheMode(CacheMode.PARTITIONED);
    employeeCacheCfg.setIndexedTypes(EmployeeKey.class, Employee.class);

    try (
        IgniteCache<Integer, Department> deptCache = ignite.createCache(deptCacheCfg);
        IgniteCache<EmployeeKey, Employee> employeeCache = ignite.createCache(employeeCacheCfg)
    ) {
        // Populate cache.
        initialize();

        // Example for SQL-based querying employees based on salary ranges.
        sqlQuery();

        // Example for SQL-based querying employees for a given department (includes SQL join).
        sqlQueryWithJoin();

        // Output all employees whos get salary bigger than their direct manager (includes SQL join).
        sqlQueryEmployeesWithSalHigherManager();

        // Example for SQL-based fields queries that return only required
        // fields instead of whole key-value pairs.
        sqlFieldsQuery();

        // Example for SQL-based fields queries that uses joins.
        sqlFieldsQueryWithJoin();

        // Example for query that uses aggregation.
        aggregateQuery();

        // Example for query that uses grouping.
        groupByQuery();

        log("Sql query example finished.");
    }
}
 
Example 16
Source File: ApplicationConfiguration.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Ignite instance bean with not default name
 */
@Bean
public Ignite igniteInstanceTWO() {
    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setIgniteInstanceName(IGNITE_INSTANCE_TWO);

    CacheConfiguration ccfg = new CacheConfiguration("PersonCache");

    ccfg.setIndexedTypes(Integer.class, Person.class);

    cfg.setCacheConfiguration(ccfg);

    TcpDiscoverySpi spi = new TcpDiscoverySpi();

    spi.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    cfg.setDiscoverySpi(spi);

    return Ignition.start(cfg);
}
 
Example 17
Source File: Config.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** */
public static IgniteConfiguration getServerConfiguration() {
    TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();

    discoverySpi.setIpFinder(ipFinder);

    IgniteConfiguration igniteCfg = new IgniteConfiguration();

    igniteCfg.setDiscoverySpi(discoverySpi);

    CacheConfiguration<Integer, Person> dfltCacheCfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    dfltCacheCfg.setIndexedTypes(Integer.class, Person.class);

    igniteCfg.setCacheConfiguration(dfltCacheCfg);

    igniteCfg.setIgniteInstanceName(UUID.randomUUID().toString());

    return igniteCfg;
}
 
Example 18
Source File: CacheConfig.java    From tutorials with MIT License 3 votes vote down vote up
public static CacheConfiguration<Integer, Employee> employeeCache() {

        CacheConfiguration<Integer, Employee> config = new CacheConfiguration<>("baeldungEmployees");

        config.setIndexedTypes(Integer.class, Employee.class);
        config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(
                new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5))));

        return config;
    }
 
Example 19
Source File: JavaEmbeddedIgniteRDDSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Creates cache configuration.
 *
 * @return Cache configuration.
 */
private static CacheConfiguration<Object, Object> cacheConfiguration() {
    CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfg.setBackups(1);

    ccfg.setName(PARTITIONED_CACHE_NAME);

    ccfg.setIndexedTypes(String.class, Entity.class);

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

    cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());

    CacheConfiguration<Integer, IndexedObject> ccfg = renamed ?
        new CacheConfiguration<>(RENAMED_CACHE_NAME) : new CacheConfiguration<>(CACHE_NAME);

    ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfg.setRebalanceMode(CacheRebalanceMode.SYNC);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, PARTS));
    ccfg.setNodeFilter(new RemoteNodeFilter());
    ccfg.setIndexedTypes(Integer.class, IndexedObject.class);

    CacheConfiguration<Integer, IndexedObject> locCcfg = new CacheConfiguration<>(LOC_CACHE_NAME);
    locCcfg.setCacheMode(CacheMode.LOCAL);
    locCcfg.setIndexedTypes(Integer.class, IndexedObject.class);

    CacheConfiguration<Object, Object> cfg1 = new CacheConfiguration<>("cache1")
        .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
        .setAffinity(new RendezvousAffinityFunction(false, 32))
        .setCacheMode(CacheMode.PARTITIONED)
        .setRebalanceMode(CacheRebalanceMode.SYNC)
        .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC)
        .setBackups(0);

    CacheConfiguration<Object, Object> cfg2 = new CacheConfiguration<>(cfg1).setName("cache2").setRebalanceOrder(10);

    cfg.setCacheConfiguration(ccfg, locCcfg, cfg1, cfg2);

    DataStorageConfiguration dbCfg = new DataStorageConfiguration();

    dbCfg.setPageSize(4 * 1024);

    DataRegionConfiguration memPlcCfg = new DataRegionConfiguration();

    memPlcCfg.setName("dfltDataRegion");
    memPlcCfg.setInitialSize(256L * 1024 * 1024);
    memPlcCfg.setMaxSize(256L * 1024 * 1024);
    memPlcCfg.setPersistenceEnabled(true);

    dbCfg.setDefaultDataRegionConfiguration(memPlcCfg);

    dbCfg.setWalRecordIteratorBufferSize(1024 * 1024);

    dbCfg.setWalHistorySize(2);

    if (logOnly)
        dbCfg.setWalMode(WALMode.LOG_ONLY);

    if (walSegmentSize != 0)
        dbCfg.setWalSegmentSize(walSegmentSize);

    dbCfg.setWalSegments(walSegments);

    dbCfg.setWalPageCompression(walPageCompression);

    dbCfg.setCheckpointFrequency(checkpointFrequency);

    cfg.setDataStorageConfiguration(dbCfg);

    BinaryConfiguration binCfg = new BinaryConfiguration();

    binCfg.setCompactFooter(false);

    cfg.setBinaryConfiguration(binCfg);

    if (!getTestIgniteInstanceName(0).equals(gridName))
        cfg.setUserAttributes(F.asMap(HAS_CACHE, true));

    if (customFailureDetectionTimeout > 0)
        cfg.setFailureDetectionTimeout(customFailureDetectionTimeout);

    return cfg;
}