@Override public GridFSBucket withWriteConcern(final WriteConcern writeConcern) { return new GridFSBucketImpl(bucketName, chunkSizeBytes, filesCollection.withWriteConcern(writeConcern), chunksCollection.withWriteConcern(writeConcern), disableMD5); }
private MongoCollection enforceWriteConcern(final MongoCollection collection, final Class klass, final WriteConcern proposed) { WriteConcern applied = proposed != null ? proposed : getWriteConcern(klass); return applied != null ? collection.withWriteConcern(applied) : collection; }
/** * Delete a record from the database. * * @param table * The name of the table * @param key * The record key of the record to delete. * @return Zero on success, a non-zero error code on error. See the {@link DB} * class's description for a discussion of error codes. */ @Override public Status delete(String table, String key) { try { MongoCollection<Document> collection = database.getCollection(table); Document query = new Document("_id", key); DeleteResult result = collection.withWriteConcern(writeConcern).deleteOne(query); if (result.wasAcknowledged() && result.getDeletedCount() == 0) { System.err.println("Nothing deleted for key " + key); return Status.NOT_FOUND; } return Status.OK; } catch (Exception e) { System.err.println(e.toString()); return Status.ERROR; } }
protected List<Object> insertDocumentList(final String collectionName, final List<Document> documents) { if (documents.isEmpty()) { return Collections.emptyList(); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Inserting list of Documents containing {} items", documents.size()); } execute(collectionName, collection -> { MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.INSERT_LIST, collectionName, null, null, null); WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); if (writeConcernToUse == null) { collection.insertMany(documents); } else { collection.withWriteConcern(writeConcernToUse).insertMany(documents); } return null; }); return MappedDocument.toIds(documents); }
public Object doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.INSERT, collectionName, entityClass, document, null); WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); if (writeConcernToUse == null) { collection.insertOne(document); } else { collection.withWriteConcern(writeConcernToUse).insertOne(document); } return operations.forEntity(document).getId(); } });
final MongoCollection<Document> collection = getCollection(context, flowFile).withWriteConcern(writeConcern); ByteArrayOutputStream bos = new ByteArrayOutputStream(); session.exportTo(flowFile, bos);
public Object doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.SAVE, collectionName, entityClass, dbDoc, null); WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); MappedDocument mapped = MappedDocument.of(dbDoc); if (!mapped.hasId()) { if (writeConcernToUse == null) { collection.insertOne(dbDoc); } else { collection.withWriteConcern(writeConcernToUse).insertOne(dbDoc); } } else if (writeConcernToUse == null) { collection.replaceOne(mapped.getIdFilter(), dbDoc, new ReplaceOptions().upsert(true)); } else { collection.withWriteConcern(writeConcernToUse).replaceOne(mapped.getIdFilter(), dbDoc, new ReplaceOptions().upsert(true)); } return mapped.getId(); } });
? collection.withWriteConcern(writeConcernToUse) : collection;
final MongoCollection<Document> collection = getCollection(context, flowFile).withWriteConcern(writeConcern); RecordSchema schema = reader.getSchema(); Record record;
WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); collection = writeConcernToUse != null ? collection.withWriteConcern(writeConcernToUse) : collection;
final MongoCollection<Document> collection = getCollection(context, flowFile).withWriteConcern(writeConcern);
protected List<Object> insertDocumentList(final String collectionName, final List<Document> documents) { if (documents.isEmpty()) { return Collections.emptyList(); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Inserting list of Documents containing {} items", documents.size()); } execute(collectionName, collection -> { MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.INSERT_LIST, collectionName, null, null, null); WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); if (writeConcernToUse == null) { collection.insertMany(documents); } else { collection.withWriteConcern(writeConcernToUse).insertMany(documents); } return null; }); return MappedDocument.toIds(documents); }
public Object doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.INSERT, collectionName, entityClass, document, null); WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); if (writeConcernToUse == null) { collection.insertOne(document); } else { collection.withWriteConcern(writeConcernToUse).insertOne(document); } return operations.forEntity(document).getId(); } });
/** * @return The MongoDB collection to which events are logged. */ protected MongoCollection getCollection() { if (concern == null) { return collection; } return collection.withWriteConcern(concern); }
/** * Set the write concern for this collection. Will be used for writes to * this collection. Overrides any setting of write concern at the DB level. * See the documentation for {@link WriteConcern} for more information. * * @param concern * write concern to use */ public void setWriteConcern(WriteConcern concern) { this.mongoCollection = mongoCollection.withWriteConcern(concern); }
public Object doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.SAVE, collectionName, entityClass, dbDoc, null); WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); MappedDocument mapped = MappedDocument.of(dbDoc); if (!mapped.hasId()) { if (writeConcernToUse == null) { collection.insertOne(dbDoc); } else { collection.withWriteConcern(writeConcernToUse).insertOne(dbDoc); } } else if (writeConcernToUse == null) { collection.replaceOne(mapped.getIdFilter(), dbDoc, new ReplaceOptions().upsert(true)); } else { collection.withWriteConcern(writeConcernToUse).replaceOne(mapped.getIdFilter(), dbDoc, new ReplaceOptions().upsert(true)); } return mapped.getId(); } });
? collection.withWriteConcern(writeConcernToUse) : collection;
WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); collection = writeConcernToUse != null ? collection.withWriteConcern(writeConcernToUse) : collection;
@Override public GridFSBucket withWriteConcern(final WriteConcern writeConcern) { return new GridFSBucketImpl(bucketName, chunkSizeBytes, filesCollection.withWriteConcern(writeConcern), chunksCollection.withWriteConcern(writeConcern), disableMD5); }
@NotNull @Override public MongoCollection<TDocument> withWriteConcern(@NotNull WriteConcern writeConcern) { return new MongoTestCollection<>(collection.withWriteConcern(writeConcern), beforeQueryException, beforeUpdateException, afterUpdateException); }