Search in sources :

Example 6 with PdxSerializationException

use of org.apache.geode.pdx.PdxSerializationException in project geode by apache.

the class CompiledOperation method eval0.

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED", justification = "Does not matter if the methodDispatch that isn't stored in the map is used")
private Object eval0(Object receiver, Class resolutionType, ExecutionContext context) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
    if (receiver == null || receiver == QueryService.UNDEFINED)
        return QueryService.UNDEFINED;
    List args = new ArrayList();
    List argTypes = new ArrayList();
    Iterator i = this.args.iterator();
    while (i.hasNext()) {
        CompiledValue arg = (CompiledValue) i.next();
        Object o = arg.evaluate(context);
        // undefined arg produces undefines method result
        if (o == QueryService.UNDEFINED)
            return QueryService.UNDEFINED;
        args.add(o);
        // pass in null for the type if the runtime value is null
        if (o == null)
            argTypes.add(null);
        else
            // commented out because we currently always use the runtime type for args
            // else if (arg.getType() == Identifier)
            // {
            // CompiledValue resolved = context.resolve(((CompiledID)arg).getId());
            // if (resolved != null && resolved.getType() == ITERATOR)
            // argTypes.add(((RuntimeIterator)resolved).getBaseCollection().getConstraint());
            // else
            // argTypes.add(o.getClass());
            // }
            // otherwise use the runtime type
            argTypes.add(o.getClass());
    }
    // see if in cache
    MethodDispatch methodDispatch;
    List key = Arrays.asList(new Object[] { resolutionType, this.methodName, argTypes });
    methodDispatch = (MethodDispatch) CompiledOperation.cache.get(key);
    if (methodDispatch == null) {
        try {
            methodDispatch = new MethodDispatch(resolutionType, this.methodName, argTypes);
        } catch (NameResolutionException nre) {
            if (!org.apache.geode.cache.query.Struct.class.isAssignableFrom(resolutionType) && (DefaultQueryService.QUERY_HETEROGENEOUS_OBJECTS || DefaultQueryService.TEST_QUERY_HETEROGENEOUS_OBJECTS)) {
                return QueryService.UNDEFINED;
            } else {
                throw nre;
            }
        }
        // cache
        CompiledOperation.cache.putIfAbsent(key, methodDispatch);
    }
    if (receiver instanceof PdxInstance) {
        try {
            if (receiver instanceof PdxInstanceImpl) {
                receiver = ((PdxInstanceImpl) receiver).getCachedObject();
            } else {
                receiver = ((PdxInstance) receiver).getObject();
            }
        } catch (PdxSerializationException ex) {
            throw new QueryInvocationTargetException(ex);
        }
    } else if (receiver instanceof PdxString) {
        receiver = ((PdxString) receiver).toString();
    }
    return methodDispatch.invoke(receiver, args);
}
Also used : ArrayList(java.util.ArrayList) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) PdxString(org.apache.geode.pdx.internal.PdxString) PdxSerializationException(org.apache.geode.pdx.PdxSerializationException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) PdxInstance(org.apache.geode.pdx.PdxInstance) PdxInstanceImpl(org.apache.geode.pdx.internal.PdxInstanceImpl) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with PdxSerializationException

use of org.apache.geode.pdx.PdxSerializationException in project geode by apache.

the class PdxWriterImpl method markIdentityField.

public PdxWriter markIdentityField(String fieldName) {
    if (definingNewPdxType()) {
        PdxField ft = this.newType.getPdxField(fieldName);
        if (ft == null) {
            throw new PdxFieldDoesNotExistException("Field " + fieldName + " must be written before calling markIdentityField");
        }
        ft.setIdentityField(true);
    } else if (doExtraValidation()) {
        PdxField ft = this.existingType.getPdxField(fieldName);
        if (ft == null) {
            throw new PdxFieldDoesNotExistException("Field " + fieldName + " must be written before calling markIdentityField");
        } else if (!ft.isIdentityField()) {
            throw new PdxSerializationException("Expected field " + fieldName + " to not be marked as an identity field since it was not for the first serialization");
        }
    }
    return this;
}
Also used : PdxSerializationException(org.apache.geode.pdx.PdxSerializationException) PdxFieldDoesNotExistException(org.apache.geode.pdx.PdxFieldDoesNotExistException)

Example 8 with PdxSerializationException

use of org.apache.geode.pdx.PdxSerializationException in project geode by apache.

the class PdxReaderImpl method basicGetObject.

protected Object basicGetObject() {
    String pdxClassName = getPdxType().getClassName();
    Class<?> pdxClass = getPdxType().getPdxClass();
    {
        AutoClassInfo ci = getPdxType().getAutoInfo(pdxClass);
        if (ci != null) {
            Object obj = ci.newInstance(pdxClass);
            this.orderedDeserialize(obj, ci);
            return obj;
        }
    }
    PdxReader pdxReader = this;
    // only create a tracking one if we might need it
    UnreadPdxType unreadLocalPdxType = null;
    boolean needToTrackReads = TESTHOOK_TRACKREADS;
    InternalCache cache = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.");
    TypeRegistry tr = cache.getPdxRegistry();
    if (!cache.getPdxIgnoreUnreadFields()) {
        PdxType localPdxType = tr.getExistingTypeForClass(pdxClass);
        if (localPdxType != null) {
            if (getPdxType().getTypeId() != localPdxType.getTypeId() && getPdxType().hasExtraFields(localPdxType)) {
                // we could calculate the extra fields here
                needToTrackReads = true;
            }
        } else {
            // we don't know what our local type would be
            needToTrackReads = true;
        }
    }
    if (needToTrackReads) {
        unreadLocalPdxType = tr.getExistingTypeForClass(pdxClass, getPdxType().getTypeId());
        if (unreadLocalPdxType != null) {
            needToTrackReads = false;
        } else {
            pdxReader = new TrackingPdxReaderImpl(this, tr, pdxClass);
        }
    }
    Object result;
    if (PdxSerializable.class.isAssignableFrom(pdxClass)) {
        try {
            result = pdxClass.newInstance();
        } catch (Exception e) {
            PdxSerializationException ex = new PdxSerializationException(LocalizedStrings.DataSerializer_COULD_NOT_CREATE_AN_INSTANCE_OF_A_CLASS_0.toLocalizedString(pdxClassName), e);
            throw ex;
        }
        ((PdxSerializable) result).fromData(pdxReader);
    } else {
        PdxSerializer pdxSerializer = cache.getPdxSerializer();
        if (pdxSerializer != null) {
            result = pdxSerializer.fromData(pdxClass, pdxReader);
            if (result == null) {
                throw new PdxSerializationException("Could not deserialize pdx because the pdx serializer's fromData returned false for a pdx of class " + pdxClassName);
            }
        } else {
            throw new PdxSerializationException("Could not deserialize pdx because a PdxSerializer does not exist.");
        }
    }
    {
        PdxUnreadData ud = getReadUnreadFieldsCalled();
        if (ud != null) {
            // User called PdxReader.readUnreadFields()
            if (unreadLocalPdxType != null) {
                if (unreadLocalPdxType.getUnreadFieldIndexes() != null) {
                    ud.initialize(unreadLocalPdxType, this);
                }
            } else if (needToTrackReads) {
                ((TrackingPdxReaderImpl) pdxReader).internalReadUnreadFields(ud);
            }
        } else {
            if (needToTrackReads) {
                ud = ((TrackingPdxReaderImpl) pdxReader).internalReadUnreadFields(new PdxUnreadData());
                if (ud != null && !ud.isEmpty()) {
                    tr.putUnreadData(result, ud);
                }
            } else if (unreadLocalPdxType != null) {
                if (unreadLocalPdxType.getUnreadFieldIndexes() != null) {
                    tr.putUnreadData(result, new PdxUnreadData(unreadLocalPdxType, this));
                }
            }
        }
    }
    return result;
}
Also used : PdxSerializer(org.apache.geode.pdx.PdxSerializer) PdxReader(org.apache.geode.pdx.PdxReader) InternalCache(org.apache.geode.internal.cache.InternalCache) PdxSerializationException(org.apache.geode.pdx.PdxSerializationException) IOException(java.io.IOException) PdxSerializationException(org.apache.geode.pdx.PdxSerializationException) PdxFieldTypeMismatchException(org.apache.geode.pdx.PdxFieldTypeMismatchException) InternalGemFireException(org.apache.geode.InternalGemFireException) AutoClassInfo(org.apache.geode.pdx.internal.AutoSerializableManager.AutoClassInfo) PdxSerializable(org.apache.geode.pdx.PdxSerializable)

Example 9 with PdxSerializationException

use of org.apache.geode.pdx.PdxSerializationException in project geode by apache.

the class PdxInstanceImpl method createDis.

private static PdxInputStream createDis(DataInput in, int len) {
    PdxInputStream dis;
    if (in instanceof PdxInputStream) {
        dis = new PdxInputStream((ByteBufferInputStream) in, len);
        try {
            int bytesSkipped = in.skipBytes(len);
            int bytesRemaining = len - bytesSkipped;
            while (bytesRemaining > 0) {
                in.readByte();
                bytesRemaining--;
            }
        } catch (IOException ex) {
            throw new PdxSerializationException("Could not deserialize PDX", ex);
        }
    } else {
        byte[] bytes = new byte[len];
        try {
            in.readFully(bytes);
        } catch (IOException ex) {
            throw new PdxSerializationException("Could not deserialize PDX", ex);
        }
        dis = new PdxInputStream(bytes);
    }
    return dis;
}
Also used : ByteBufferInputStream(org.apache.geode.internal.tcp.ByteBufferInputStream) IOException(java.io.IOException) PdxSerializationException(org.apache.geode.pdx.PdxSerializationException)

Aggregations

PdxSerializationException (org.apache.geode.pdx.PdxSerializationException)9 IOException (java.io.IOException)6 PdxInstance (org.apache.geode.pdx.PdxInstance)3 InternalGemFireException (org.apache.geode.InternalGemFireException)2 StoredObject (org.apache.geode.internal.offheap.StoredObject)2 PdxSerializable (org.apache.geode.pdx.PdxSerializable)2 PdxSerializer (org.apache.geode.pdx.PdxSerializer)2 PdxInstanceImpl (org.apache.geode.pdx.internal.PdxInstanceImpl)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CacheException (org.apache.geode.cache.CacheException)1 Region (org.apache.geode.cache.Region)1 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)1 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)1 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 MemoryAllocator (org.apache.geode.internal.offheap.MemoryAllocator)1 Retained (org.apache.geode.internal.offheap.annotations.Retained)1