use of io.vertx.ext.mongo.IndexOptions in project hono by eclipse.
the class MongoDbBasedDeviceDao method createIndices.
/**
* Creates the indices in the MongoDB that can be used to make querying of data more efficient.
*
* @return A succeeded future if the indices have been created. Otherwise, a failed future.
*/
public Future<Void> createIndices() {
final Promise<Void> result = Promise.promise();
if (creatingIndices.compareAndSet(false, true)) {
// create unique index on device ID
return createIndex(new JsonObject().put(DeviceDto.FIELD_TENANT_ID, 1).put(DeviceDto.FIELD_DEVICE_ID, 1), new IndexOptions().unique(true)).onSuccess(ok -> indicesCreated.set(true)).onComplete(r -> {
creatingIndices.set(false);
result.handle(r);
});
} else {
LOG.debug("already trying to create indices");
}
return result.future();
}
use of io.vertx.ext.mongo.IndexOptions in project hono by eclipse.
the class MongoDbBasedTenantDao method createIndices.
/**
* Creates the indices in the MongoDB that can be used to make querying of data more efficient.
*
* @return A succeeded future if the indices have been created. Otherwise, a failed future.
*/
public Future<Void> createIndices() {
final Promise<Void> result = Promise.promise();
if (creatingIndices.compareAndSet(false, true)) {
final String trustedCaField = TenantDto.FIELD_TENANT + "." + RegistryManagementConstants.FIELD_PAYLOAD_TRUSTED_CA;
// create unique index on tenant ID
return createIndex(new JsonObject().put(RegistryManagementConstants.FIELD_PAYLOAD_TENANT_ID, 1), new IndexOptions().unique(true)).compose(ok -> {
final String aliasField = TenantDto.FIELD_TENANT + "." + RegistryManagementConstants.FIELD_ALIAS;
return createIndex(new JsonObject().put(aliasField, 1), new IndexOptions().unique(true).partialFilterExpression(new JsonObject().put(aliasField, new JsonObject().put("$exists", true))));
}).compose(ok -> {
return createIndex(new JsonObject().put(RegistryManagementConstants.FIELD_PAYLOAD_TENANT_ID, 1).put(TenantDto.FIELD_TENANT + "." + RegistryManagementConstants.FIELD_TRUST_ANCHOR_GROUP, 1).put(trustedCaField + "." + RegistryManagementConstants.FIELD_PAYLOAD_SUBJECT_DN, 1), new IndexOptions().partialFilterExpression(new JsonObject().put(trustedCaField, new JsonObject().put("$exists", true))));
}).compose(ok -> dropIndex(new JsonObject().put(trustedCaField + "." + RegistryManagementConstants.FIELD_PAYLOAD_SUBJECT_DN, 1), new IndexOptions().unique(true).partialFilterExpression(new JsonObject().put(trustedCaField, new JsonObject().put("$exists", true))))).onSuccess(ok -> indicesCreated.set(true)).onComplete(r -> {
creatingIndices.set(false);
result.handle(r);
});
} else {
LOG.debug("already trying to create indices");
}
return result.future();
}
use of io.vertx.ext.mongo.IndexOptions in project hono by eclipse.
the class MongoDbBasedCredentialsDao method createIndices.
/**
* Creates the indices in the MongoDB that can be used to make querying of data more efficient.
*
* @return A succeeded future if the indices have been created. Otherwise, a failed future.
*/
public Future<Void> createIndices() {
final Promise<Void> result = Promise.promise();
if (creatingIndices.compareAndSet(false, true)) {
// create unique index on tenant and device ID
createIndex(new JsonObject().put(RegistryManagementConstants.FIELD_PAYLOAD_TENANT_ID, 1).put(RegistryManagementConstants.FIELD_PAYLOAD_DEVICE_ID, 1), new IndexOptions().unique(true)).compose(ok -> createIndex(new JsonObject().put(RegistryManagementConstants.FIELD_PAYLOAD_TENANT_ID, 1).put(KEY_AUTH_ID, 1).put(KEY_CREDENTIALS_TYPE, 1), new IndexOptions().unique(true).partialFilterExpression(new JsonObject().put(KEY_AUTH_ID, new JsonObject().put("$exists", true)).put(KEY_CREDENTIALS_TYPE, new JsonObject().put("$exists", true))))).compose(ok -> createIndex(new JsonObject().put(KEY_AUTH_ID, 1).put(KEY_CREDENTIALS_TYPE, 1), new IndexOptions().name(IDX_CREDENTIALS_TYPE_AND_AUTH_ID))).onSuccess(ok -> indicesCreated.set(true)).onComplete(r -> {
creatingIndices.set(false);
result.handle(r);
});
} else {
LOG.debug("already trying to create indices");
}
return result.future();
}
Aggregations