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));
}
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();
}
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);
}
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);
}
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));
}
Aggregations