Search in sources :

Example 1 with Updates

use of com.mongodb.client.model.Updates in project engine by Lumeer.

the class MongoUserNotificationDao method updateNotifications.

@Override
public void updateNotifications(final String searchField, final String searchId, final Map<String, String> updates) {
    final List<Bson> sets = updates.entrySet().stream().map(e -> Updates.set(e.getKey(), e.getValue())).collect(Collectors.toList());
    final UpdateResult result = databaseCollection().updateMany(Filters.eq(searchField, searchId), Updates.combine(sets));
    if (result.getModifiedCount() > 0 && createOrUpdateUserNotificationEvent != null) {
        final List<UserNotification> updatedNotifications = databaseCollection().find(Filters.eq(searchField, searchId)).into(new ArrayList<>());
        updatedNotifications.forEach(notification -> createOrUpdateUserNotificationEvent.fire(new CreateOrUpdateUserNotification(notification)));
    }
}
Also used : Document(org.bson.Document) MongoCollection(com.mongodb.client.MongoCollection) UserNotification(io.lumeer.api.model.UserNotification) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Filters(com.mongodb.client.model.Filters) Bson(org.bson.conversions.Bson) Inject(javax.inject.Inject) UpdateResult(com.mongodb.client.result.UpdateResult) Map(java.util.Map) Event(javax.enterprise.event.Event) UserNotificationCodec(io.lumeer.storage.mongodb.codecs.UserNotificationCodec) MongoException(com.mongodb.MongoException) ReturnDocument(com.mongodb.client.model.ReturnDocument) Updates(com.mongodb.client.model.Updates) Set(java.util.Set) IndexOptions(com.mongodb.client.model.IndexOptions) Collectors(java.util.stream.Collectors) CreateOrUpdateUserNotification(io.lumeer.engine.api.event.CreateOrUpdateUserNotification) Indexes(com.mongodb.client.model.Indexes) StorageException(io.lumeer.storage.api.exception.StorageException) List(java.util.List) MongoFilters.idFilter(io.lumeer.storage.mongodb.util.MongoFilters.idFilter) Sorts(com.mongodb.client.model.Sorts) RemoveUserNotification(io.lumeer.engine.api.event.RemoveUserNotification) UserNotificationDao(io.lumeer.storage.api.dao.UserNotificationDao) PostConstruct(javax.annotation.PostConstruct) DeleteResult(com.mongodb.client.result.DeleteResult) ObjectId(org.bson.types.ObjectId) FindOneAndReplaceOptions(com.mongodb.client.model.FindOneAndReplaceOptions) ApplicationScoped(javax.enterprise.context.ApplicationScoped) UserNotification(io.lumeer.api.model.UserNotification) CreateOrUpdateUserNotification(io.lumeer.engine.api.event.CreateOrUpdateUserNotification) RemoveUserNotification(io.lumeer.engine.api.event.RemoveUserNotification) CreateOrUpdateUserNotification(io.lumeer.engine.api.event.CreateOrUpdateUserNotification) UpdateResult(com.mongodb.client.result.UpdateResult) Bson(org.bson.conversions.Bson)

Example 2 with Updates

use of com.mongodb.client.model.Updates in project docs-java by mongodb.

the class Updates method main.

public static void main(String[] args) {
    Updates updates = new Updates();
    updates.resetCollection(updates);
    System.out.println("setUpdate:");
    updates.setUpdate();
    updates.resetCollection(updates);
    System.out.println("unsetUpdate:");
    updates.unsetUpdate();
    updates.resetCollection(updates);
    System.out.println("setOnInsertUpdate:");
    updates.setOnInsertUpdate();
    updates.resetCollection(updates);
    System.out.println("incUpdate:");
    updates.incUpdate();
    updates.resetCollection(updates);
    System.out.println("mulUpdate:");
    updates.mulUpdate();
    updates.resetCollection(updates);
    System.out.println("renameUpdate:");
    updates.renameUpdate();
    updates.resetCollection(updates);
    System.out.println("minUpdate:");
    updates.minUpdate();
    updates.resetCollection(updates);
    System.out.println("maxUpdate:");
    updates.maxUpdate();
    updates.resetCollection(updates);
    System.out.println("currentDateUpdate:");
    updates.currentDateUpdate();
    updates.resetCollection(updates);
    System.out.println("currentTimestampUpdate:");
    updates.currentTimestampUpdate();
    updates.resetCollection(updates);
    System.out.println("bitwiseOrUpdate:");
    updates.bitwiseOrUpdate();
    updates.resetCollection(updates);
    System.out.println("addToSetUpdate:");
    updates.addToSetUpdate();
    updates.resetCollection(updates);
    System.out.println("popFirstUpdate:");
    updates.popFirstUpdate();
    updates.resetCollection(updates);
    System.out.println("pullAllUpdate:");
    updates.pullAllUpdate();
    updates.resetCollection(updates);
    System.out.println("pullUpdate:");
    updates.pullUpdate();
    updates.resetCollection(updates);
    System.out.println("pushUpdate:");
    updates.pushUpdate();
    updates.resetCollection(updates);
    System.out.println("combineUpdate:");
    updates.combineUpdate();
    updates.resetCollection(updates);
}
Also used : Updates(com.mongodb.client.model.Updates)

Aggregations

Updates (com.mongodb.client.model.Updates)2 MongoException (com.mongodb.MongoException)1 MongoCollection (com.mongodb.client.MongoCollection)1 Filters (com.mongodb.client.model.Filters)1 FindOneAndReplaceOptions (com.mongodb.client.model.FindOneAndReplaceOptions)1 IndexOptions (com.mongodb.client.model.IndexOptions)1 Indexes (com.mongodb.client.model.Indexes)1 ReturnDocument (com.mongodb.client.model.ReturnDocument)1 Sorts (com.mongodb.client.model.Sorts)1 DeleteResult (com.mongodb.client.result.DeleteResult)1 UpdateResult (com.mongodb.client.result.UpdateResult)1 UserNotification (io.lumeer.api.model.UserNotification)1 CreateOrUpdateUserNotification (io.lumeer.engine.api.event.CreateOrUpdateUserNotification)1 RemoveUserNotification (io.lumeer.engine.api.event.RemoveUserNotification)1 UserNotificationDao (io.lumeer.storage.api.dao.UserNotificationDao)1 StorageException (io.lumeer.storage.api.exception.StorageException)1 UserNotificationCodec (io.lumeer.storage.mongodb.codecs.UserNotificationCodec)1 MongoFilters.idFilter (io.lumeer.storage.mongodb.util.MongoFilters.idFilter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1