Java Code Examples for org.mybatis.generator.api.dom.java.Field#setVisibility()

The following examples show how to use org.mybatis.generator.api.dom.java.Field#setVisibility() . 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: CustomPlugin.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
/**
 * 增加数据源名称字段
 * 
 * @author 吴帅
 * @parameter @param interfaze
 * @parameter @param introspectedTable
 * @createDate 2015年10月2日 上午10:06:47
 */
private void addDataSourceNameField(Interface interfaze, IntrospectedTable introspectedTable) {
	TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
	Properties properties = tableConfiguration.getProperties();
	String dataSourceName = properties.getProperty("dataSourceName");
	if (dataSourceName == null || dataSourceName == "") {
		return;
	}
	Field field = new Field();
	field.setVisibility(JavaVisibility.PUBLIC);
	field.setStatic(true);
	field.setFinal(true);
	field.setType(FullyQualifiedJavaType.getStringInstance());
	field.setName("DATA_SOURCE_NAME");
	field.setInitializationString("\"" + dataSourceName + "\"");
	interfaze.addField(field);
}
 
Example 2
Source File: WrapObjectPlugin.java    From mybatis-generator-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	if (tableMatches(introspectedTable)) {
		FullyQualifiedJavaType type = new FullyQualifiedJavaType(objectClass.getName());
		Field field = new Field(objectFieldName, type);
		field.setVisibility(JavaVisibility.PROTECTED);
		field.setInitializationString(String.format("new %s()", objectClass.getSimpleName()));

		field.addJavaDocLine("/**");
		field.addJavaDocLine(" * This field was generated by MyBatis Generator.");
		field.addJavaDocLine(" * This field corresponds to the wrapped object.");
		field.addJavaDocLine(" *");
		field.addJavaDocLine(" * @mbggenerated");
		field.addJavaDocLine(" */");

		topLevelClass.addField(field);
		topLevelClass.addImportedType(type);
	}

	return true;
}
 
Example 3
Source File: HySwaggerMapperPlugin.java    From jvue-admin with MIT License 6 votes vote down vote up
private void impSerializableInterface(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	if (this.implementSerializableInteface) {
		String serializable = "java.io.Serializable";
		topLevelClass.addImportedType(serializable);
		FullyQualifiedJavaType superInterface = new FullyQualifiedJavaType(serializable);
		topLevelClass.addSuperInterface(superInterface);

		Field serialVersionUID = new Field("serialVersionUID", new FullyQualifiedJavaType("long"));
		serialVersionUID.setVisibility(JavaVisibility.PRIVATE);
		serialVersionUID.setStatic(true);
		serialVersionUID.setFinal(true);

		serialVersionUID.setInitializationString("1L");
		topLevelClass.addField(serialVersionUID);
	}
}
 
Example 4
Source File: CustomSerializablePlugin.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    if (addGWTInterface) {
        topLevelClass.addImportedType(gwtSerializable);
        topLevelClass.addSuperInterface(gwtSerializable);
    }

    if (!suppressJavaInterface) {
        topLevelClass.addImportedType(serializable);
        topLevelClass.addSuperInterface(serializable);

        Field field = new Field();
        field.setFinal(true);
        field.setInitializationString("1L"); //$NON-NLS-1$
        field.setName("serialVersionUID"); //$NON-NLS-1$
        field.setStatic(true);
        field.setType(new FullyQualifiedJavaType("long")); //$NON-NLS-1$
        field.setVisibility(JavaVisibility.PRIVATE);
        context.getCommentGenerator().addFieldComment(field, introspectedTable);

        topLevelClass.addField(field);
    }
}
 
Example 5
Source File: SerializablePlugin.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
protected void makeSerializable(TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable) {
    if (addGWTInterface) {
        topLevelClass.addImportedType(gwtSerializable);
        topLevelClass.addSuperInterface(gwtSerializable);
    }
    
    if (!suppressJavaInterface) {
        topLevelClass.addImportedType(serializable);
        topLevelClass.addSuperInterface(serializable);

        Field field = new Field();
        field.setFinal(true);
        field.setInitializationString("1L"); //$NON-NLS-1$
        field.setName("serialVersionUID"); //$NON-NLS-1$
        field.setStatic(true);
        field.setType(new FullyQualifiedJavaType("long")); //$NON-NLS-1$
        field.setVisibility(JavaVisibility.PRIVATE);
        context.getCommentGenerator().addFieldComment(field, introspectedTable);

        topLevelClass.addField(field);
    }
}
 
Example 6
Source File: JavaBeansUtil.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the java beans field.
 *
 * @param introspectedColumn
 *            the introspected column
 * @param context
 *            the context
 * @param introspectedTable
 *            the introspected table
 * @return the java beans field
 */
public static Field getJavaBeansField(IntrospectedColumn introspectedColumn,
        Context context,
        IntrospectedTable introspectedTable) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(fqjt);
    field.setName(property);
    context.getCommentGenerator().addFieldComment(field,
            introspectedTable, introspectedColumn);

    return field;
}
 
Example 7
Source File: AbstractDAOTemplate.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the field clones.
 *
 * @param commentGenerator
 *            the comment generator
 * @param introspectedTable
 *            the introspected table
 * @return the field clones
 */
public final List<Field> getFieldClones(CommentGenerator commentGenerator,
        IntrospectedTable introspectedTable) {
    configure();
    List<Field> answer = new ArrayList<Field>();
    for (Field oldField : fields) {
        Field field = new Field();

        field.setInitializationString(oldField.getInitializationString());
        field.setFinal(oldField.isFinal());
        field.setStatic(oldField.isStatic());
        field.setName(oldField.getName());
        field.setType(oldField.getType());
        field.setVisibility(oldField.getVisibility());
        commentGenerator.addFieldComment(field, introspectedTable);
        answer.add(field);
    }

    return answer;
}
 
Example 8
Source File: SerializablePlugin.java    From feiqu-opensource with Apache License 2.0 6 votes vote down vote up
protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    if(this.addGWTInterface) {
        topLevelClass.addImportedType(this.gwtSerializable);
        topLevelClass.addSuperInterface(this.gwtSerializable);
    }

    if(!this.suppressJavaInterface) {
        topLevelClass.addImportedType(this.serializable);
        topLevelClass.addSuperInterface(this.serializable);
        Field field = new Field();
        field.setFinal(true);
        field.setInitializationString("1L");
        field.setName("serialVersionUID");
        field.setStatic(true);
        field.setType(new FullyQualifiedJavaType("long"));
        field.setVisibility(JavaVisibility.PRIVATE);
        this.context.getCommentGenerator().addFieldComment(field, introspectedTable);
        topLevelClass.addField(field);
    }

}
 
Example 9
Source File: SerializablePlugin.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
protected void makeSerializable(TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable) {
    if (addGWTInterface) {
        topLevelClass.addImportedType(gwtSerializable);
        topLevelClass.addSuperInterface(gwtSerializable);
    }
    
    if (!suppressJavaInterface) {
        topLevelClass.addImportedType(serializable);
        topLevelClass.addSuperInterface(serializable);

        Field field = new Field();
        field.setFinal(true);
        field.setInitializationString("1L"); //$NON-NLS-1$
        field.setName("serialVersionUID"); //$NON-NLS-1$
        field.setStatic(true);
        field.setType(new FullyQualifiedJavaType("long")); //$NON-NLS-1$
        field.setVisibility(JavaVisibility.PRIVATE);
        context.getCommentGenerator().addFieldComment(field, introspectedTable);

        topLevelClass.addField(field);
    }
}
 
Example 10
Source File: AbstractDAOTemplate.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
public final List<Field> getFieldClones(CommentGenerator commentGenerator,
        IntrospectedTable introspectedTable) {
    configure();
    List<Field> answer = new ArrayList<Field>();
    for (Field oldField : fields) {
        Field field = new Field();

        field.setInitializationString(oldField.getInitializationString());
        field.setFinal(oldField.isFinal());
        field.setStatic(oldField.isStatic());
        field.setName(oldField.getName());
        field.setType(oldField.getType());
        field.setVisibility(oldField.getVisibility());
        commentGenerator.addFieldComment(field, introspectedTable);
        answer.add(field);
    }

    return answer;
}
 
Example 11
Source File: GenericSIDAOTemplate.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureFields() {
    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(sqlMapClientType);
    field.setName("sqlMapClient"); //$NON-NLS-1$
    addField(field);
}
 
Example 12
Source File: DynamicSqlSupportClassGenerator.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
private Field calculateTableDefinition(TopLevelClass topLevelClass) {
	FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sqlTableClassName);
	String fieldName = JavaBeansUtil.getValidPropertyName(sqlTableClassName);
	Field field = new Field(fieldName, fqjt);
	commentGenerator.addFieldAnnotation(field, introspectedTable, topLevelClass.getImportedTypes());
	field.setVisibility(JavaVisibility.PUBLIC);
	field.setStatic(true);
	field.setFinal(true);

	StringBuilder initializationString = new StringBuilder();
	initializationString.append(String.format("new %s()", //$NON-NLS-1$
			escapeStringForJava(sqlTableClassName)));
	field.setInitializationString(initializationString.toString());
	return field;
}
 
Example 13
Source File: PluginUtil.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 *  生成class中的logger属性
 * 
 * @return
 */
public static Field getLoggerField (String className){
	Field field = new Field();
       field.setVisibility(JavaVisibility.PRIVATE);
       field.setType(new FullyQualifiedJavaType("Logger"));
       field.setName("logger");
       field.setStatic(true);
       field.setInitializationString("LoggerFactory.getLogger(" + className + ".class)");
       return field;
}
 
Example 14
Source File: GenericSIDAOTemplate.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureFields() {
    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(sqlMapClientType);
    field.setName("sqlMapClient"); //$NON-NLS-1$
    addField(field);
}
 
Example 15
Source File: GenericCIDAOTemplate.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureFields() {
    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(sqlMapClientType);
    field.setName("sqlMapClient"); //$NON-NLS-1$
    addField(field);
}
 
Example 16
Source File: GenericCIDAOTemplate.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureFields() {
    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(sqlMapClientType);
    field.setName("sqlMapClient"); //$NON-NLS-1$
    addField(field);
}
 
Example 17
Source File: TemplateFilePlugin.java    From Mapper with MIT License 5 votes vote down vote up
/**
 * 列转换为字段
 *
 * @param introspectedColumn
 * @return
 */
public static Field convertToJavaBeansField(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn.getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();
    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(fqjt);
    field.setName(property);
    return field;
}
 
Example 18
Source File: SerializablePlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    final boolean serializable = Boolean.parseBoolean(introspectedTable.getTableConfigurationProperty("jdkSerializable"));
    if (!serializable) {
        return;
    }

    if (addGWTInterface) {
        topLevelClass.addImportedType(gwtSerializable);
        topLevelClass.addSuperInterface(gwtSerializable);
    }

    if (!suppressJavaInterface) {
        topLevelClass.addImportedType(this.serializable);
        topLevelClass.addSuperInterface(this.serializable);

        Field field = new Field("serialVersionUID", new FullyQualifiedJavaType("long"));
        field.setFinal(true);
        field.setInitializationString("1L");
        field.setStatic(true);
        field.setVisibility(JavaVisibility.PRIVATE);

        if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3_DSQL) {
            context.getCommentGenerator().addFieldAnnotation(field, introspectedTable, topLevelClass.getImportedTypes());
        } else {
            context.getCommentGenerator().addFieldComment(field, introspectedTable);
        }

        topLevelClass.addField(field);
    }
}
 
Example 19
Source File: JavaBeansUtil.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
private static Field getBasicJavaBeansField(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn.getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Field field = new Field(property, fqjt);
    field.setVisibility(JavaVisibility.PRIVATE);

    return field;
}
 
Example 20
Source File: HySwaggerMapperPlugin.java    From jvue-admin with MIT License 4 votes vote down vote up
private void addFieldEnum(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	if (this.modelFieldEnum) {
		String enumName = "FieldEnum";
		String javaFieldName = "javaFieldName";
		String dbFieldName = "dbFieldName";
		InnerEnum enum1 = new InnerEnum(new FullyQualifiedJavaType(enumName));
		enum1.setVisibility(JavaVisibility.PUBLIC);

		StringBuilder enumConstant = new StringBuilder();
		List<IntrospectedColumn> allColumns = introspectedTable.getAllColumns();
		int index = 0;
		for (IntrospectedColumn column : allColumns) {
			String dbName = column.getActualColumnName();
			String javaName = column.getJavaProperty();
			enumConstant.append(dbName.toUpperCase()).append("(\"").append(javaName).append("\",\"").append(dbName).append("\")");
			if (++index < allColumns.size()) {
				enumConstant.append(",\n\t\t");
			}
		}
		enum1.addEnumConstant(enumConstant.toString());
		
		//java字段
		Field field = new Field();
		field.setVisibility(JavaVisibility.PRIVATE);
		field.setStatic(false);
		field.setType(new FullyQualifiedJavaType("String"));
		field.setName(javaFieldName);
		enum1.addField(field);
		//db字段
		Field field1 = new Field();
		field1.setVisibility(JavaVisibility.PRIVATE);
		field1.setStatic(false);
		field1.setType(new FullyQualifiedJavaType("String"));
		field1.setName(dbFieldName);
		enum1.addField(field1);
		
		//构造器
		Method method = new Method();
		method.setConstructor(true);
		method.setVisibility(JavaVisibility.DEFAULT);
		method.setStatic(false);
		method.setName(enumName);
		method.addParameter(new Parameter(new FullyQualifiedJavaType("String"), javaFieldName));
		method.addParameter(new Parameter(new FullyQualifiedJavaType("String"), dbFieldName));
		method.addBodyLine("this."+javaFieldName+" = "+javaFieldName+";");
		method.addBodyLine("this."+dbFieldName+" = "+dbFieldName+";");
		enum1.addMethod(method);
		
		
		//方法
		Method getMethod = new Method();
		getMethod.setConstructor(false);
		getMethod.setVisibility(JavaVisibility.PUBLIC);
		getMethod.setStatic(false);
		getMethod.setName(javaFieldName);
		getMethod.addBodyLine("return "+javaFieldName+";");
		getMethod.setReturnType(new FullyQualifiedJavaType("String"));
		enum1.addMethod(getMethod);
		
		Method getMethod1 = new Method();
		getMethod1.setConstructor(false);
		getMethod1.setVisibility(JavaVisibility.PUBLIC);
		getMethod1.setStatic(false);
		getMethod1.setName(dbFieldName);
		getMethod1.addBodyLine("return "+dbFieldName+";");
		getMethod1.setReturnType(new FullyQualifiedJavaType("String"));
		enum1.addMethod(getMethod1);
		
		topLevelClass.addInnerEnum(enum1);
	}
}