public void testWriteField() throws IOException, ClassNotFoundException { PdxInstanceFactory c = PdxInstanceFactoryImpl.newCreator("byteField", false); c.writeField("f", (byte)37, Byte.class); WritablePdxInstance pi = c.create().createWriter(); assertEquals((byte)37, pi.getField("f")); pi.setField("f", (byte)38); pi = c.create().createWriter(); assertEquals(true, pi.getField("f")); pi.setField("f", false); pi = c.create().createWriter(); assertEquals((char)37, pi.getField("f")); pi.setField("f", (char)38); pi = c.create().createWriter(); assertEquals((short)37, pi.getField("f")); pi.setField("f", (short)38); pi = c.create().createWriter(); assertEquals((int)37, pi.getField("f")); pi.setField("f", (int)38); pi = c.create().createWriter(); assertEquals((long)37, pi.getField("f")); pi.setField("f", (long)38); pi = c.create().createWriter(); assertEquals((float)37, pi.getField("f")); pi.setField("f", (float)38);
public void testNestedPdxInstance() throws IOException, ClassNotFoundException { PdxInstanceFactory c = PdxInstanceFactoryImpl.newCreator("testNestedPdxInstanceChild", false); c.writeField("f", 37, int.class); PdxInstance child = c.create(); c = PdxInstanceFactoryImpl.newCreator("testNestedPdxInstanceParent", false); c.writeObject("f", child); WritablePdxInstance parent = c.create().createWriter(); checkPdxInstance(child); checkPdxInstance(parent); WritablePdxInstance child2 = ((PdxInstance)parent.getField("f")).createWriter(); assertEquals(child, child2); assertTrue(child != child2); child2.setField("f", 38); assertFalse(child.equals(child2)); assertEquals(child, parent.getField("f")); parent.setField("f", child2); assertFalse(child.equals(parent.getField("f"))); assertEquals(child2, parent.getField("f")); PdxInstance parentCopy = checkPdxInstance(parent); assertEquals(child2, parentCopy.getField("f")); }
public void testWritePrimitiveField() throws IOException, ClassNotFoundException { PdxInstanceFactory c = PdxInstanceFactoryImpl.newCreator("byteField", false); c.writeField("f", (byte)37, byte.class); WritablePdxInstance pi = c.create().createWriter(); assertEquals((byte)37, pi.getField("f")); pi.setField("f", (byte)38); pi = c.create().createWriter(); assertEquals(true, pi.getField("f")); pi.setField("f", false); pi = c.create().createWriter(); assertEquals((char)37, pi.getField("f")); pi.setField("f", (char)38); pi = c.create().createWriter(); assertEquals((short)37, pi.getField("f")); pi.setField("f", (short)38); pi = c.create().createWriter(); assertEquals((int)37, pi.getField("f")); pi.setField("f", (int)38); pi = c.create().createWriter(); assertEquals((long)37, pi.getField("f")); pi.setField("f", (long)38); pi = c.create().createWriter(); assertEquals((float)37, pi.getField("f")); pi.setField("f", (float)38);
Log.getLogWriter().info("updating " + key + " with WritablePdxInstance to " + updatedValue); PdxInstance pdxInst = (PdxInstance)newValue; WritablePdxInstance writable = pdxInst.createWriter(); writable.setField("myValue", updatedValue); newValue = writable; Log.getLogWriter().info("replacing " + key + " with WritablePdxInstance to " + updatedValue); PdxInstance pdxInst = (PdxInstance)newValue; WritablePdxInstance writable = pdxInst.createWriter(); writable.setField("myValue", updatedValue); newValue = writable; Log.getLogWriter().info("updating " + key + " with WritablePdxInstance to " + updatedValue); PdxInstance pdxInst = (PdxInstance)newValue; WritablePdxInstance writable = pdxInst.createWriter(); writable.setField("myValue", updatedValue); newValue = writable; Log.getLogWriter().info("replacing " + key + " with WritablePdxInstance to " + updatedValue); PdxInstance pdxInst = (PdxInstance)newValue; WritablePdxInstance writable = pdxInst.createWriter(); writable.setField("myValue", updatedValue); newValue = writable;
public void testObjectPdxInstance() throws IOException, ClassNotFoundException { DefaultQuery.setPdxReadSerialized(true); PdxReaderImpl.TESTHOOK_TRACKREADS = true; try { PdxInstance pi = (PdxInstance) serializeAndDeserialize(new ObjectHolder("hello")); ObjectHolder v3 = (ObjectHolder)pi.getObject(); WritablePdxInstance wpi = pi.createWriter(); wpi.setField("f1", "goodbye"); assertEquals("goodbye", wpi.getField("f1")); ObjectHolder v = (ObjectHolder)wpi.getObject(); ObjectHolder v2 = (ObjectHolder)wpi.getObject(); assertEquals("goodbye", v.getObject()); assertEquals("goodbye", v2.getObject()); assertEquals("hello", v3.getObject()); assertEquals("goodbye", wpi.getField("f1")); } finally { DefaultQuery.setPdxReadSerialized(false); PdxReaderImpl.TESTHOOK_TRACKREADS = false; } } public void testObjectArrayPdxInstance() throws IOException, ClassNotFoundException {
public void testFieldTypes() throws IOException, ClassNotFoundException { PdxInstanceFactory c = PdxInstanceFactoryImpl.newCreator("byteField", false); c.writeByte("f", (byte)37); WritablePdxInstance pi = c.create().createWriter(); assertEquals((byte)37, pi.getField("f")); try { pi = c.create().createWriter(); assertEquals(true, pi.getField("f")); try { pi = c.create().createWriter(); assertEquals((char)37, pi.getField("f")); try { pi = c.create().createWriter(); assertEquals((short)37, pi.getField("f")); try { pi = c.create().createWriter(); assertEquals((int)37, pi.getField("f")); try { pi = c.create().createWriter(); assertEquals((long)37, pi.getField("f")); try { pi = c.create().createWriter(); assertEquals((float)37, pi.getField("f")); try {
if (getObj instanceof PdxInstance) { // we can return a PdxInstance to put PdxInstance pdxInst = (PdxInstance)getObj; WritablePdxInstance writablePdxInst = pdxInst.createWriter(); writablePdxInst.setField("myValue", vh.myValue); writablePdxInst.setField("extraObject", vh.extraObject);
public void testBasics() throws IOException, ClassNotFoundException { PdxInstanceFactory c = PdxInstanceFactoryImpl.newCreator("basics", false); c.writeInt("intField", 37); PdxInstance pi = c.create(); WritablePdxInstance wpi = pi.createWriter(); assertEquals(true, wpi.hasField("intField")); assertEquals(37, wpi.getField("intField")); assertEquals(false, wpi.isIdentityField("intField")); wpi.setField("intField", 38); assertEquals(38, wpi.getField("intField")); checkPdxInstance(wpi); PdxType t1 = ((PdxInstanceImpl)pi).getPdxType(); PdxInstanceFactory c2 = PdxInstanceFactoryImpl.newCreator("basics", false); c2.writeInt("intField", 46); PdxInstance pi2 = c2.create(); PdxType t2 = ((PdxInstanceImpl)pi2).getPdxType(); assertEquals(t1, t2); assertEquals(t1.getTypeId(), t2.getTypeId()); } public void testEnums() throws IOException, ClassNotFoundException {
c.writeInt("intField3", 3); c.markIdentityField("intField1"); WritablePdxInstance pi = c.create().createWriter(); assertEquals(true, pi.hasField("intField1")); assertEquals(true, pi.hasField("intField2"));