|
16 | 16 | import java.util.logging.Level; |
17 | 17 | import java.util.logging.Logger; |
18 | 18 |
|
| 19 | +import com.mongodb.BulkWriteException; |
19 | 20 | import org.json.JSONArray; |
20 | 21 | import org.json.JSONException; |
21 | 22 | import org.json.JSONObject; |
@@ -361,45 +362,54 @@ record = lookupEntireRecord(collection, name); |
361 | 362 |
|
362 | 363 | @Override |
363 | 364 | public AbstractRecordCursor getAllRowsIterator(String collection) throws FailedDBOperationException { |
364 | | - getMap(collection).commit(); |
| 365 | + commit(collection); |
365 | 366 | return getMongoRecords(collection).getAllRowsIterator(MongoRecords.DBNAMERECORD); |
366 | 367 | } |
367 | 368 |
|
368 | 369 | @Override |
369 | 370 | public AbstractRecordCursor selectRecords(String collection, ColumnField valuesMapField, String key, Object value) throws FailedDBOperationException { |
370 | | - getMap(collection).commit(); |
| 371 | + commit(collection); |
371 | 372 | return getMongoRecords(collection).selectRecords(MongoRecords.DBNAMERECORD, valuesMapField, key, value); |
372 | 373 | } |
373 | 374 |
|
374 | 375 | @Override |
375 | 376 | public AbstractRecordCursor selectRecordsWithin(String collection, ColumnField valuesMapField, String key, String value) throws FailedDBOperationException { |
376 | | - getMap(collection).commit(); |
| 377 | + commit(collection); |
377 | 378 | return getMongoRecords(collection).selectRecordsWithin(MongoRecords.DBNAMERECORD, valuesMapField, key, value); |
378 | 379 | } |
379 | 380 |
|
380 | 381 | @Override |
381 | 382 | public AbstractRecordCursor selectRecordsNear(String collection, ColumnField valuesMapField, String key, String value, Double maxDistance) throws FailedDBOperationException { |
382 | | - getMap(collection).commit(); |
| 383 | + commit(collection); |
383 | 384 | return getMongoRecords(collection).selectRecordsNear(MongoRecords.DBNAMERECORD, valuesMapField, key, value, maxDistance); |
384 | 385 | } |
385 | 386 |
|
386 | 387 | @Override |
387 | 388 | public AbstractRecordCursor selectRecordsQuery(String collection, ColumnField valuesMapField, |
388 | 389 | String query, List<String> projection) throws FailedDBOperationException { |
389 | | - getMap(collection).commit(); |
| 390 | + commit(collection); |
390 | 391 | return getMongoRecords(collection).selectRecordsQuery(MongoRecords.DBNAMERECORD, valuesMapField, |
391 | 392 | query, projection); |
392 | 393 | } |
393 | 394 |
|
394 | 395 | @Override |
395 | 396 | public void createIndex(String collection, String field, String index) { |
396 | | - getMap(collection).commit(); |
| 397 | + commit(collection); |
397 | 398 | getMongoRecords(collection).createIndex(MongoRecords.DBNAMERECORD, field, index); |
398 | 399 | } |
399 | 400 |
|
400 | 401 | @Override |
401 | 402 | public void printAllEntries(String collection) throws FailedDBOperationException { |
402 | | - getMap(collection).commit(); |
| 403 | + commit(collection); |
403 | 404 | getMongoRecords(collection).printAllEntries(MongoRecords.DBNAMERECORD); |
404 | 405 | } |
| 406 | + |
| 407 | + private void commit(String collection) { |
| 408 | + try{ |
| 409 | + getMap(collection).commit(); |
| 410 | + } catch (BulkWriteException e) { |
| 411 | + LOGGER.log(Level.WARNING, "Caught {e}, ignoring and proceeding: {1}", new Object[]{e.getClass().getSimpleName(), e.getMessage()}); |
| 412 | + } |
| 413 | + |
| 414 | + } |
405 | 415 | } |
0 commit comments