/** * Gets the cache for current cache id, with binary mode enabled. * * @param ctx Kernal context. * @return Cache. */ protected IgniteCache cache(ClientConnectionContext ctx) { return rawCache(ctx).withKeepBinary(); }
/** * Get common cache. * * @param node Node. * @return Cache. */ protected static IgniteCache<BinaryObject, BinaryObject> cache(Ignite node) { return node.cache(CACHE_NAME).withKeepBinary(); }
@Override public Object call() throws Exception { clientCache.withKeepBinary(); clientCache.withSkipStore(); return null; } });
/** * @return Cache with keep binary flag. */ private <K, V> IgniteCache<K, V> keepBinaryCache() { return ignite(0).cache(DEFAULT_CACHE_NAME).withKeepBinary(); }
/** * @return Cache tuned to utilize classless binary objects as keys. */ private <K, V> IgniteCache<K, V> binKeysCache() { return ignite(0).cache("BinKeysCache").withKeepBinary(); }
@Override public Object call() throws Exception { barrier.await(MAX_AWAIT, TimeUnit.MILLISECONDS); return ((BinaryObject) ignite2.cache(DEFAULT_CACHE_NAME).withKeepBinary().get(1)).field("f1"); } });
/** * @param nodesCount Nodes count. */ private void examineDynamicMetadata(int nodesCount, BinaryObjectExaminer... examiners) { for (int i = 0; i < nodesCount; i++) { Ignite ignite = grid(i); for (BinaryObjectExaminer examiner : examiners) examiner.examine(ignite.cache(CACHE_NAME).withKeepBinary()); } }
/** * @param id person id. * @return Name for person with given id currently stored in cache. */ protected String nameForIdInCache(int id) { Object o = cache().withKeepBinary().get(id); assertTrue(String.valueOf(o), o instanceof BinaryObject); return ((BinaryObject)o).field("name"); } }
/** * @return Cache. */ protected IgniteCache cache() { if (!isBinaryMarshaller()) return ignite(0).cache("S2P"); else return ignite(0).cache("S2P-bin").withKeepBinary(); }
/** * */ @Test public void testPrimitives() { IgniteCache<Integer, Integer> p = ignite(0).cache("I2I").withKeepBinary(); p.query(new SqlFieldsQuery("merge into Integer(_key, _val) values (1, ?), " + "(?, 4)").setArgs(2, 3)); assertEquals(2, (int)p.get(1)); assertEquals(4, (int)p.get(3)); } }
/** * @throws Exception If failed. */ @Test public void testBinaryContains() throws Exception { IgniteEx ignite = grid(0); IgniteCache<Object, Object> cache = ignite.cache("tx-cache").withKeepBinary(); try (Transaction tx = ignite.transactions().txStart()) { BinaryObject key = ignite.binary().builder("test2") .setField("id", 1).build(); assertFalse(cache.containsKey(key)); } }
/** * @throws Exception If failed. */ @Test public void testBinaryGet() throws Exception { IgniteEx ignite = grid(0); IgniteCache<Object, Object> cache = ignite.cache("tx-cache").withKeepBinary(); try (Transaction tx = ignite.transactions().txStart()) { BinaryObject key = ignite.binary().builder("test1") .setField("id", 1).build(); assertNull(cache.get(key)); } }
/** * */ @Test public void testMergeWithExplicitPrimitiveKey() { IgniteCache<Integer, Person> p = ignite(0).cache("I2P").withKeepBinary(); p.query(new SqlFieldsQuery( "merge into Person (_key, id, firstName) values (cast(? as int), ?, ?), (2, (5 - 3), 'Alex')") .setArgs("1", 1, "Sergi")); assertEquals(createPerson(1, "Sergi"), p.get(1)); assertEquals(createPerson(2, "Alex"), p.get(2)); }
/** * */ @Test public void testMergeWithExplicitKey() { IgniteCache<String, Person> p = ignite(0).cache("S2P").withKeepBinary(); p.query(new SqlFieldsQuery("merge into Person (_key, id, firstName) values ('s', ?, ?), " + "('a', 2, 'Alex')").setArgs(1, "Sergi")); assertEquals(createPerson(1, "Sergi"), p.get("s")); assertEquals(createPerson(2, "Alex"), p.get("a")); }
/** * */ @Test public void testInsertWithExplicitPrimitiveKey() { IgniteCache<Integer, Person> p = ignite(0).cache("I2P").withKeepBinary(); p.query(new SqlFieldsQuery( "insert into Person (_key, id, firstName) values (cast('1' as int), ?, ?), (2, (5 - 3), 'Alex')") .setArgs(1, "Sergi")); assertEquals(createPerson(1, "Sergi"), p.get(1)); assertEquals(createPerson(2, "Alex"), p.get(2)); }
/** * */ @Test public void testInsertWithExplicitKey() { IgniteCache<String, Person> p = ignite(0).cache("S2P").withKeepBinary(); p.query(new SqlFieldsQuery("insert into Person (_key, id, firstName) values ('s', ?, ?), " + "('a', 2, 'Alex')").setArgs(1, "Sergi")); assertEquals(createPerson(1, "Sergi"), p.get("s")); assertEquals(createPerson(2, "Alex"), p.get("a")); }
/** * */ @Test public void testMergeWithDynamicKeyInstantiation() { IgniteCache<Key, Person> p = ignite(0).cache("K2P").withKeepBinary(); p.query(new SqlFieldsQuery( "merge into Person (key, id, firstName) values (1, ?, ?), (2, 2, 'Alex')").setArgs(1, "Sergi")); assertEquals(createPerson(1, "Sergi"), p.get(new Key(1))); assertEquals(createPerson(2, "Alex"), p.get(new Key(2))); }
/** * */ @Test public void testFieldsCaseSensitivity() { IgniteCache<Key2, Person> p = ignite(0).cache("K22P").withKeepBinary(); p.query(new SqlFieldsQuery("merge into \"Person2\" (\"Id\", \"id\", \"firstName\", \"IntVal\") values (1, ?, ?, 5), " + "(2, 3, 'Alex', 6)").setArgs(4, "Sergi")); assertEquals(createPerson2(4, "Sergi", 5), p.get(new Key2(1))); assertEquals(createPerson2(3, "Alex", 6), p.get(new Key2(2))); }
/** * */ @Test public void testFieldsCaseSensitivity() { IgniteCache<Key2, Person> p = ignite(0).cache("K22P").withKeepBinary(); p.query(new SqlFieldsQuery("insert into \"Person2\" (\"Id\", \"id\", \"firstName\", \"IntVal\") " + "values (1, ?, ?, 5), (2, 3, 'Alex', 6)").setArgs(4, "Sergi")); assertEquals(createPerson2(4, "Sergi", 5), p.get(new Key2(1))); assertEquals(createPerson2(3, "Alex", 6), p.get(new Key2(2))); }
/** * */ @Test public void testInsertWithDynamicKeyInstantiation() { IgniteCache<Key, Person> p = ignite(0).cache("K2P").withKeepBinary(); p.query(new SqlFieldsQuery( "insert into Person (key, id, firstName) values (1, ?, ?), (2, 2, 'Alex')").setArgs(1, "Sergi")); assertEquals(createPerson(1, "Sergi"), p.get(new Key(1))); assertEquals(createPerson(2, "Alex"), p.get(new Key(2))); }