Index indexDefinition = new Index().on(dotPath, IndexDirection.ASCENDING.equals(index.direction()) ? Sort.Direction.ASC : Sort.Direction.DESC); indexDefinition.named(pathAwareIndexName(index.name(), dotPath, persitentProperty)); indexDefinition.unique(); indexDefinition.sparse(); indexDefinition.background(); indexDefinition.expire(index.expireAfterSeconds(), TimeUnit.SECONDS);
@Override public Document getIndexKeys() { Document document = new Document(); document.putAll(this.keys); document.putAll(super.getIndexKeys()); return document; } }
@Override public String toString() { return String.format("Index: %s - Options: %s", getIndexKeys(), getIndexOptions()); } }
public void onCreation(PartTreeMongoQuery query) { PartTree tree = query.getTree(); if (!tree.hasPredicate()) { return; } Index index = new Index(); index.named(query.getQueryMethod().getName()); Sort sort = tree.getSort(); for (Part part : tree.getParts()) { if (GEOSPATIAL_TYPES.contains(part.getType())) { return; } String property = part.getProperty().toDotPath(); Direction order = toDirection(sort, property); index.on(property, order); } // Add fixed sorting criteria to index if (sort.isSorted()) { for (Order order : sort) { index.on(order.getProperty(), order.getDirection()); } } MongoEntityMetadata<?> metadata = query.getQueryMethod().getEntityInformation(); indexOperationsProvider.indexOps(metadata.getCollectionName()).ensureIndex(index); LOG.debug(String.format("Created %s!", index)); }
@Override public void afterPropertiesSet() throws Exception { if (this.mongoTemplate == null) { if (this.mappingMongoConverter == null) { this.mappingMongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(this.mongoDbFactory), new MongoMappingContext()); this.mappingMongoConverter.setApplicationContext(this.applicationContext); List<Object> customConverters = new ArrayList<Object>(); customConverters.add(new MessageToBinaryConverter()); customConverters.add(new BinaryToMessageConverter()); this.mappingMongoConverter.setCustomConversions(new MongoCustomConversions(customConverters)); this.mappingMongoConverter.afterPropertiesSet(); } this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mappingMongoConverter); } this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.applicationContext); IndexOperations indexOperations = this.mongoTemplate.indexOps(this.collectionName); indexOperations.ensureIndex(new Index(MessageDocumentFields.MESSAGE_ID, Sort.Direction.ASC)); indexOperations.ensureIndex(new Index(MessageDocumentFields.GROUP_ID, Sort.Direction.ASC) .on(MessageDocumentFields.MESSAGE_ID, Sort.Direction.ASC) .unique()); indexOperations.ensureIndex(new Index(MessageDocumentFields.GROUP_ID, Sort.Direction.ASC) .on(MessageDocumentFields.LAST_MODIFIED_TIME, Sort.Direction.DESC) .on(MessageDocumentFields.SEQUENCE, Sort.Direction.DESC)); }
@Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); this.mongoTemplate.indexOps(this.collectionName) .ensureIndex(new Index(MessageDocumentFields.GROUP_ID, Sort.Direction.ASC) .on(MessageDocumentFields.PRIORITY, Sort.Direction.DESC) .on(MessageDocumentFields.LAST_MODIFIED_TIME, Sort.Direction.ASC) .on(MessageDocumentFields.SEQUENCE, Sort.Direction.ASC)); }
/** * 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)); }
public MongoIndex on(String key, Direction direction) { index.on(key, direction); return this; }
public MongoIndex() { index = new Index(); options = new IndexOptions(); }
/** * Specifies TTL in seconds. * * @param value * @return * @since 1.5 */ public Index expire(long value) { return expire(value, TimeUnit.SECONDS); }
public void onCreation(PartTreeMongoQuery query) { PartTree tree = query.getTree(); if (!tree.hasPredicate()) { return; } Index index = new Index(); index.named(query.getQueryMethod().getName()); Sort sort = tree.getSort(); for (Part part : tree.getParts()) { if (GEOSPATIAL_TYPES.contains(part.getType())) { return; } String property = part.getProperty().toDotPath(); Direction order = toDirection(sort, property); index.on(property, order); } // Add fixed sorting criteria to index if (sort.isSorted()) { for (Order order : sort) { index.on(order.getProperty(), order.getDirection()); } } MongoEntityMetadata<?> metadata = query.getQueryMethod().getEntityInformation(); indexOperationsProvider.indexOps(metadata.getCollectionName()).ensureIndex(index); LOG.debug(String.format("Created %s!", index)); }
@Override public void afterPropertiesSet() throws Exception { if (this.applicationContext != null) { this.converter.setApplicationContext(this.applicationContext); } this.converter.afterPropertiesSet(); IndexOperations indexOperations = this.template.indexOps(this.collectionName); indexOperations.ensureIndex(new Index(GROUP_ID_KEY, Sort.Direction.ASC) .on(GROUP_UPDATE_TIMESTAMP_KEY, Sort.Direction.DESC) .on(SEQUENCE, Sort.Direction.DESC)); }
public MongoIndex on(String key) { index.on(key, Direction.ASC); return this; }
public MongoIndex() { index = new Index(); options = new IndexOptions(); }
@Override public String toString() { return String.format("Index: %s - Options: %s", getIndexKeys(), getIndexOptions()); } }
/** * Specifies TTL in seconds. * * @param value * @return * @since 1.5 */ public Index expire(long value) { return expire(value, TimeUnit.SECONDS); }
@PostConstruct public void ensureIndexes() throws Exception { mongoTemplate().indexOps(GRID_FS_THESIS_CONTENT_BUCKET +".files").ensureIndex(new Index("metadata.thesisMetadataId", Direction.ASC)); mongoTemplate().indexOps(DataClient.class).ensureIndex(new Index().unique().on("name", Direction.ASC)); mongoTemplate().indexOps(InstitutionalServer.class).ensureIndex(new Index().unique().on("institutionId", Direction.ASC)); }
Index indexDefinition = new Index().on(dotPath, IndexDirection.ASCENDING.equals(index.direction()) ? Sort.Direction.ASC : Sort.Direction.DESC); indexDefinition.named(pathAwareIndexName(index.name(), dotPath, persitentProperty)); indexDefinition.unique(); indexDefinition.sparse(); indexDefinition.background(); indexDefinition.expire(index.expireAfterSeconds(), TimeUnit.SECONDS);
private void upgradeIndexes() { if (indexNotExists(CONTENT_HASH_INDEX)) { mongoTemplate.indexOps(collectionName).ensureIndex(new Index().on("contentHash", Direction.ASC).named(CONTENT_HASH_INDEX)); } if (indexNotExists(FLOW_NAME_INDEX)) { mongoTemplate.indexOps(collectionName).ensureIndex(new Index().on("flowName", Direction.ASC).named(FLOW_NAME_INDEX)); } }