当前位置: 首页>>代码示例>>Java>>正文


Java IndexOptions.background方法代码示例

本文整理汇总了Java中com.mongodb.client.model.IndexOptions.background方法的典型用法代码示例。如果您正苦于以下问题:Java IndexOptions.background方法的具体用法?Java IndexOptions.background怎么用?Java IndexOptions.background使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.client.model.IndexOptions的用法示例。


在下文中一共展示了IndexOptions.background方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: internalSetupIndexes

import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
private void internalSetupIndexes(Class<?> entityClass, MongoCollection<Document> collection) {

        if (entityClass == null || collection == null) {
            return;
        }

        MongoIndex[] indexes = entityClass.getAnnotationsByType(MongoIndex.class);
        if (indexes != null && indexes.length > 0) {
            for (MongoIndex index : indexes) {
                Document indexDocument = new Document();
                indexDocument.put(index.key(), index.direction());

                IndexOptions options = new IndexOptions();
                options.unique(index.unique());
                options.background(index.background());
                collection.createIndex(indexDocument, options);
            }
        }
    }
 
开发者ID:seventyone-io,项目名称:mongo-utils,代码行数:20,代码来源:MongoServiceImplementation.java

示例2: createIndex

import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
/**
 *
 * @param dbName
 * @param collection
 * @param keys
 * @param options
 */
void createIndex(
        String dbName,
        String collection,
        BsonDocument keys,
        BsonDocument options) {
    if (options == null) {
        client
                .getDatabase(dbName)
                .getCollection(collection)
                .createIndex(keys);
    } else {
        // need to find a way to get IndexOptions from json
        IndexOptions io = new IndexOptions();

        io.background(true);

        client
                .getDatabase(dbName)
                .getCollection(collection)
                .createIndex(keys, getIndexOptions(options));
    }
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:30,代码来源:IndexDAO.java

示例3: init

import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
private void init() {
    LOG.info(">>> init");

    try {
        mongo = new MongoDbAccessor(serverDto.getAdminUser(), serverDto.getAdminPw(), serverDto.getHosts());
        final MongoDatabase db = mongo.getMongoDatabase(serverDto.getDb());
        profileCollection =  db.getCollection(serverDto.getCollection());

        if(profileCollection == null) {
            throw new IllegalArgumentException("Can't continue without profile collection for " + serverDto.getHosts());
        }

        IndexOptions indexOptions = new IndexOptions();
        indexOptions.background(true);
        LOG.info("Create index {ts:-1, lbl:1} in the background if it does not yet exists");
        profileCollection.createIndex(new BasicDBObject("ts",-1).append("lbl", 1), indexOptions);
        LOG.info("Create index {adr:1, db:1, ts:-1} in the background if it does not yet exists");
        profileCollection.createIndex(new BasicDBObject("adr",1).append("db",1).append("ts", -1), indexOptions);

    } catch (MongoException e) {
        LOG.error("Exception while connecting to: {}", serverDto.getHosts(), e);
    }    
    
    LOG.info("<<< init");
}
 
开发者ID:idealo,项目名称:mongodb-slow-operations-profiler,代码行数:26,代码来源:ProfilingWriter.java

示例4: createChange

import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
private MongoIndexChange createChange (CompoundIndex index, boolean replace){
	
	Document definition = Document.parse(index.def());
	
	IndexOptions opts = new IndexOptions();
	opts.name(index.name());
	opts.unique(index.unique());
	opts.sparse(index.sparse());
	opts.background(index.background());
	
	return new MongoIndexChange(index.name(), definition, opts, replace);
}
 
开发者ID:wesley-ramos,项目名称:spring-multitenancy,代码行数:13,代码来源:MongoPersistentEntityIndexCreator.java

示例5: createIndex

import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
/**
 * 创建索引
 *
 * @param collectionName 集合
 * @param indexName      索引名
 * @param keys           键信息,如 securityCode:1
 * @param isUnique       是否唯一索引
 */
public void createIndex(String collectionName, String indexName, Map<String, Integer> keys, boolean isUnique) {
    MongoCollection collection = sMongoDatabase.getCollection(collectionName);
    IndexOptions indexOptions = new IndexOptions();
    indexOptions.background(true);
    indexOptions.unique(isUnique);
    indexOptions.name(indexName);
    Map<String, Object> keyIndexs = new HashMap<>(16);
    for (Map.Entry<String, Integer> entry : keys.entrySet()) {
        keyIndexs.put(entry.getKey(), entry.getValue() > 0 ? 1 : entry.getValue() == 0 ? 0 : -1);
    }
    collection.createIndex(new Document(keyIndexs), indexOptions);
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:21,代码来源:MongodbDataAccess.java

示例6: AbstractOperation

import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
public AbstractOperation(MongoDbAccessor mongoDbAccessor, String db, String collection, String queriedField){
    this.mongoDbAccessor = mongoDbAccessor;
    mongoCollection = mongoDbAccessor.getMongoDatabase(db).getCollection(collection);
    this.queriedField = queriedField;

    final IndexOptions options = new IndexOptions();
    options.background(false);
    mongoCollection.createIndex(new BasicDBObject(queriedField, 1), options);
    minId = getMinMax(mongoDbAccessor, queriedField, true);
    maxId = getMinMax(mongoDbAccessor, queriedField, false);

}
 
开发者ID:idealo,项目名称:mongodb-performance-test,代码行数:13,代码来源:AbstractOperation.java

示例7: PrepareSystem

import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
private void PrepareSystem(POCTestOptions testOpts,POCTestResults results)
{
	MongoDatabase db;
	MongoCollection<Document>  coll;
	//Create indexes and suchlike
	db = mongoClient.getDatabase(testOpts.databaseName);
	coll = db.getCollection(testOpts.collectionName);
	if(testOpts.emptyFirst)
	{
		coll.drop();
	}
	

	for(int x=0;x<testOpts.secondaryidx;x++)
	{
		coll.createIndex(new Document("fld"+x,1));
	}
       if (testOpts.fulltext) 
       {
           IndexOptions options = new IndexOptions();
           options.background(true);
           BasicDBObject weights = new BasicDBObject();
           weights.put("lorem", 15);
           weights.put("_fulltext.text", 5);
           options.weights(weights);
           Document index = new Document();
           index.put("$**", "text");
           coll.createIndex(index, options);
       }
	
	results.initialCount = coll.count();
	//Now have a look and see if we are sharded
	//And how many shards and make sure that the collection is sharded
	if(! testOpts.singleserver) {
		ConfigureSharding(testOpts);
	}
	
	
}
 
开发者ID:johnlpage,项目名称:POCDriver,代码行数:40,代码来源:LoadRunner.java

示例8: createIndex

import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
protected void createIndex(String name, BasicDBList dbList, MongoCollection<Document> collection) {
    if (dbList.isEmpty() || name == null) {
        return;
    }

    BasicDBObject index = (BasicDBObject) dbList.get(0);
    IndexOptions options = new IndexOptions().name(name);
    if (dbList.size() > 1) {
        BasicDBObject opts = (BasicDBObject) dbList.get(1);
        if (opts.get("unique") != null && opts.get("unique") instanceof Boolean) {
            options = options.unique(opts.getBoolean("unique"));
        }
        if (opts.get("expireAfterSeconds") != null && opts.get("expireAfterSeconds") instanceof Integer) {
            options = options.expireAfter(Long.valueOf(opts.getInt("expireAfterSeconds")), TimeUnit.SECONDS);
        }
        if (opts.get("background") != null && opts.get("background") instanceof Boolean) {
            options = options.background(opts.getBoolean("background"));
        }
        if (opts.get("bits") != null && opts.get("bits") instanceof Integer) {
            options = options.bits(opts.getInt("bits"));
        }
        if (opts.get("bucketSize") != null && opts.get("bucketSize") instanceof Double) {
            options = options.bucketSize(opts.getDouble("bucketSize"));
        }
        if (opts.get("defaultLanguage") != null && opts.get("defaultLanguage") instanceof String) {
            options = options.defaultLanguage(opts.getString("defaultLanguage"));
        }
        if (opts.get("languageOverride") != null && opts.get("languageOverride") instanceof String) {
            options = options.languageOverride(opts.getString("languageOverride"));
        }
        if (opts.get("min") != null && opts.get("min") instanceof Double) {
            options = options.min(opts.getDouble("min"));
        }
        if (opts.get("max") != null && opts.get("max") instanceof Double) {
            options = options.max(opts.getDouble("max"));
        }
        if (opts.get("sparse") != null && opts.get("sparse") instanceof Boolean) {
            options = options.sparse(opts.getBoolean("sparse"));
        }
        if (opts.get("textVersion") != null && opts.get("textVersion") instanceof Integer) {
            options = options.textVersion(opts.getInt("textVersion"));
        }
        if (opts.get("version") != null && opts.get("version") instanceof Integer) {
            options = options.version(opts.getInt("version"));
        }
        if (opts.get("weights") != null && opts.get("weights") instanceof Bson) {
            options = options.weights((Bson) opts.get("weights"));
        }
    }
    collection.createIndex(new Document(index), options);
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:52,代码来源:AbstractMongoProcessor.java

示例9: getIndexs

import com.mongodb.client.model.IndexOptions; //导入方法依赖的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;
}
 
开发者ID:lolog,项目名称:mogodb-dao,代码行数:63,代码来源:DocumentUtilImpl.java


注:本文中的com.mongodb.client.model.IndexOptions.background方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。