Java 类com.mongodb.client.model.IndexModel 实例源码

项目:ibm-performance-monitor    文件:ProfiledMongoCollection.java   
@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;
}
项目:mogodb-dao    文件:MongoDaoImpl.java   
@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;
}
项目:mogodb-dao    文件:MongoDaoImpl.java   
@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;
}
项目:ibm-performance-monitor    文件:MongoUtilities.java   
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;
}
项目:mongo-java-driver-rx    文件:MongoCollectionImpl.java   
@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);
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@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);
        }
    }));
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@Override
public Publisher<String> createIndexes(final ClientSession clientSession, 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(clientSession, indexes, createIndexOptions, callback);
        }
    }));
}
项目:mogodb-dao    文件:DocumentUtilImpl.java   
@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;
}
项目:sam    文件:CreateDatabaseCommand.java   
@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")
    )
  ));
}
项目:MongoDB-Plugin    文件:MongoIndex.java   
public MongoIndex add(MongoIndex mongoIndex) {
    indexModels.add(new IndexModel(Indexes.compoundIndex(mongoIndex.getBson()), mongoIndex));
    return this;
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@Override
public Publisher<String> createIndexes(final List<IndexModel> indexes) {
    return createIndexes(indexes, new CreateIndexOptions());
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@Override
public Publisher<String> createIndexes(final ClientSession clientSession, final List<IndexModel> indexes) {
    return createIndexes(clientSession, indexes, new CreateIndexOptions());
}
项目:ibm-performance-monitor    文件:ProfiledMongoClientTest.java   
@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();
}
项目:mogodb-dao    文件:DocumentUtil.java   
/**
 * @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);
项目:mongo-java-driver-rx    文件:MongoCollection.java   
/**
 * 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);
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * 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);
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * Create multiple indexes.
 *
 * @param indexes the list of indexes
 * @param createIndexOptions options to use when creating 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
 * @since 1.7
 */
Publisher<String> createIndexes(List<IndexModel> indexes, CreateIndexOptions createIndexOptions);
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * Create multiple indexes.
 *
 * @param clientSession the client session with which to associate this operation
 * @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 3.6
 * @since 1.7
 */
Publisher<String> createIndexes(ClientSession clientSession, List<IndexModel> indexes);
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * Create multiple indexes.
 *
 * @param clientSession the client session with which to associate this operation
 * @param indexes the list of indexes
 * @param createIndexOptions options to use when creating 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 3.6
 * @since 1.7
 */
Publisher<String> createIndexes(ClientSession clientSession, List<IndexModel> indexes, CreateIndexOptions createIndexOptions);