@@ -334,21 +334,26 @@ private void addBulkWriteResultToCommandResult(final BulkWriteResult bulkWriteRe
334
334
335
335
public void createIndex (final DBObject keys , final DBObject options , DBEncoder encoder ) {
336
336
DBTCPConnector connector = db .getConnector ();
337
- DBPort port = db .getConnector ().getPrimaryPort ();
337
+ final DBPort port = db .getConnector ().getPrimaryPort ();
338
338
339
339
try {
340
340
DBObject index = defaultOptions (keys );
341
341
index .putAll (options );
342
342
index .put ("key" , keys );
343
343
344
344
if (connector .getServerDescription (port .getAddress ()).getVersion ().compareTo (new ServerVersion (2 , 6 )) >= 0 ) {
345
- BasicDBObject createIndexes = new BasicDBObject ("createIndexes" , getName ());
345
+ final BasicDBObject createIndexes = new BasicDBObject ("createIndexes" , getName ());
346
346
347
347
BasicDBList list = new BasicDBList ();
348
348
list .add (index );
349
349
createIndexes .put ("indexes" , list );
350
350
351
- CommandResult commandResult = port .runCommand (db , createIndexes );
351
+ CommandResult commandResult = connector .doOperation (db , port , new DBPort .Operation <CommandResult >() {
352
+ @ Override
353
+ public CommandResult execute () throws IOException {
354
+ return port .runCommand (db , createIndexes );
355
+ }
356
+ });
352
357
try {
353
358
commandResult .throwOnError ();
354
359
} catch (CommandFailureException e ) {
@@ -362,8 +367,6 @@ public void createIndex(final DBObject keys, final DBObject options, DBEncoder e
362
367
db .doGetCollection ("system.indexes" ).insertWithWriteProtocol (asList (index ), WriteConcern .SAFE ,
363
368
DefaultDBEncoder .FACTORY .create (), port , false );
364
369
}
365
- } catch (IOException e ) {
366
- throw new MongoException .Network ("Operation on server " + port .getAddress () + " failed" , e );
367
370
} finally {
368
371
connector .releasePort (port );
369
372
}
0 commit comments