Search in sources :

Example 1 with IndexOptionDefaults

use of com.mongodb.client.model.IndexOptionDefaults in project mongo-java-driver by mongodb.

the class MongoDatabaseImpl method createCollection.

@Override
@SuppressWarnings("deprecation")
public void createCollection(final String collectionName, final CreateCollectionOptions createCollectionOptions, final SingleResultCallback<Void> callback) {
    CreateCollectionOperation operation = new CreateCollectionOperation(name, collectionName, writeConcern).capped(createCollectionOptions.isCapped()).sizeInBytes(createCollectionOptions.getSizeInBytes()).autoIndex(createCollectionOptions.isAutoIndex()).maxDocuments(createCollectionOptions.getMaxDocuments()).usePowerOf2Sizes(createCollectionOptions.isUsePowerOf2Sizes()).storageEngineOptions(toBsonDocument(createCollectionOptions.getStorageEngineOptions())).collation(createCollectionOptions.getCollation());
    IndexOptionDefaults indexOptionDefaults = createCollectionOptions.getIndexOptionDefaults();
    if (indexOptionDefaults.getStorageEngine() != null) {
        operation.indexOptionDefaults(new BsonDocument("storageEngine", toBsonDocument(indexOptionDefaults.getStorageEngine())));
    }
    ValidationOptions validationOptions = createCollectionOptions.getValidationOptions();
    if (validationOptions.getValidator() != null) {
        operation.validator(toBsonDocument(validationOptions.getValidator()));
    }
    if (validationOptions.getValidationLevel() != null) {
        operation.validationLevel(validationOptions.getValidationLevel());
    }
    if (validationOptions.getValidationAction() != null) {
        operation.validationAction(validationOptions.getValidationAction());
    }
    executor.execute(operation, callback);
}
Also used : CreateCollectionOperation(com.mongodb.operation.CreateCollectionOperation) BsonDocument(org.bson.BsonDocument) ValidationOptions(com.mongodb.client.model.ValidationOptions) IndexOptionDefaults(com.mongodb.client.model.IndexOptionDefaults)

Example 2 with IndexOptionDefaults

use of com.mongodb.client.model.IndexOptionDefaults in project mongo-java-driver by mongodb.

the class CollectionHelper method create.

public void create(final String collectionName, final CreateCollectionOptions options) {
    drop(namespace);
    CreateCollectionOperation operation = new CreateCollectionOperation(namespace.getDatabaseName(), collectionName, WriteConcern.ACKNOWLEDGED).capped(options.isCapped()).sizeInBytes(options.getSizeInBytes()).autoIndex(options.isAutoIndex()).maxDocuments(options.getMaxDocuments());
    IndexOptionDefaults indexOptionDefaults = options.getIndexOptionDefaults();
    if (indexOptionDefaults.getStorageEngine() != null) {
        operation.indexOptionDefaults(new BsonDocument("storageEngine", toBsonDocument(indexOptionDefaults.getStorageEngine())));
    }
    ValidationOptions validationOptions = options.getValidationOptions();
    if (validationOptions.getValidator() != null) {
        operation.validator(toBsonDocument(validationOptions.getValidator()));
    }
    if (validationOptions.getValidationLevel() != null) {
        operation.validationLevel(validationOptions.getValidationLevel());
    }
    if (validationOptions.getValidationAction() != null) {
        operation.validationAction(validationOptions.getValidationAction());
    }
    operation.execute(getBinding());
}
Also used : CreateCollectionOperation(com.mongodb.operation.CreateCollectionOperation) BsonDocument(org.bson.BsonDocument) ValidationOptions(com.mongodb.client.model.ValidationOptions) IndexOptionDefaults(com.mongodb.client.model.IndexOptionDefaults)

Example 3 with IndexOptionDefaults

use of com.mongodb.client.model.IndexOptionDefaults in project mongo-java-driver by mongodb.

the class MongoDatabaseImpl method createCollection.

@Override
@SuppressWarnings("deprecation")
public void createCollection(final String collectionName, final CreateCollectionOptions createCollectionOptions) {
    CreateCollectionOperation operation = new CreateCollectionOperation(name, collectionName, writeConcern).collation(createCollectionOptions.getCollation()).capped(createCollectionOptions.isCapped()).sizeInBytes(createCollectionOptions.getSizeInBytes()).autoIndex(createCollectionOptions.isAutoIndex()).maxDocuments(createCollectionOptions.getMaxDocuments()).usePowerOf2Sizes(createCollectionOptions.isUsePowerOf2Sizes()).storageEngineOptions(toBsonDocument(createCollectionOptions.getStorageEngineOptions()));
    IndexOptionDefaults indexOptionDefaults = createCollectionOptions.getIndexOptionDefaults();
    if (indexOptionDefaults.getStorageEngine() != null) {
        operation.indexOptionDefaults(new BsonDocument("storageEngine", toBsonDocument(indexOptionDefaults.getStorageEngine())));
    }
    ValidationOptions validationOptions = createCollectionOptions.getValidationOptions();
    if (validationOptions.getValidator() != null) {
        operation.validator(toBsonDocument(validationOptions.getValidator()));
    }
    if (validationOptions.getValidationLevel() != null) {
        operation.validationLevel(validationOptions.getValidationLevel());
    }
    if (validationOptions.getValidationAction() != null) {
        operation.validationAction(validationOptions.getValidationAction());
    }
    executor.execute(operation);
}
Also used : CreateCollectionOperation(com.mongodb.operation.CreateCollectionOperation) BsonDocument(org.bson.BsonDocument) ValidationOptions(com.mongodb.client.model.ValidationOptions) IndexOptionDefaults(com.mongodb.client.model.IndexOptionDefaults)

Example 4 with IndexOptionDefaults

use of com.mongodb.client.model.IndexOptionDefaults in project mongo-java-driver by mongodb.

the class CollectionHelper method create.

public void create(final String collectionName, final CreateCollectionOptions options, final WriteConcern writeConcern) {
    drop(namespace, writeConcern);
    CreateCollectionOperation operation = new CreateCollectionOperation(namespace.getDatabaseName(), collectionName, writeConcern).capped(options.isCapped()).sizeInBytes(options.getSizeInBytes()).maxDocuments(options.getMaxDocuments());
    IndexOptionDefaults indexOptionDefaults = options.getIndexOptionDefaults();
    if (indexOptionDefaults.getStorageEngine() != null) {
        operation.indexOptionDefaults(new BsonDocument("storageEngine", toBsonDocument(indexOptionDefaults.getStorageEngine())));
    }
    ValidationOptions validationOptions = options.getValidationOptions();
    if (validationOptions.getValidator() != null) {
        operation.validator(toBsonDocument(validationOptions.getValidator()));
    }
    if (validationOptions.getValidationLevel() != null) {
        operation.validationLevel(validationOptions.getValidationLevel());
    }
    if (validationOptions.getValidationAction() != null) {
        operation.validationAction(validationOptions.getValidationAction());
    }
    operation.execute(getBinding());
}
Also used : CreateCollectionOperation(com.mongodb.internal.operation.CreateCollectionOperation) BsonDocument(org.bson.BsonDocument) ValidationOptions(com.mongodb.client.model.ValidationOptions) IndexOptionDefaults(com.mongodb.client.model.IndexOptionDefaults)

Example 5 with IndexOptionDefaults

use of com.mongodb.client.model.IndexOptionDefaults in project mongo-java-driver by mongodb.

the class MongoOperationPublisher method createCollection.

Publisher<Void> createCollection(@Nullable final ClientSession clientSession, final MongoNamespace namespace, final CreateCollectionOptions options) {
    return createWriteOperationMono(() -> {
        CreateCollectionOperation operation = new CreateCollectionOperation(namespace.getDatabaseName(), namespace.getCollectionName(), getWriteConcern()).capped(options.isCapped()).sizeInBytes(options.getSizeInBytes()).maxDocuments(options.getMaxDocuments()).storageEngineOptions(toBsonDocument(options.getStorageEngineOptions())).collation(options.getCollation()).expireAfter(options.getExpireAfter(TimeUnit.SECONDS)).timeSeriesOptions(options.getTimeSeriesOptions());
        IndexOptionDefaults indexOptionDefaults = options.getIndexOptionDefaults();
        Bson storageEngine = indexOptionDefaults.getStorageEngine();
        if (storageEngine != null) {
            operation.indexOptionDefaults(new BsonDocument("storageEngine", toBsonDocument(storageEngine)));
        }
        ValidationOptions validationOptions = options.getValidationOptions();
        Bson validator = validationOptions.getValidator();
        if (validator != null) {
            operation.validator(toBsonDocument(validator));
        }
        if (validationOptions.getValidationLevel() != null) {
            operation.validationLevel(validationOptions.getValidationLevel());
        }
        if (validationOptions.getValidationAction() != null) {
            operation.validationAction(validationOptions.getValidationAction());
        }
        return operation;
    }, clientSession);
}
Also used : CreateCollectionOperation(com.mongodb.internal.operation.CreateCollectionOperation) BsonDocument(org.bson.BsonDocument) ValidationOptions(com.mongodb.client.model.ValidationOptions) IndexOptionDefaults(com.mongodb.client.model.IndexOptionDefaults) Bson(org.bson.conversions.Bson)

Aggregations

IndexOptionDefaults (com.mongodb.client.model.IndexOptionDefaults)6 ValidationOptions (com.mongodb.client.model.ValidationOptions)6 BsonDocument (org.bson.BsonDocument)6 CreateCollectionOperation (com.mongodb.internal.operation.CreateCollectionOperation)3 CreateCollectionOperation (com.mongodb.operation.CreateCollectionOperation)3 Bson (org.bson.conversions.Bson)2