Search in sources :

Example 6 with BinaryObjectException

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

the class BinaryUtils method doReadDecimalArray.

/**
     * @return Value.
     * @throws BinaryObjectException In case of error.
     */
public static BigDecimal[] doReadDecimalArray(BinaryInputStream in) throws BinaryObjectException {
    int len = in.readInt();
    BigDecimal[] arr = new BigDecimal[len];
    for (int i = 0; i < len; i++) {
        byte flag = in.readByte();
        if (flag == GridBinaryMarshaller.NULL)
            arr[i] = null;
        else {
            if (flag != GridBinaryMarshaller.DECIMAL)
                throw new BinaryObjectException("Invalid flag value: " + flag);
            arr[i] = doReadDecimal(in);
        }
    }
    return arr;
}
Also used : BigDecimal(java.math.BigDecimal) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 7 with BinaryObjectException

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

the class BinaryContext method descriptorForTypeId.

/**
     * @param userType User type or not.
     * @param typeId Type ID.
     * @param ldr Class loader.
     * @return Class descriptor.
     */
public BinaryClassDescriptor descriptorForTypeId(boolean userType, int typeId, ClassLoader ldr, boolean deserialize) {
    assert typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID;
    //TODO: As a workaround for IGNITE-1358 we always check the predefined map before without checking 'userType'
    BinaryClassDescriptor desc = predefinedTypes.get(typeId);
    if (desc != null)
        return desc;
    if (ldr == null)
        ldr = sysLdr;
    Class cls;
    try {
        cls = marshCtx.getClass(typeId, ldr);
        desc = descByCls.get(cls);
    } catch (ClassNotFoundException e) {
        // Class might have been loaded by default class loader.
        if (userType && !ldr.equals(sysLdr) && (desc = descriptorForTypeId(true, typeId, sysLdr, deserialize)) != null)
            return desc;
        throw new BinaryInvalidTypeException(e);
    } catch (IgniteCheckedException e) {
        // Class might have been loaded by default class loader.
        if (userType && !ldr.equals(sysLdr) && (desc = descriptorForTypeId(true, typeId, sysLdr, deserialize)) != null)
            return desc;
        throw new BinaryObjectException("Failed resolve class for ID: " + typeId, e);
    }
    if (desc == null) {
        desc = registerClassDescriptor(cls, deserialize);
        assert desc.typeId() == typeId : "Duplicate typeId [typeId=" + typeId + ", cls=" + cls + ", desc=" + desc + "]";
    }
    return desc;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryInvalidTypeException(org.apache.ignite.binary.BinaryInvalidTypeException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 8 with BinaryObjectException

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

the class BinaryReaderExImpl method findFieldByName.

/**
     * Try finding the field by name.
     *
     * @param name Field name.
     * @return Offset.
     */
public boolean findFieldByName(String name) {
    if (raw)
        throw new BinaryObjectException("Failed to read named field because reader is in raw mode.");
    assert dataStart != start;
    if (footerLen == 0)
        return false;
    if (userType) {
        int order;
        if (matching) {
            int expOrder = matchingOrder++;
            BinarySchema.Confirmation confirm = schema.confirmOrder(expOrder, name);
            switch(confirm) {
                case CONFIRMED:
                    // The best case: got order without ID calculation and (ID -> order) lookup.
                    if (expOrder == 0)
                        // When we read the very first field, position is set to start, hence this re-positioning.
                        streamPosition(dataStart);
                    return true;
                case REJECTED:
                    // Rejected, no more speculations are possible. Fallback to the slowest scenario.
                    matching = false;
                    order = schema.order(fieldId(name));
                    break;
                default:
                    // Field name is not know for this order. Need to calculate ID and repeat speculation.
                    assert confirm == BinarySchema.Confirmation.CLARIFY;
                    int id = fieldId(name);
                    int realId = schema.fieldId(expOrder);
                    if (id == realId) {
                        // IDs matched, cache field name inside schema.
                        schema.clarifyFieldName(expOrder, name);
                        if (expOrder == 0)
                            streamPosition(dataStart);
                        return true;
                    } else {
                        // No match, stop further speculations.
                        matching = false;
                        order = schema.order(id);
                    }
                    break;
            }
        } else
            order = schema.order(fieldId(name));
        return trySetUserFieldPosition(order);
    } else
        return trySetSystemFieldPosition(fieldId(name));
}
Also used : BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 9 with BinaryObjectException

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

the class BinaryReaderExImpl method rawReader.

/** {@inheritDoc} */
@Override
public BinaryRawReader rawReader() {
    if (!raw) {
        streamPositionRandom(rawOff);
        raw = true;
        return this;
    } else
        throw new BinaryObjectException("Method \"rawReader\" can be called only once.");
}
Also used : BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 10 with BinaryObjectException

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

the class BinaryEnumArrayLazyValue method init.

/** {@inheritDoc} */
@Override
protected Object init() {
    reader.position(valOff + 1);
    //skipping component type id
    reader.readInt();
    int size = reader.readInt();
    BinaryBuilderEnum[] res = new BinaryBuilderEnum[size];
    for (int i = 0; i < size; i++) {
        byte flag = reader.readByte();
        if (flag == GridBinaryMarshaller.NULL)
            continue;
        if (flag != GridBinaryMarshaller.ENUM)
            throw new BinaryObjectException("Invalid flag value: " + flag);
        res[i] = new BinaryBuilderEnum(reader);
    }
    return res;
}
Also used : 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