Search in sources :

Example 1 with IndexRequest

use of com.mongodb.internal.bulk.IndexRequest in project mongo-java-driver by mongodb.

the class OperationHelper method validateIndexRequestCollations.

static void validateIndexRequestCollations(final AsyncConnection connection, final List<IndexRequest> requests, final AsyncCallableWithConnection callable) {
    boolean calledTheCallable = false;
    for (IndexRequest request : requests) {
        if (request.getCollation() != null) {
            calledTheCallable = true;
            validateCollation(connection, request.getCollation(), new AsyncCallableWithConnection() {

                @Override
                public void call(final AsyncConnection connection, final Throwable t) {
                    callable.call(connection, t);
                }
            });
            break;
        }
    }
    if (!calledTheCallable) {
        callable.call(connection, null);
    }
}
Also used : AsyncConnection(com.mongodb.internal.connection.AsyncConnection) IndexRequest(com.mongodb.internal.bulk.IndexRequest)

Example 2 with IndexRequest

use of com.mongodb.internal.bulk.IndexRequest in project mongo-java-driver by mongodb.

the class Operations method createIndexes.

@SuppressWarnings("deprecation")
public CreateIndexesOperation createIndexes(final List<IndexModel> indexes, final CreateIndexOptions createIndexOptions) {
    notNull("indexes", indexes);
    notNull("createIndexOptions", createIndexOptions);
    List<IndexRequest> indexRequests = new ArrayList<>(indexes.size());
    for (IndexModel model : indexes) {
        if (model == null) {
            throw new IllegalArgumentException("indexes can not contain a null value");
        }
        indexRequests.add(new IndexRequest(toBsonDocument(model.getKeys())).name(model.getOptions().getName()).background(model.getOptions().isBackground()).unique(model.getOptions().isUnique()).sparse(model.getOptions().isSparse()).expireAfter(model.getOptions().getExpireAfter(TimeUnit.SECONDS), TimeUnit.SECONDS).version(model.getOptions().getVersion()).weights(toBsonDocument(model.getOptions().getWeights())).defaultLanguage(model.getOptions().getDefaultLanguage()).languageOverride(model.getOptions().getLanguageOverride()).textVersion(model.getOptions().getTextVersion()).sphereVersion(model.getOptions().getSphereVersion()).bits(model.getOptions().getBits()).min(model.getOptions().getMin()).max(model.getOptions().getMax()).bucketSize(model.getOptions().getBucketSize()).storageEngine(toBsonDocument(model.getOptions().getStorageEngine())).partialFilterExpression(toBsonDocument(model.getOptions().getPartialFilterExpression())).collation(model.getOptions().getCollation()).wildcardProjection(toBsonDocument(model.getOptions().getWildcardProjection())).hidden(model.getOptions().isHidden()));
    }
    return new CreateIndexesOperation(namespace, indexRequests, writeConcern).maxTime(createIndexOptions.getMaxTime(MILLISECONDS), MILLISECONDS).commitQuorum(createIndexOptions.getCommitQuorum());
}
Also used : ArrayList(java.util.ArrayList) IndexRequest(com.mongodb.internal.bulk.IndexRequest) IndexModel(com.mongodb.client.model.IndexModel)

Example 3 with IndexRequest

use of com.mongodb.internal.bulk.IndexRequest in project mongo-java-driver by mongodb.

the class CreateIndexesOperation method getCommand.

private BsonDocument getCommand(final ConnectionDescription description) {
    BsonDocument command = new BsonDocument("createIndexes", new BsonString(namespace.getCollectionName()));
    List<BsonDocument> values = new ArrayList<BsonDocument>();
    for (IndexRequest request : requests) {
        values.add(getIndex(request));
    }
    command.put("indexes", new BsonArray(values));
    putIfNotZero(command, "maxTimeMS", maxTimeMS);
    appendWriteConcernToCommand(writeConcern, command, description);
    if (commitQuorum != null) {
        if (serverIsAtLeastVersionFourDotFour(description)) {
            command.put("commitQuorum", commitQuorum.toBsonValue());
        } else {
            throw new MongoClientException("Specifying a value for the create index commit quorum option " + "requires a minimum MongoDB version of 4.4");
        }
    }
    return command;
}
Also used : BsonDocument(org.bson.BsonDocument) MongoClientException(com.mongodb.MongoClientException) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) ArrayList(java.util.ArrayList) IndexRequest(com.mongodb.internal.bulk.IndexRequest)

Aggregations

IndexRequest (com.mongodb.internal.bulk.IndexRequest)3 ArrayList (java.util.ArrayList)2 MongoClientException (com.mongodb.MongoClientException)1 IndexModel (com.mongodb.client.model.IndexModel)1 AsyncConnection (com.mongodb.internal.connection.AsyncConnection)1 BsonArray (org.bson.BsonArray)1 BsonDocument (org.bson.BsonDocument)1 BsonString (org.bson.BsonString)1