Search in sources :

Example 81 with QueryEntity

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

the class JdbcThinBulkLoadAbstractSelfTest method cacheConfigWithQueryEntity.

/**
 * Creates cache configuration with {@link QueryEntity} created
 * using {@link CacheConfiguration#setQueryEntities(Collection)} call.
 *
 * @return The cache configuration.
 */
private CacheConfiguration cacheConfigWithQueryEntity() {
    CacheConfiguration<?, ?> cache = defaultCacheConfiguration();
    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    QueryEntity e = new QueryEntity();
    e.setKeyType(String.class.getName());
    e.setValueType("Person");
    e.addQueryField("id", Integer.class.getName(), null);
    e.addQueryField("age", Integer.class.getName(), null);
    e.addQueryField("firstName", String.class.getName(), null);
    e.addQueryField("lastName", String.class.getName(), null);
    cache.setQueryEntities(Collections.singletonList(e));
    return cache;
}
Also used : QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 82 with QueryEntity

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

the class JdbcAbstractDmlStatementSelfTest method binaryCacheConfig.

/**
 * @return Cache configuration for binary marshaller tests.
 */
final CacheConfiguration binaryCacheConfig() {
    CacheConfiguration<?, ?> cache = defaultCacheConfiguration();
    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    QueryEntity e = new QueryEntity();
    e.setKeyType(String.class.getName());
    e.setValueType("Person");
    e.setKeyFieldName(KEY_ALIAS);
    e.addQueryField(KEY_ALIAS, e.getKeyType(), null);
    e.addQueryField("id", Integer.class.getName(), null);
    e.addQueryField("age", Integer.class.getName(), null);
    e.addQueryField("firstName", String.class.getName(), null);
    e.addQueryField("lastName", String.class.getName(), null);
    e.addQueryField("data", byte[].class.getName(), null);
    cache.setQueryEntities(Collections.singletonList(e));
    return cache;
}
Also used : QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 83 with QueryEntity

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

the class QueryUtils method checkQueryEntityConflicts.

/**
 * Check given {@link CacheConfiguration} for conflicts in table and index names from any query entities
 *     found in collection of {@link DynamicCacheDescriptor}s and belonging to the same schema.
 *
 * @param ccfg New cache configuration.
 * @param descs Cache descriptors.
 * @return Exception message describing found conflict or {@code null} if none found.
 */
public static SchemaOperationException checkQueryEntityConflicts(CacheConfiguration<?, ?> ccfg, Collection<DynamicCacheDescriptor> descs) {
    String schema = QueryUtils.normalizeSchemaName(ccfg.getName(), ccfg.getSqlSchema());
    Set<String> idxNames = new HashSet<>();
    Set<String> tblNames = new HashSet<>();
    for (DynamicCacheDescriptor desc : descs) {
        if (F.eq(ccfg.getName(), desc.cacheName()))
            continue;
        String descSchema = QueryUtils.normalizeSchemaName(desc.cacheName(), desc.cacheConfiguration().getSqlSchema());
        if (!F.eq(schema, descSchema))
            continue;
        for (QueryEntity e : desc.schema().entities()) {
            tblNames.add(e.getTableName());
            for (QueryIndex idx : e.getIndexes()) idxNames.add(idx.getName());
        }
    }
    for (QueryEntity e : ccfg.getQueryEntities()) {
        if (!tblNames.add(e.getTableName()))
            return new SchemaOperationException(SchemaOperationException.CODE_TABLE_EXISTS, e.getTableName());
        for (QueryIndex idx : e.getIndexes()) if (!idxNames.add(idx.getName()))
            return new SchemaOperationException(SchemaOperationException.CODE_INDEX_EXISTS, idx.getName());
    }
    return null;
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) HashSet(java.util.HashSet)

Example 84 with QueryEntity

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

the class QueryUtils method normalizeQueryEntity.

/**
 * Normalize query entity. If "escape" flag is set, nothing changes. Otherwise we convert all object names to
 * upper case and replace inner class separator characters ('$' for Java and '.' for .NET) with underscore.
 *
 * @param entity Query entity.
 * @param escape Escape flag taken form configuration.
 * @return Normalized query entity.
 */
public static QueryEntity normalizeQueryEntity(QueryEntity entity, boolean escape) {
    if (escape) {
        String tblName = tableName(entity);
        entity.setTableName(tblName);
        Map<String, String> aliases = new HashMap<>(entity.getAliases());
        for (String fieldName : entity.getFields().keySet()) {
            String fieldAlias = entity.getAliases().get(fieldName);
            if (fieldAlias == null) {
                fieldAlias = aliasForFieldName(fieldName);
                aliases.put(fieldName, fieldAlias);
            }
        }
        entity.setAliases(aliases);
        for (QueryIndex idx : entity.getIndexes()) idx.setName(indexName(tblName, idx));
        validateQueryEntity(entity);
        return entity;
    }
    QueryEntity normalEntity = entity instanceof QueryEntityEx ? new QueryEntityEx() : new QueryEntity();
    // Propagate plain properties.
    normalEntity.setKeyType(entity.getKeyType());
    normalEntity.setValueType(entity.getValueType());
    normalEntity.setFields(entity.getFields());
    normalEntity.setKeyFields(entity.getKeyFields());
    normalEntity.setKeyFieldName(entity.getKeyFieldName());
    normalEntity.setValueFieldName(entity.getValueFieldName());
    normalEntity.setNotNullFields(entity.getNotNullFields());
    normalEntity.setDefaultFieldValues(entity.getDefaultFieldValues());
    // Normalize table name.
    String normalTblName = entity.getTableName();
    if (normalTblName == null)
        // Replace special characters for auto-generated table name.
        normalTblName = normalizeObjectName(tableName(entity), true);
    else
        // No replaces for manually defined table.
        normalTblName = normalizeObjectName(normalTblName, false);
    normalEntity.setTableName(normalTblName);
    // Normalize field names through aliases.
    Map<String, String> normalAliases = new HashMap<>(normalEntity.getAliases());
    for (String fieldName : normalEntity.getFields().keySet()) {
        String fieldAlias = entity.getAliases().get(fieldName);
        if (fieldAlias == null)
            fieldAlias = aliasForFieldName(fieldName);
        assert fieldAlias != null;
        normalAliases.put(fieldName, normalizeObjectName(fieldAlias, false));
    }
    normalEntity.setAliases(normalAliases);
    // Normalize indexes.
    Collection<QueryIndex> normalIdxs = new LinkedList<>();
    for (QueryIndex idx : entity.getIndexes()) {
        QueryIndex normalIdx = new QueryIndex();
        normalIdx.setFields(idx.getFields());
        normalIdx.setIndexType(idx.getIndexType());
        normalIdx.setInlineSize(idx.getInlineSize());
        normalIdx.setName(normalizeObjectName(indexName(normalTblName, idx), false));
        normalIdxs.add(normalIdx);
    }
    normalEntity.setIndexes(normalIdxs);
    validateQueryEntity(normalEntity);
    return normalEntity;
}
Also used : HashMap(java.util.HashMap) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedList(java.util.LinkedList)

Example 85 with QueryEntity

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

the class CacheBinaryKeyConcurrentQueryTest method cacheConfiguration.

/**
 * @param name Cache name.
 * @param atomicityMode Cache atomicity mode.
 * @return Cache configuration.
 */
private CacheConfiguration cacheConfiguration(String name, CacheAtomicityMode atomicityMode) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setName(name);
    ccfg.setCacheMode(PARTITIONED);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setBackups(1);
    QueryEntity qryEntity = new QueryEntity();
    qryEntity.setKeyType(TestKey.class.getName());
    qryEntity.setValueType(TestValue.class.getName());
    qryEntity.addQueryField("id", Integer.class.getName(), null);
    qryEntity.addQueryField("val", Integer.class.getName(), null);
    qryEntity.setIndexes(F.asList(new QueryIndex("id"), new QueryIndex("val")));
    ccfg.setQueryEntities(F.asList(qryEntity));
    return ccfg;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryIndex(org.apache.ignite.cache.QueryIndex) 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