use of net.anweisen.utilities.database.internal.mongodb.where.MongoDBWhere in project Utility by anweisen.
the class MongoUtils method applyWhere.
public static void applyWhere(@Nonnull FindIterable<Document> iterable, @Nonnull Map<String, MongoDBWhere> where) {
for (Entry<String, MongoDBWhere> entry : where.entrySet()) {
MongoDBWhere value = entry.getValue();
iterable.filter(value.toBson());
Collation collation = value.getCollation();
if (collation != null)
iterable.collation(collation);
}
}
use of net.anweisen.utilities.database.internal.mongodb.where.MongoDBWhere in project Utility by anweisen.
the class MongoDBDeletion method execute.
@Override
public Void execute() throws DatabaseException {
try {
MongoCollection<Document> collection = database.getCollection(this.collection);
Document filter = new Document();
DeleteOptions options = new DeleteOptions();
for (MongoDBWhere where : where.values()) {
Bson whereBson = where.toBson();
BsonDocument asBsonDocument = BsonUtils.convertBsonToBsonDocument(whereBson);
filter.putAll(asBsonDocument);
Collation collation = where.getCollation();
if (collation != null)
options.collation(collation);
}
collection.deleteMany(filter, options);
return null;
} catch (Exception ex) {
throw new DatabaseException(ex);
}
}
use of net.anweisen.utilities.database.internal.mongodb.where.MongoDBWhere in project Utility by anweisen.
the class MongoDBInsertionOrUpdate method execute.
@Override
public Void execute() throws DatabaseException {
if (database.query(collection, where).execute().isSet()) {
return super.execute();
} else {
Document document = new Document(values);
for (Entry<String, MongoDBWhere> entry : where.entrySet()) {
BsonDocument bson = BsonUtils.convertBsonToBsonDocument(entry.getValue().toBson());
document.putAll(bson);
}
database.insert(collection, document).execute();
return null;
}
}
use of net.anweisen.utilities.database.internal.mongodb.where.MongoDBWhere in project Utility by anweisen.
the class MongoDBUpdate method execute.
@Override
public Void execute() throws DatabaseException {
try {
MongoCollection<Document> collection = database.getCollection(this.collection);
Document filter = new Document();
UpdateOptions options = new UpdateOptions();
for (MongoDBWhere where : where.values()) {
Bson whereBson = where.toBson();
BsonDocument asBsonDocument = BsonUtils.convertBsonToBsonDocument(whereBson);
filter.putAll(asBsonDocument);
Collation collation = where.getCollation();
if (collation != null)
options.collation(collation);
}
Document newDocument = new Document();
for (Entry<String, Object> entry : values.entrySet()) {
newDocument.put(entry.getKey(), MongoUtils.packObject(entry.getValue()));
}
BasicDBObject update = new BasicDBObject();
update.put("$set", newDocument);
collection.updateMany(filter, update, options);
return null;
} catch (Exception ex) {
throw new DatabaseException(ex);
}
}
Aggregations