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


Java CollectionOptions类代码示例

本文整理汇总了Java中org.springframework.data.mongodb.core.CollectionOptions的典型用法代码示例。如果您正苦于以下问题:Java CollectionOptions类的具体用法?Java CollectionOptions怎么用?Java CollectionOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CollectionOptions类属于org.springframework.data.mongodb.core包,在下文中一共展示了CollectionOptions类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
@Before
public void setUp() {

	operations.collectionExists(Person.class) //
			.flatMap(exists -> exists ? operations.dropCollection(Person.class) : Mono.just(exists)) //
			.flatMap(o -> operations.createCollection(Person.class, new CollectionOptions(1024 * 1024, 100, true))) //
			.then() //
			.block();

	repository
			.save(Flux.just(new Person("Walter", "White", 50), //
					new Person("Skyler", "White", 45), //
					new Person("Saul", "Goodman", 42), //
					new Person("Jesse", "Pinkman", 27))) //
			.then() //
			.block();

}
 
开发者ID:callistaenterprise,项目名称:spring-react-one,代码行数:19,代码来源:ReactivePersonRepositoryIntegrationTest.java

示例2: setUp

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
@Before
public void setUp() {

	operations.collectionExists(Person.class) //
			.flatMap(exists -> exists ? operations.dropCollection(Person.class) : Mono.just(exists)) //
			.flatMap(o -> operations.createCollection(Person.class, new CollectionOptions(1024 * 1024, 100, true))) //
			.then() //
			.block();

	repository
			.save(Observable.just(new Person("Walter", "White", 50), //
					new Person("Skyler", "White", 45), //
					new Person("Saul", "Goodman", 42), //
					new Person("Jesse", "Pinkman", 27))) //
			.toBlocking() //
			.last();
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:18,代码来源:RxJava1PersonRepositoryIntegrationTest.java

示例3: onStart

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
/**
 * Application runner to initialize a capped collection for {@link Event}s and insert a new {@link Event} every two
 * seconds.
 * 
 * @param operations
 * @param reactiveOperations
 * @return
 */
@Bean
ApplicationRunner onStart(MongoOperations operations, ReactiveMongoOperations reactiveOperations) {

	return args -> {

		CollectionOptions options = CollectionOptions.empty() //
				.capped() //
				.size(2048) //
				.maxDocuments(1000);

		operations.dropCollection(Event.class);
		operations.createCollection(Event.class, options);

		Flux.interval(Duration.ofSeconds(2)) //
				.map(counter -> new Event(LocalDateTime.now())) //
				.flatMap(reactiveOperations::save) //
				.log() //
				.subscribe();
	};
}
 
开发者ID:olivergierke,项目名称:spring-five-functional-reactive,代码行数:29,代码来源:WebfluxDemo.java

示例4: commandLineRunner

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
@Bean
CommandLineRunner commandLineRunner(MongoOperations operations) {
    return (args) -> {
        // Setup the streaming data endpoint
        if (operations.collectionExists("tightCouplingEvent")) {
            operations.dropCollection("tightCouplingEvent");
        }
        if (operations.collectionExists("query")) {
            operations.dropCollection("query");
        }

        CollectionOptions options = new CollectionOptions(5242880, 100000, true);
        operations.createCollection("tightCouplingEvent", options);
    };
}
 
开发者ID:kbastani,项目名称:service-block-samples,代码行数:16,代码来源:MongoConfig.java

示例5: checkCollection

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
private void checkCollection(String collectionName) {

		if (!mongoAuditTemplate.collectionExists(collectionName)) {
			CollectionOptions options = new CollectionOptions(512000, MAX_DOCUMENTS, true);
			mongoAuditTemplate.createCollection(collectionName, options);
		}

	}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:9,代码来源:TenantLogRepository.java

示例6: MongoDBProvisioner

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param connectionContext - connectionContext
 * @param credentials       - credentials
 * @param clientOptions     - clientOptions
 * @param database          - database
 * @param schemaOptions     - schemaOptions
 * @param collectionOptions - collectionOptions
 */
private MongoDBProvisioner(MongoDBConnectionContext connectionContext, List<MongoCredential> credentials,
                           MongoClientOptions clientOptions, String database, SchemaOptions schemaOptions,
                           CollectionOptions collectionOptions) {

    this.connectionContext = connectionContext;
    this.mongoCredentials = credentials;
    this.clientOptions = clientOptions;
    this.database = database;
    this.schemaOptions = schemaOptions;
    this.collectionOptions = collectionOptions;
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:22,代码来源:MongoDBProvisioner.java

示例7: MongoDBJsonProvisionerBuilder

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param connectionContext  shared Mongo DB resources
 * @param mongoCredentials   logon credentials
 * @param mongoClientOptions client options
 * @param database           database name
 * @param schemaOptions      schema policy
 * @param collectionOptions  collection options
 */
public MongoDBJsonProvisionerBuilder(MongoDBConnectionContext connectionContext,
                                     List<MongoCredential> mongoCredentials,
                                     MongoClientOptions mongoClientOptions,
                                     String database,
                                     SchemaOptions schemaOptions,
                                     CollectionOptions collectionOptions) {
    super(connectionContext, database);
    this.mongoCredentials = mongoCredentials;
    this.mongoClientOptions = mongoClientOptions;
    this.schemaOptions = schemaOptions;
    this.collectionOptions = collectionOptions;
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:23,代码来源:MongoDBProvisioner.java

示例8: MongoDBJsonProvisioner

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param connectionContext  - connectionContext
 * @param mongoCredentials   - mongoCredentials
 * @param mongoClientOptions - mongoClientOptions
 * @param database           - database
 * @param schemaOptions      - schemaOptions
 * @param collectionOptions  - collectionOptions
 * @param collection         - collection
 */
public MongoDBJsonProvisioner(MongoDBConnectionContext connectionContext,
                              List<MongoCredential> mongoCredentials,
                              MongoClientOptions mongoClientOptions,
                              String database, SchemaOptions schemaOptions,
                              CollectionOptions collectionOptions, String collection) {
    this.connectionContext = connectionContext;
    this.mongoCredentials = mongoCredentials;
    this.mongoClientOptions = mongoClientOptions;
    this.database = database;
    this.schemaOptions = schemaOptions;
    this.collectionOptions = collectionOptions;
    this.collection = collection;
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:25,代码来源:MongoDBJsonProvisioner.java

示例9: test

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
@Test
public void test() {
    mockedEntityRepository = mock(MongoRepository.class);
    DBCollection mockedCollection = Mockito.mock(DBCollection.class);
    DB mockedDB = Mockito.mock(DB.class);
    SecurityEvent event = createSecurityEvent();
    LoggerCarrierAspect.aspectOf().setEntityRepository(mockedEntityRepository);
    LoggerCarrierAspect.aspectOf().setCapSize(new String("100"));

    MongoEntityTemplate mockedMongoTemplate = mock(MongoEntityTemplate.class);
    when(mockedEntityRepository.getTemplate()).thenReturn(mockedMongoTemplate);

    when(mockedMongoTemplate.collectionExists("securityEvent")).thenReturn(false);
    audit(event);
    Mockito.verify(mockedMongoTemplate, times(1)).createCollection(any(String.class), any(CollectionOptions.class));
    Mockito.verify(mockedEntityRepository, times(1)).create(any(String.class), any(Map.class), any(Map.class), any(String.class));

    when(mockedMongoTemplate.collectionExists("securityEvent")).thenReturn(true);
    when(mockedMongoTemplate.getCollection("securityEvent")).thenReturn(mockedCollection);
    when(mockedCollection.isCapped()).thenReturn(true);
    audit(event);
    Mockito.verify(mockedEntityRepository, times(2)).create(any(String.class), any(Map.class), any(Map.class), any(String.class));

    when(mockedMongoTemplate.collectionExists("securityEvent")).thenReturn(true);
    when(mockedMongoTemplate.getCollection("securityEvent")).thenReturn(mockedCollection);
    when(mockedMongoTemplate.getDb()).thenReturn(mockedDB);
    when(mockedCollection.isCapped()).thenReturn(false);
    audit(event);
    Mockito.verify(mockedDB, times(1)).command(any(DBObject.class));

    Mockito.verify(mockedEntityRepository, times(3)).create(any(String.class), any(Map.class), any(Map.class), any(String.class));
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:33,代码来源:LoggerCarrierAspectTest.java

示例10: postConstruct

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
@PostConstruct
public void postConstruct() {

	blockingMongo.dropCollection(LoginEvent.class);
	blockingMongo.createCollection(LoginEvent.class, CollectionOptions.empty().capped().size(2048).maxDocuments(1000));

	Flux.interval(Duration.ofSeconds(2)).flatMap(counter -> {

		return mongo.findAll(Person.class).collectList().map(people -> {

			ThreadLocalRandom random = ThreadLocalRandom.current();

			return people.get(random.nextInt(people.size()));
		});
	}).map(p -> new LoginEvent(p, Instant.now())).flatMap(mongo::save).subscribe();
}
 
开发者ID:mp911de,项目名称:reactive-spring,代码行数:17,代码来源:LoginEventController.java

示例11: initializeAllData

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
public static void initializeAllData(final ReactiveMongoTemplate mongoTemplate) {
    
    /*
     *  Drop collections, then create them again
     */
    final Mono<Void> initializeCollections =
            mongoTemplate
                    .dropCollection(Team.class)
                    .then(mongoTemplate.dropCollection(Match.class))
                    .then(mongoTemplate.dropCollection(Player.class))
                    .then(mongoTemplate.dropCollection(MatchEvent.class))
                    .then(mongoTemplate.dropCollection(MatchComment.class))
                    .then(mongoTemplate.createCollection(Team.class))
                    .then(mongoTemplate.createCollection(Match.class))
                    .then(mongoTemplate.createCollection(Player.class))
                    .then(mongoTemplate.createCollection(
                            MatchEvent.class, CollectionOptions.empty().size(104857600).capped())) // max: 100MBytes
                    .then(mongoTemplate.createCollection(
                            MatchComment.class, CollectionOptions.empty().size(104857600).capped())) // max: 100MBytes
                    .then();

    /*
     * Add some test data to the collections: teams and players will come from the
     * utility Data class, but we will generate matches between teams randomly each
     * time the application starts (for the fun of it)
     */
    final Mono<Void> initializeData =
            mongoTemplate
                    // Insert all the teams into the corresponding collection and log
                    .insert(Data.TEAMS, Team.class)
                    .log(LOGGER_INITIALIZE, Level.FINEST)
                    // Collect all inserted team codes and randomly shuffle the list
                    .map(Team::getCode).collectList().doOnNext(Collections::shuffle)
                    .flatMapMany(list -> Flux.fromIterable(list))
                    // Create groups of two teams and insert a new Match for them
                    .buffer(2).map(twoTeams -> new Match(twoTeams.get(0), twoTeams.get(1)))
                    .flatMap(mongoTemplate::insert)
                    .log(LOGGER_INITIALIZE, Level.FINEST)
                    .concatMap(match -> mongoTemplate.insert(new MatchEvent(match.getId(), MatchEvent.Type.MATCH_START, null, null)))
                    // Finally insert the players into their corresponding collection
                    .thenMany(Flux.fromIterable(Data.PLAYERS))
                    .flatMap(mongoTemplate::insert)
                    .log(LOGGER_INITIALIZE, Level.FINEST)
                    .then();


    /*
     * Perform the initialization, blocking (that's OK, we are bootstrapping a testing app)
     */
    initializeCollections.then(initializeData).block();
    
}
 
开发者ID:danielfernandez,项目名称:reactive-matchday,代码行数:53,代码来源:Data.java

示例12: withCollectionOptions

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
public MongoDBProvisionerBuilder withCollectionOptions(CollectionOptions collectionOptions) {
    this.collectionOptions = collectionOptions;
    return this;
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:5,代码来源:MongoDBProvisioner.java

示例13: init

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
@PostConstruct
    public void init(){
        IndexOperations iOps = mongo.indexOps(StoredEvent.class);
        log.info("Preparing stored EventStore Mongo JS..");
        if(!mongo.collectionExists(StoredEvent.class) ){
            DBCollection c = mongo.createCollection(
                    StoredEvent.class,
                    new CollectionOptions(EVT_STORE_SIZE, EVT_STORE_COUNT, Boolean.TRUE)
                    );
            COLL_NAME = c.getName();
        }else{
            COLL_NAME = mongo.getCollectionName(StoredEvent.class);
        }
        iOps.ensureIndex(new Index()
                .on("_id", Sort.Direction.ASC));
        DBCollection coll_Counters = mongo.getDb().getCollection("counters");
        DBObject eventCollCounter = coll_Counters.findOne(new BasicDBObject("_id", COLL_NAME));
        if(eventCollCounter == null){ 
            // We create a new counter, that actually holds the state of the last ID requested
            CommandResult counterCollRes = mongo.getDb().doEval(
                    "db.counters.insert(" +
                    "   {" +
//                    "      _id: '" + COLL_NAME + "'," +
                    "      collTarget: '" + COLL_NAME + "'," +
                    "      seq: 0" +
                    "   }" +
                    ")"
                    );
            counterCollRes.throwOnError();
        }
        CommandResult nextSeqFnRes = mongo.getDb().doEval(
                    "db.system.js.save(" +
                    "   {" +
                    "     _id : 'getNextSequence' ," +
                    "     value : " +
                    "       function getNextSequence(name) { " +
                    "           var oldVal = db.counters.findOne( {collTarget : 'storedEvent'}, {seq:1}).seq; " +
                    "           var ret = db.counters.findAndModify(" + 
                    "           {" + 
                    "               query: { collTarget: name },"+ 
                    "               update: { $set : { seq: oldVal + 1} },"+ 
                    "               'new' : true" + 
                    "           });" +
                    "           return ret.seq;" +
                    "       }" +
                          // Increment ($inc) doesn't work on Mongopi version  
//                            "function getNextSequence(name) {" +
//                            "   var ret = db.counters.findAndModify(" +
//                            "          {" +
//                            "            query: { collTarget: name }," +
//                            "            update: { $inc: { seq: 1 } }," +
//                            "            new: true" +
//                            "          }" +
//                            "   );" +
//                            "   return ret.seq;" +
//                            "}" +
                    "   }" +
                    ");"
                );
        nextSeqFnRes.throwOnError();
        log.info(nextSeqFnRes.toString());
        
    }
 
开发者ID:datenstrudel,项目名称:bulbs-core,代码行数:64,代码来源:DomainEventStoreMongo.java

示例14: MongoDBCacheLoader

import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
/**
 * Constructor.
 * @param keyType - keyType
 * @param valueType - valueType
 * @param connectionContext - connectionContext
 * @param credentials - credentials
 * @param clientOptions - clientOptions
 * @param database - database
 * @param schemaOptions - schemaOptions
 * @param collectionOptions - collectionOptions
 */
public MongoDBCacheLoader(Class<K> keyType, Class<V> valueType,
                          MongoDBConnectionContext connectionContext,
                          List<MongoCredential> credentials,
                          MongoClientOptions clientOptions,
                          String database, SchemaOptions schemaOptions,
                          CollectionOptions collectionOptions) {
    super(connectionContext, clientOptions, keyType, schemaOptions, valueType,
        credentials, database);
    this.collectionOptions = collectionOptions;
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:22,代码来源:MongoDBCacheLoader.java


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