/** */ private void assertBinaryTypesEqual(BinaryType exp, BinaryType actual) { assertEquals(exp.typeId(), actual.typeId()); assertEquals(exp.typeName(), actual.typeName()); assertEquals(exp.fieldNames(), actual.fieldNames()); for (String f : exp.fieldNames()) assertEquals(exp.fieldTypeName(f), actual.fieldTypeName(f)); assertEquals(exp.affinityKeyFieldName(), actual.affinityKeyFieldName()); assertEquals(exp.isEnum(), actual.isEnum()); }
for (String s : F.isEmpty(fields) ? binType.fieldNames() : fields) { BinaryField bfld = fieldsCache.get(s); bfld = binType.field(s); fieldsCache.put(s, bfld); log.info("fields in po{" + binType.fieldNames() + "}"); log.info("result {" + result + "}");
@Override public void examine(IgniteCache cache) { BinaryObject enumBo = (BinaryObject) cache.get(4); assertEquals(EnumType.ENUM_VAL_0.ordinal(), enumBo.enumOrdinal()); BinaryType type = enumBo.type(); assertTrue(type.isEnum()); assertEquals(EnumType.class.getName(), type.typeName()); Collection<BinaryObject> enumVals = type.enumValues(); assertEquals(2, enumVals.size()); int i = 0; for (BinaryObject bo : enumVals) { assertEquals(i, bo.enumOrdinal()); assertEquals("ENUM_VAL_" + (i++), bo.enumName()); } } };
/** * Default constructor. */ public VisorBinaryMetadata(IgniteBinary binary, BinaryType binaryType) { typeName = binaryType.typeName(); typeId = binary.typeId(typeName); affinityKeyFieldName = binaryType.affinityKeyFieldName(); Collection<String> binaryTypeFields = binaryType.fieldNames(); fields = new ArrayList<>(binaryTypeFields.size()); for (String metaField : binaryTypeFields) fields.add(new VisorBinaryMetadataField(metaField, binaryType.fieldTypeName(metaField), null)); }
@Override public void examine(IgniteCache cache) { BinaryObject bo = (BinaryObject) cache.get(2); BinaryType type = bo.type(); assertFalse(type.isEnum()); assertEquals(DYNAMIC_TYPE_NAME, type.typeName()); Collection<String> fieldNames = type.fieldNames(); assertEquals(1, fieldNames.size()); assertTrue(fieldNames.contains(DYNAMIC_INT_FIELD_NAME)); assertEquals(DYNAMIC_INT_FIELD_NAME, type.affinityKeyFieldName()); } };
/** * @throws Exception If failed. */ @Test public void testReflection() throws Exception { BinaryType meta = binaries().type(TestObject1.class); assertNotNull(meta); assertEquals(expectedTypeName(TestObject1.class.getName()), meta.typeName()); Collection<String> fields = meta.fieldNames(); assertEquals(7, fields.size()); assertTrue(fields.contains("intVal")); assertTrue(fields.contains("strVal")); assertTrue(fields.contains("arrVal")); assertTrue(fields.contains("obj1Val")); assertTrue(fields.contains("obj2Val")); assertTrue(fields.contains("decVal")); assertTrue(fields.contains("decArrVal")); assertEquals("int", meta.fieldTypeName("intVal")); assertEquals("String", meta.fieldTypeName("strVal")); assertEquals("byte[]", meta.fieldTypeName("arrVal")); assertEquals("Object", meta.fieldTypeName("obj1Val")); assertEquals("Object", meta.fieldTypeName("obj2Val")); assertEquals("decimal", meta.fieldTypeName("decVal")); assertEquals("decimal[]", meta.fieldTypeName("decArrVal")); }
if (meta.isEnum()) { try { return obj.deserialize().toString(); SB buf = new SB(meta.typeName()); if (meta.fieldNames() != null) { buf.a(" [hash=").a(hash); for (String name : meta.fieldNames()) { Object val = objEx.field(name); "typeId", obj.type().typeId(), true);
if (m1.typeName().equals(m2.typeName())) { assertEquals(m1.affinityKeyFieldName(), m2.affinityKeyFieldName()); assertEquals(m1.fieldNames(), m2.fieldNames());
/** {@inheritDoc} */ @Override public boolean matchType(CacheObject val) { if (val instanceof BinaryObject) return ((BinaryObject)val).type().typeId() == typeId; // Value type name can be manually set in QueryEntity to any random value, // also for some reason our conversion from setIndexedTypes sets a full class name // instead of a simple name there, thus we can have a typeId mismatch. // Also, if the type is not in binary format, we always must have it's class available. return val.value(coCtx, false).getClass() == valCls; }
@Override public void examine(IgniteCache cache) { BinaryObject bo = (BinaryObject) cache.get(2); BinaryType type = bo.type(); assertFalse(bo.type().isEnum()); assertEquals(DYNAMIC_TYPE_NAME, type.typeName()); Collection<String> fieldNames = type.fieldNames(); assertEquals(2, fieldNames.size()); assertTrue(fieldNames.contains(DYNAMIC_INT_FIELD_NAME)); assertTrue(fieldNames.contains(DYNAMIC_STR_FIELD_NAME)); } };
/** {@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"); }
/** {@inheritDoc} */ @Override public Collection<String> fieldNames() { return target().fieldNames(); }
/** */ private void assertBinaryObjectsEqual(BinaryObject exp, BinaryObject actual) throws Exception { assertBinaryTypesEqual(exp.type(), actual.type()); for (String f : exp.type().fieldNames()) { Object expVal = exp.field(f); Class<?> cls = expVal.getClass(); if (cls.getMethod("equals", Object.class).getDeclaringClass() == cls) assertEquals(expVal, actual.field(f)); } if (exp.type().isEnum()) assertEquals(exp.enumOrdinal(), actual.enumOrdinal()); }
SB buf = new SB(meta.typeName()); if (meta.fieldNames() != null) { buf.a(" [idHash=").a(idHash).a(", hash=").a(hash); for (String name : meta.fieldNames()) { Object val = field(ctx, name);
String oldFldTypeName = meta == null ? null : meta.fieldTypeName(name); throw new BinaryObjectException( "Wrong value has been set [" + "typeName=" + (typeName == null ? meta.typeName() : typeName) + ", fieldName=" + name + ", fieldType=" + oldFldTypeName +
/** {@inheritDoc} */ @Override public String typeName() { return target().typeName(); }
/** * */ @Test public void testMetadataChanging() { GridBinaryTestClasses.TestObjectContainer c = new GridBinaryTestClasses.TestObjectContainer(); BinaryObjectBuilderImpl mutableObj = wrap(c); mutableObj.setField("intField", 1); mutableObj.setField("intArrField", new int[] {1}); mutableObj.setField("arrField", new String[] {"1"}); mutableObj.setField("strField", "1"); mutableObj.setField("colField", Lists.newArrayList("1")); mutableObj.setField("mapField", Maps.newHashMap(ImmutableMap.of(1, "1"))); mutableObj.setField("enumField", GridBinaryTestClasses.TestObjectEnum.A); mutableObj.setField("enumArrField", new Enum[] {GridBinaryTestClasses.TestObjectEnum.A}); mutableObj.build(); BinaryType metadata = binaries().type(c.getClass()); assertTrue(metadata.fieldNames().containsAll(Arrays.asList("intField", "intArrField", "arrField", "strField", "colField", "mapField", "enumField", "enumArrField"))); assertEquals("int", metadata.fieldTypeName("intField")); assertEquals("int[]", metadata.fieldTypeName("intArrField")); assertEquals("String[]", metadata.fieldTypeName("arrField")); assertEquals("String", metadata.fieldTypeName("strField")); assertEquals("Collection", metadata.fieldTypeName("colField")); assertEquals("Map", metadata.fieldTypeName("mapField")); assertEquals("Enum", metadata.fieldTypeName("enumField")); assertEquals("Enum[]", metadata.fieldTypeName("enumArrField")); }
/** * Get binary field for the property. * * @param obj Target object. * @return Binary field. */ private BinaryField binaryField(BinaryObject obj) { if (ctx.query().skipFieldLookup()) return null; BinaryField field0 = field; if (field0 == null && !fieldTaken) { BinaryType type = obj instanceof BinaryObjectEx ? ((BinaryObjectEx)obj).rawType() : obj.type(); if (type != null) { field0 = type.field(propName); assert field0 != null; field = field0; } fieldTaken = true; } return field0; }
/** * 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()); }
/** * @param nodesCnt Number of nodes in grid. */ private void examineStaticMetadata(int nodesCnt) { for (int i = 0; i < nodesCnt; i++) { IgniteCache cache = grid(i).cache(CACHE_NAME).withKeepBinary(); BinaryObject o1 = (BinaryObject) cache.get(0); TestValue1 t1 = o1.deserialize(); assertEquals(0, t1.getValue()); BinaryObject o2 = (BinaryObject) cache.get(1); TestValue2 t2 = o2.deserialize(); assertEquals("value", t2.getValue()); assertEquals(TestValue1.class.getName(), o1.type().typeName()); assertEquals(TestValue2.class.getName(), o2.type().typeName()); assertEquals("val", o1.type().affinityKeyFieldName()); } }