当前位置: 首页>>代码示例>>Java>>正文


Java AbstractRepositoryMetadata类代码示例

本文整理汇总了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);
        }
    }

}
 
开发者ID:hatunet,项目名称:spring-data-mybatis,代码行数:56,代码来源:MybatisRepositoryConfigExtension.java


注:本文中的org.springframework.data.repository.core.support.AbstractRepositoryMetadata类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。