Skip to content

Commit af4b84e

Browse files
committed
DATAMONGO-835 - Code cleanups.
1 parent f911082 commit af4b84e

File tree

17 files changed

+158
-120
lines changed

17 files changed

+158
-120
lines changed

spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoChangeSetPersister.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2013 the original author or authors.
2+
* Copyright 2011-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,17 +41,13 @@
4141
public class MongoChangeSetPersister implements ChangeSetPersister<Object> {
4242

4343
private static final String ENTITY_CLASS = "_entity_class";
44-
4544
private static final String ENTITY_ID = "_entity_id";
46-
4745
private static final String ENTITY_FIELD_NAME = "_entity_field_name";
48-
4946
private static final String ENTITY_FIELD_CLASS = "_entity_field_class";
5047

5148
protected final Logger log = LoggerFactory.getLogger(getClass());
5249

5350
private MongoTemplate mongoTemplate;
54-
5551
private EntityManagerFactory entityManagerFactory;
5652

5753
public void setMongoTemplate(MongoTemplate mongoTemplate) {
@@ -113,12 +109,14 @@ public Object doInCollection(DBCollection collection) throws MongoException, Dat
113109
* @see org.springframework.data.crossstore.ChangeSetPersister#getPersistentId(org.springframework.data.crossstore.ChangeSetBacked, org.springframework.data.crossstore.ChangeSet)
114110
*/
115111
public Object getPersistentId(ChangeSetBacked entity, ChangeSet cs) throws DataAccessException {
112+
116113
log.debug("getPersistentId called on " + entity);
114+
117115
if (entityManagerFactory == null) {
118116
throw new DataAccessResourceFailureException("EntityManagerFactory cannot be null");
119117
}
120-
Object o = entityManagerFactory.getPersistenceUnitUtil().getIdentifier(entity);
121-
return o;
118+
119+
return entityManagerFactory.getPersistenceUnitUtil().getIdentifier(entity);
122120
}
123121

124122
/*

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MappingMongoConverterParser.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2013 the original author or authors.
2+
* Copyright 2011-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@
7575
public class MappingMongoConverterParser implements BeanDefinitionParser {
7676

7777
private static final String BASE_PACKAGE = "base-package";
78-
private static final boolean jsr303Present = ClassUtils.isPresent("javax.validation.Validator",
78+
private static final boolean JSR_303_PRESENT = ClassUtils.isPresent("javax.validation.Validator",
7979
MappingMongoConverterParser.class.getClassLoader());
8080

8181
/* (non-Javadoc)
@@ -166,7 +166,7 @@ private BeanDefinition potentiallyCreateValidatingMongoEventListener(Element ele
166166

167167
private RuntimeBeanReference getValidator(Object source, ParserContext parserContext) {
168168

169-
if (!jsr303Present) {
169+
if (!JSR_303_PRESENT) {
170170
return null;
171171
}
172172

@@ -195,7 +195,8 @@ static String potentiallyCreateMappingContext(Element element, ParserContext par
195195
BeanDefinitionBuilder mappingContextBuilder = BeanDefinitionBuilder
196196
.genericBeanDefinition(MongoMappingContext.class);
197197

198-
Set<String> classesToAdd = getInititalEntityClasses(element, mappingContextBuilder);
198+
Set<String> classesToAdd = getInititalEntityClasses(element);
199+
199200
if (classesToAdd != null) {
200201
mappingContextBuilder.addPropertyValue("initialEntitySet", classesToAdd);
201202
}
@@ -262,7 +263,7 @@ private BeanDefinition getCustomConversions(Element element, ParserContext parse
262263
return null;
263264
}
264265

265-
private static Set<String> getInititalEntityClasses(Element element, BeanDefinitionBuilder builder) {
266+
private static Set<String> getInititalEntityClasses(Element element) {
266267

267268
String basePackage = element.getAttribute(BASE_PACKAGE);
268269

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
1+
/*
2+
* Copyright 2011-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.data.mongodb.core;
217

318
import org.springframework.jmx.export.annotation.ManagedOperation;
419

20+
/**
21+
* @author Mark Pollack
22+
* @author Oliver Gierke
23+
*/
524
public interface MongoAdminOperations {
625

726
@ManagedOperation
8-
public abstract void dropDatabase(String databaseName);
27+
void dropDatabase(String databaseName);
928

1029
@ManagedOperation
11-
public abstract void createDatabase(String databaseName);
30+
void createDatabase(String databaseName);
1231

1332
@ManagedOperation
14-
public abstract String getDatabaseStats(String databaseName);
15-
16-
}
33+
String getDatabaseStats(String databaseName);
34+
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOptionsFactoryBean.java

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2013 the original author or authors.
2+
* Copyright 2010-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,27 +30,28 @@
3030
* @author Mike Saavedra
3131
* @author Thomas Darimont
3232
*/
33+
@SuppressWarnings("deprecation")
3334
public class MongoOptionsFactoryBean implements FactoryBean<MongoOptions>, InitializingBean {
3435

35-
@SuppressWarnings("deprecation")//
36-
private final MongoOptions MONGO_OPTIONS = new MongoOptions();
37-
38-
private int connectionsPerHost = MONGO_OPTIONS.connectionsPerHost;
39-
40-
private int threadsAllowedToBlockForConnectionMultiplier = MONGO_OPTIONS.threadsAllowedToBlockForConnectionMultiplier;
41-
private int maxWaitTime = MONGO_OPTIONS.maxWaitTime;
42-
private int connectTimeout = MONGO_OPTIONS.connectTimeout;
43-
private int socketTimeout = MONGO_OPTIONS.socketTimeout;
44-
private boolean socketKeepAlive = MONGO_OPTIONS.socketKeepAlive;
45-
private boolean autoConnectRetry = MONGO_OPTIONS.autoConnectRetry;
46-
private long maxAutoConnectRetryTime = MONGO_OPTIONS.maxAutoConnectRetryTime;
47-
private int writeNumber;
48-
private int writeTimeout;
49-
private boolean writeFsync;
50-
@SuppressWarnings("deprecation") private boolean slaveOk = MONGO_OPTIONS.slaveOk;
36+
private static final MongoOptions DEFAULT_MONGO_OPTIONS = new MongoOptions();
37+
38+
private int connectionsPerHost = DEFAULT_MONGO_OPTIONS.connectionsPerHost;
39+
private int threadsAllowedToBlockForConnectionMultiplier = DEFAULT_MONGO_OPTIONS.threadsAllowedToBlockForConnectionMultiplier;
40+
private int maxWaitTime = DEFAULT_MONGO_OPTIONS.maxWaitTime;
41+
private int connectTimeout = DEFAULT_MONGO_OPTIONS.connectTimeout;
42+
private int socketTimeout = DEFAULT_MONGO_OPTIONS.socketTimeout;
43+
private boolean socketKeepAlive = DEFAULT_MONGO_OPTIONS.socketKeepAlive;
44+
private boolean autoConnectRetry = DEFAULT_MONGO_OPTIONS.autoConnectRetry;
45+
private long maxAutoConnectRetryTime = DEFAULT_MONGO_OPTIONS.maxAutoConnectRetryTime;
46+
private int writeNumber = DEFAULT_MONGO_OPTIONS.w;
47+
private int writeTimeout = DEFAULT_MONGO_OPTIONS.wtimeout;
48+
private boolean writeFsync = DEFAULT_MONGO_OPTIONS.fsync;
49+
private boolean slaveOk = DEFAULT_MONGO_OPTIONS.slaveOk;
5150
private boolean ssl;
5251
private SSLSocketFactory sslSocketFactory;
5352

53+
private MongoOptions options;
54+
5455
/**
5556
* Configures the maximum number of connections allowed per host until we will block.
5657
*
@@ -197,32 +198,36 @@ public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) {
197198
* (non-Javadoc)
198199
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
199200
*/
200-
@SuppressWarnings("deprecation")
201201
public void afterPropertiesSet() {
202202

203-
MONGO_OPTIONS.connectionsPerHost = connectionsPerHost;
204-
MONGO_OPTIONS.threadsAllowedToBlockForConnectionMultiplier = threadsAllowedToBlockForConnectionMultiplier;
205-
MONGO_OPTIONS.maxWaitTime = maxWaitTime;
206-
MONGO_OPTIONS.connectTimeout = connectTimeout;
207-
MONGO_OPTIONS.socketTimeout = socketTimeout;
208-
MONGO_OPTIONS.socketKeepAlive = socketKeepAlive;
209-
MONGO_OPTIONS.autoConnectRetry = autoConnectRetry;
210-
MONGO_OPTIONS.maxAutoConnectRetryTime = maxAutoConnectRetryTime;
211-
MONGO_OPTIONS.slaveOk = slaveOk;
212-
MONGO_OPTIONS.w = writeNumber;
213-
MONGO_OPTIONS.wtimeout = writeTimeout;
214-
MONGO_OPTIONS.fsync = writeFsync;
203+
MongoOptions options = new MongoOptions();
204+
205+
options.connectionsPerHost = connectionsPerHost;
206+
options.threadsAllowedToBlockForConnectionMultiplier = threadsAllowedToBlockForConnectionMultiplier;
207+
options.maxWaitTime = maxWaitTime;
208+
options.connectTimeout = connectTimeout;
209+
options.socketTimeout = socketTimeout;
210+
options.socketKeepAlive = socketKeepAlive;
211+
options.autoConnectRetry = autoConnectRetry;
212+
options.maxAutoConnectRetryTime = maxAutoConnectRetryTime;
213+
options.slaveOk = slaveOk;
214+
options.w = writeNumber;
215+
options.wtimeout = writeTimeout;
216+
options.fsync = writeFsync;
217+
215218
if (ssl) {
216-
MONGO_OPTIONS.setSocketFactory(sslSocketFactory != null ? sslSocketFactory : SSLSocketFactory.getDefault());
219+
options.setSocketFactory(sslSocketFactory != null ? sslSocketFactory : SSLSocketFactory.getDefault());
217220
}
221+
222+
this.options = options;
218223
}
219224

220225
/*
221226
* (non-Javadoc)
222227
* @see org.springframework.beans.factory.FactoryBean#getObject()
223228
*/
224229
public MongoOptions getObject() {
225-
return MONGO_OPTIONS;
230+
return this.options;
226231
}
227232

228233
/*

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ protected void executeQuery(Query query, String collectionName, DocumentCallback
375375
DBObject fieldsObject = query.getFieldsObject();
376376

377377
if (LOGGER.isDebugEnabled()) {
378-
LOGGER.debug(String.format("Executing query: %s sort: %s fields: %s in collection: $s",
378+
LOGGER.debug(String.format("Executing query: %s sort: %s fields: %s in collection: %s",
379379
serializeToJsonSafely(queryObject), sortObject, fieldsObject, collectionName));
380380
}
381381

@@ -1181,6 +1181,7 @@ public <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName
11811181

11821182
public <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, String mapFunction,
11831183
String reduceFunction, MapReduceOptions mapReduceOptions, Class<T> entityClass) {
1184+
11841185
String mapFunc = replaceWithResourceIfNecessary(mapFunction);
11851186
String reduceFunc = replaceWithResourceIfNecessary(reduceFunction);
11861187
DBCollection inputCollection = getCollection(inputCollectionName);
@@ -1205,12 +1206,12 @@ public <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName
12051206
MapReduceOutput mapReduceOutput = new MapReduceOutput(inputCollection, commandObject, commandResult);
12061207
List<T> mappedResults = new ArrayList<T>();
12071208
DbObjectCallback<T> callback = new ReadDbObjectCallback<T>(mongoConverter, entityClass);
1209+
12081210
for (DBObject dbObject : mapReduceOutput.results()) {
12091211
mappedResults.add(callback.doWith(dbObject));
12101212
}
12111213

1212-
MapReduceResults<T> mapReduceResult = new MapReduceResults<T>(mappedResults, commandResult);
1213-
return mapReduceResult;
1214+
return new MapReduceResults<T>(mappedResults, commandResult);
12141215
}
12151216

12161217
public <T> GroupByResults<T> group(String inputCollectionName, GroupBy groupBy, Class<T> entityClass) {
@@ -1264,15 +1265,14 @@ public <T> GroupByResults<T> group(Criteria criteria, String inputCollectionName
12641265

12651266
@SuppressWarnings("unchecked")
12661267
Iterable<DBObject> resultSet = (Iterable<DBObject>) commandResult.get("retval");
1267-
12681268
List<T> mappedResults = new ArrayList<T>();
12691269
DbObjectCallback<T> callback = new ReadDbObjectCallback<T>(mongoConverter, entityClass);
1270+
12701271
for (DBObject dbObject : resultSet) {
12711272
mappedResults.add(callback.doWith(dbObject));
12721273
}
1273-
GroupByResults<T> groupByResult = new GroupByResults<T>(mappedResults, commandResult);
1274-
return groupByResult;
12751274

1275+
return new GroupByResults<T>(mappedResults, commandResult);
12761276
}
12771277

12781278
@Override

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ExposedFields.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@
3232
* @author Thomas Darimont
3333
* @since 1.3
3434
*/
35-
public class ExposedFields implements Iterable<ExposedField> {
35+
public final class ExposedFields implements Iterable<ExposedField> {
3636

3737
private static final List<ExposedField> NO_FIELDS = Collections.emptyList();
3838
private static final ExposedFields EMPTY = new ExposedFields(NO_FIELDS, NO_FIELDS);

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,13 +32,13 @@
3232
* @author Oliver Gierke
3333
* @since 1.3
3434
*/
35-
public class Fields implements Iterable<Field> {
35+
public final class Fields implements Iterable<Field> {
3636

3737
private static final String AMBIGUOUS_EXCEPTION = "Found two fields both using '%s' as name: %s and %s! Please "
3838
+ "customize your field definitions to get to unique field names!";
3939

40-
public static String UNDERSCORE_ID = "_id";
41-
public static String UNDERSCORE_ID_REF = "$_id";
40+
public static final String UNDERSCORE_ID = "_id";
41+
public static final String UNDERSCORE_ID_REF = "$_id";
4242

4343
private final List<Field> fields;
4444

@@ -203,7 +203,7 @@ public AggregationField(String name, String target) {
203203
Assert.hasText(nameToSet, "AggregationField name must not be null or empty!");
204204

205205
if (target == null && name.contains(".")) {
206-
this.name = nameToSet.substring(nameToSet.indexOf(".") + 1);
206+
this.name = nameToSet.substring(nameToSet.indexOf('.') + 1);
207207
this.target = nameToSet;
208208
} else {
209209
this.name = nameToSet;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GroupOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -99,7 +99,7 @@ protected GroupOperation and(Operation operation) {
9999
*
100100
* @author Thomas Darimont
101101
*/
102-
public class GroupOperationBuilder {
102+
public static final class GroupOperationBuilder {
103103

104104
private final GroupOperation groupOperation;
105105
private final Operation operation;

0 commit comments

Comments
 (0)