diff --git a/pom.xml b/pom.xml index 56c7bc75b..255645be8 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,6 @@ 2.13.4 - 3.0.0-SNAPSHOT 3.0.0-SNAPSHOT 3.0.0-SNAPSHOT 4.0.0-SNAPSHOT diff --git a/spring-batch-docs/src/main/asciidoc/appendix.adoc b/spring-batch-docs/src/main/asciidoc/appendix.adoc index 0338c768a..60cc0ed67 100644 --- a/spring-batch-docs/src/main/asciidoc/appendix.adoc +++ b/spring-batch-docs/src/main/asciidoc/appendix.adoc @@ -85,9 +85,6 @@ This reader stores message offsets in the execution context to support restart c in an injected `List` of `ItemWriter` objects. |`FlatFileItemWriter`|Writes to a flat file. Includes `ItemStream` and Skippable functionality. See link:readersAndWriters.html#flatFileItemWriter["`FlatFileItemWriter`"]. -|`GemfireItemWriter`|Using a `GemfireOperations` object, items are either written - or removed from the Gemfire instance based on the configuration of the delete - flag. |`HibernateItemWriter`|This item writer is Hibernate-session aware and handles some transaction-related work that a non-"`hibernate-aware`" item writer would not need to know about and then delegates diff --git a/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc b/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc index e49b95f69..9db545568 100644 --- a/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc +++ b/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc @@ -2933,7 +2933,6 @@ Spring Batch offers the following database writers: * <> * <> * <> -* <> [[neo4jItemWriter]] ===== `Neo4jItemWriter` @@ -2972,12 +2971,6 @@ The `JpaItemWriter` is an `ItemWriter` that uses a JPA `EntityManagerFactory` to any entities that are not part of the persistence context. Spring Batch provides a `JpaItemWriterBuilder` to construct an instance of the `JpaItemWriter`. -[[gemfireItemWriter]] -===== `GemfireItemWriter` -The `GemfireItemWriter` is an `ItemWriter` that uses a `GemfireTemplate` that stores -items in GemFire as key/value pairs. Spring Batch provides a `GemfireItemWriterBuilder` -to construct an instance of the `GemfireItemWriter`. - [[specializedReaders]] ==== Specialized Readers Spring Batch offers the following specialized readers: diff --git a/spring-batch-infrastructure/pom.xml b/spring-batch-infrastructure/pom.xml index 5aba4b252..1c73ba790 100644 --- a/spring-batch-infrastructure/pom.xml +++ b/spring-batch-infrastructure/pom.xml @@ -131,12 +131,6 @@ ${jakarta.persistence-api.version} true - - org.springframework.data - spring-data-geode - ${spring-data-geode.version} - true - org.springframework.data spring-data-commons diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/GemfireItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/GemfireItemWriter.java deleted file mode 100644 index 4921af899..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/GemfireItemWriter.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2002-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.batch.item.data; - -import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.item.KeyValueItemWriter; -import org.springframework.data.gemfire.GemfireOperations; -import org.springframework.data.gemfire.GemfireTemplate; -import org.springframework.util.Assert; - -/** - * An {@link ItemWriter} that stores items in GemFire - * - * @author David Turanski - * @since 2.2 - * - */ -public class GemfireItemWriter extends KeyValueItemWriter { - - private GemfireOperations gemfireTemplate; - - /** - * @param gemfireTemplate the {@link GemfireTemplate} to set - */ - public void setTemplate(GemfireTemplate gemfireTemplate) { - this.gemfireTemplate = gemfireTemplate; - } - - /* - * (non-Javadoc) - * - * @see - * org.springframework.batch.item.KeyValueItemWriter#writeKeyValue(java.lang.Object, - * java.lang.Object) - */ - @Override - protected void writeKeyValue(K key, V value) { - if (delete) { - gemfireTemplate.remove(key); - } - else { - gemfireTemplate.put(key, value); - } - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.item.KeyValueItemWriter#init() - */ - @Override - protected void init() { - Assert.notNull(gemfireTemplate, "A GemfireTemplate is required."); - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/SpELMappingGemfireItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/SpELMappingGemfireItemWriter.java deleted file mode 100644 index df8a547cd..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/SpELMappingGemfireItemWriter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2002-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.batch.item.data; - -import org.springframework.batch.item.SpELItemKeyMapper; -import org.springframework.util.Assert; - -/** - * A convenient {@link GemfireItemWriter} implementation that uses a - * {@link SpELItemKeyMapper} - * - * @author David Turanski - * @since 2.2 - */ -public class SpELMappingGemfireItemWriter extends GemfireItemWriter { - - /** - * A constructor that accepts a SpEL expression used to derive the key - * @param keyExpression - */ - SpELMappingGemfireItemWriter(String keyExpression) { - super(); - Assert.hasText(keyExpression, "a valid keyExpression is required."); - setItemKeyMapper(new SpELItemKeyMapper<>(keyExpression)); - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilder.java deleted file mode 100644 index 6c69493a8..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilder.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.item.data.builder; - -import org.springframework.batch.item.data.GemfireItemWriter; -import org.springframework.core.convert.converter.Converter; -import org.springframework.data.gemfire.GemfireTemplate; -import org.springframework.util.Assert; - -/** - * A builder implementation for the {@link GemfireItemWriter} - * - * @author Glenn Renfro - * @since 4.0 - * @see GemfireItemWriterBuilder - */ -public class GemfireItemWriterBuilder { - - private GemfireTemplate template; - - private Converter itemKeyMapper; - - private boolean delete; - - /** - * Establishes the GemfireTemplate the writer should use. - * @param template the {@link GemfireTemplate} to set. - * @return The current instance of the builder. - * @see GemfireItemWriter#setTemplate(GemfireTemplate) - */ - public GemfireItemWriterBuilder template(GemfireTemplate template) { - this.template = template; - - return this; - } - - /** - * Set the {@link Converter} to use to derive the key from the item. - * @param itemKeyMapper the Converter to use. - * @return The current instance of the builder. - * @see GemfireItemWriter#setItemKeyMapper(Converter) - */ - public GemfireItemWriterBuilder itemKeyMapper(Converter itemKeyMapper) { - this.itemKeyMapper = itemKeyMapper; - - return this; - } - - /** - * Indicates if the items being passed to the writer are to be saved or removed from - * the data store. If set to false (default), the items will be saved. If set to true, - * the items will be removed. - * @param delete removal indicator. - * @return The current instance of the builder. - * @see GemfireItemWriter#setDelete(boolean) - */ - public GemfireItemWriterBuilder delete(boolean delete) { - this.delete = delete; - - return this; - } - - /** - * Validates and builds a {@link GemfireItemWriter}. - * @return a {@link GemfireItemWriter} - */ - public GemfireItemWriter build() { - Assert.notNull(this.template, "template is required."); - Assert.notNull(this.itemKeyMapper, "itemKeyMapper is required."); - - GemfireItemWriter writer = new GemfireItemWriter<>(); - writer.setTemplate(this.template); - writer.setItemKeyMapper(this.itemKeyMapper); - writer.setDelete(this.delete); - return writer; - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java deleted file mode 100644 index 651627e56..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2013-2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.item.data; - -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import org.springframework.batch.item.Chunk; -import org.springframework.batch.item.SpELItemKeyMapper; -import org.springframework.data.gemfire.GemfireTemplate; -import org.springframework.core.convert.converter.Converter; - -@ExtendWith(MockitoExtension.class) -class GemfireItemWriterTests { - - private GemfireItemWriter writer; - - @Mock - private GemfireTemplate template; - - @BeforeEach - void setUp() throws Exception { - writer = new GemfireItemWriter<>(); - writer.setTemplate(template); - writer.setItemKeyMapper(new SpELItemKeyMapper<>("bar.val")); - writer.afterPropertiesSet(); - } - - @Test - void testAfterPropertiesSet() throws Exception { - writer = new GemfireItemWriter<>(); - assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet); - - writer.setTemplate(template); - assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet); - - writer.setItemKeyMapper(new SpELItemKeyMapper<>("foo")); - writer.afterPropertiesSet(); - } - - @Test - void testBasicWrite() throws Exception { - Chunk chunk = new Chunk() { - { - add(new Foo(new Bar("val1"))); - add(new Foo(new Bar("val2"))); - } - }; - - writer.write(chunk); - - List items = chunk.getItems(); - verify(template).put("val1", items.get(0)); - verify(template).put("val2", items.get(1)); - } - - @Test - void testBasicDelete() throws Exception { - Chunk chunk = new Chunk() { - { - add(new Foo(new Bar("val1"))); - add(new Foo(new Bar("val2"))); - } - }; - writer.setDelete(true); - writer.write(chunk); - - verify(template).remove("val1"); - verify(template).remove("val2"); - } - - @Test - void testWriteWithCustomItemKeyMapper() throws Exception { - Chunk chunk = new Chunk() { - { - add(new Foo(new Bar("val1"))); - add(new Foo(new Bar("val2"))); - } - }; - writer = new GemfireItemWriter<>(); - writer.setTemplate(template); - writer.setItemKeyMapper(new Converter() { - - @Override - public String convert(Foo item) { - String index = item.bar.val.replaceAll("val", ""); - return "item" + index; - } - }); - writer.afterPropertiesSet(); - writer.write(chunk); - - List items = chunk.getItems(); - verify(template).put("item1", items.get(0)); - verify(template).put("item2", items.get(1)); - } - - @Test - void testWriteNoTransactionNoItems() throws Exception { - writer.write(null); - verifyNoInteractions(template); - } - - static class Foo { - - public Bar bar; - - public Foo(Bar bar) { - this.bar = bar; - } - - } - - static class Bar { - - public String val; - - public Bar(String b1) { - this.val = b1; - } - - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java deleted file mode 100644 index 0ffe43a52..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2017-2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.item.data.builder; - -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import org.springframework.batch.item.Chunk; -import org.springframework.batch.item.SpELItemKeyMapper; -import org.springframework.batch.item.data.GemfireItemWriter; -import org.springframework.data.gemfire.GemfireTemplate; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - -/** - * @author Glenn Renfro - * @author Mahmoud Ben Hassine - */ -@ExtendWith(MockitoExtension.class) -class GemfireItemWriterBuilderTests { - - @Mock - private GemfireTemplate template; - - private SpELItemKeyMapper itemKeyMapper; - - private Chunk items; - - @BeforeEach - void setUp() { - this.items = Chunk.of(new GemfireItemWriterBuilderTests.Foo(new GemfireItemWriterBuilderTests.Bar("val1")), - new GemfireItemWriterBuilderTests.Foo(new GemfireItemWriterBuilderTests.Bar("val2"))); - this.itemKeyMapper = new SpELItemKeyMapper<>("bar.val"); - } - - @Test - void testBasicWrite() throws Exception { - GemfireItemWriter writer = new GemfireItemWriterBuilder() - .template(this.template).itemKeyMapper(this.itemKeyMapper).build(); - - writer.write(this.items); - - verify(this.template).put("val1", items.getItems().get(0)); - verify(this.template).put("val2", items.getItems().get(1)); - verify(this.template, never()).remove("val1"); - verify(this.template, never()).remove("val2"); - } - - @Test - void testBasicDelete() throws Exception { - GemfireItemWriter writer = new GemfireItemWriterBuilder() - .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.getItems().get(0)); - verify(this.template, never()).put("val2", items.getItems().get(1)); - } - - @Test - void testNullTemplate() { - var builder = new GemfireItemWriterBuilder() - .itemKeyMapper(this.itemKeyMapper); - Exception exception = assertThrows(IllegalArgumentException.class, builder::build); - assertEquals("template is required.", exception.getMessage()); - } - - @Test - void testNullItemKeyMapper() { - var builder = new GemfireItemWriterBuilder().template(this.template); - Exception exception = assertThrows(IllegalArgumentException.class, builder::build); - assertEquals("itemKeyMapper is required.", exception.getMessage()); - } - - static class Foo { - - public GemfireItemWriterBuilderTests.Bar bar; - - public Foo(GemfireItemWriterBuilderTests.Bar bar) { - this.bar = bar; - } - - } - - static class Bar { - - public String val; - - public Bar(String b1) { - this.val = b1; - } - - } - -}