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);
}
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());
}
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);
}
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());
}
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);
}
Aggregations