本文整理汇总了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();
}
示例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();
};
}
示例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);
};
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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();
}
示例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();
}
示例12: withCollectionOptions
import org.springframework.data.mongodb.core.CollectionOptions; //导入依赖的package包/类
public MongoDBProvisionerBuilder withCollectionOptions(CollectionOptions collectionOptions) {
this.collectionOptions = collectionOptions;
return this;
}
示例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());
}
示例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;
}