use of org.apache.geode.pdx.internal.PdxInstanceImpl in project geode by apache.
the class PdxStringJUnitTest method testToString.
@Test
public void testToString() throws Exception {
String s = "abc";
PdxString pdx = new PdxString(s);
assertEquals(s, pdx.toString());
PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pf.writeString("secId", "abc");
PdxInstanceImpl pi = (PdxInstanceImpl) pf.create();
pdx = (PdxString) pi.getRawField("secId");
assertEquals(s, pdx.toString());
}
use of org.apache.geode.pdx.internal.PdxInstanceImpl in project geode by apache.
the class PdxStringJUnitTest method testJSONFieldNameAsNull.
@Test
public void testJSONFieldNameAsNull() throws Exception {
String verifyString = null;
String jsonString = "{name:null, age:14}";
PdxInstanceImpl pi = (PdxInstanceImpl) JSONFormatter.fromJSON(jsonString);
PdxString pdx = (PdxString) pi.getRawField("name");
assertEquals(verifyString, pdx);
}
use of org.apache.geode.pdx.internal.PdxInstanceImpl 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.internal.PdxInstanceImpl in project geode by apache.
the class AutoSerializableJUnitTest method testPrimitiveObjects.
@Test
public void testPrimitiveObjects() throws Exception {
setupSerializer(new PrimitiveObjectsAutoSerializer(true, "org.apache.geode.pdx.AutoSerializableJUnitTest.PrimitiveObjectHolder"), true);
PrimitiveObjectHolder nullHolder = new PrimitiveObjectHolder();
PrimitiveObjectHolder defaultHolder = new PrimitiveObjectHolder();
defaultHolder.bool = false;
defaultHolder.b = 0;
defaultHolder.c = 0;
defaultHolder.s = 0;
defaultHolder.i = 0;
defaultHolder.l = 0L;
defaultHolder.f = 0.0f;
defaultHolder.d = 0.0;
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(nullHolder, out);
PdxInstance pi = DataSerializer.readObject(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));
PdxField pf = ((PdxInstanceImpl) pi).getPdxField("f");
assertEquals(FieldType.FLOAT, pf.getFieldType());
Object dObj = pi.getObject();
assertFalse(nullHolder.equals(dObj));
assertEquals(defaultHolder, dObj);
out = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(defaultHolder, out);
pi = DataSerializer.readObject(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));
dObj = pi.getObject();
assertEquals(defaultHolder, dObj);
}
Aggregations