Search in sources :

Example 16 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class IgniteCacheCrossCacheJoinRandomTest method configuration.

/**
     * @param name Cache name.
     * @param cacheMode Cache mode.
     * @param backups Number of backups.
     * @return Cache configuration.
     */
private CacheConfiguration configuration(String name, CacheMode cacheMode, int backups) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setName(name);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setAtomicityMode(ATOMIC);
    ccfg.setCacheMode(cacheMode);
    if (cacheMode == PARTITIONED)
        ccfg.setBackups(backups);
    QueryEntity entity = new QueryEntity();
    entity.setKeyType(Integer.class.getName());
    entity.setValueType(TestObject.class.getName());
    entity.addQueryField("parentId", Integer.class.getName(), null);
    entity.setIndexes(F.asList(new QueryIndex("parentId")));
    ccfg.setQueryEntities(F.asList(entity));
    return ccfg;
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 17 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class IgniteCacheMultipleIndexedTypesTest method testMultipleIndexedTypes.

/**
     * @throws Exception If failed.
     */
public void testMultipleIndexedTypes() throws Exception {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    List<QueryEntity> qryEntities = new ArrayList<>();
    {
        QueryEntity qryEntity = new QueryEntity();
        qryEntity.setKeyType(Integer.class.getName());
        qryEntity.setValueType(Person.class.getName());
        LinkedHashMap<String, String> fields = new LinkedHashMap<>();
        fields.put("name", String.class.getName());
        qryEntity.setFields(fields);
        qryEntity.setIndexes(F.asList(new QueryIndex("name")));
        qryEntities.add(qryEntity);
    }
    {
        QueryEntity qryEntity = new QueryEntity();
        qryEntity.setKeyType(Integer.class.getName());
        qryEntity.setValueType(Organization.class.getName());
        LinkedHashMap<String, String> fields = new LinkedHashMap<>();
        fields.put("name", String.class.getName());
        qryEntity.setFields(fields);
        qryEntity.setIndexes(F.asList(new QueryIndex("name")));
        qryEntities.add(qryEntity);
    }
    ccfg.setQueryEntities(qryEntities);
    Ignite ignite = ignite(0);
    IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
    checkCount(cache, Person.class, 0);
    cache.put(1, new Person("a"));
    checkCount(cache, Person.class, 1);
    cache.remove(1);
    checkCount(cache, Person.class, 0);
    cache.put(1, new Person("a"));
    checkCount(cache, Person.class, 1);
    cache.put(1, new Organization("a"));
    checkCount(cache, Person.class, 0);
    checkCount(cache, Organization.class, 1);
    cache.put(1, new Person("a"));
    checkCount(cache, Person.class, 1);
    checkCount(cache, Organization.class, 0);
    cache.put(2, new Person("a"));
    checkCount(cache, Person.class, 2);
    checkCount(cache, Organization.class, 0);
    cache.put(1, new Organization("a"));
    checkCount(cache, Person.class, 1);
    checkCount(cache, Organization.class, 1);
}
Also used : ArrayList(java.util.ArrayList) QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 18 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class IgniteCacheNoClassQuerySelfTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    c.setDiscoverySpi(new TcpDiscoverySpi().setForceServerMode(true).setIpFinder(ipFinder));
    CacheConfiguration cc = defaultCacheConfiguration();
    c.setMarshaller(new BinaryMarshaller());
    cc.setName("cache");
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setRebalanceMode(SYNC);
    QueryEntity qryEntity = new QueryEntity();
    qryEntity.setKeyType(Integer.class.getName());
    qryEntity.setValueType("MyClass");
    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    fields.put("strField", String.class.getName());
    fields.put("intField", Integer.class.getName());
    fields.put("doubleField", Double.class.getName());
    qryEntity.setFields(fields);
    qryEntity.setFields(fields);
    qryEntity.setIndexes(Arrays.asList(new QueryIndex("strField"), new QueryIndex("intField"), new QueryIndex("doubleField")));
    cc.setQueryEntities(Collections.singletonList(qryEntity));
    c.setCacheConfiguration(cc);
    return c;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) LinkedHashMap(java.util.LinkedHashMap)

Example 19 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class IgniteCacheQueriesLoadTest1 method getDepositCfg.

/**
     * @param parentCfg Parent config.
     * @return Configuration.
     */
private static CacheConfiguration<Object, Object> getDepositCfg(CacheConfiguration<Object, Object> parentCfg) {
    CacheConfiguration<Object, Object> depositCfg = new CacheConfiguration<>(parentCfg);
    depositCfg.setName(DEPOSIT_CACHE);
    String strCls = String.class.getCanonicalName();
    String dblCls = Double.class.getCanonicalName();
    String intCls = Integer.class.getCanonicalName();
    LinkedHashMap<String, String> qryFields = new LinkedHashMap<>();
    qryFields.put(ID, strCls);
    qryFields.put(TRADER_ID, strCls);
    qryFields.put(TRADER_LINK, intCls);
    qryFields.put(BALANCE, dblCls);
    qryFields.put(MARGIN_RATE, dblCls);
    qryFields.put(BALANCE_ON_DAY_OPEN, dblCls);
    QueryEntity qryEntity = new QueryEntity();
    qryEntity.setValueType(DEPOSIT);
    qryEntity.setKeyType(strCls);
    qryEntity.setFields(qryFields);
    qryEntity.setIndexes(Collections.singleton(new QueryIndex(ID, false)));
    depositCfg.setQueryEntities(Collections.singleton(qryEntity));
    return depositCfg;
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) BinaryObject(org.apache.ignite.binary.BinaryObject) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class QueryEntityValidationSelfTest method testIndexTypeNull.

/**
     * Test failure if index type is null.
     *
     * @throws Exception If failed.
     */
public void testIndexTypeNull() throws Exception {
    final CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME);
    QueryEntity entity = new QueryEntity();
    entity.setKeyType("Key");
    entity.setValueType("Value");
    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    fields.put("a", Integer.class.getName());
    entity.setFields(fields);
    LinkedHashMap<String, Boolean> idxFields = new LinkedHashMap<>();
    idxFields.put("a", true);
    QueryIndex idx = new QueryIndex().setName("idx").setFields(idxFields).setIndexType(null);
    List<QueryIndex> idxs = new ArrayList<>();
    idxs.add(idx);
    entity.setIndexes(idxs);
    ccfg.setQueryEntities(Collections.singleton(entity));
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            grid(0).createCache(ccfg);
            return null;
        }
    }, IgniteCheckedException.class, "Index type is not set");
}
Also used : ArrayList(java.util.ArrayList) QueryEntity(org.apache.ignite.cache.QueryEntity) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) LinkedHashMap(java.util.LinkedHashMap) QueryIndex(org.apache.ignite.cache.QueryIndex) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

QueryIndex (org.apache.ignite.cache.QueryIndex)69 QueryEntity (org.apache.ignite.cache.QueryEntity)35 LinkedHashMap (java.util.LinkedHashMap)25 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)21 ArrayList (java.util.ArrayList)18 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)16 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 Ignite (org.apache.ignite.Ignite)13 IgniteException (org.apache.ignite.IgniteException)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)8 HashMap (java.util.HashMap)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 CacheException (javax.cache.CacheException)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 BinaryObject (org.apache.ignite.binary.BinaryObject)4