下面列出了怎么用org.springframework.boot.autoconfigure.domain.EntityScanner的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testDatabaseOperationsOnDynamicallyNamedCollection() throws ClassNotFoundException {
final CosmosDBConfig dbConfig = CosmosDBConfig.builder(dbUri, dbKey, TestConstants.DB_NAME).build();
final CosmosDbFactory dbFactory = new CosmosDbFactory(dbConfig);
cosmosEntityInformation = new CosmosEntityInformation<>(SpELPropertyStudent.class);
final CosmosMappingContext dbContext = new CosmosMappingContext();
dbContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));
final ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
final MappingCosmosConverter mappingConverter = new MappingCosmosConverter(dbContext, objectMapper);
staticTemplate = new CosmosTemplate(dbFactory, mappingConverter, TestConstants.DB_NAME);
staticTemplate.createContainerIfNotExists(cosmosEntityInformation);
final SpELPropertyStudent insertedRecord =
staticTemplate.insert(cosmosEntityInformation.getContainerName(), TEST_PROPERTY_STUDENT, null);
assertNotNull(insertedRecord);
final SpELPropertyStudent readRecord =
staticTemplate.findById(TestConstants.DYNAMIC_PROPERTY_COLLECTION_NAME,
insertedRecord.getId(), SpELPropertyStudent.class);
assertNotNull(readRecord);
}
@Before
public void setUp() throws ClassNotFoundException {
if (!initialized) {
final CosmosDbFactory cosmosDbFactory = new CosmosDbFactory(dbConfig);
roleInfo = new CosmosEntityInformation<>(Role.class);
sampleInfo = new CosmosEntityInformation<>(TimeToLiveSample.class);
final CosmosMappingContext dbContext = new CosmosMappingContext();
dbContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));
final MappingCosmosConverter mappingConverter = new MappingCosmosConverter(dbContext, null);
cosmosTemplate = new CosmosTemplate(cosmosDbFactory, mappingConverter, dbConfig.getDatabase());
initialized = true;
}
collectionRole = cosmosTemplate.createContainerIfNotExists(roleInfo);
collectionSample = cosmosTemplate.createContainerIfNotExists(sampleInfo);
cosmosTemplate.insert(roleInfo.getContainerName(), TEST_ROLE, null);
}
@Before
public void setUp() throws ClassNotFoundException {
if (!initialized) {
final CosmosDbFactory dbFactory = new CosmosDbFactory(dbConfig);
final CosmosMappingContext mappingContext = new CosmosMappingContext();
personInfo =
new CosmosEntityInformation<>(PartitionPerson.class);
containerName = personInfo.getContainerName();
mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));
final MappingCosmosConverter dbConverter = new MappingCosmosConverter(mappingContext,
null);
cosmosTemplate = new ReactiveCosmosTemplate(dbFactory, dbConverter, dbConfig.getDatabase());
cosmosTemplate.createContainerIfNotExists(personInfo).block();
initialized = true;
}
cosmosTemplate.insert(TEST_PERSON).block();
}
@Before
public void setUp() throws ClassNotFoundException {
if (!initialized) {
final CosmosDbFactory cosmosDbFactory = new CosmosDbFactory(dbConfig);
final CosmosMappingContext mappingContext = new CosmosMappingContext();
personInfo = new CosmosEntityInformation<>(PartitionPerson.class);
mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));
final MappingCosmosConverter dbConverter = new MappingCosmosConverter(mappingContext, null);
cosmosTemplate = new CosmosTemplate(cosmosDbFactory, dbConverter, dbConfig.getDatabase());
containerName = personInfo.getContainerName();
cosmosTemplate.createContainerIfNotExists(personInfo);
initialized = true;
}
cosmosTemplate.insert(PartitionPerson.class.getSimpleName(), TEST_PERSON,
new PartitionKey(TEST_PERSON.getLastName()));
}
@Before
public void setUp() throws ClassNotFoundException {
if (!initialized) {
final CosmosDbFactory cosmosDbFactory = new CosmosDbFactory(dbConfig);
final CosmosMappingContext mappingContext = new CosmosMappingContext();
personInfo = new CosmosEntityInformation<>(Person.class);
containerName = personInfo.getContainerName();
mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));
final MappingCosmosConverter cosmosConverter = new MappingCosmosConverter(mappingContext,
null);
cosmosTemplate = new CosmosTemplate(cosmosDbFactory, cosmosConverter, dbConfig.getDatabase());
cosmosTemplate.createContainerIfNotExists(personInfo);
initialized = true;
}
insertedPerson = cosmosTemplate.insert(Person.class.getSimpleName(), TEST_PERSON, null);
}
@Before
public void setUp() throws ClassNotFoundException {
if (!initialized) {
cosmosKeyCredential = new CosmosKeyCredential(dbConfig.getKey());
final CosmosDbFactory dbFactory = new CosmosDbFactory(dbConfig);
final CosmosMappingContext mappingContext = new CosmosMappingContext();
personInfo = new CosmosEntityInformation<>(Person.class);
containerName = personInfo.getContainerName();
mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));
final MappingCosmosConverter dbConverter =
new MappingCosmosConverter(mappingContext, null);
cosmosTemplate = new ReactiveCosmosTemplate(dbFactory, dbConverter, dbConfig.getDatabase());
cosmosTemplate.createContainerIfNotExists(personInfo).block().container();
initialized = true;
}
insertedPerson = cosmosTemplate.insert(TEST_PERSON,
new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON))).block();
}
@Bean
@ConditionalOnMissingBean
public Neo4jMappingContext neo4jMappingContext(
ApplicationContext applicationContext, Neo4jConversions neo4jConversions
) throws ClassNotFoundException {
Set<Class<?>> initialEntityClasses = new EntityScanner(applicationContext).scan(Node.class);
Neo4jMappingContext context = new Neo4jMappingContext(neo4jConversions);
context.setInitialEntitySet(initialEntityClasses);
return context;
}
@Bean
@ConditionalOnMissingBean
public MongoMappingContext mongoMappingContext(MongoCustomConversions conversions)
throws ClassNotFoundException {
MongoMappingContext context = new MongoMappingContext();
context.setInitialEntitySet(new EntityScanner(this.applicationContext)
.scan(Document.class, Persistent.class));
Class<?> strategyClass = this.beihuMongoProperties.getFieldNamingStrategy();
if (strategyClass != null) {
context.setFieldNamingStrategy(
(FieldNamingStrategy) BeanUtils.instantiateClass(strategyClass));
}
context.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
return context;
}