Search in sources :

Example 16 with BinaryObjectException

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

the class CacheObjectBinaryProcessorImpl method buildEnum.

/** {@inheritDoc} */
@Override
public BinaryObject buildEnum(String typeName, String name) throws BinaryObjectException {
    A.notNullOrEmpty(typeName, "enum type name");
    A.notNullOrEmpty(name, "enum name");
    int typeId = binaryCtx.typeId(typeName);
    BinaryMetadata metadata = metadata0(typeId);
    if (metadata == null)
        throw new BinaryObjectException("Failed to get metadata for type [typeId=" + typeId + ", typeName='" + typeName + "']");
    Integer ordinal = metadata.getEnumOrdinalByName(name);
    typeName = binaryCtx.userTypeName(typeName);
    if (ordinal == null)
        throw new BinaryObjectException("Failed to resolve enum ordinal by name [typeId=" + typeId + ", typeName='" + typeName + "', name='" + name + "']");
    return new BinaryEnumObjectImpl(binaryCtx, typeId, null, ordinal);
}
Also used : BinaryEnumObjectImpl(org.apache.ignite.internal.binary.BinaryEnumObjectImpl) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 17 with BinaryObjectException

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

the class CacheObjectBinaryProcessorImpl method metadata.

/** {@inheritDoc} */
@Override
public Map<Integer, BinaryType> metadata(Collection<Integer> typeIds) throws BinaryObjectException {
    try {
        Collection<BinaryMetadataKey> keys = new ArrayList<>(typeIds.size());
        for (Integer typeId : typeIds) keys.add(new BinaryMetadataKey(typeId));
        Map<Integer, BinaryType> res = U.newHashMap(metadataLocCache.size());
        for (Map.Entry<Integer, BinaryMetadataHolder> e : metadataLocCache.entrySet()) res.put(e.getKey(), e.getValue().metadata().wrap(binaryCtx));
        return res;
    } catch (CacheException e) {
        throw new BinaryObjectException(e);
    }
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) CacheException(javax.cache.CacheException) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 18 with BinaryObjectException

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

the class BinaryArrayIdentityResolver method equals0.

/** {@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());
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 19 with BinaryObjectException

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

the class BinaryClassDescriptor method constructor.

/**
     * @param cls Class.
     * @return Constructor.
     * @throws BinaryObjectException If constructor doesn't exist.
     */
@SuppressWarnings("ConstantConditions")
@Nullable
private static Constructor<?> constructor(Class<?> cls) throws BinaryObjectException {
    assert cls != null;
    try {
        Constructor<?> ctor = U.forceEmptyConstructor(cls);
        if (ctor == null)
            throw new BinaryObjectException("Failed to find empty constructor for class: " + cls.getName());
        ctor.setAccessible(true);
        return ctor;
    } catch (IgniteCheckedException e) {
        throw new BinaryObjectException("Failed to get constructor for class: " + cls.getName(), e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with BinaryObjectException

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

the class BinaryClassDescriptor method read.

/**
     * @param reader Reader.
     * @return Object.
     * @throws BinaryObjectException If failed.
     */
Object read(BinaryReaderExImpl reader) throws BinaryObjectException {
    try {
        assert reader != null;
        assert mode != BinaryWriteMode.OPTIMIZED : "OptimizedMarshaller should not be used here: " + cls.getName();
        Object res;
        switch(mode) {
            case BINARY:
                res = newInstance();
                reader.setHandle(res);
                if (serializer != null)
                    serializer.readBinary(res, reader);
                else
                    ((Binarylizable) res).readBinary(reader);
                break;
            case OBJECT:
                res = newInstance();
                reader.setHandle(res);
                for (BinaryFieldAccessor info : fields) info.read(res, reader);
                break;
            default:
                assert false : "Invalid mode: " + mode;
                return null;
        }
        if (readResolveMtd != null) {
            try {
                res = readResolveMtd.invoke(res);
                reader.setHandle(res);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InvocationTargetException e) {
                if (e.getTargetException() instanceof BinaryObjectException)
                    throw (BinaryObjectException) e.getTargetException();
                throw new BinaryObjectException("Failed to execute readResolve() method on " + res, e);
            }
        }
        return res;
    } catch (Exception e) {
        if (S.INCLUDE_SENSITIVE && !F.isEmpty(typeName))
            throw new BinaryObjectException("Failed to deserialize object [typeName=" + typeName + ']', e);
        else
            throw new BinaryObjectException("Failed to deserialize object [typeId=" + typeId + ']', e);
    }
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Aggregations

BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)42 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)9 BinaryObject (org.apache.ignite.binary.BinaryObject)8 Date (java.util.Date)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 BinarySerializer (org.apache.ignite.binary.BinarySerializer)4 BinaryType (org.apache.ignite.binary.BinaryType)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 BigInteger (java.math.BigInteger)2 Time (java.sql.Time)2 Timestamp (java.sql.Timestamp)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 BinaryBasicIdMapper (org.apache.ignite.binary.BinaryBasicIdMapper)2 BinaryInvalidTypeException (org.apache.ignite.binary.BinaryInvalidTypeException)2 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)2 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)2 BinaryEnumObjectImpl (org.apache.ignite.internal.binary.BinaryEnumObjectImpl)2