Fixed stream handling and some sonar issues

This commit is contained in:
Kai Zimmermann
2016-01-27 14:16:24 +01:00
parent b51113af89
commit bed3f0c8c9
4 changed files with 43 additions and 58 deletions

View File

@@ -59,7 +59,7 @@ public class MongoConfiguration extends AbstractMongoConfiguration {
}
/**
* Closes mongo client when destroyd.
* Closes mongo client when destroyed.
*/
@PreDestroy
public void close() {
@@ -74,22 +74,13 @@ public class MongoConfiguration extends AbstractMongoConfiguration {
public Mongo mongo() throws UnknownHostException {
final MongoClientURI uri = new MongoClientURI(properties.getUri(), createBuilderOutOfOptions(options));
try {
if (properties.getPort() != null) {
LOG.debug("Create mongo by properties (host: {}, port: {})", uri.getHosts().get(0),
properties.getPort());
this.mongoConnection = new MongoClient(
Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())),
uri.getOptions());
} else {
LOG.debug("Create mongo by URI : {}", uri);
this.mongoConnection = new MongoClient(uri);
}
} finally {
if (this.mongoConnection != null) {
this.mongoConnection.close();
}
if (properties.getPort() != null) {
LOG.debug("Create mongo by properties (host: {}, port: {})", uri.getHosts().get(0), properties.getPort());
this.mongoConnection = new MongoClient(
Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())), uri.getOptions());
} else {
LOG.debug("Create mongo by URI : {}", uri);
this.mongoConnection = new MongoClient(uri);
}
return this.mongoConnection;