/** {@inheritDoc} */ @Override public Object value(Object key, Object val) throws IgniteCheckedException { Object obj; if (parent != null) { obj = parent.value(key, val); if (obj == null) return null; if (!ctx.cacheObjects().isBinaryObject(obj)) throw new IgniteCheckedException("Non-binary object received as a result of property extraction " + "[parent=" + parent + ", propName=" + propName + ", obj=" + obj + ']'); } else obj = isKeyProp ? key : val; if (obj instanceof BinaryObject) { BinaryObject obj0 = (BinaryObject) obj; return fieldValue(obj0); } else if (obj instanceof BinaryObjectBuilder) { BinaryObjectBuilder obj0 = (BinaryObjectBuilder)obj; return obj0.getField(propName); } else throw new IgniteCheckedException("Unexpected binary object class [type=" + obj.getClass() + ']'); }
/** * @throws Exception If failed. */ @Test public void testSimpleTypeFieldRead() throws Exception { GridBinaryTestClasses.TestObjectAllTypes exp = new GridBinaryTestClasses.TestObjectAllTypes(); exp.setDefaultData(); BinaryObjectBuilder mutPo = wrap(exp); for (Field field : GridBinaryTestClasses.TestObjectAllTypes.class.getDeclaredFields()) { Object expVal = field.get(exp); Object actVal = mutPo.getField(field.getName()); switch (field.getName()) { case "anEnum": assertEquals(((BinaryBuilderEnum)actVal).getOrdinal(), ((Enum)expVal).ordinal()); break; case "enumArr": { BinaryBuilderEnum[] actArr = (BinaryBuilderEnum[])actVal; Enum[] expArr = (Enum[])expVal; assertEquals(expArr.length, actArr.length); for (int i = 0; i < actArr.length; i++) assertEquals(expArr[i].ordinal(), actArr[i].getOrdinal()); break; } } } }
/** {@inheritDoc} */ @Override public Void process(MutableEntry<Integer, BinaryObject> entry, Object... arguments) throws EntryProcessorException { BinaryObjectBuilder bldr = entry.getValue().toBuilder(); Integer val = bldr.<Integer>getField("val"); bldr.setField("val", val + 1); bldr.setField("strVal", "updated-" + val); entry.setValue(bldr.build()); return null; } }
BinaryObjectBuilder obj0 = (BinaryObjectBuilder)obj; return obj0.getField(propName);