From 73a63d007fcc7445198db70266dd671de9709b3a Mon Sep 17 00:00:00 2001 From: eugenp Date: Fri, 31 Jul 2015 16:20:14 +0300 Subject: [PATCH] minor cleanup --- spring-data-mongodb/pom.xml | 36 ++++++++++--------- .../baeldung/repository/UserRepository.java | 4 +-- .../org/baeldung/service/UserService.java | 31 ++++++++-------- .../UserRepositoryIntegrationTest.java | 16 ++++----- 4 files changed, 44 insertions(+), 43 deletions(-) diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index d04c717916..539e4136e4 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -7,21 +7,8 @@ spring-data-mongodb - - UTF-8 - - 1.7.1.RELEASE - 4.1.7.RELEASE - 1.3 - 4.11 - 2.4.1 - - 1.7.12 - 1.1.3 - - - + org.springframework.data spring-data-mongodb @@ -60,19 +47,19 @@ slf4j-api ${org.slf4j.version} - + ch.qos.logback logback-classic ${logback.version} - + org.slf4j jcl-over-slf4j ${org.slf4j.version} - + org.slf4j log4j-over-slf4j @@ -80,6 +67,7 @@ + @@ -92,4 +80,18 @@ + + + UTF-8 + + 1.7.1.RELEASE + 4.1.7.RELEASE + 1.3 + 4.11 + 2.4.1 + + 1.7.12 + 1.1.3 + + diff --git a/spring-data-mongodb/src/main/java/org/baeldung/repository/UserRepository.java b/spring-data-mongodb/src/main/java/org/baeldung/repository/UserRepository.java index 846e2f18bf..3625e1d1de 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/repository/UserRepository.java +++ b/spring-data-mongodb/src/main/java/org/baeldung/repository/UserRepository.java @@ -1,8 +1,8 @@ package org.baeldung.repository; -import org.springframework.data.mongodb.repository.MongoRepository; import org.baeldung.model.User; +import org.springframework.data.mongodb.repository.MongoRepository; public interface UserRepository extends MongoRepository { - + // } diff --git a/spring-data-mongodb/src/main/java/org/baeldung/service/UserService.java b/spring-data-mongodb/src/main/java/org/baeldung/service/UserService.java index 9d4643ddd6..06a6735340 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/service/UserService.java +++ b/spring-data-mongodb/src/main/java/org/baeldung/service/UserService.java @@ -11,13 +11,12 @@ import org.springframework.data.mongodb.core.query.Update; import com.mongodb.WriteResult; - public class UserService { @Autowired private MongoTemplate mongoTemplate; - public void insertUser(User user) { + public void insertUser(final User user) { mongoTemplate.insert(user, "user"); } @@ -25,42 +24,42 @@ public class UserService { return mongoTemplate.findAll(User.class, "user"); } - public void removeUser(User user) { + public void removeUser(final User user) { mongoTemplate.remove(user, "user"); } - public void saveUser(User user) { + public void saveUser(final User user) { mongoTemplate.save(user, "user"); } - public User findAndModifyUser(String name, String newName) { - Query query = new Query(); + public User findAndModifyUser(final String name, final String newName) { + final Query query = new Query(); query.addCriteria(Criteria.where("name").is(name)); - Update update = new Update(); + final Update update = new Update(); update.set("name", newName); return mongoTemplate.findAndModify(query, update, User.class); } - public void updateFirstUser(String name, String newName) { - Query query = new Query(); + public void updateFirstUser(final String name, final String newName) { + final Query query = new Query(); query.addCriteria(Criteria.where("name").is(name)); - Update update = new Update(); + final Update update = new Update(); update.set("name", newName); mongoTemplate.updateFirst(query, update, User.class); } - public WriteResult upsertUser(String name, String newName) { - Query query = new Query(); + public WriteResult upsertUser(final String name, final String newName) { + final Query query = new Query(); query.addCriteria(Criteria.where("name").is(name)); - Update update = new Update(); + final Update update = new Update(); update.set("name", newName); return mongoTemplate.upsert(query, update, User.class); } - public void updateMultiUser(String name, String newName) { - Query query = new Query(); + public void updateMultiUser(final String name, final String newName) { + final Query query = new Query(); query.addCriteria(Criteria.where("name").is(name)); - Update update = new Update(); + final Update update = new Update(); update.set("name", newName); mongoTemplate.updateMulti(query, update, User.class); } diff --git a/spring-data-mongodb/src/test/java/org/baeldung/repository/UserRepositoryIntegrationTest.java b/spring-data-mongodb/src/test/java/org/baeldung/repository/UserRepositoryIntegrationTest.java index b5c7befa16..ea88151324 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/repository/UserRepositoryIntegrationTest.java +++ b/spring-data-mongodb/src/test/java/org/baeldung/repository/UserRepositoryIntegrationTest.java @@ -44,7 +44,7 @@ public class UserRepositoryIntegrationTest { @Test public void testInsert() { - User user = new User(); + final User user = new User(); user.setName("Jon"); userRepository.insert(user); @@ -58,7 +58,7 @@ public class UserRepositoryIntegrationTest { mongoOps.insert(user); user = mongoOps.findOne(Query.query(Criteria.where("name").is("Jack")), User.class); - String id = user.getId(); + final String id = user.getId(); user.setName("Jim"); userRepository.save(user); @@ -68,7 +68,7 @@ public class UserRepositoryIntegrationTest { @Test public void testDelete() { - User user = new User(); + final User user = new User(); user.setName("Benn"); mongoOps.insert(user); @@ -84,7 +84,7 @@ public class UserRepositoryIntegrationTest { mongoOps.insert(user); user = mongoOps.findOne(Query.query(Criteria.where("name").is("Chris")), User.class); - User foundUser = userRepository.findOne(user.getId()); + final User foundUser = userRepository.findOne(user.getId()); assertThat(user.getName(), is(foundUser.getName())); } @@ -96,7 +96,7 @@ public class UserRepositoryIntegrationTest { mongoOps.insert(user); user = mongoOps.findOne(Query.query(Criteria.where("name").is("Harris")), User.class); - boolean isExists = userRepository.exists(user.getId()); + final boolean isExists = userRepository.exists(user.getId()); assertThat(isExists, is(true)); } @@ -111,7 +111,7 @@ public class UserRepositoryIntegrationTest { user.setName("Adam"); mongoOps.insert(user); - List users = userRepository.findAll(new Sort(Sort.Direction.ASC, "name")); + final List users = userRepository.findAll(new Sort(Sort.Direction.ASC, "name")); assertThat(users.size(), is(2)); assertThat(users.get(0).getName(), is("Adam")); @@ -128,9 +128,9 @@ public class UserRepositoryIntegrationTest { user.setName("Adam"); mongoOps.insert(user); - Pageable pageableRequest = new PageRequest(0, 2); + final Pageable pageableRequest = new PageRequest(0, 2); - Page users = userRepository.findAll(pageableRequest); + final Page users = userRepository.findAll(pageableRequest); assertThat(users.getTotalPages(), is(1)); assertThat(users.iterator().next().getName(), is("Brendan"));