use of org.springframework.data.mongodb.core.convert.MongoCustomConversions in project spring-integration by spring-projects.
the class AbstractConfigurableMongoDbMessageStore method afterPropertiesSet.
@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));
}
use of org.springframework.data.mongodb.core.convert.MongoCustomConversions in project spring-data-mongodb by spring-projects.
the class MongoTemplate method getDefaultMongoConverter.
private static MongoConverter getDefaultMongoConverter(MongoDatabaseFactory factory) {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
MongoCustomConversions conversions = new MongoCustomConversions(Collections.emptyList());
MongoMappingContext mappingContext = new MongoMappingContext();
mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
mappingContext.afterPropertiesSet();
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContext);
converter.setCustomConversions(conversions);
converter.setCodecRegistryProvider(factory);
converter.afterPropertiesSet();
return converter;
}
use of org.springframework.data.mongodb.core.convert.MongoCustomConversions in project spring-data-mongodb by spring-projects.
the class MappingMongoJsonSchemaCreatorUnitTests method converterRegistered.
// DATAMONGO-1849
@Test
public void converterRegistered() {
MappingMongoConverter converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext);
MongoCustomConversions mcc = new MongoCustomConversions(Collections.singletonList(SimpleToDocumentConverter.INSTANCE));
converter.setCustomConversions(mcc);
converter.afterPropertiesSet();
schemaCreator = new MappingMongoJsonSchemaCreator(converter);
MongoJsonSchema schema = schemaCreator.createSchemaFor(WithNestedDomainType.class);
assertThat(schema.toDocument().get("$jsonSchema", Document.class)).isEqualTo("{ 'type' : 'object', 'properties' : { '_id' : { 'type' : 'object' }, 'nested' : { 'type' : 'object' } } }");
}
use of org.springframework.data.mongodb.core.convert.MongoCustomConversions in project spring-data-mongodb by spring-projects.
the class SessionBoundMongoTemplateTests method getDefaultMongoConverter.
private MongoConverter getDefaultMongoConverter(MongoDatabaseFactory factory) {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
MongoCustomConversions conversions = new MongoCustomConversions(Collections.emptyList());
MongoMappingContext mappingContext = new MongoMappingContext();
mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
mappingContext.afterPropertiesSet();
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContext);
converter.setCustomConversions(conversions);
converter.setCodecRegistryProvider(factory);
converter.afterPropertiesSet();
return converter;
}
use of org.springframework.data.mongodb.core.convert.MongoCustomConversions in project spring-data-mongodb by spring-projects.
the class SpringDataMongodbSerializerUnitTests method takesCustomConversionForEnumsIntoAccount.
// DATAMONGO-1485
@Test
public void takesCustomConversionForEnumsIntoAccount() {
MongoMappingContext context = new MongoMappingContext();
MappingMongoConverter converter = new MappingMongoConverter(dbFactory, context);
converter.setCustomConversions(new MongoCustomConversions(Collections.singletonList(new SexTypeWriteConverter())));
converter.afterPropertiesSet();
this.converter = converter;
this.serializer = new SpringDataMongodbSerializer(this.converter);
Object mappedPredicate = serializer.handle(QPerson.person.sex.eq(Sex.FEMALE));
assertThat(mappedPredicate).isInstanceOf(Document.class);
assertThat(((Document) mappedPredicate).get("sex")).isEqualTo("f");
}
Aggregations