Search in sources :

Example 16 with QueryEntity

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

the class Indexes method withQueryEntities.

void withQueryEntities() {
    // tag::index-using-queryentity[]
    CacheConfiguration<Long, Person> cache = new CacheConfiguration<Long, Person>("myCache");
    QueryEntity queryEntity = new QueryEntity();
    queryEntity.setKeyFieldName("id").setKeyType(Long.class.getName()).setValueType(Person.class.getName());
    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    fields.put("id", "java.lang.Long");
    fields.put("name", "java.lang.String");
    fields.put("salary", "java.lang.Long");
    queryEntity.setFields(fields);
    queryEntity.setIndexes(Arrays.asList(new QueryIndex("name"), new QueryIndex(Arrays.asList("id", "salary"), QueryIndexType.SORTED)));
    cache.setQueryEntities(Arrays.asList(queryEntity));
// end::index-using-queryentity[]
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 17 with QueryEntity

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

the class QueryEntityExample method main.

public static void main(String[] args) {
    Ignite ignite = Ignition.start();
    CacheConfiguration<Long, Person> personCacheCfg = new CacheConfiguration<Long, Person>();
    personCacheCfg.setName("Person");
    QueryEntity queryEntity = new QueryEntity(Long.class, Person.class).addQueryField("id", Long.class.getName(), null).addQueryField("age", Integer.class.getName(), null).addQueryField("salary", Float.class.getName(), null).addQueryField("name", String.class.getName(), null);
    queryEntity.setIndexes(Arrays.asList(new QueryIndex("id"), new QueryIndex("salary", false)));
    personCacheCfg.setQueryEntities(Arrays.asList(queryEntity));
    IgniteCache<Long, Person> cache = ignite.createCache(personCacheCfg);
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 18 with QueryEntity

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

the class JdbcThinMetadataSelfTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    super.beforeTestsStarted();
    startGridsMultiThreaded(3);
    Map<String, Integer> orgPrecision = new HashMap<>();
    orgPrecision.put("name", 42);
    IgniteCache<String, Organization> orgCache = jcache(grid(0), cacheConfiguration(new QueryEntity(String.class.getName(), Organization.class.getName()).addQueryField("id", Integer.class.getName(), null).addQueryField("name", String.class.getName(), null).setFieldsPrecision(orgPrecision).setIndexes(Arrays.asList(new QueryIndex("id"), new QueryIndex("name", false, "org_name_index")))), "org");
    assert orgCache != null;
    orgCache.put("o1", new Organization(1, "A"));
    orgCache.put("o2", new Organization(2, "B"));
    LinkedHashMap<String, Boolean> persFields = new LinkedHashMap<>();
    persFields.put("name", true);
    persFields.put("age", false);
    IgniteCache<AffinityKey, Person> personCache = jcache(grid(0), cacheConfiguration(new QueryEntityEx(new QueryEntity(AffinityKey.class.getName(), Person.class.getName()).addQueryField("name", String.class.getName(), null).addQueryField("age", Integer.class.getName(), null).addQueryField("orgId", Integer.class.getName(), null).setIndexes(Arrays.asList(new QueryIndex("orgId"), new QueryIndex().setFields(persFields)))).setNotNullFields(new HashSet<>(Arrays.asList("age", "name")))), "pers");
    assert personCache != null;
    personCache.put(new AffinityKey<>("p1", "o1"), new Person("John White", 25, 1));
    personCache.put(new AffinityKey<>("p2", "o1"), new Person("Joe Black", 35, 1));
    personCache.put(new AffinityKey<>("p3", "o2"), new Person("Mike Green", 40, 2));
    jcache(grid(0), defaultCacheConfiguration().setIndexedTypes(Integer.class, Department.class), "dep");
    try (Connection conn = DriverManager.getConnection(URL)) {
        Statement stmt = conn.createStatement();
        stmt.execute("CREATE TABLE TEST (ID INT, NAME VARCHAR(50) default 'default name', " + "age int default 21, VAL VARCHAR(50), PRIMARY KEY (ID, NAME))");
        stmt.execute("CREATE TABLE \"Quoted\" (\"Id\" INT primary key, \"Name\" VARCHAR(50)) WITH WRAP_KEY");
        stmt.execute("CREATE INDEX \"MyTestIndex quoted\" on \"Quoted\" (\"Id\" DESC)");
        stmt.execute("CREATE INDEX IDX ON TEST (ID ASC)");
        stmt.execute("CREATE TABLE TEST_DECIMAL_COLUMN (ID INT primary key, DEC_COL DECIMAL(8, 3))");
        stmt.execute("CREATE TABLE TEST_DECIMAL_COLUMN_PRECISION (ID INT primary key, DEC_COL DECIMAL(8))");
        stmt.execute("CREATE TABLE TEST_DECIMAL_DATE_COLUMN_META (ID INT primary key, DEC_COL DECIMAL(8), DATE_COL DATE)");
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) QueryEntityEx(org.apache.ignite.internal.processors.query.QueryEntityEx) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap) QueryIndex(org.apache.ignite.cache.QueryIndex) AffinityKey(org.apache.ignite.cache.affinity.AffinityKey)

Example 19 with QueryEntity

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

the class GridCommandHandlerIndexingUtils method organizationEntity.

/**
 * Create query {@link Person} entity.
 *
 * @return Query {@link Person} entity.
 */
static QueryEntity organizationEntity() {
    String idField = "id";
    String nameField = "name";
    return new QueryEntity().setKeyType(Integer.class.getName()).setValueType(Organization.class.getName()).addQueryField(idField, Integer.class.getName(), null).addQueryField(nameField, String.class.getName(), null).setIndexes(asList(new QueryIndex(nameField), new QueryIndex(idField)));
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 20 with QueryEntity

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

the class GridCommandHandlerIndexingUtils method prepareQueryEntity.

/**
 * Creates test three field entity.
 *
 * @return new {@code QueryEntity}.
 */
private static QueryEntity prepareQueryEntity() {
    QueryEntity entity = new QueryEntity();
    entity.setKeyType(Integer.class.getName());
    entity.setValueType(CacheEntityThreeFields.class.getName());
    entity.addQueryField(ID_NAME, Integer.class.getName(), null);
    entity.addQueryField(STR_NAME, String.class.getName(), null);
    entity.addQueryField(DOUBLE_NAME, Double.class.getName(), null);
    return entity;
}
Also used : QueryEntity(org.apache.ignite.cache.QueryEntity)

Aggregations

QueryEntity (org.apache.ignite.cache.QueryEntity)221 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)115 QueryIndex (org.apache.ignite.cache.QueryIndex)87 LinkedHashMap (java.util.LinkedHashMap)83 ArrayList (java.util.ArrayList)53 Test (org.junit.Test)42 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)41 HashMap (java.util.HashMap)27 HashSet (java.util.HashSet)22 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)21 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)21 CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)19 List (java.util.List)18 Ignite (org.apache.ignite.Ignite)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)13 Map (java.util.Map)12 BinaryObject (org.apache.ignite.binary.BinaryObject)12 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)12 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)12