本文整理汇总了Java中com.mongodb.client.model.IndexModel类的典型用法代码示例。如果您正苦于以下问题:Java IndexModel类的具体用法?Java IndexModel怎么用?Java IndexModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IndexModel类属于com.mongodb.client.model包,在下文中一共展示了IndexModel类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reCreateIndex
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
@Override
public List<String> reCreateIndex (T... t) {
T theT = null;
if (t == null || t.length < 1 || t[0] == null) {
try {
// new Instance
theT = (T) Class.forName(clazz.getName()).newInstance();
} catch (Exception e) {
gc(); // clear data
throw new RuntimeException(e);
}
}
else {
theT = t[0];
}
// get current collection name
String collectionNameForT = getCollectionName(collectionNames.get());
List<IndexModel> indexs = getIndexs(theT);
// delete collection indexes
database.getCollection(collectionNameForT).dropIndexes();
List<String> index = database.getCollection(collectionNameForT).createIndexes(indexs);
// clear garbage
gc();
return index;
}
示例2: createIndexes
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
@Override
public List<String> createIndexes(List<IndexModel> arg0)
{
int writeSize = 0;
OperationMetric metric = null;
if (MongoLogger.GATHERER.isEnabled())
{
List<String> keyValuePairs = MongoUtilities.getIndexModelKeyValuePairs(arg0);
String operationName = "Mongo : " + getNamespace().getCollectionName() + " : createIndexes";
metric = startMetric(operationName, keyValuePairs);
}
List<String> retVal = collection.createIndexes(arg0);
stopMetric(metric, writeSize);
return retVal;
}
示例3: getIndexModelKeyValuePairs
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
public static List<String> getIndexModelKeyValuePairs(List<IndexModel> arg0)
{
List<String> retVal = new ArrayList<String>();
for (IndexModel indexModel : arg0)
{
retVal.add(indexModel.getKeys().toString());
}
return retVal;
}
示例4: run
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
@Override
public void run(Environment environment, Namespace namespace, SamConfiguration configuration) throws Exception {
final MongoDatabase database = configuration.getDbConnectionFactory().getDatabase(environment.lifecycle());
final MongoCollection<Document> servers = database.getCollection(Collections.SERVERS);
servers.createIndexes(Lists.newArrayList(
new IndexModel(
ascending("fqdn"),
new IndexOptions().unique(true).sparse(true)
),
new IndexModel(
compoundIndex(ascending("hostname"), ascending("environment")),
new IndexOptions().unique(true)
),
new IndexModel(
compoundIndex(Indexes.text("hostname"), Indexes.text("environment"), Indexes.text("fqdn"), Indexes.text("description")),
new IndexOptions().weights(new Document().append("hostname", 10).append("fqdn", 10).append("environment", 5)).defaultLanguage("sv")
)
));
final MongoCollection<Document> applications = database.getCollection(Collections.APPLICATIONS);
applications.createIndexes(Lists.newArrayList(
new IndexModel(
ascending("id"),
new IndexOptions().unique(true)
),
new IndexModel(
compoundIndex(Indexes.text("id"), Indexes.text("name"), Indexes.text("description")),
new IndexOptions().weights(new Document().append("id", 10).append("name", 10)).defaultLanguage("sv")
)
));
final MongoCollection<Document> groups = database.getCollection(Collections.GROUPS);
groups.createIndexes(Lists.newArrayList(
new IndexModel(
ascending("id"),
new IndexOptions().unique(true)
),
new IndexModel(
ascending("tags")
),
new IndexModel(
compoundIndex(Indexes.text("id"), Indexes.text("name"), Indexes.text("description"), Indexes.text("tags")),
new IndexOptions().weights(new Document().append("id", 10).append("name", 10).append("tags", 5)).defaultLanguage("sv")
)
));
final MongoCollection<Document> assets = database.getCollection(Collections.ASSETS);
assets.createIndexes(Lists.newArrayList(
new IndexModel(
ascending("id"),
new IndexOptions().unique(true)
),
new IndexModel(
compoundIndex(Indexes.text("id"), Indexes.text("name"), Indexes.text("description")),
new IndexOptions().weights(new Document().append("id", 10).append("name", 10)).defaultLanguage("sv")
)
));
}
示例5: createIndexes
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
@Override
public Observable<String> createIndexes(final List<IndexModel> indexes) {
return RxObservables.create(Observables.observeAndFlatten(new Block<SingleResultCallback<List<String>>>() {
@Override
public void apply(final SingleResultCallback<List<String>> callback) {
wrapped.createIndexes(indexes, callback);
}
}), observableAdapter);
}
示例6: createIndexes
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
@Override
public Publisher<String> createIndexes(final List<IndexModel> indexes, final CreateIndexOptions createIndexOptions) {
return new ObservableToPublisher<String>(observeAndFlatten(new Block<SingleResultCallback<List<String>>>() {
@Override
public void apply(final SingleResultCallback<List<String>> callback) {
wrapped.createIndexes(indexes, createIndexOptions, callback);
}
}));
}
示例7: createIndex
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
@Override
public List<String> createIndex (T... t) {
T theT = null;
if (t == null || t.length < 1 || t[0] == null) {
try {
// new Instance
theT = (T) Class.forName(clazz.getName()).newInstance();
} catch (Exception e) {
gc(); // clear data
throw new RuntimeException(e);
}
}
else {
theT = t[0];
}
// get current collection name
String collectionNameForT = getCollectionName(collectionNames.get());
List<String> index = new ArrayList<String>();
List<IndexModel> indexs = getIndexs(theT);
if (indexs.isEmpty() == false) {
index = database.getCollection(collectionNameForT).createIndexes(indexs);
}
return index;
}
示例8: getIndexs
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
@Override
public List<IndexModel> getIndexs (T t) {
// 获取该类的属性
Field[] clazz_fields = clazz.getDeclaredFields();
// 获取T父对象的属性
Field[] superFields = superClazz.getDeclaredFields();
Field[] fields = new Field[clazz_fields.length + superFields.length];
// 合并T与T父对象的属性
System.arraycopy(clazz_fields, 0, fields, 0, clazz_fields.length);
// 合并T与T父对象的属性
System.arraycopy(superFields, 0, fields, clazz_fields.length, superFields.length);
// 创建索引序列
List<IndexModel> indexModels = new ArrayList<IndexModel>();
// 循环该类的属性
for (Field field: fields) {
// 如果属性被Index注解,那么
if (field.isAnnotationPresent(Index.class)) {
// 获取注解对象
Index index = field.getAnnotation(Index.class);
// MongoDB ObjectID主键或者不是主键
if(index.id() == true || index.key() == false) {
continue;
}
// 创建索引键
BasicDBObject keys = new BasicDBObject();
keys.append(field.getName(), index.order());
// 附加选项
IndexOptions indexOptions = new IndexOptions();
if(index.background()) {
indexOptions.background(index.background());
}
// 所有名字
if("".equals(index.name()) == false) {
indexOptions.name(index.name());
}
// 唯一字段
if(index.unique()) {
indexOptions.unique(index.unique());
}
if(index.sparse()) {
indexOptions.sparse(index.sparse());
}
// 创建索引
IndexModel indexModel = new IndexModel(keys,indexOptions);
// 索引
indexModels.add(indexModel);
}
}
return indexModels;
}
示例9: add
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
public MongoIndex add(MongoIndex mongoIndex) {
indexModels.add(new IndexModel(Indexes.compoundIndex(mongoIndex.getBson()), mongoIndex));
return this;
}
示例10: createIndex
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
@Test
public void createIndex()
{
coll.createIndex(new Document("name", 1));
coll.dropIndex(new Document("name", 1));
coll.createIndex(new Document("name", 1), new IndexOptions());
coll.dropIndex(new Document("name", 1));
coll.createIndexes(Arrays.asList(new IndexModel(new Document("name", 1))));
coll.dropIndexes();
}
示例11: getIndexs
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
/**
* @title getIndexs
* @author lolog
* @description get The Document Indexes
* @param t Object
* @return Indexes
* @throws exception
* @date 2016.07.10 08:48:06
*/
public List<IndexModel> getIndexs (T t);
示例12: createIndexes
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
/**
* Create multiple indexes.
*
* @param indexes the list of indexes
* @return an Observable with a single element indicating when the operation has completed
* @mongodb.driver.manual reference/command/createIndexes Create indexes
* @mongodb.server.release 2.6
*/
Observable<String> createIndexes(List<IndexModel> indexes);
示例13: createIndexes
import com.mongodb.client.model.IndexModel; //导入依赖的package包/类
/**
* Create multiple indexes.
*
* @param indexes the list of indexes
* @return a publisher with a single element indicating when the operation has completed
* @mongodb.driver.manual reference/command/createIndexes Create indexes
* @mongodb.server.release 2.6
*/
Publisher<String> createIndexes(List<IndexModel> indexes);