@@ -88,6 +88,7 @@ public class MongoConnection implements Connection {
88
88
private String logDirPath ;
89
89
private boolean extJsonMode ;
90
90
private UuidRepresentation uuidRepresentation ;
91
+ private String appName ;
91
92
92
93
public MongoConnection (
93
94
MongoClient mongoClient , MongoConnectionProperties connectionProperties ) {
@@ -104,7 +105,13 @@ public MongoConnection(
104
105
this .mongoClientSettings = createMongoClientSettings (connectionProperties );
105
106
106
107
if (mongoClient == null ) {
107
- this .mongoClient = createMongoClient (connectionProperties );
108
+ this .mongoClient =
109
+ MongoClients .create (
110
+ this .mongoClientSettings ,
111
+ MongoDriverInformation .builder ()
112
+ .driverName (MongoDriver .NAME )
113
+ .driverVersion (MongoDriver .getVersion ())
114
+ .build ());
108
115
} else {
109
116
this .mongoClient = mongoClient ;
110
117
}
@@ -121,44 +128,32 @@ private void initializeConnection(MongoConnectionProperties connectionProperties
121
128
this .extJsonMode = connectionProperties .getExtJsonMode ();
122
129
this .uuidRepresentation =
123
130
connectionProperties .getConnectionString ().getUuidRepresentation ();
131
+ this .appName = buildAppName (connectionProperties );
124
132
125
133
this .isClosed = false ;
126
134
}
127
135
128
- private MongoClient createMongoClient (MongoConnectionProperties connectionProperties ) {
129
- StringBuilder appName =
136
+ private String buildAppName (MongoConnectionProperties connectionProperties ) {
137
+ StringBuilder appNameBuilder =
130
138
new StringBuilder (MongoDriver .NAME ).append ("+" ).append (MongoDriver .getVersion ());
131
139
132
- MongoDriverInformation .Builder mdiBuilder ;
133
140
String clientInfo = connectionProperties .getClientInfo ();
134
- String [] clientInfoSplit = (clientInfo == null ) ? null : clientInfo .split ("\\ +" );
135
- if (clientInfoSplit != null && clientInfoSplit .length == 2 ) {
136
- appName .append ('|' ).append (clientInfo );
137
- MongoDriverInformation driverInfoWithClientInfo =
138
- MongoDriverInformation .builder ()
139
- .driverName (clientInfoSplit [0 ])
140
- .driverVersion (clientInfoSplit [1 ])
141
- .build ();
142
- mdiBuilder = MongoDriverInformation .builder (driverInfoWithClientInfo );
143
- } else {
144
- mdiBuilder = MongoDriverInformation .builder ();
141
+ if (clientInfo != null ) {
142
+ String [] clientInfoSplit = clientInfo .split ("\\ +" );
143
+ if (clientInfoSplit .length == 2 ) {
144
+ appNameBuilder .append ('|' ).append (clientInfo );
145
+ }
145
146
}
146
- MongoDriverInformation mongoDriverInformation =
147
- mdiBuilder
148
- .driverName (MongoDriver .NAME )
149
- .driverVersion (MongoDriver .getVersion ())
150
- .build ();
151
147
152
- return MongoClients . create ( this . mongoClientSettings , mongoDriverInformation );
148
+ return appNameBuilder . toString ( );
153
149
}
154
150
155
151
private MongoClientSettings createMongoClientSettings (
156
152
MongoConnectionProperties connectionProperties ) {
157
- String appName = MongoDriver .NAME + "+" + MongoDriver .getVersion ();
158
153
159
154
MongoClientSettings .Builder settingsBuilder =
160
155
MongoClientSettings .builder ()
161
- .applicationName (appName )
156
+ .applicationName (this . appName )
162
157
.applyConnectionString (connectionProperties .getConnectionString ());
163
158
164
159
MongoCredential credential = connectionProperties .getConnectionString ().getCredential ();
0 commit comments