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);
}
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;
}
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;
}
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;
}
Aggregations