/** * @param useCollocatedData Use colocated data. * @return Key. */ public Object key(boolean useCollocatedData) { return useCollocatedData ? new AffinityKey<>(id, orgId) : id; }
/** * @param useColocatedData Use colocated data. * @return Key. */ public Object key(boolean useColocatedData) { return useColocatedData ? new AffinityKey<>(id, refOrderId) : id; }
/** * @return Custom affinity key to guarantee that purchase is always collocated with person. */ public AffinityKey<Integer> key() { return new AffinityKey<>(id, organizationId); }
/** * @param useColocatedData Use colocated data. * @return Key. */ public Object key(boolean useColocatedData) { return useColocatedData ? new AffinityKey<>(id, orderId) : id; }
/** * @param useColocatedData Use colocated data.* * @return Key. */ public Object key(boolean useColocatedData) { return useColocatedData ? new AffinityKey<>(id, orderId) : id; }
/** * @return Custom affinity key to guarantee that person is always collocated with organization. */ public AffinityKey<Integer> key() { return new AffinityKey<>(id, orgId); }
/** * @param useCollocatedData Use collocated data. * @return Key. */ public Object key(boolean useCollocatedData) { return useCollocatedData ? new AffinityKey<>(id, orgId) : id; }
public Object key(boolean useColocatedData) { return useColocatedData ? new AffinityKey<>(id, rootOrderId) : id; } }
/** * @param cacheKey Cache key. * @param terminalId Terminal ID. * @return Cached object. */ @SuppressWarnings({"RedundantCast"}) private <T> Object get(String cacheKey, String terminalId) { Object key = new AffinityKey<>(cacheKey, terminalId); return (T) ignite.cache(DEFAULT_CACHE_NAME).get(key); } }
/** */ @Test public void testSubQueryWithAggregate() { CacheConfiguration ccfg1 = cacheConfig("pers", true, AffinityKey.class, Person2.class); IgniteCache<AffinityKey<Integer>, Person2> c1 = ignite(0).getOrCreateCache(ccfg1); try { int orgId = 100500; c1.put(new AffinityKey<>(1, orgId), new Person2(orgId, "Vasya")); c1.put(new AffinityKey<>(2, orgId), new Person2(orgId, "Another Vasya")); List<List<?>> rs = c1.query(new SqlFieldsQuery("select name, " + "select count(1) from Person2 q where q.orgId = p.orgId " + "from Person2 p order by name desc")).getAll(); assertEquals(2, rs.size()); assertEquals("Vasya", rs.get(0).get(0)); assertEquals(2L, rs.get(0).get(1)); assertEquals("Another Vasya", rs.get(1).get(0)); assertEquals(2L, rs.get(1).get(1)); } finally { c1.destroy(); } }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGridsMultiThreaded(3); IgniteCache<String, Organization> orgCache = grid(0).cache("org"); orgCache.put("o1", new Organization(1, "A")); orgCache.put("o2", new Organization(2, "B")); IgniteCache<AffinityKey<String>, Person> personCache = grid(0).cache("pers"); 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)); }
/** * */ @Test public void testMethodAffinityMapper() { AffinityKeyMapper mapper = new GridCacheDefaultAffinityKeyMapper(); GridTestUtils.setFieldValue(mapper, "ignite", grid()); List<AffinityKey<Integer>> keys = new ArrayList<>(); for (int i = 1; i <= 10; i++) keys.add(new AffinityKey<>(i, Integer.toString(i))); for (int i = 1; i <= 10; i++) { AffinityKey<Integer> key = keys.get(i - 1); Object mapped = mapper.affinityKey(key); info("Mapped key: " + mapped); assertNotNull(mapped); assertSame(key.affinityKey(), mapped); } }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGrids(3); IgniteCache<String, Organization> orgCache = grid(0).cache("org"); assert orgCache != null; orgCache.put("o1", new Organization(1, "A")); orgCache.put("o2", new Organization(2, "B")); IgniteCache<AffinityKey, Person> personCache = grid(0).cache("pers"); assert personCache != null; personCache.put(new AffinityKey<>("p1", "o1"), new Person(1, "John White", 25, 1)); personCache.put(new AffinityKey<>("p2", "o1"), new Person(2, "Joe Black", 35, 1)); personCache.put(new AffinityKey<>("p3", "o2"), new Person(3, "Mike Green", 40, 2)); }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGrids(3); IgniteCache<String, Organization> orgCache = jcache(grid(0), cacheConfiguration(), "org", String.class, Organization.class); assert orgCache != null; orgCache.put("o1", new Organization(1, "A")); orgCache.put("o2", new Organization(2, "B")); IgniteCache<AffinityKey, Person> personCache = jcache(grid(0), cacheConfiguration(), "pers", AffinityKey.class, Person.class); assert personCache != null; personCache.put(new AffinityKey<>("p1", "o1"), new Person(1, "John White", 25, 1)); personCache.put(new AffinityKey<>("p2", "o1"), new Person(2, "Joe Black", 35, 1)); personCache.put(new AffinityKey<>("p3", "o2"), new Person(3, "Mike Green", 40, 2)); }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { super.beforeTestsStarted(); startGrids(3); IgniteCache<String, Organization> orgCache = jcache(grid(0), cacheConfiguration(), "org", String.class, Organization.class); assert orgCache != null; orgCache.put("o1", new Organization(1, "A")); orgCache.put("o2", new Organization(2, "B")); IgniteCache<AffinityKey, Person> personCache = jcache(grid(0), cacheConfiguration(), "pers", AffinityKey.class, Person.class); assert personCache != null; personCache.put(new AffinityKey<>("p1", "o1"), new Person(1, "John White", 25, 1)); personCache.put(new AffinityKey<>("p2", "o1"), new Person(2, "Joe Black", 35, 1)); personCache.put(new AffinityKey<>("p3", "o2"), new Person(3, "Mike Green", 40, 2)); }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGridsMultiThreaded(3); IgniteCache<String, Organization> orgCache = jcache(grid(0), cacheConfiguration(), "org", String.class, Organization.class); assert orgCache != null; orgCache.put("o1", new Organization(1, "A")); orgCache.put("o2", new Organization(2, "B")); IgniteCache<AffinityKey, Person> personCache = jcache(grid(0), cacheConfiguration(), "pers", AffinityKey.class, Person.class); 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), cacheConfiguration(), "metaTest", AffinityKey.class, MetaTest.class); }
/** * */ private void fillCaches() { IgniteCache<Integer, Company> co = grid(0).cache("co"); for (int i = 0; i < COMPANY_CNT; i++) co.put(i, new Company(i)); IgniteCache<Integer, Product> pr = grid(0).cache("pr"); Random rnd = new GridRandom(); for (int i = 0; i < PRODUCT_CNT; i++) pr.put(i, new Product(i, rnd.nextInt(COMPANY_CNT))); IgniteCache<Integer, Person> pe = grid(0).cache("pe"); for (int i = 0; i < PERS_CNT; i++) pe.put(i, new Person(i)); IgniteCache<AffinityKey<Integer>, Purchase> pu = grid(0).cache("pu"); for (int i = 0; i < PURCHASE_CNT; i++) { int persId = rnd.nextInt(PERS_CNT); int prodId = rnd.nextInt(PRODUCT_CNT); pu.put(new AffinityKey<>(i, persId), new Purchase(persId, prodId)); } }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { hasCache = true; startGridsMultiThreaded(gridCount()); hasCache = false; startGrid(gridCount()); orgCache = jcache(String.class, Organization.class); assert orgCache != null; orgCache.put("o1", new Organization(1, "A")); orgCache.put("o2", new Organization(2, "B")); IgniteCache<?, ?> c = jcache(AffinityKey.class, Person.class); personCache = (IgniteCache<AffinityKey<String>, Person>)c; 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)); strCache = jcache(String.class, String.class); assert strCache != null; strCache.put("key", "val"); intCache = jcache(Integer.class, Integer.class); assert intCache != null; for (int i = 0; i < 200; i++) intCache.put(i, i); noOpCache = grid(0).getOrCreateCache("noop"); }
/** * */ private void fillCaches() { IgniteCache<Integer, Company> co = grid(0).cache("co"); for (int i = 0; i < COMPANY_CNT; i++) co.put(i, new Company(i)); IgniteCache<Integer, Product> pr = grid(0).cache("pr"); Random rnd = new GridRandom(); for (int i = 0; i < PRODUCT_CNT; i++) pr.put(i, new Product(i, rnd.nextInt(COMPANY_CNT))); IgniteCache<Integer, Person> pe = grid(0).cache("pe"); for (int i = 0; i < PERS_CNT; i++) pe.put(i, new Person(i)); IgniteCache<AffinityKey<Integer>, Purchase> pu = grid(0).cache("pu"); for (int i = 0; i < PURCHASE_CNT; i++) { int persId = rnd.nextInt(PERS_CNT); int prodId = rnd.nextInt(PRODUCT_CNT); pu.put(new AffinityKey<>(i, persId), new Purchase(persId, prodId)); } }
/** * @throws Exception If failed. */ @Test public void testPartitionWithAffinityMapper() throws Exception { AffinityKey<Integer> key = new AffinityKey<>(1, 2); int expPart = affinity().partition(affinityMapper().affinityKey(key)); for (int i = 0; i < gridCount(); i++) assertEquals(expPart, grid(i).affinity(DEFAULT_CACHE_NAME).partition(key)); } }