Example usage for org.apache.ibatis.builder MapperBuilderAssistant MapperBuilderAssistant

List of usage examples for org.apache.ibatis.builder MapperBuilderAssistant MapperBuilderAssistant

Introduction

In this page you can find the example usage for org.apache.ibatis.builder MapperBuilderAssistant MapperBuilderAssistant.

Prototype

public MapperBuilderAssistant(Configuration configuration, String resource) 

Source Link

Usage

From source file:com.baomidou.mybatisplus.MybatisMapperAnnotationBuilder.java

License:Apache License

public MybatisMapperAnnotationBuilder(Configuration configuration, Class<?> type) {
    // TODO //w w  w .ja  v a  2 s  .  c  om
    super(configuration, type);
    String resource = type.getName().replace('.', '/') + ".java (best guess)";
    this.assistant = new MapperBuilderAssistant(configuration, resource);
    this.configuration = configuration;
    this.type = type;
    sqlAnnotationTypes.add(Select.class);
    sqlAnnotationTypes.add(Insert.class);
    sqlAnnotationTypes.add(Update.class);
    sqlAnnotationTypes.add(Delete.class);
    sqlProviderAnnotationTypes.add(SelectProvider.class);
    sqlProviderAnnotationTypes.add(InsertProvider.class);
    sqlProviderAnnotationTypes.add(UpdateProvider.class);
    sqlProviderAnnotationTypes.add(DeleteProvider.class);
}

From source file:com.baomidou.mybatisplus.MybatisXMLMapperBuilder.java

License:Apache License

private MybatisXMLMapperBuilder(XPathParser parser, Configuration configuration, String resource,
        Map<String, XNode> sqlFragments) {
    super(configuration);
    this.builderAssistant = new MapperBuilderAssistant(configuration, resource);
    this.parser = parser;
    this.sqlFragments = sqlFragments;
    this.resource = resource;
}

From source file:com.dmm.framework.basedb.apache.ibatis.builder.xml.XMLMapperBuilder.java

License:Apache License

private XMLMapperBuilder(XPathParser parser, Configuration configuration, String resource,
        Map<String, XNode> sqlFragments) {
    super(configuration);
    this.builderAssistant = new MapperBuilderAssistant(configuration, resource);
    this.parser = parser;
    this.sqlFragments = sqlFragments;
    this.resource = resource;
}

From source file:com.github.yuxiaobin.mybatis.gm.GeneralSqlSessionFactoryBean.java

License:Apache License

private void injectSql(GeneralMapperSqlInjector generalSqlInjector) {
    if (configuration instanceof GeneralConfiguration) {
        typeAliasesPackage = ((GeneralConfiguration) configuration).getTypeAliasesPackage();
    }/*www .  j  av  a  2 s.co m*/
    if (StringUtils.hasLength(typeAliasesPackage)) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("injectSql(): typeAliasesPackage=" + typeAliasesPackage);
        }
        String[] typeAliasPackageArray = MybatisGeneralEntityProcessor
                .parseTypeAliasPackage(this.typeAliasesPackage);
        if (typeAliasPackageArray != null) {
            MybatisGeneralEntityProcessor.typeAliasPackageArray = typeAliasPackageArray;
            for (String packageToScan : typeAliasPackageArray) {
                configuration.getTypeAliasRegistry().registerAliases(packageToScan, Object.class);
            }
        }
    }
    for (Map.Entry<String, Class<?>> type : configuration.getTypeAliasRegistry().getTypeAliases().entrySet()) {
        if (checkValidateClassTypes(type.getValue())) {
            MapperBuilderAssistant assistant = new MapperBuilderAssistant(configuration,
                    type.getValue().getPackage().getName());
            assistant.setCurrentNamespace(MybatisGeneralEntityProcessor.generateNamespace(type.getValue()));
            generalSqlInjector.inject(configuration, assistant, GeneralMapper.class, type.getValue(), null);
        }
    }
}

From source file:com.mybatisX.core.MybatisMapperAnnotationBuilder.java

License:Apache License

public MybatisMapperAnnotationBuilder(Configuration configuration, Class<?> type) {
    super(configuration, type);
    String resource = type.getName().replace('.', '/') + ".java (best guess)";
    this.assistant = new MapperBuilderAssistant(configuration, resource);
    this.configuration = configuration;
    this.type = type;
    sqlAnnotationTypes.add(Select.class);
    sqlAnnotationTypes.add(Insert.class);
    sqlAnnotationTypes.add(Update.class);
    sqlAnnotationTypes.add(Delete.class);
    sqlProviderAnnotationTypes.add(SelectProvider.class);
    sqlProviderAnnotationTypes.add(InsertProvider.class);
    sqlProviderAnnotationTypes.add(UpdateProvider.class);
    sqlProviderAnnotationTypes.add(DeleteProvider.class);
}

From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java

License:Open Source License

public GenericStatementBuilder(Configuration configuration, final Class<?> entityClass) {
    super(configuration);
    this.entityClass = entityClass;
    sharded = ConfigurationProperties.isSharded(configuration);
    String resource = entityClass.getName().replace('.', '/') + ".java (best guess)";
    assistant = new MapperBuilderAssistant(configuration, resource);
    entity = entityClass.getAnnotation(Entity.class);
    mapperType = entity.mapper();// w  ww .  j a  va  2s.c  o m

    if (!mapperType.isAssignableFrom(Void.class)) {
        namespace = mapperType.getName();
    } else {
        namespace = entityClass.getName();
    }
    assistant.setCurrentNamespace(namespace);
    Collection<String> cacheNames = configuration.getCacheNames();
    for (String name : cacheNames)
        if (namespace.equals(name)) {
            assistant.useCacheRef(name);
            break;
        }

    databaseId = super.getConfiguration().getDatabaseId();
    lang = super.getConfiguration().getDefaultScriptingLanuageInstance();

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Table table = entityClass.getAnnotation(Table.class);
    if (table == null) {
        tableName = CaseFormatUtils.camelToUnderScore(entityClass.getSimpleName());
    } else {
        tableName = table.name();
    }

    ///~~~~~~~~~~~~~~~~~~~~~~
    idField = AnnotationUtils.findDeclaredFieldWithAnnoation(Id.class, entityClass);
    if (!sharded && (this.idField.isAnnotationPresent(GeneratedValue.class))
            && (((GeneratedValue) this.idField.getAnnotation(GeneratedValue.class))
                    .strategy() == GenerationType.UUID))
        columnFields.add(idField);
    else
        columnFields.add(idField);
    versionField = AnnotationUtils.findDeclaredFieldWithAnnoation(Version.class, entityClass);

    ReflectionUtils.doWithFields(entityClass, new FieldCallback() {

        public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
            if (field.isAnnotationPresent(Column.class))
                columnFields.add(field);
            if (field.isAnnotationPresent(Sn.class))
                containSn = true;

        }
    }, new FieldFilter() {

        public boolean matches(Field field) {
            if (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) {
                return false;
            }

            for (Annotation annotation : field.getAnnotations()) {
                if (Transient.class.isAssignableFrom(annotation.getClass())
                        || Id.class.isAssignableFrom(annotation.getClass())) {
                    return false;
                }
            }

            return true;
        }
    });
}

From source file:ee.ut.cs.mc.and.activiti521.custom.ibatis.NonValidatingXMLMapperBuilder.java

License:Apache License

private NonValidatingXMLMapperBuilder(XPathParser parser, Configuration configuration, String resource,
        Map<String, XNode> sqlFragments) {
    super(configuration);
    this.builderAssistant = new MapperBuilderAssistant(configuration, resource);
    this.parser = parser;
    this.sqlFragments = sqlFragments;
    this.resource = resource;
}

From source file:org.makersoft.activesql.builder.GenericStatementBuilder.java

License:Open Source License

public GenericStatementBuilder(Configuration configuration, Class<?> entityClass) {
    super(configuration);
    this.entityClass = entityClass;

    String resource = entityClass.getName().replace('.', '/') + ".java (best guess)";
    assistant = new MapperBuilderAssistant(configuration, resource);

    entity = entityClass.getAnnotation(Entity.class);
    mapperType = entity.mapper();/*  w  w  w .ja  va2  s .  co  m*/

    if (!mapperType.isAssignableFrom(Void.class)) {
        namespace = mapperType.getName();
    } else {
        namespace = entityClass.getName();
    }

    assistant.setCurrentNamespace(namespace);

    databaseId = super.getConfiguration().getDatabaseId();
    lang = super.getConfiguration().getDefaultScriptingLanuageInstance();

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Table table = entityClass.getAnnotation(Table.class);
    if (table == null) {
        tableName = CaseFormatUtils.camelToUnderScore(entityClass.getSimpleName());
    } else {
        tableName = table.name();
    }

    ///~~~~~~~~~~~~~~~~~~~~~~
    idField = AnnotationUtils.findDeclaredFieldWithAnnoation(Id.class, entityClass);

    versionField = AnnotationUtils.findDeclaredFieldWithAnnoation(Version.class, entityClass);

    ReflectionUtils.doWithFields(entityClass, new FieldCallback() {

        @Override
        public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
            columnFields.add(field);
        }
    }, new FieldFilter() {

        @Override
        public boolean matches(Field field) {
            if (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) {
                return false;
            }

            for (Annotation annotation : field.getAnnotations()) {
                if (Transient.class.isAssignableFrom(annotation.getClass())
                        || Id.class.isAssignableFrom(annotation.getClass())) {
                    return false;
                }
            }

            return true;
        }
    });
}