Search in sources :

Example 1 with MapperFactoryBean

use of cn.taketoday.orm.mybatis.mapper.MapperFactoryBean in project today-framework by TAKETODAY.

the class MapperScannerRegistrar method registerBeanDefinitions.

protected void registerBeanDefinitions(AnnotationMetadata annoMeta, MergedAnnotation<MapperScan> mapperScan, BeanDefinitionRegistry registry, String beanName) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
    builder.addPropertyValue("processPropertyPlaceHolders", true);
    Class<? extends Annotation> annotationClass = mapperScan.getClass("annotationClass");
    if (!Annotation.class.equals(annotationClass)) {
        builder.addPropertyValue("annotationClass", annotationClass);
    }
    Class<?> markerInterface = mapperScan.getClass("markerInterface");
    if (!Class.class.equals(markerInterface)) {
        builder.addPropertyValue("markerInterface", markerInterface);
    }
    Class<? extends BeanNameGenerator> generatorClass = mapperScan.getClass("nameGenerator");
    if (!BeanNameGenerator.class.equals(generatorClass)) {
        builder.addPropertyValue("nameGenerator", BeanUtils.newInstance(generatorClass));
    }
    Class<? extends MapperFactoryBean<?>> mapperFactoryBeanClass = mapperScan.getClass("factoryBean");
    if (!MapperFactoryBean.class.equals(mapperFactoryBeanClass)) {
        builder.addPropertyValue("mapperFactoryBeanClass", mapperFactoryBeanClass);
    }
    String sqlSessionTemplateRef = mapperScan.getString("sqlSessionTemplateRef");
    if (StringUtils.hasText(sqlSessionTemplateRef)) {
        builder.addPropertyValue("sqlSessionTemplateBeanName", sqlSessionTemplateRef);
    }
    String sqlSessionFactoryRef = mapperScan.getString("sqlSessionFactoryRef");
    if (StringUtils.hasText(sqlSessionFactoryRef)) {
        builder.addPropertyValue("sqlSessionFactoryBeanName", sqlSessionFactoryRef);
    }
    ArrayList<String> basePackages = new ArrayList<>();
    basePackages.addAll(Arrays.stream(mapperScan.getStringArray("value")).filter(StringUtils::hasText).toList());
    basePackages.addAll(Arrays.stream(mapperScan.getStringArray("basePackages")).filter(StringUtils::hasText).toList());
    basePackages.addAll(Arrays.stream(mapperScan.getClassArray("basePackageClasses")).map(ClassUtils::getPackageName).toList());
    if (basePackages.isEmpty()) {
        basePackages.add(getDefaultBasePackage(annoMeta));
    }
    String lazyInitialization = mapperScan.getString("lazyInitialization");
    if (StringUtils.hasText(lazyInitialization)) {
        builder.addPropertyValue("lazyInitialization", lazyInitialization);
    }
    String defaultScope = mapperScan.getString("defaultScope");
    if (StringUtils.hasText(defaultScope)) {
        builder.addPropertyValue("defaultScope", defaultScope);
    }
    builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(basePackages));
    builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    registry.registerBeanDefinition(beanName, builder.getRawBeanDefinition());
}
Also used : MapperFactoryBean(cn.taketoday.orm.mybatis.mapper.MapperFactoryBean) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) MergedAnnotation(cn.taketoday.core.annotation.MergedAnnotation) ClassUtils(cn.taketoday.util.ClassUtils) BeanNameGenerator(cn.taketoday.beans.factory.support.BeanNameGenerator) BeanDefinitionBuilder(cn.taketoday.beans.factory.support.BeanDefinitionBuilder) StringUtils(cn.taketoday.util.StringUtils)

Example 2 with MapperFactoryBean

use of cn.taketoday.orm.mybatis.mapper.MapperFactoryBean in project today-infrastructure by TAKETODAY.

the class MapperScannerRegistrar method registerBeanDefinitions.

protected void registerBeanDefinitions(AnnotationMetadata annoMeta, MergedAnnotation<MapperScan> mapperScan, BeanDefinitionRegistry registry, String beanName) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
    builder.addPropertyValue("processPropertyPlaceHolders", true);
    Class<? extends Annotation> annotationClass = mapperScan.getClass("annotationClass");
    if (!Annotation.class.equals(annotationClass)) {
        builder.addPropertyValue("annotationClass", annotationClass);
    }
    Class<?> markerInterface = mapperScan.getClass("markerInterface");
    if (!Class.class.equals(markerInterface)) {
        builder.addPropertyValue("markerInterface", markerInterface);
    }
    Class<? extends BeanNameGenerator> generatorClass = mapperScan.getClass("nameGenerator");
    if (!BeanNameGenerator.class.equals(generatorClass)) {
        builder.addPropertyValue("nameGenerator", BeanUtils.newInstance(generatorClass));
    }
    Class<? extends MapperFactoryBean<?>> mapperFactoryBeanClass = mapperScan.getClass("factoryBean");
    if (!MapperFactoryBean.class.equals(mapperFactoryBeanClass)) {
        builder.addPropertyValue("mapperFactoryBeanClass", mapperFactoryBeanClass);
    }
    String sqlSessionTemplateRef = mapperScan.getString("sqlSessionTemplateRef");
    if (StringUtils.hasText(sqlSessionTemplateRef)) {
        builder.addPropertyValue("sqlSessionTemplateBeanName", sqlSessionTemplateRef);
    }
    String sqlSessionFactoryRef = mapperScan.getString("sqlSessionFactoryRef");
    if (StringUtils.hasText(sqlSessionFactoryRef)) {
        builder.addPropertyValue("sqlSessionFactoryBeanName", sqlSessionFactoryRef);
    }
    ArrayList<String> basePackages = new ArrayList<>();
    basePackages.addAll(Arrays.stream(mapperScan.getStringArray("value")).filter(StringUtils::hasText).toList());
    basePackages.addAll(Arrays.stream(mapperScan.getStringArray("basePackages")).filter(StringUtils::hasText).toList());
    basePackages.addAll(Arrays.stream(mapperScan.getClassArray("basePackageClasses")).map(ClassUtils::getPackageName).toList());
    if (basePackages.isEmpty()) {
        basePackages.add(getDefaultBasePackage(annoMeta));
    }
    String lazyInitialization = mapperScan.getString("lazyInitialization");
    if (StringUtils.hasText(lazyInitialization)) {
        builder.addPropertyValue("lazyInitialization", lazyInitialization);
    }
    String defaultScope = mapperScan.getString("defaultScope");
    if (StringUtils.hasText(defaultScope)) {
        builder.addPropertyValue("defaultScope", defaultScope);
    }
    builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(basePackages));
    builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    registry.registerBeanDefinition(beanName, builder.getRawBeanDefinition());
}
Also used : MapperFactoryBean(cn.taketoday.orm.mybatis.mapper.MapperFactoryBean) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) MergedAnnotation(cn.taketoday.core.annotation.MergedAnnotation) ClassUtils(cn.taketoday.util.ClassUtils) BeanNameGenerator(cn.taketoday.beans.factory.support.BeanNameGenerator) BeanDefinitionBuilder(cn.taketoday.beans.factory.support.BeanDefinitionBuilder) StringUtils(cn.taketoday.util.StringUtils)

Aggregations

BeanDefinitionBuilder (cn.taketoday.beans.factory.support.BeanDefinitionBuilder)2 BeanNameGenerator (cn.taketoday.beans.factory.support.BeanNameGenerator)2 MergedAnnotation (cn.taketoday.core.annotation.MergedAnnotation)2 MapperFactoryBean (cn.taketoday.orm.mybatis.mapper.MapperFactoryBean)2 ClassUtils (cn.taketoday.util.ClassUtils)2 StringUtils (cn.taketoday.util.StringUtils)2 Annotation (java.lang.annotation.Annotation)2 ArrayList (java.util.ArrayList)2