Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
@Configuration
class UserJobConfiguration {

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private final JobRepository jobRepository;
private final PlatformTransactionManager transactionManager;
private final MongoOperations mongo;
Expand All @@ -52,7 +54,7 @@ private Step step() throws MalformedURLException {
private JsonItemReader<User> reader() throws MalformedURLException {
JacksonJsonObjectReader<User> jsonObjectReader = new JacksonJsonObjectReader<>(User.class);

jsonObjectReader.setMapper(new ObjectMapper());
jsonObjectReader.setMapper(OBJECT_MAPPER);

return new JsonItemReaderBuilder<User>()
.name("userReader")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.database.ItemPreparedStatementSetter;
import org.springframework.batch.item.database.JdbcBatchItemWriter;
import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder;
import org.springframework.batch.item.json.JacksonJsonObjectReader;
Expand All @@ -19,19 +18,19 @@
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
* @author Rashidi Zin
*/
@Configuration
class UserJobConfiguration {

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private JsonItemReader<UserFile> reader() {
JacksonJsonObjectReader<UserFile> reader = new JacksonJsonObjectReader<>(UserFile.class);

reader.setMapper(new ObjectMapper());
reader.setMapper(OBJECT_MAPPER);

return new JsonItemReaderBuilder<UserFile>()
.jsonObjectReader(reader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexDefinitionBuilder;
import org.springframework.data.mongodb.core.index.TextIndexDefinition;
import org.springframework.data.mongodb.core.query.TextCriteria;
import org.springframework.data.mongodb.core.query.TextQuery;

Expand All @@ -22,7 +22,7 @@ class CharacterSearchRepositoryImpl implements CharacterSearchRepository {
@Override
public List<Character> findByText(String text, Sort sort) {
operations.indexOps(Character.class)
.createIndex(new TextIndexDefinitionBuilder().onFields("name", "publisher").build());
.createIndex(TextIndexDefinition.builder().onFields("name", "publisher").build());

var parameters = text.split(" ");
var query = TextQuery.queryText(new TextCriteria().matchingAny(parameters)).with(sort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexDefinitionBuilder;
import org.springframework.data.mongodb.core.index.TextIndexDefinition;
import org.springframework.data.mongodb.core.query.TextCriteria;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.junit.jupiter.Container;
Expand All @@ -40,7 +40,7 @@ class CharacterRepositoryTests {
@DisplayName("Generated query: Search for 'captain marvel' should return 'Captain Marvel' and 'Thanos'")
void withGeneratedQuery() {
// Simulate predefined index
operations.indexOps(Character.class).ensureIndex(new TextIndexDefinitionBuilder().onFields("name", "publisher").build());
operations.indexOps(Character.class).ensureIndex(TextIndexDefinition.builder().onFields("name", "publisher").build());

var characters = repository.findAllBy(new TextCriteria().matchingAny("captain", "marvel"), Sort.by("name"));

Expand Down
Loading