1 | /* |
2 | * Copyright 2002-2013 the original author or authors. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
5 | * the License. You may obtain a copy of the License at |
6 | * |
7 | * http://www.apache.org/licenses/LICENSE-2.0 |
8 | * |
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
11 | * specific language governing permissions and limitations under the License. |
12 | */ |
13 | package org.springframework.batch.item.data; |
14 | |
15 | import org.springframework.batch.item.ItemWriter; |
16 | import org.springframework.batch.item.KeyValueItemWriter; |
17 | import org.springframework.data.gemfire.GemfireOperations; |
18 | import org.springframework.data.gemfire.GemfireTemplate; |
19 | import org.springframework.util.Assert; |
20 | |
21 | /** |
22 | * An {@link ItemWriter} that stores items in GemFire |
23 | * |
24 | * @author David Turanski |
25 | * @since 2.2 |
26 | * |
27 | */ |
28 | public class GemfireItemWriter<K,V> extends KeyValueItemWriter<K,V> { |
29 | private GemfireOperations gemfireTemplate; |
30 | /** |
31 | * @param gemfireTemplate the {@link GemfireTemplate} to set |
32 | */ |
33 | public void setTemplate(GemfireTemplate gemfireTemplate) { |
34 | this.gemfireTemplate = gemfireTemplate; |
35 | } |
36 | |
37 | /* (non-Javadoc) |
38 | * @see org.springframework.batch.item.KeyValueItemWriter#writeKeyValue(java.lang.Object, java.lang.Object) |
39 | */ |
40 | @Override |
41 | protected void writeKeyValue(K key, V value) { |
42 | if (delete) { |
43 | gemfireTemplate.remove(key); |
44 | } else { |
45 | gemfireTemplate.put(key, value); |
46 | } |
47 | } |
48 | |
49 | /* (non-Javadoc) |
50 | * @see org.springframework.batch.item.KeyValueItemWriter#init() |
51 | */ |
52 | @Override |
53 | protected void init() { |
54 | Assert.notNull(gemfireTemplate, "A GemfireTemplate is required."); |
55 | } |
56 | |
57 | } |