Search in sources :

Example 16 with BinaryType

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);
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) BigDecimal(java.math.BigDecimal) IgniteUuid(org.apache.ignite.lang.IgniteUuid) Iterator(java.util.Iterator) BinaryObject(org.apache.ignite.binary.BinaryObject) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map)

Example 17 with BinaryType

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);
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) BinaryObjectEx(org.apache.ignite.internal.binary.BinaryObjectEx) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 18 with BinaryType

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);
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType)

Example 19 with BinaryType

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"));
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 20 with BinaryType

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;
}
Also used : BinaryField(org.apache.ignite.binary.BinaryField) BinaryType(org.apache.ignite.binary.BinaryType) BinaryObjectEx(org.apache.ignite.internal.binary.BinaryObjectEx)

Aggregations

BinaryType (org.apache.ignite.binary.BinaryType)24 BinaryObject (org.apache.ignite.binary.BinaryObject)8 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)4 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 BinaryField (org.apache.ignite.binary.BinaryField)3 BinaryObjectEx (org.apache.ignite.internal.binary.BinaryObjectEx)3 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)3 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)3 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Ignite (org.apache.ignite.Ignite)2 IgniteBinary (org.apache.ignite.IgniteBinary)2 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)2 SB (org.apache.ignite.internal.util.typedef.internal.SB)2 ConcurrentHashSet (org.eclipse.jetty.util.ConcurrentHashSet)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1