本文整理汇总了Java中org.springframework.data.mongodb.core.index.Index类的典型用法代码示例。如果您正苦于以下问题:Java Index类的具体用法?Java Index怎么用?Java Index使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Index类属于org.springframework.data.mongodb.core.index包,在下文中一共展示了Index类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
@Override
public void init() throws DaoException {
if (collectionName == null) {
throw makeNoSensorException();
}
if (!mongoOperation.collectionExists(collectionName)) {
mongoOperation.createCollection(collectionName);
mongoOperation.indexOps(collectionName).ensureIndex(new Index("timestamp", Sort.Direction.ASC).unique());
// Distribute the database across multiple servers (useful in prod)
/* BasicDBObject shardCommand = new BasicDBObject("shardcollection", shardDbName + "." + collectionName);
shardCommand.put("key", new BasicDBObject("timestamp", 1));
CommandResult result = adminMongoOperation.executeCommand(shardCommand);
System.out.println(result.toString()); */
}
}
示例2: run
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
@Override
public void run(String... strings) throws Exception {
createCollectionIfMissing(IAViewUpdate.class);
createCollectionIfMissing(MongoInformationAssetView.class);
mongoTemplate.indexOps(IAViewUpdate.class).ensureIndex(
new Index().on("creationDate", Sort.Direction.DESC).background()
);
mongoTemplate.indexOps(IAViewUpdate.class).ensureIndex(
new Index().on("creationDate", Sort.Direction.ASC).on("docReference", Sort.Direction.ASC).background()
);
mongoTemplate.indexOps(IAViewUpdate.class).ensureIndex(
new Index().on("docReference", Sort.Direction.ASC).background()
);
mongoTemplate.indexOps(MongoInformationAssetView.class).ensureIndex(
new Index().on("series", Sort.Direction.ASC).on("categories", Sort.Direction
.ASC).background()
);
}
示例3: init
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
@PostConstruct
public void init(){
log.info("|- INIT BulbPresetRepositoryImpl..");
log.info(" - DB used: " + mongo.getDb().getName());
IndexOperations iOps = mongo.indexOps(Preset.class);
iOps.ensureIndex(new Index()
.on("_id.presetUuid", Sort.Direction.ASC)
.on("_id.creator", Sort.Direction.ASC)
.unique(Index.Duplicates.DROP)
);
iOps.ensureIndex(new Index()
.on("name", Sort.Direction.ASC)
.on("_id.creator", Sort.Direction.ASC));
}
示例4: ensureIndexes
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
/**
* Method ensures that there is a TTL index on {@literal expireAt} field. It's has
* {@literal expireAfterSeconds} set to zero seconds, so the expiration time is
* controlled by the application.
*
* It can be extended in custom converters when there is a need for creating
* additional custom indexes.
* @param sessionCollectionIndexes {@link IndexOperations} to use
*/
protected void ensureIndexes(IndexOperations sessionCollectionIndexes) {
for (IndexInfo info : sessionCollectionIndexes.getIndexInfo()) {
if (EXPIRE_AT_FIELD_NAME.equals(info.getName())) {
LOG.debug("TTL index on field " + EXPIRE_AT_FIELD_NAME + " already exists");
return;
}
}
LOG.info("Creating TTL index on field " + EXPIRE_AT_FIELD_NAME);
sessionCollectionIndexes
.ensureIndex(new Index(EXPIRE_AT_FIELD_NAME, Sort.Direction.ASC).named(EXPIRE_AT_FIELD_NAME).expire(0));
}
开发者ID:spring-projects,项目名称:spring-session-data-mongodb,代码行数:23,代码来源:AbstractMongoSessionConverter.java
示例5: init
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
@Override
public void init() {
if (!mongoOperation.collectionExists(COLLECTION_NAME)) {
mongoOperation.createCollection(COLLECTION_NAME);
mongoOperation.indexOps(User.class).ensureIndex(new Index("name", Sort.Direction.ASC).unique());
}
}
示例6: initIndices
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
@PostConstruct
public void initIndices() {
log.info("Init BulbsContextUserRepositoryImpl..");
IndexOperations iOps = mongo.indexOps(BulbsContextUser.class);
iOps.ensureIndex(new Index().on("email", Sort.Direction.ASC).unique(Index.Duplicates.RETAIN));
iOps.ensureIndex(new Index().on("apiKey", Sort.Direction.ASC).unique(Index.Duplicates.RETAIN));
}
示例7: init
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
@PostConstruct
public void init(){
log.info("|- INIT BulbGroupRepositoryImpl..");
log.info(" - DB used: " + mongo.getDb().getName());
IndexOperations iOps = mongo.indexOps(BulbGroup.class);
iOps.ensureIndex(new Index()
.on("name", Sort.Direction.ASC));
iOps.ensureIndex(new Index()
.on("_id", Sort.Direction.ASC)
.on("name", Sort.Direction.ASC));
}
示例8: init
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
@PostConstruct
public void init(){
log.info("|- INIT ScheduledActuationRepositoryImpl..");
log.info(" - DB used: " + mongo.getDb().getName());
IndexOperations iOps = mongo.indexOps(ScheduledActuation.class);
iOps.ensureIndex(new Index()
.on("name", Sort.Direction.ASC) );
}
示例9: clearAndIndexCollection
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
private void clearAndIndexCollection(String profiledCollectionName) {
Query query = new Query();
da.mongoTemplate.remove(query, profiledCollectionName);
List<String> indexes = getIndexes();
for(int i = 0; i < indexes.size(); i++) {
da.mongoTemplate.indexOps(profiledCollectionName).ensureIndex(new Index().on(indexes.get(i), Order.ASCENDING));
}
}
示例10: setup
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
private void setup(String profiledCollectionName) {
// setup
da.mongoTemplate.dropCollection(profiledCollectionName);
da.mongoTemplate.createCollection(profiledCollectionName);
List<String> indexes = getIndexes();
for(int i = 0; i < indexes.size(); i++) {
da.mongoTemplate.indexOps(profiledCollectionName).ensureIndex(new Index().on(indexes.get(i), Order.ASCENDING));
}
}
示例11: init
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
@PostConstruct
public void init() {
this.mongoTemplate.indexOps(AccessToken.class).
ensureIndex(new Index().on("lastUsed", Sort.Direction.ASC).expire(expire, TimeUnit.SECONDS));
}
示例12: setupFileNameIndex
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
/**
* We expect filenames in GridFS to be unique.
*/
@PostConstruct
protected void setupFileNameIndex() {
mongoOperations.indexOps("fs.files").ensureIndex(
new Index().on("filename", Direction.ASC).unique());
}
示例13: init
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
@PostConstruct
public void init(){
IndexOperations iOps = mongo.indexOps(BulbBridge.class);
iOps.ensureIndex(new Index()
.on("owner", Sort.Direction.ASC));
}
示例14: init
import org.springframework.data.mongodb.core.index.Index; //导入依赖的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());
}
示例15: createIndexIfNotExisting
import org.springframework.data.mongodb.core.index.Index; //导入依赖的package包/类
private void createIndexIfNotExisting() {
LOGGER.debug("Creating index on OpenIdAssociation collection if none exists.");
this.mongoTemplate.indexOps(OpenIdAssociation.class).ensureIndex(
new Index().on(HANDLE_FIELD, ASCENDING).unique());
}