Remove Gemfire support in Spring Batch
Based on the decision to discontinue the support of Spring Data for Apache Geode [1], this commit removes the support for Geode in Spring Batch. The code will be moved to the spring-batch-extensions repository as a community-driven effort. [1]: https://github.com/spring-projects/spring-data-geode#notice Resolves #4214
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -59,7 +59,6 @@
|
||||
|
||||
<!-- optional production dependencies -->
|
||||
<jackson.version>2.13.4</jackson.version>
|
||||
<spring-data-geode.version>3.0.0-SNAPSHOT</spring-data-geode.version>
|
||||
<spring-data-commons.version>3.0.0-SNAPSHOT</spring-data-commons.version>
|
||||
<spring-data-jpa.version>3.0.0-SNAPSHOT</spring-data-jpa.version>
|
||||
<spring-data-mongodb.version>4.0.0-SNAPSHOT</spring-data-mongodb.version>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2933,7 +2933,6 @@ Spring Batch offers the following database writers:
|
||||
* <<hibernateItemWriter>>
|
||||
* <<jdbcBatchItemWriter>>
|
||||
* <<jpaItemWriter>>
|
||||
* <<gemfireItemWriter>>
|
||||
|
||||
[[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:
|
||||
|
||||
@@ -131,12 +131,6 @@
|
||||
<version>${jakarta.persistence-api.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-geode</artifactId>
|
||||
<version>${spring-data-geode.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-commons</artifactId>
|
||||
|
||||
@@ -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<K, V> extends KeyValueItemWriter<K, V> {
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<K, V> extends GemfireItemWriter<K, V> {
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<K, V> {
|
||||
|
||||
private GemfireTemplate template;
|
||||
|
||||
private Converter<V, K> 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<K, V> 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<K, V> itemKeyMapper(Converter<V, K> 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<K, V> delete(boolean delete) {
|
||||
this.delete = delete;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and builds a {@link GemfireItemWriter}.
|
||||
* @return a {@link GemfireItemWriter}
|
||||
*/
|
||||
public GemfireItemWriter<K, V> build() {
|
||||
Assert.notNull(this.template, "template is required.");
|
||||
Assert.notNull(this.itemKeyMapper, "itemKeyMapper is required.");
|
||||
|
||||
GemfireItemWriter<K, V> writer = new GemfireItemWriter<>();
|
||||
writer.setTemplate(this.template);
|
||||
writer.setItemKeyMapper(this.itemKeyMapper);
|
||||
writer.setDelete(this.delete);
|
||||
return writer;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String, Foo> 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<Foo> chunk = new Chunk<Foo>() {
|
||||
{
|
||||
add(new Foo(new Bar("val1")));
|
||||
add(new Foo(new Bar("val2")));
|
||||
}
|
||||
};
|
||||
|
||||
writer.write(chunk);
|
||||
|
||||
List<Foo> items = chunk.getItems();
|
||||
verify(template).put("val1", items.get(0));
|
||||
verify(template).put("val2", items.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBasicDelete() throws Exception {
|
||||
Chunk<Foo> chunk = new Chunk<Foo>() {
|
||||
{
|
||||
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<Foo> chunk = new Chunk<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(chunk);
|
||||
|
||||
List<Foo> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String, GemfireItemWriterBuilderTests.Foo> itemKeyMapper;
|
||||
|
||||
private Chunk<Foo> 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<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.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<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.getItems().get(0));
|
||||
verify(this.template, never()).put("val2", items.getItems().get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNullTemplate() {
|
||||
var builder = new GemfireItemWriterBuilder<String, GemfireItemWriterBuilderTests.Foo>()
|
||||
.itemKeyMapper(this.itemKeyMapper);
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("template is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNullItemKeyMapper() {
|
||||
var builder = new GemfireItemWriterBuilder<String, GemfireItemWriterBuilderTests.Foo>().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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user