Search in sources :

Example 71 with QueryEntity

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

the class QueryEntityValidationSelfTest method testIndexNameDuplicate.

/**
 * Test duplicated index name.
 *
 * @throws Exception If failed.
 */
public void testIndexNameDuplicate() 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());
    fields.put("b", Integer.class.getName());
    entity.setFields(fields);
    LinkedHashMap<String, Boolean> idx1Fields = new LinkedHashMap<>();
    LinkedHashMap<String, Boolean> idx2Fields = new LinkedHashMap<>();
    idx1Fields.put("a", true);
    idx1Fields.put("b", true);
    QueryIndex idx1 = new QueryIndex().setName("idx").setFields(idx1Fields);
    QueryIndex idx2 = new QueryIndex().setName("idx").setFields(idx2Fields);
    List<QueryIndex> idxs = new ArrayList<>();
    idxs.add(idx1);
    idxs.add(idx2);
    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, "Duplicate index name");
}
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)

Example 72 with QueryEntity

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

the class IgniteSqlNotNullConstraintTest method checkNodeState.

/**
 */
private void checkNodeState(IgniteEx node, String schemaName, String tableName, String fieldName) {
    String cacheName = F.eq(schemaName, QueryUtils.DFLT_SCHEMA) ? QueryUtils.createTableCacheName(schemaName, tableName) : schemaName;
    DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName);
    assertNotNull("Cache descriptor not found", desc);
    QuerySchema schema = desc.schema();
    assertNotNull(schema);
    QueryEntity entity = null;
    for (QueryEntity e : schema.entities()) {
        if (F.eq(tableName, e.getTableName())) {
            entity = e;
            break;
        }
    }
    assertNotNull(entity);
    assertNotNull(entity.getNotNullFields());
    assertTrue(entity.getNotNullFields().contains(fieldName));
}
Also used : DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 73 with QueryEntity

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

the class IgniteSqlNotNullConstraintTest method testQueryEntityGetSetNotNullFields.

/**
 */
public void testQueryEntityGetSetNotNullFields() throws Exception {
    QueryEntity qe = new QueryEntity();
    assertNull(qe.getNotNullFields());
    Set<String> val = Collections.singleton("test");
    qe.setNotNullFields(val);
    assertEquals(val, Collections.singleton("test"));
    qe.setNotNullFields(null);
    assertNull(qe.getNotNullFields());
}
Also used : QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 74 with QueryEntity

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

the class IgniteSqlSkipReducerOnUpdateDmlFlagSelfTest method buildCacheConfiguration.

/**
 * Creates a cache configuration.
 *
 * @param name Name of the cache.
 * @return Cache configuration.
 */
private CacheConfiguration buildCacheConfiguration(String name) {
    if (name.equals(CACHE_ACCOUNT)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_ACCOUNT);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        QueryEntity entity = new QueryEntity(Integer.class, Account.class);
        ccfg.setQueryEntities(Collections.singletonList(entity));
        return ccfg;
    }
    if (name.equals(CACHE_STOCK)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_STOCK);
        ccfg.setCacheMode(CacheMode.REPLICATED);
        QueryEntity entity = new QueryEntity(Integer.class, Stock.class);
        ccfg.setQueryEntities(Collections.singletonList(entity));
        return ccfg;
    }
    if (name.equals(CACHE_TRADE)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_TRADE);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        QueryEntity entity = new QueryEntity(Integer.class, Trade.class);
        ccfg.setQueryEntities(Collections.singletonList(entity));
        return ccfg;
    }
    if (name.equals(CACHE_REPORT)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_REPORT);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        QueryEntity entity = new QueryEntity(Integer.class, Report.class);
        ccfg.setQueryEntities(Collections.singletonList(entity));
        return ccfg;
    }
    if (name.equals(CACHE_LIST)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_LIST);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        QueryEntity entity = new QueryEntity(Integer.class, String.class);
        ccfg.setQueryEntities(Collections.singletonList(entity));
        return ccfg;
    }
    assert false;
    return null;
}
Also used : QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 75 with QueryEntity

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

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method buildCacheConfiguration.

/**
 * Creates cache configuration.
 *
 * @param name Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration buildCacheConfiguration(String name) {
    if (name.equals(CACHE_ORG)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_ORG);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        QueryEntity entity = new QueryEntity(Integer.class, Organization.class);
        ccfg.setQueryEntities(Collections.singletonList(entity));
        ccfg.setSqlFunctionClasses(IgniteSqlSkipReducerOnUpdateDmlSelfTest.class);
        return ccfg;
    }
    if (name.equals(CACHE_PERSON)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_PERSON);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        QueryEntity entity = new QueryEntity(PersonKey.class, Person.class);
        ccfg.setQueryEntities(Collections.singletonList(entity));
        ccfg.setKeyConfiguration(new CacheKeyConfiguration(PersonKey.class));
        ccfg.setSqlFunctionClasses(IgniteSqlSkipReducerOnUpdateDmlSelfTest.class);
        return ccfg;
    }
    if (name.equals(CACHE_POSITION)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_POSITION);
        ccfg.setCacheMode(CacheMode.REPLICATED);
        QueryEntity entity = new QueryEntity(Integer.class, Position.class);
        ccfg.setQueryEntities(Collections.singletonList(entity));
        ccfg.setSqlFunctionClasses(IgniteSqlSkipReducerOnUpdateDmlSelfTest.class);
        return ccfg;
    }
    assert false;
    return null;
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

QueryEntity (org.apache.ignite.cache.QueryEntity)97 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)59 QueryIndex (org.apache.ignite.cache.QueryIndex)46 LinkedHashMap (java.util.LinkedHashMap)38 ArrayList (java.util.ArrayList)33 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)17 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)12 HashSet (java.util.HashSet)8 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)8 HashMap (java.util.HashMap)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 BinaryObject (org.apache.ignite.binary.BinaryObject)5 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)5 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)4 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)4 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)4 List (java.util.List)3 Map (java.util.Map)3