/** {@inheritDoc} */ @Override public IgniteBinary binary() { checkIgnite(); return g.binary(); }
/** {@inheritDoc} */ @Override protected Object typeIdForTypeName(TypeKind kind, String typeName) throws CacheException { if (kind == TypeKind.BINARY) return ignite.binary().typeId(typeName); try { return Class.forName(typeName); } catch (ClassNotFoundException e) { throw new CacheException("Failed to find class: " + typeName, e); } }
@Override public boolean apply() { return ignite0.binary().types().size() == 100; } }, 5000);
/** * @param val value to be used for creating the instance. */ public T instance(int val) { return BINARY_QUEUE_MODE ? (T)ignite.binary().toBinary(new SameHashItem(Integer.toString(val))) : (T)new SameHashItem(Integer.toString(val)); }
/** * Create key object. * * @param ignite Ignite instance. * @param id ID. * @return Key object. */ protected static BinaryObject key(Ignite ignite, long id) { return ignite.binary().builder(KeyClass.class.getName()).setField(FIELD_KEY, id).build(); }
/** * Check arrays with builder. * * @param registered Registered flag. * @throws Exception If failed. */ public void checkSimpleBuilderArray(boolean registered) throws Exception { startUp(registered); BinaryObject binaryOne = node1.binary().buildEnum(EnumType.class.getName(), EnumType.ONE.ordinal()); BinaryObject binaryTwo = node1.binary().buildEnum(EnumType.class.getName(), EnumType.TWO.ordinal()); cacheBinary1.put(1, new BinaryObject[] { binaryOne, binaryTwo }); validateSimpleArray(registered); }
/** * Check if Binary facade is disabled test. Test uses JDK marshaller to provide warranty facade is not available * @throws Exception If failed. */ @Test public void testBinaryDisabled() throws Exception { enableJdkMarshaller = true; assertNull(startGrid().binary()); }
@Override public void run() { try { for (int j = 0; j < updatesNum; j++) { BinaryObjectBuilder bob = client.binary().builder(BINARY_TYPE_NAME); bob.setField("field" + j, threadId); cache.put(threadId, bob.build()); } } catch (Exception e) { e.printStackTrace(); } } }, "updater-" + i);
/** * Create value object. * * @param ignite Ignite instance. * @param id ID. * @return Value object. */ protected static BinaryObject value(Ignite ignite, long id) { return ignite.binary().builder(ValueClass.class.getName()) .setField(FIELD_NAME_1_ESCAPED, id) .setField(FIELD_NAME_2_ESCAPED, id) .build(); }
@Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) { BinaryObject val = e.getValue(); assertNotNull("Unexpected value: " + val, val); assertEquals(new Integer(1), val.field("val")); Ignite ignite = e.unwrap(Ignite.class); IgniteBinary binaries = ignite.binary(); BinaryObjectBuilder builder = binaries.builder(val); builder.setField("val", 2); e.setValue(builder.build()); return null; } });
@Override public Object call() throws Exception { try (Ignite grid = startGrid()) { IgniteCache<BinaryObject, String> cache = grid.cache(CACHE_NAME); HashMap<BinaryObject, String> batch = new HashMap<>(); for (int i = 0; i < batchSize; i++) { BinaryObject key = grid.binary().builder("KEY_TYPE_NAME").setField("id", i).build(); batch.put(key, "VALUE"); } cache.putAllAsync(batch).get(); } return null; } }, CacheWriterException.class, null);
@Override public Object call() throws Exception { node2.binary().registerEnum(enumName, F.asMap(EnumType.ONE.name(), EnumType.TWO.ordinal())); return null; } }, BinaryObjectException.class, "Conflicting enum values. Value ");
@Override public Object call() throws Exception { node2.binary().registerEnum(enumName, F.asMap(EnumType.TWO.name(), EnumType.ONE.ordinal())); return null; } }, BinaryObjectException.class, "Conflicting enum values. Name ");
/** * @param node Node. * @param val Number to form string field value from. * @return PERSON cache value. */ private BinaryObject val(Ignite node, int val) { String valTypeName = ((IgniteEx)node).context().query().types(CACHE_NAME).iterator().next().valueTypeName(); return node.binary().builder(valTypeName).setField("name", "person" + val).build(); }
/** Register enum */ private void defineEnum() { node1.binary().registerEnum(EnumType.class.getName(), F.asMap(EnumType.ONE.name(), EnumType.ONE.ordinal(), EnumType.TWO.name(), EnumType.TWO.ordinal())); }
/** * fill data by default */ private void fillTestData(Ignite ig) { try (IgniteDataStreamer<Object, Object> s = ig.dataStreamer(TEST_CACHE_NAME)) { for (int i = 0; i < 500; i++) { BinaryObject bo = ig.binary().builder("TestIndexObject") .setField("a", i, Object.class) .setField("b", String.valueOf(i), Object.class) .build(); s.addData(i, bo); } } }
/** * Validate single value. * * @param obj Binary value. * @param val Expected value. */ private void validate(BinaryObject obj, DeclaredBodyEnum val) { assertTrue(obj.type().isEnum()); assertEquals(node1.binary().typeId(DeclaredBodyEnum.class.getName()), obj.type().typeId()); assertEquals(node2.binary().typeId(DeclaredBodyEnum.class.getName()), obj.type().typeId()); assertEquals(val.ordinal(), obj.enumOrdinal()); }
@Override public Object call() throws Exception { node1.binary().registerEnum("invalidEnumType1", F.asMap(EnumType.ONE.name(), EnumType.ONE.ordinal(), EnumType.TWO.name(), EnumType.ONE.ordinal())); return null; } }, BinaryObjectException.class, "Conflicting enum values");
/** * @param ignite Node. * @param id Identifier. * @return Trader entity as binary object. */ private BinaryObject createTrader(Ignite ignite, String id) { return ignite.binary() .builder(TRADER) .setField(ID, id) .setField(FIRSTNAME, "First name " + id) .setField(SECONDNAME, "Second name " + id) .setField(EMAIL, "trader" + id + "@mail.org") .build(); }
/** {@inheritDoc} */ @Nullable @Override public Object execute() { BinaryObjectEx arg0 = ((BinaryObjectEx)arg); BinaryType meta = ignite.binary().type(arg0.typeId()); if (meta == null) throw new IgniteException("Metadata doesn't exist."); if (meta.fieldNames() == null || !meta.fieldNames().contains("Field")) throw new IgniteException("Field metadata doesn't exist."); if (!F.eq("int", meta.fieldTypeName("Field"))) throw new IgniteException("Invalid field type: " + meta.fieldTypeName("Field")); if (meta.affinityKeyFieldName() != null) throw new IgniteException("Unexpected affinity key: " + meta.affinityKeyFieldName()); return arg0.field("field"); }