@Test public void testBasicDelete() throws Exception { GemfireItemWriter<String, GemfireItemWriterBuilderTests.Foo> writer = new GemfireItemWriterBuilder<String, GemfireItemWriterBuilderTests.Foo>() .template(this.template).delete(true).itemKeyMapper(this.itemKeyMapper).build(); writer.write(this.items); verify(this.template).remove("val1"); verify(this.template).remove("val2"); verify(this.template, never()).put("val1", items.get(0)); verify(this.template, never()).put("val2", items.get(1)); }
@Test public void testBasicWrite() throws Exception { GemfireItemWriter<String, GemfireItemWriterBuilderTests.Foo> writer = new GemfireItemWriterBuilder<String, GemfireItemWriterBuilderTests.Foo>() .template(this.template).itemKeyMapper(this.itemKeyMapper).build(); writer.write(this.items); verify(this.template).put("val1", items.get(0)); verify(this.template).put("val2", items.get(1)); verify(this.template, never()).remove("val1"); verify(this.template, never()).remove("val2"); }
@Test public void testWriteWithCustomItemKeyMapper() throws Exception { List<Foo> items = new ArrayList<Foo>() { { add(new Foo(new Bar("val1"))); add(new Foo(new Bar("val2"))); } }; writer = new GemfireItemWriter<>(); writer.setTemplate(template); writer.setItemKeyMapper(new Converter<Foo, String>() { @Override public String convert(Foo item) { String index = item.bar.val.replaceAll("val", ""); return "item" + index; } }); writer.afterPropertiesSet(); writer.write(items); verify(template).put("item1", items.get(0)); verify(template).put("item2", items.get(1)); }
@Override public <U extends T> U save(U entity) { ID id = this.entityInformation.getRequiredId(entity); this.template.put(id, entity); return entity; }
@Override public Customer save(Customer customer) { return customerTemplate.put(customer.getId(),customer); }
@Override public <U extends T> U save(U entity) { ID id = this.entityInformation.getRequiredId(entity); this.template.put(id, entity); return entity; }
@Override public Order save(Order order) { return orderTemplate.put(order.getId(), order); }
@Override public T save(Wrapper<T, ID> wrapper) { T entity = wrapper.getEntity(); this.template.put(wrapper.getKey(), entity); return entity; }
@Override public T save(Wrapper<T, ID> wrapper) { T entity = wrapper.getEntity(); this.template.put(wrapper.getKey(), entity); return entity; }
public void setResourceLabel(ResourceKey resource, String label) { PersistedResource r = getResource(resource); PersistedResource clone = r.cloneIfLabelDifferent(label); if (clone != r) { gemfire.put(new PersistedResourceKey(resource), clone); } }
public void syncProperties(ResourceProperties props) { PersistedResource r = getResource(props.getResourceKey()); PersistedResource clone = r.cloneIfPropsAreDifferent(props); if (clone != r) { gemfire.put(new PersistedResourceKey(props.getResourceKey()), clone); } }