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[]
}
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);
}
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)");
}
}
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)));
}
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;
}
Aggregations