/** * Calculate type ID for object. * * @param obj Object to calculate type ID for. * @return Type ID. * @throws CacheException If failed to calculate type ID for given object. */ @Override protected Object typeIdForObject(Object obj) throws CacheException { if (obj instanceof BinaryObject) return ((BinaryObjectEx)obj).typeId(); return obj.getClass(); }
/** {@inheritDoc} */ @Override protected boolean equals0(BinaryObject o1, BinaryObject o2) { if (o1 instanceof BinaryObjectEx && o2 instanceof BinaryObjectEx) { BinaryObjectEx ex1 = (BinaryObjectEx)o1; BinaryObjectEx ex2 = (BinaryObjectEx)o2; if (ex1.typeId() != ex2.typeId()) return false; if (ex1 instanceof BinaryObjectExImpl) { // Handle regular object. assert ex2 instanceof BinaryObjectExImpl; BinaryObjectExImpl exx1 = (BinaryObjectExImpl)ex1; BinaryObjectExImpl exx2 = (BinaryObjectExImpl)ex2; if (exx1.hasArray()) return exx2.hasArray() ? equalsHeap(exx1, exx2) : equalsHeapOffheap(exx1, exx2); else return exx2.hasArray() ? equalsHeapOffheap(exx2, exx1) : equalsOffheap(exx1, exx2); } else { // Handle enums. assert ex1 instanceof BinaryEnumObjectImpl; assert ex2 instanceof BinaryEnumObjectImpl; return ex1.enumOrdinal() == ex2.enumOrdinal(); } } BinaryObject o = o1 instanceof BinaryObjectEx ? o2 : o1; throw new BinaryObjectException("Array identity resolver cannot be used with provided BinaryObject " + "implementation: " + o.getClass().getName()); }
/** * 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; }
/** {@inheritDoc} */ @Nullable @Override public Object execute() { BinaryObjectEx arg0 = ((BinaryObjectEx)arg); BinaryType meta = ignite.binary().type(arg0.typeId()); if (meta == null) throw new IgniteException("Metadata doesn't exist."); if (meta.fieldNames() == null || !meta.fieldNames().contains("Field")) throw new IgniteException("Field metadata doesn't exist."); if (!F.eq("int", meta.fieldTypeName("Field"))) throw new IgniteException("Invalid field type: " + meta.fieldTypeName("Field")); if (meta.affinityKeyFieldName() != null) throw new IgniteException("Unexpected affinity key: " + meta.affinityKeyFieldName()); return arg0.field("field"); }
/** {@inheritDoc} */ @Override public int typeId(Object obj) { if (obj == null) return 0; return isBinaryObject(obj) ? ((BinaryObjectEx)obj).typeId() : typeId(obj.getClass().getSimpleName()); }
/** {@inheritDoc} */ @Override protected boolean equals0(BinaryObject o1, BinaryObject o2) { if (o1 instanceof BinaryObjectEx && o2 instanceof BinaryObjectEx) { BinaryObjectEx ex1 = (BinaryObjectEx)o1; BinaryObjectEx ex2 = (BinaryObjectEx)o2; if (ex1.typeId() != ex2.typeId()) return false; if (ex1 instanceof BinaryObjectExImpl) { // Handle regular object. assert ex2 instanceof BinaryObjectExImpl; BinaryObjectExImpl exx1 = (BinaryObjectExImpl)ex1; BinaryObjectExImpl exx2 = (BinaryObjectExImpl)ex2; if (exx1.hasArray()) return exx2.hasArray() ? equalsHeap(exx1, exx2) : equalsHeapOffheap(exx1, exx2); else return exx2.hasArray() ? equalsHeapOffheap(exx2, exx1) : equalsOffheap(exx1, exx2); } else { // Handle enums. assert ex1 instanceof BinaryEnumObjectImpl; assert ex2 instanceof BinaryEnumObjectImpl; return ex1.enumOrdinal() == ex2.enumOrdinal(); } } BinaryObject o = o1 instanceof BinaryObjectEx ? o2 : o1; throw new BinaryObjectException("Array identity resolver cannot be used with provided BinaryObject " + "implementation: " + o.getClass().getName()); }
/** * 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; }
/** * Create binary type which is used by users. * * @param ctx Context. * @param obj Binary object. * @return Binary type. */ public static BinaryType type(BinaryContext ctx, BinaryObjectEx obj) { if (ctx == null) throw new BinaryObjectException("BinaryContext is not set for the object."); return ctx.metadata(obj.typeId()); }
/** * Create binary type proxy. * * @param ctx Context. * @param obj Binary object. * @return Binary type proxy. */ public static BinaryType typeProxy(BinaryContext ctx, BinaryObjectEx obj) { if (ctx == null) throw new BinaryObjectException("BinaryContext is not set for the object."); String clsName = obj instanceof BinaryEnumObjectImpl ? ((BinaryEnumObjectImpl)obj).className() : null; return new BinaryTypeProxy(ctx, obj.typeId(), clsName); }
/** {@inheritDoc} */ @Override public Object affinityKey(Object key) { try { key = proc.toBinary(key, false); } catch (IgniteException e) { U.error(log, "Failed to marshal key to binary: " + key, e); } if (key instanceof BinaryObject) { assert key instanceof BinaryObjectEx : "All BinaryObject implementations must implement " + BinaryObjectEx.class.getName() + ": " + key.getClass().getName(); BinaryObjectEx key0 = (BinaryObjectEx)key; BinaryField affField = affinityKeyField(key0.typeId()); if (affField != null) { Object res = affField.value(key0); if (res != null) return res; } return key; } else return super.affinityKey(key); }
/** * Calculate type ID for object. * * @param obj Object to calculate type ID for. * @return Type ID. * @throws CacheException If failed to calculate type ID for given object. */ @Override protected Object typeIdForObject(Object obj) throws CacheException { if (obj instanceof BinaryObject) return ((BinaryObjectEx)obj).typeId(); return obj.getClass(); }
/** {@inheritDoc} */ @Override public int typeId(Object obj) { if (obj == null) return 0; return isBinaryObject(obj) ? ((BinaryObjectEx)obj).typeId() : typeId(obj.getClass().getSimpleName()); }
/** * Create binary type which is used by users. * * @param ctx Context. * @param obj Binary object. * @return Binary type. */ public static BinaryType type(BinaryContext ctx, BinaryObjectEx obj) { if (ctx == null) throw new BinaryObjectException("BinaryContext is not set for the object."); return ctx.metadata(obj.typeId()); }
/** * Create binary type proxy. * * @param ctx Context. * @param obj Binary object. * @return Binary type proxy. */ public static BinaryType typeProxy(BinaryContext ctx, BinaryObjectEx obj) { if (ctx == null) throw new BinaryObjectException("BinaryContext is not set for the object."); String clsName = obj instanceof BinaryEnumObjectImpl ? ((BinaryEnumObjectImpl)obj).className() : null; return new BinaryTypeProxy(ctx, obj.typeId(), clsName); }
/** {@inheritDoc} */ @Override public Object affinityKey(Object key) { try { key = proc.toBinary(key, false); } catch (IgniteException e) { U.error(log, "Failed to marshal key to binary: " + key, e); } if (key instanceof BinaryObject) { assert key instanceof BinaryObjectEx : "All BinaryObject implementations must implement " + BinaryObjectEx.class.getName() + ": " + key.getClass().getName(); BinaryObjectEx key0 = (BinaryObjectEx)key; BinaryField affField = affinityKeyField(key0.typeId()); if (affField != null) { Object res = affField.value(key0); if (res != null) return res; } return key; } else return super.affinityKey(key); }