/** * {@inheritDoc} */ @Override public Object process(MutableEntry<String, BinaryObject> mutableEntry, Object... objects) throws EntryProcessorException { BinaryObjectBuilder bob = mutableEntry.getValue().toBuilder(); for (int i = 0; i < flds.length; ++i) { bob.setField(flds[i], vals[i]); } mutableEntry.setValue(bob.build()); return null; } }
/** */ public BinaryObject testBinaryObject(BinaryObject o) { if (o == null) return null; return o.toBuilder().setField("field", 15).build(); } }
/** {@inheritDoc} */ @Override public Void process(MutableEntry<Integer, BinaryObject> entry, Object... arguments) throws EntryProcessorException { BinaryObjectBuilder bldr = entry.getValue().toBuilder(); Integer val = bldr.<Integer>getField("val"); bldr.setField("val", val + 1); bldr.setField("strVal", "updated-" + val); entry.setValue(bldr.build()); return null; } }
@Override public Object call() throws Exception { BinaryObject deposit = depositCache.get(depositKey); BigDecimal amount = deposit.field(BALANCE); BigDecimal rate = deposit.field(MARGIN_RATE); BigDecimal newBalance = amount.multiply(rate.add(BigDecimal.ONE)); deposit = deposit.toBuilder() .setField(BALANCE, newBalance) .build(); SqlFieldsQuery findDepositHist = new SqlFieldsQuery(LAST_HISTORY_ROW_SQL).setLocal(true); try (QueryCursor cursor1 = histCache.query(findDepositHist.setArgs(depositKey))) { for (Object o: cursor1){ // No-op. } } String depositHistKey = depositKey + "&histId=" + System.nanoTime(); BinaryObject depositHistRow = node.binary().builder(OPERATION) .setField(ID, depositHistKey) .setField(DEPOSIT_ID, depositKey) .setField(BUSINESS_DAY, new Date()) .setField(BALANCE, newBalance) .build(); histCache.put(depositHistKey, depositHistRow); depositCache.put(depositKey, deposit); return null; } });
/** * Checks that externalizable value is correctly serialized/deserialized. * * @throws Exception If failed. */ @Test public void testBuilderExternalizable() throws Exception { BinaryObjectBuilder builder = newWrapper("TestType"); final TestObjectExternalizable exp = new TestObjectExternalizable("test"); final TestObjectExternalizable[] expArr = new TestObjectExternalizable[]{ new TestObjectExternalizable("test1"), new TestObjectExternalizable("test2")}; BinaryObject extObj = builder.setField("extVal", exp).setField("extArr", expArr).build(); assertEquals(exp, extObj.field("extVal")); Assert.assertArrayEquals(expArr, (Object[])extObj.field("extArr")); builder = extObj.toBuilder(); extObj = builder.setField("intVal", 10).build(); assertEquals(exp, extObj.field("extVal")); Assert.assertArrayEquals(expArr, (Object[])extObj.field("extArr")); assertEquals(Integer.valueOf(10), extObj.field("intVal")); builder = extObj.toBuilder(); extObj = builder.setField("strVal", "some string").build(); assertEquals(exp, extObj.field("extVal")); Assert.assertArrayEquals(expArr, (Object[])extObj.field("extArr")); assertEquals(Integer.valueOf(10), extObj.field("intVal")); assertEquals("some string", extObj.field("strVal")); }