Java Code Examples for org.mybatis.generator.api.IntrospectedTable#getBaseRecordType()

The following examples show how to use org.mybatis.generator.api.IntrospectedTable#getBaseRecordType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapperExtendsPlugin.java    From S-mall-ssm with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    // 获取实体类

    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());

    // 获取Example类
    FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    // import接口

    for (String mapper : mappers) {
        interfaze.addImportedType(new FullyQualifiedJavaType(mapper));
        interfaze.addSuperInterface(
                new FullyQualifiedJavaType(
                        mapper + "<" + entityType.getShortName() + "," + exampleType.getShortName() + ">"));
    }
    // import实体类

    interfaze.addImportedType(entityType);
    return true;

}
 
Example 2
Source File: CustomSettingsPlugin.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
/**
 * 配置生成的Mapper接口
 * @param i
 * @param table
 * @author Frodez
 * @date 2018-12-13
 */
private void configImportAndJavaDoc(Interface i, IntrospectedTable table) {
	// 获取实体类
	FullyQualifiedJavaType entity = new FullyQualifiedJavaType(table.getBaseRecordType());
	// import接口
	i.addImportedType(new FullyQualifiedJavaType(MAPPER_NAME));
	i.addSuperInterface(new FullyQualifiedJavaType(MAPPER_NAME + "<" + entity.getShortName() + ">"));
	// import实体类
	i.addImportedType(entity);
	// import Spring Repository注解
	i.addImportedType(new FullyQualifiedJavaType("org.springframework.stereotype.Repository"));
	i.addAnnotation("@Repository");
	i.addJavaDocLine("/**");
	i.addJavaDocLine(" * @description " + (table.getRemarks() == null ? "" : table.getRemarks()));
	i.addJavaDocLine(" * @table " + table.getFullyQualifiedTable());
	i.addJavaDocLine(" * @date " + LocalDate.now().toString());
	i.addJavaDocLine(" */");
}
 
Example 3
Source File: CrudSupportPlugin.java    From azeroth with Apache License 2.0 6 votes vote down vote up
/**
 * 生成的Mapper接口
 *
 * @param interfaze
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    //获取实体类
    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    //主键
    FullyQualifiedJavaType idType = null;
    List<IntrospectedColumn> columns = introspectedTable.getPrimaryKeyColumns();
    for (IntrospectedColumn col : columns) {
        idType = javaTypeResolver.calculateJavaType(col);
        break;
    }
    //import接口
    for (String mapper : mappers) {
        interfaze.addImportedType(new FullyQualifiedJavaType(mapper));
        interfaze.addSuperInterface(
                new FullyQualifiedJavaType(mapper + "<" + entityType.getShortName() + "," + idType.getShortName() + ">"));
    }
    //import实体类
    interfaze.addImportedType(entityType);
    return true;
}
 
Example 4
Source File: UpdateByOptimisticLockMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
@Override
public void addMethod(Interface interfaze, IntrospectedTable introspectedTable) {
    TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
    Properties properties = tableConfiguration.getProperties();
    String versionField = properties.getProperty("versionField");
    if (versionField == null || versionField == "") {
        return;
    }
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>();
    FullyQualifiedJavaType parameterType;
    if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
        parameterType = new FullyQualifiedJavaType(introspectedTable.getRecordWithBLOBsType());
    } else {
        parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    }
    importedTypes.add(parameterType);
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(METHOD_NAME);
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$
    interfaze.addImportedTypes(importedTypes);
    interfaze.addMethod(method);
}
 
Example 5
Source File: SelectByBigOffsetMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
public void addMethod(Interface interfaze,IntrospectedTable introspectedTable) {
    Method method = new Method();
    // 1.设置方法可见性
    method.setVisibility(JavaVisibility.PUBLIC);
    // 2.设置返回值类型
    FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
    FullyQualifiedJavaType paramListType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    returnType.addTypeArgument(paramListType);
    method.setReturnType(returnType);
    // 3.设置方法名
    method.setName(METHOD_NAME);
    // 4.设置方法入参
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    method.addParameter(new Parameter(type, "example"));
    interfaze.addMethod(method);
}
 
Example 6
Source File: MybatisPageTools.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
private void addPageTemplate(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    CommentGenerator commentGenerator = context.getCommentGenerator();
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("pageByExample");

    FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    FullyQualifiedJavaType baseQueryType = new FullyQualifiedJavaType("com.diligrp.shop.constant.BaseQuery");
    FullyQualifiedJavaType pageTmplType = new FullyQualifiedJavaType("com.diligrp.shop.constant.PageTemplate");

    String recordType = introspectedTable.getBaseRecordType();

    method.setReturnType(pageTmplType);

    method.addParameter(new Parameter(exampleType, "example"));
    method.addParameter(new Parameter(baseQueryType, "baseQuery"));

    StringBuffer code = new StringBuffer(32);
    code.append("int count = this.countByExample(example);\n");
    code.append("List<" + recordType + "> list = this.selectByExample(example);\n");
    code.append("com.diligrp.shop.constant.PageTemplate<" + recordType + "> pageTemplate = com.diligrp.shop.constant.PageTemplate.build();\n ");
    code.append("pageTemplate.setTotalSize(count);\n");
    code.append("pageTemplate.setList(list);\n");
    code.append("if(baseQuery != null){");
    code.append("pageTemplate.setCurrPage(baseQuery.getCurrent());\n");
    code.append("pageTemplate.setPageSize(baseQuery.getSize());\n");
    code.append("}");
    code.append("return pageTemplate;");

    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
}
 
Example 7
Source File: GenPlugin.java    From scaffold-cloud with MIT License 5 votes vote down vote up
/**
 * 生成的Mapper接口
 *
 * @param interfaze
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass,
                               IntrospectedTable introspectedTable) {
    // 获取实体类
    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    // import接口
    for (String mapper : mappers) {
        interfaze.addImportedType(new FullyQualifiedJavaType(mapper));
        interfaze.addSuperInterface(new FullyQualifiedJavaType(mapper + "<" + entityType.getShortName() + ">"));
    }
    // import实体类
    interfaze.addImportedType(entityType);
    return true;
}
 
Example 8
Source File: MyPgMapperPlugin.java    From jvue-admin with MIT License 5 votes vote down vote up
/**
 * 生成的Mapper接口
 *
 * @param interfaze
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    //获取实体类
    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    //import接口
    for (String mapper : mappers) {
        interfaze.addImportedType(new FullyQualifiedJavaType(mapper));
        interfaze.addSuperInterface(new FullyQualifiedJavaType(mapper + "<" + entityType.getShortName() + ">"));
    }
    //import实体类
    interfaze.addImportedType(entityType);
    return true;
}
 
Example 9
Source File: MapperPlugin.java    From tk-mybatis with MIT License 5 votes vote down vote up
/**
 * 生成的Mapper接口
 *
 * @param interfaze
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    //获取实体类
    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    //import接口
    for (String mapper : mappers) {
        interfaze.addImportedType(new FullyQualifiedJavaType(mapper));
        interfaze.addSuperInterface(new FullyQualifiedJavaType(mapper + "<" + entityType.getShortName() + ">"));
    }
    //import实体类
    interfaze.addImportedType(entityType);
    return true;
}
 
Example 10
Source File: JavaElementGeneratorTools.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 获取Model没有BLOBs类时的类型
 * @param introspectedTable
 * @return
 */
public static FullyQualifiedJavaType getModelTypeWithoutBLOBs(IntrospectedTable introspectedTable) {
    FullyQualifiedJavaType type;
    if (introspectedTable.getRules().generateBaseRecordClass()) {
        type = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    } else if (introspectedTable.getRules().generatePrimaryKeyClass()) {
        type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
    } else {
        throw new RuntimeException(getString("RuntimeError.12"));
    }
    return type;
}
 
Example 11
Source File: JavaElementGeneratorTools.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 获取Model有BLOBs类时的类型
 * @param introspectedTable
 * @return
 */
public static FullyQualifiedJavaType getModelTypeWithBLOBs(IntrospectedTable introspectedTable) {
    FullyQualifiedJavaType type;
    if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
        type = new FullyQualifiedJavaType(introspectedTable.getRecordWithBLOBsType());
    } else {
        // the blob fields must be rolled up into the base class
        type = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    }
    return type;
}
 
Example 12
Source File: MapperPlugin.java    From Mapper with MIT License 5 votes vote down vote up
/**
 * 生成的Mapper接口
 *
 * @param interfaze
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    //获取实体类
    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    //import接口
    for (String mapper : mappers) {
        interfaze.addImportedType(new FullyQualifiedJavaType(mapper));
        interfaze.addSuperInterface(new FullyQualifiedJavaType(mapper + "<" + entityType.getShortName() + ">"));
    }
    //import实体类
    interfaze.addImportedType(entityType);
    return true;
}
 
Example 13
Source File: AliasResultMapWithoutBLOBsElementGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * addElements: 在当前的parentElement元素中添加别名ReulstMap列元素. <br/>
 *
 * @author Hongbin Yuan			父元素,新的elements将作为子元素添加到该元素
 * @param parentElement
 * @param introspectedTable		当前表的信息
 * @since JDK 1.6
 */
public void addElements(XmlElement parentElement,IntrospectedTable introspectedTable) {
	XmlElement answer = new XmlElement("resultMap"); //$NON-NLS-1$
	
	introspectedTable.getContext().getCommentGenerator().addComment(answer);
	
	answer.addAttribute(new Attribute("id", resultMapId));
	String returnType = null;
	if (isSimple) {
		returnType = introspectedTable.getBaseRecordType();
	} else {
		if (introspectedTable.getRules().generateBaseRecordClass()) {
			returnType = introspectedTable.getBaseRecordType();
		} else {
			returnType = introspectedTable.getPrimaryKeyType();
		}
	}
	answer.addAttribute(new Attribute("type", //$NON-NLS-1$
			returnType));

	if (introspectedTable.isConstructorBased()) {
		addResultMapConstructorElements(answer,introspectedTable);
	} else {
		addResultMapElements(answer,introspectedTable);
	}
	
	parentElement.addElement(answer);
}