Search in sources :

Example 6 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class JdbcResultSetSelfTest method checkFieldPresenceInToString.

/**
     * Checks particular field from original binary object
     *
     * @param original binary object representation of original object
     * @param strToCheck string from result set, to be checked for presence of all fields
     * @param fieldName field name have being checked
     */
private static void checkFieldPresenceInToString(final BinaryObject original, final String strToCheck, final String fieldName) {
    final Object fieldVal = original.field(fieldName);
    String strValToSearch = Objects.toString(fieldVal);
    if (fieldVal != null) {
        final Class<?> aCls = fieldVal.getClass();
        if (aCls.isArray()) {
            final Class<?> elemCls = aCls.getComponentType();
            if (elemCls == Byte.TYPE)
                strValToSearch = Arrays.toString((byte[]) fieldVal);
        } else if (BinaryObject.class.isAssignableFrom(aCls)) {
            // hack to avoid search of unpredictable toString representation like
            // JdbcResultSetSelfTest$TestObjectField [idHash=1518952510, hash=11433031, a=100, b=AAAA]
            // in toString
            // other way to fix: iterate on binary object fields: final BinaryObject binVal = (BinaryObject)fieldVal;
            strValToSearch = "";
        }
    }
    assertTrue("Expected to find field " + fieldName + " having value " + strValToSearch + " in toString representation [" + strToCheck + "]", strToCheck.contains(fieldName + "=" + strValToSearch));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 7 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryObjectExImpl method toString.

/**
     * @param ctx Reader context.
     * @param handles Handles for already traversed objects.
     * @return String representation.
     */
private String toString(BinaryReaderHandles ctx, IdentityHashMap<BinaryObject, Integer> handles) {
    int idHash = System.identityHashCode(this);
    int hash = hashCode();
    BinaryType meta;
    try {
        meta = rawType();
    } catch (BinaryObjectException ignore) {
        meta = null;
    }
    if (meta == null || !S.INCLUDE_SENSITIVE)
        return S.toString(S.INCLUDE_SENSITIVE ? BinaryObject.class.getSimpleName() : "BinaryObject", "idHash", idHash, false, "hash", hash, false, "typeId", typeId(), true);
    handles.put(this, idHash);
    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);
            buf.a(", ").a(name).a('=');
            appendValue(val, buf, ctx, handles);
        }
        buf.a(']');
    }
    return buf.toString();
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 8 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryPlainBinaryObject method writeTo.

/** {@inheritDoc} */
@Override
public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
    BinaryObject val = binaryObj;
    if (val instanceof BinaryObjectOffheapImpl)
        val = ((BinaryObjectOffheapImpl) val).heapCopy();
    writer.doWriteBinaryObject((BinaryObjectImpl) val);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectOffheapImpl(org.apache.ignite.internal.binary.BinaryObjectOffheapImpl)

Example 9 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class GridCacheAffinityImpl method affinityKey.

/** {@inheritDoc} */
@Override
public Object affinityKey(K key) {
    A.notNull(key, "key");
    if (key instanceof CacheObject && !(key instanceof BinaryObject)) {
        CacheObjectContext ctx = cctx.cacheObjectContext();
        if (ctx == null)
            throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
        key = ((CacheObject) key).value(ctx, false);
    }
    CacheConfiguration ccfg = cctx.config();
    if (ccfg == null)
        throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
    return ccfg.getAffinityMapper().affinityKey(key);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteException(org.apache.ignite.IgniteException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 10 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class PlatformCompute method executeJavaTask.

/**
     * Execute task taking arguments from the given reader.
     *
     * @param reader Reader.
     * @param async Execute asynchronously flag.
     * @return Task result.
     * @throws IgniteCheckedException On error.
     */
protected Object executeJavaTask(BinaryRawReaderEx reader, boolean async) throws IgniteCheckedException {
    String taskName = reader.readString();
    boolean keepBinary = reader.readBoolean();
    Object arg = reader.readObjectDetached();
    Collection<UUID> nodeIds = readNodeIds(reader);
    IgniteCompute compute0 = computeForTask(nodeIds);
    if (!keepBinary && arg instanceof BinaryObjectImpl)
        arg = ((BinaryObject) arg).deserialize();
    if (async)
        return readAndListenFuture(reader, new ComputeConvertingFuture(compute0.executeAsync(taskName, arg)));
    else
        return toBinary(compute0.execute(taskName, arg));
}
Also used : BinaryObjectImpl(org.apache.ignite.internal.binary.BinaryObjectImpl) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) UUID(java.util.UUID) IgniteCompute(org.apache.ignite.IgniteCompute)

Aggregations

BinaryObject (org.apache.ignite.binary.BinaryObject)173 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)54 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)24 IgniteCache (org.apache.ignite.IgniteCache)21 Ignite (org.apache.ignite.Ignite)19 HashMap (java.util.HashMap)14 Map (java.util.Map)14 LinkedHashMap (java.util.LinkedHashMap)13 ArrayList (java.util.ArrayList)12 Cache (javax.cache.Cache)12 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)10 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)9 List (java.util.List)8 UUID (java.util.UUID)8 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)8 BigInteger (java.math.BigInteger)7 Date (java.util.Date)6 BinaryType (org.apache.ignite.binary.BinaryType)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 Transaction (org.apache.ignite.transactions.Transaction)6