minor formatting work
This commit is contained in:
parent
4631f7e915
commit
0b42f56f49
|
@ -7,9 +7,9 @@ import org.baeldung.converter.UserWriterConverter;
|
|||
import org.baeldung.event.CascadeSaveMongoEventListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
|
||||
import org.springframework.data.mongodb.core.convert.CustomConversions;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
|
||||
import com.mongodb.Mongo;
|
||||
|
@ -19,7 +19,7 @@ import com.mongodb.MongoClient;
|
|||
@EnableMongoRepositories(basePackages = "org.baeldung.repository")
|
||||
public class MongoConfig extends AbstractMongoConfiguration {
|
||||
|
||||
private List<Converter<?, ?>> converters = new ArrayList<Converter<?, ?>>();
|
||||
private final List<Converter<?, ?>> converters = new ArrayList<Converter<?, ?>>();
|
||||
|
||||
@Override
|
||||
protected String getDatabaseName() {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.converter;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.baeldung.model.User;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
|
@ -10,12 +10,12 @@ import com.mongodb.DBObject;
|
|||
@Component
|
||||
public class UserWriterConverter implements Converter<User, DBObject> {
|
||||
@Override
|
||||
public DBObject convert(User user) {
|
||||
DBObject dbObject = new BasicDBObject();
|
||||
public DBObject convert(final User user) {
|
||||
final DBObject dbObject = new BasicDBObject();
|
||||
dbObject.put("name", user.getName());
|
||||
dbObject.put("age", user.getAge());
|
||||
if (user.getEmailAddress() != null) {
|
||||
DBObject emailDbObject = new BasicDBObject();
|
||||
final DBObject emailDbObject = new BasicDBObject();
|
||||
emailDbObject.put("value", user.getEmailAddress().getValue());
|
||||
dbObject.put("email", emailDbObject);
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@ public class CascadeCallback implements ReflectionUtils.FieldCallback {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
|
||||
public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException {
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
|
||||
if (field.isAnnotationPresent(DBRef.class) && field.isAnnotationPresent(CascadeSave.class)) {
|
||||
final Object fieldValue = field.get(getSource());
|
||||
|
||||
if (fieldValue != null) {
|
||||
FieldCallback callback = new FieldCallback();
|
||||
final FieldCallback callback = new FieldCallback();
|
||||
|
||||
ReflectionUtils.doWithFields(fieldValue.getClass(), callback);
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class CascadeCallback implements ReflectionUtils.FieldCallback {
|
|||
return source;
|
||||
}
|
||||
|
||||
public void setSource(Object source) {
|
||||
public void setSource(final Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class CascadeCallback implements ReflectionUtils.FieldCallback {
|
|||
return mongoOperations;
|
||||
}
|
||||
|
||||
public void setMongoOperations(MongoOperations mongoOperations) {
|
||||
public void setMongoOperations(final MongoOperations mongoOperations) {
|
||||
this.mongoOperations = mongoOperations;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ import org.springframework.util.ReflectionUtils;
|
|||
public class FieldCallback implements ReflectionUtils.FieldCallback {
|
||||
private boolean idFound;
|
||||
|
||||
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
|
||||
@Override
|
||||
public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException {
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
|
||||
if (field.isAnnotationPresent(Id.class)) {
|
||||
|
|
|
@ -73,7 +73,7 @@ public class User {
|
|||
return emailAddress;
|
||||
}
|
||||
|
||||
public void setEmailAddress(EmailAddress emailAddress) {
|
||||
public void setEmailAddress(final EmailAddress emailAddress) {
|
||||
this.emailAddress = emailAddress;
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class User {
|
|||
return yearOfBirth;
|
||||
}
|
||||
|
||||
public void setYearOfBirth(Integer yearOfBirth) {
|
||||
public void setYearOfBirth(final Integer yearOfBirth) {
|
||||
this.yearOfBirth = yearOfBirth;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.baeldung.repository;
|
|||
import java.util.List;
|
||||
|
||||
import org.baeldung.model.User;
|
||||
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.data.mongodb.repository.Query;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
|
|
Loading…
Reference in New Issue