本文整理汇总了Java中org.springframework.data.repository.core.support.AbstractRepositoryMetadata类的典型用法代码示例。如果您正苦于以下问题:Java AbstractRepositoryMetadata类的具体用法?Java AbstractRepositoryMetadata怎么用?Java AbstractRepositoryMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractRepositoryMetadata类属于org.springframework.data.repository.core.support包,在下文中一共展示了AbstractRepositoryMetadata类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerBeansForRoot
import org.springframework.data.repository.core.support.AbstractRepositoryMetadata; //导入依赖的package包/类
@Override
public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource config) {
super.registerBeansForRoot(registry, config);
Set<Class<?>> initialEntitySet = new HashSet<Class<?>>();
Collection<BeanDefinition> candidates = config.getCandidates(resourceLoader);
for (BeanDefinition candidate : candidates) {
Class<?> repositoryInterface = loadRepositoryInterface(candidate.getBeanClassName(), resourceLoader);
if (null == repositoryInterface) {
continue;
}
RepositoryMetadata metadata = AbstractRepositoryMetadata.getMetadata(repositoryInterface);
if (null == metadata) {
continue;
}
initialEntitySet.add(metadata.getDomainType());
}
Object source = config.getSource();
String sqlSessionFactoryRef = config.getAttribute("sqlSessionFactoryRef");
sqlSessionFactoryRef = (null == sqlSessionFactoryRef ? DEFAULT_SQL_SESSION_FACTORY_BEAN_NAME : sqlSessionFactoryRef);
BeanDefinitionBuilder mappingContextBuilder = BeanDefinitionBuilder.rootBeanDefinition(MybatisMappingContext.class);
mappingContextBuilder.addPropertyValue("initialEntitySet", initialEntitySet);
registerIfNotAlreadyRegistered(mappingContextBuilder.getBeanDefinition(), registry, sqlSessionFactoryRef.concat(MAPPING_CONTEXT_SUFFIX), source);
// create database dialect
BeanDefinitionBuilder dialectBuilder = BeanDefinitionBuilder.rootBeanDefinition(DialectFactoryBean.class);
dialectBuilder.addPropertyReference("sqlSessionFactory", sqlSessionFactoryRef);
registerIfNotAlreadyRegistered(dialectBuilder.getBeanDefinition(), registry, sqlSessionFactoryRef.concat(DIALECT_BEAN_NAME_SUFFIX), source);
// create sqlSessionTemplate bean.
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SqlSessionTemplate.class);
builder.addConstructorArgReference(sqlSessionFactoryRef);
registerIfNotAlreadyRegistered(builder.getBeanDefinition(), registry, sqlSessionFactoryRef.concat(SQL_SESSION_TEMPLATE_BEAN_NAME_SUFFIX), source);
// create mybatis mapper register
if (config instanceof MybatisAnnotationRepositoryConfigurationSource) {
String[] mapperLocations = ((MybatisAnnotationRepositoryConfigurationSource) config).getMapperLocations();
if (null != mapperLocations && mapperLocations.length > 0) {
BeanDefinitionBuilder builder1 = BeanDefinitionBuilder.rootBeanDefinition(MybatisMappersRegister.class);
builder1.addPropertyReference("sqlSessionFactory", sqlSessionFactoryRef);
builder1.addPropertyValue("locations", mapperLocations);
registerIfNotAlreadyRegistered(builder1.getBeanDefinition(), registry, sqlSessionFactoryRef.concat("_MapperLocations"), source);
}
}
}