use of com.mongodb.WriteConcern in project mongo-java-driver by mongodb.
the class JsonPoweredCrudTestHelper method getBulkWriteResult.
BsonDocument getBulkWriteResult(final BsonDocument arguments) {
WriteConcern writeConcern = WriteConcern.ACKNOWLEDGED;
if (arguments.containsKey("writeConcern")) {
if (arguments.getDocument("writeConcern").size() > 1) {
throw new UnsupportedOperationException("Write concern document contains unexpected keys: " + arguments.getDocument("writeConcern").keySet());
}
writeConcern = new WriteConcern(arguments.getDocument("writeConcern").getInt32("w").intValue());
}
List<WriteModel<BsonDocument>> writeModels = new ArrayList<WriteModel<BsonDocument>>();
for (Iterator<BsonValue> iter = arguments.getArray("requests").iterator(); iter.hasNext(); ) {
BsonDocument cur = iter.next().asDocument();
if (cur.get("insertOne") != null) {
writeModels.add(new InsertOneModel<BsonDocument>(cur.getDocument("insertOne").getDocument("document")));
} else if (cur.get("updateOne") != null) {
writeModels.add(new UpdateOneModel<BsonDocument>(cur.getDocument("updateOne").getDocument("filter"), cur.getDocument("updateOne").getDocument("update")));
} else {
throw new UnsupportedOperationException("Unsupported write request type");
}
}
return toResult(collection.withWriteConcern(writeConcern).bulkWrite(writeModels, new BulkWriteOptions().ordered(arguments.getBoolean("ordered", BsonBoolean.TRUE).getValue())));
}
use of com.mongodb.WriteConcern in project spring-cloud-connectors by spring-cloud.
the class MongoDbFactoryCreator method getMongoOptions.
private MongoClientOptions.Builder getMongoOptions(MongoDbFactoryConfig config) {
MongoClientOptions.Builder builder;
Method builderMethod = ClassUtils.getMethodIfAvailable(MongoClientOptions.class, "builder");
if (builderMethod != null) {
builder = (Builder) ReflectionUtils.invokeMethod(builderMethod, null);
} else {
Constructor<Builder> builderConstructor = ClassUtils.getConstructorIfAvailable(MongoClientOptions.Builder.class);
try {
builder = builderConstructor.newInstance(new Object[0]);
} catch (InstantiationException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (IllegalArgumentException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(e);
}
}
if (config != null) {
if (config.getConnectionsPerHost() != null) {
builder.connectionsPerHost(config.getConnectionsPerHost());
}
if (config.getMaxWaitTime() != null) {
builder.maxWaitTime(config.getMaxWaitTime());
}
if (config.getWriteConcern() != null) {
builder.writeConcern(new WriteConcern(config.getWriteConcern()));
}
}
return builder;
}
use of com.mongodb.WriteConcern in project camel by apache.
the class MongoDbEndpoint method setWriteConcernRef.
/**
* Set the {@link WriteConcern} for write operations on MongoDB, passing in
* the bean ref to a custom WriteConcern which exists in the Registry. You
* can also use standard WriteConcerns by passing in their key. See the
* {@link #setWriteConcern(String) setWriteConcern} method.
*
* @param writeConcernRef the name of the bean in the registry that
* represents the WriteConcern to use
*/
public void setWriteConcernRef(String writeConcernRef) {
WriteConcern wc = this.getCamelContext().getRegistry().lookupByNameAndType(writeConcernRef, WriteConcern.class);
if (wc == null) {
String msg = "Camel MongoDB component could not find the WriteConcern in the Registry. Verify that the " + "provided bean name (" + writeConcernRef + ") is correct. Aborting initialization.";
throw new IllegalArgumentException(msg);
}
this.writeConcernRef = wc;
}
use of com.mongodb.WriteConcern in project camel by apache.
the class GridFsEndpoint method setWriteConcernRef.
/**
* Set the {@link WriteConcern} for write operations on MongoDB, passing in the bean ref to a custom WriteConcern which exists in the Registry.
* You can also use standard WriteConcerns by passing in their key. See the {@link #setWriteConcern(String) setWriteConcern} method.
*
* @param writeConcernRef the name of the bean in the registry that represents the WriteConcern to use
*/
public void setWriteConcernRef(String writeConcernRef) {
WriteConcern wc = this.getCamelContext().getRegistry().lookupByNameAndType(writeConcernRef, WriteConcern.class);
if (wc == null) {
String msg = "Camel MongoDB component could not find the WriteConcern in the Registry. Verify that the " + "provided bean name (" + writeConcernRef + ") is correct. Aborting initialization.";
throw new IllegalArgumentException(msg);
}
this.writeConcernRef = wc;
}
use of com.mongodb.WriteConcern in project camel by apache.
the class MongoDbEndpoint method setWriteConcernRef.
/**
* Set the {@link WriteConcern} for write operations on MongoDB, passing in the bean ref to a custom WriteConcern which exists in the Registry.
* You can also use standard WriteConcerns by passing in their key. See the {@link #setWriteConcern(String) setWriteConcern} method.
*
* @param writeConcernRef the name of the bean in the registry that represents the WriteConcern to use
*/
public void setWriteConcernRef(String writeConcernRef) {
WriteConcern wc = this.getCamelContext().getRegistry().lookupByNameAndType(writeConcernRef, WriteConcern.class);
if (wc == null) {
String msg = "Camel MongoDB component could not find the WriteConcern in the Registry. Verify that the " + "provided bean name (" + writeConcernRef + ") is correct. Aborting initialization.";
throw new IllegalArgumentException(msg);
}
this.writeConcernRef = wc;
}
Aggregations