/** * Unwraps cache object, if needed. * * @param o Object to unwrap. * @return Unwrapped object. */ private Object unwrap(Object o) { return coCtx == null ? o : o instanceof CacheObject ? ((CacheObject)o).value(coCtx, false) : o; }
/** {@inheritDoc} */ @Override public V value(CacheObjectValueContext ctx) { return val != null ? val.<V>value(ctx, false) : null; }
/** * @param cpy Copy flag. * @return Value. */ public Object getObject(boolean cpy) { return obj.isPlatformType() ? obj.value(valCtx, cpy) : obj; }
/** * @param key Key. * @return Affinity key. */ private Object affinityKey(Object key) { if (key instanceof CacheObject && !(key instanceof BinaryObject)) key = ((CacheObject)key).value(cacheObjCtx, false); return mapper.affinityKey(key); }
/** * @param cacheObj Cache object. * @param ctx Cache context. * @param cpy Copy flag. * @return Cache object value. */ @Nullable public static <T> T value(@Nullable CacheObject cacheObj, GridCacheContext ctx, boolean cpy) { return cacheObj != null ? cacheObj.<T>value(ctx.cacheObjectContext(), cpy) : null; }
/** * Isolated method to get length of IGFS block. * * @param cctx Cache context. * @param val Value. * @return Length of value. */ private int valueLength(GridCacheContext cctx, @Nullable CacheObject val) { if (val == null) return 0; byte[] bytes = val.value(cctx.cacheObjectContext(), false); if (bytes != null) return bytes.length; else return 0; }
/** {@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; }
/** * Unwrap CacheObject if needed. */ private Object unwrapIfNeeded(CacheObject obj, CacheObjectContext coctx) { return isIndexingSpiAllowsBinary && cctx.cacheObjects().isBinaryObject(obj) ? obj : obj.value(coctx, false); }
/** * If Key is {@link GridCacheInternal GridCacheInternal} entry when won't passed into user's mapper and * will use {@link GridCacheDefaultAffinityKeyMapper default}. * * @param key Key. * @return Affinity key. */ public Object affinityKey(Object key) { CacheObjectContext coCtx = cctx.cacheObjectContext(); if (key instanceof CacheObject && !(key instanceof BinaryObject)) key = ((CacheObject)key).value(coCtx, false); return (key instanceof GridCacheInternal ? coCtx.defaultAffMapper() : affMapper).affinityKey(key); }
/** * @return Peeks value. */ @Nullable public V peek() { try { CacheObject val = cached.peek(); return val != null ? val.<V>value(cached.context().cacheObjectContext(), false) : null; } catch (GridCacheEntryRemovedException ignored) { return null; } catch (IgniteCheckedException e) { throw new IgniteException(e); } }
/** * Gets type descriptor for cache by given object's type. * * @param cacheName Cache name. * @param val Object to determine type for. * @return Type descriptor. * @throws IgniteCheckedException If failed. */ @SuppressWarnings("ConstantConditions") private QueryTypeDescriptorImpl type(@Nullable String cacheName, CacheObject val) throws IgniteCheckedException { CacheObjectContext coctx = cacheObjectContext(cacheName); QueryTypeIdKey id; boolean binaryVal = ctx.cacheObjects().isBinaryObject(val); if (binaryVal) id = new QueryTypeIdKey(cacheName, ctx.cacheObjects().typeId(val)); else id = new QueryTypeIdKey(cacheName, val.value(coctx, false).getClass()); return types.get(id); }
/** * @param col Collection. * @param ctx Cache context. * @throws IgniteCheckedException If failed. */ protected final void prepareMarshalCacheObjects(@Nullable Collection<? extends CacheObject> col, GridCacheContext ctx) throws IgniteCheckedException { if (col == null) return; for (CacheObject obj : col) { if (obj != null) { obj.prepareMarshal(ctx.cacheObjectContext()); if (addDepInfo) prepareObject(obj.value(ctx.cacheObjectContext(), false), ctx.shared()); } } }
/** {@inheritDoc} */ @Override public Object unwrappedValue() { try { if (val == null) return null; if (keepBinary && val instanceof BinaryObject) return val; return val.value(cacheObjValCtx, false); } catch (Exception e) { cacheObjValCtx.kernalContext().log(UnwrapDataEntry.class) .error("Unable to convert value [" + value() + "]", e); return null; } }
/** {@inheritDoc} */ @Override public Object unwrappedValue() { try { if (val == null) return null; if (keepBinary && val instanceof BinaryObject) return val; return val.value(cacheObjValCtx, false); } catch (Exception e) { cacheObjValCtx.kernalContext().log(UnwrapMvccDataEntry.class) .error("Unable to convert value [" + value() + "]", e); return null; } }
/** * @param obj Object. * @param ctx Context. * @throws IgniteCheckedException If failed. */ protected final void prepareMarshalCacheObject(CacheObject obj, GridCacheContext ctx) throws IgniteCheckedException { if (obj != null) { obj.prepareMarshal(ctx.cacheObjectContext()); if (addDepInfo) prepareObject(obj.value(ctx.cacheObjectContext(), false), ctx.shared()); } }
/** * @return Entry which holds key, value and version. */ private <K, V> CacheEntryImplEx<K, V> wrapVersionedWithValue() { lockEntry(); try { V val = this.val == null ? null : this.val.<V>value(cctx.cacheObjectContext(), false); return new CacheEntryImplEx<>(key.<K>value(cctx.cacheObjectContext(), false), val, ver); } finally { unlockEntry(); } }
/** * @param o Object to unwrap. * @return Unwrapped object. */ private static Object unwrapBinary(CacheObjectValueContext ctx, Object o, boolean keepBinary, boolean cpy) { if (o == null) return o; while (BinaryUtils.knownCacheObject(o)) { CacheObject co = (CacheObject)o; if (!co.isPlatformType() && keepBinary) return o; // It may be a collection of binaries o = co.value(ctx, cpy); } if (BinaryUtils.knownCollection(o)) return unwrapKnownCollection(ctx, (Collection<Object>)o, keepBinary, cpy); else if (BinaryUtils.knownMap(o)) return unwrapBinariesIfNeeded(ctx, (Map<Object, Object>)o, keepBinary, cpy); else if (o instanceof Object[]) return unwrapBinariesInArrayIfNeeded(ctx, (Object[])o, keepBinary, cpy); return o; }
/** {@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); }
/** * @param cctx Context. * @param row Row. * @param expKey Expected row key. * @param expVal Expected row value. */ private void checkRow(GridCacheContext cctx, CacheDataRow row, KeyCacheObject expKey, Object expVal) { assertNotNull(row); assertEquals(expKey, row.key()); assertEquals(expVal, row.value().value(cctx.cacheObjectContext(), false)); }
/** * @param info Entry to marshal. * @param ctx Context. * @param cacheObjCtx Cache object context. * @throws IgniteCheckedException If failed. */ protected final void marshalInfo(GridCacheEntryInfo info, GridCacheSharedContext ctx, CacheObjectContext cacheObjCtx ) throws IgniteCheckedException { assert ctx != null; if (info != null) { info.marshal(cacheObjCtx); if (addDepInfo) { if (info.key() != null) prepareObject(info.key().value(cacheObjCtx, false), ctx); CacheObject val = info.value(); if (val != null) { val.finishUnmarshal(cacheObjCtx, ctx.deploy().globalLoader()); prepareObject(val.value(cacheObjCtx, false), ctx); } } } }