use of org.apache.ignite.binary.BinaryType in project ignite by apache.
the class BinaryObjectExImpl method appendValue.
/**
* @param val Value to append.
* @param buf Buffer to append to.
* @param ctx Reader context.
* @param handles Handles for already traversed objects.
*/
@SuppressWarnings("unchecked")
private void appendValue(Object val, SB buf, BinaryReaderHandles ctx, IdentityHashMap<BinaryObject, Integer> handles) {
if (val instanceof byte[])
buf.a(Arrays.toString((byte[]) val));
else if (val instanceof short[])
buf.a(Arrays.toString((short[]) val));
else if (val instanceof int[])
buf.a(Arrays.toString((int[]) val));
else if (val instanceof long[])
buf.a(Arrays.toString((long[]) val));
else if (val instanceof float[])
buf.a(Arrays.toString((float[]) val));
else if (val instanceof double[])
buf.a(Arrays.toString((double[]) val));
else if (val instanceof char[])
buf.a(Arrays.toString((char[]) val));
else if (val instanceof boolean[])
buf.a(Arrays.toString((boolean[]) val));
else if (val instanceof BigDecimal[])
buf.a(Arrays.toString((BigDecimal[]) val));
else if (val instanceof IgniteUuid)
buf.a(val);
else if (val instanceof BinaryObjectExImpl) {
BinaryObjectExImpl po = (BinaryObjectExImpl) val;
Integer idHash0 = handles.get(val);
if (idHash0 != null) {
// Circular reference.
BinaryType meta0 = po.rawType();
assert meta0 != null;
buf.a(meta0.typeName()).a(" [hash=").a(idHash0).a(", ...]");
} else
buf.a(po.toString(ctx, handles));
} else if (val instanceof Object[]) {
Object[] arr = (Object[]) val;
buf.a('[');
for (int i = 0; i < arr.length; i++) {
Object o = arr[i];
appendValue(o, buf, ctx, handles);
if (i < arr.length - 1)
buf.a(", ");
}
} else if (val instanceof Iterable) {
Iterable<Object> col = (Iterable<Object>) val;
buf.a(col.getClass().getSimpleName()).a(" {");
Iterator it = col.iterator();
while (it.hasNext()) {
Object o = it.next();
appendValue(o, buf, ctx, handles);
if (it.hasNext())
buf.a(", ");
}
buf.a('}');
} else if (val instanceof Map) {
Map<Object, Object> map = (Map<Object, Object>) val;
buf.a(map.getClass().getSimpleName()).a(" {");
Iterator<Map.Entry<Object, Object>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Object, Object> e = it.next();
appendValue(e.getKey(), buf, ctx, handles);
buf.a('=');
appendValue(e.getValue(), buf, ctx, handles);
if (it.hasNext())
buf.a(", ");
}
buf.a('}');
} else
buf.a(val);
}
use of org.apache.ignite.binary.BinaryType in project ignite by apache.
the class VisorQueryUtils method binaryToString.
/**
* Convert Binary object to string.
*
* @param obj Binary object.
* @return String representation of Binary object.
*/
public static String binaryToString(BinaryObject obj) {
int hash = obj.hashCode();
if (obj instanceof BinaryObjectEx) {
BinaryObjectEx objEx = (BinaryObjectEx) obj;
BinaryType meta;
try {
meta = ((BinaryObjectEx) obj).rawType();
} catch (BinaryObjectException ignore) {
meta = null;
}
if (meta != null) {
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);
buf.a(", ").a(name).a('=').a(val);
}
buf.a(']');
return buf.toString();
}
}
}
return S.toString(obj.getClass().getSimpleName(), "hash", hash, false, "typeId", obj.type().typeId(), true);
}
use of org.apache.ignite.binary.BinaryType in project ignite by apache.
the class PlatformContextImpl method writeAllMetadata.
/** {@inheritDoc} */
@Override
public void writeAllMetadata(BinaryRawWriterEx writer) {
Collection<BinaryType> metas = cacheObjProc.metadata();
writer.writeInt(metas.size());
for (BinaryType m : metas) writeMetadata0(writer, cacheObjProc.typeId(m.typeName()), m);
}
use of org.apache.ignite.binary.BinaryType in project ignite by apache.
the class BinaryObjectBuilderDefaultMappersSelfTest method testMetaData.
/**
* @throws Exception If failed.
*/
public void testMetaData() throws Exception {
BinaryObjectBuilder builder = builder("org.test.MetaTest");
builder.setField("intField", 1);
builder.setField("byteArrayField", new byte[] { 1, 2, 3 });
BinaryObject po = builder.build();
BinaryType meta = po.type();
assertEquals(expectedTypeName("org.test.MetaTest"), meta.typeName());
Collection<String> fields = meta.fieldNames();
assertEquals(2, fields.size());
assertTrue(fields.contains("intField"));
assertTrue(fields.contains("byteArrayField"));
assertEquals("int", meta.fieldTypeName("intField"));
assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
builder = builder("org.test.MetaTest");
builder.setField("intField", 2);
builder.setField("uuidField", UUID.randomUUID());
po = builder.build();
meta = po.type();
assertEquals(expectedTypeName("org.test.MetaTest"), meta.typeName());
fields = meta.fieldNames();
assertEquals(3, fields.size());
assertTrue(fields.contains("intField"));
assertTrue(fields.contains("byteArrayField"));
assertTrue(fields.contains("uuidField"));
assertEquals("int", meta.fieldTypeName("intField"));
assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
assertEquals("UUID", meta.fieldTypeName("uuidField"));
}
use of org.apache.ignite.binary.BinaryType in project ignite by apache.
the class QueryBinaryProperty method binaryField.
/**
* 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;
}
Aggregations