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)); }
Index indexDefinition = new Index().on(dotPath, IndexDirection.ASCENDING.equals(index.direction()) ? Sort.Direction.ASC : 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)); }
@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)); }
@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)); }
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)); }
public MongoIndex on(String key, Direction direction) { index.on(key, direction); return this; }
public MongoIndex on(String key) { index.on(key, Direction.ASC); return this; }
public MongoIndex on(String key, Direction direction) { index.on(key, direction); return this; }
Index indexDefinition = new Index().on(dotPath, IndexDirection.ASCENDING.equals(index.direction()) ? Sort.Direction.ASC : 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)); }
@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)); }
private void ensureIndex() { IndexOperations indexOperations = mongoTemplate.indexOps(collection); indexOperations.ensureIndex(new Index().on("key", Direction.ASC).unique()); }
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)); } }
@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)); }
@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)); }