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

The following examples show how to use org.mybatis.generator.api.dom.java.Field#setInitializationString() . 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: 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 2
Source File: DynamicSqlSupportClassGenerator.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
private Field calculateTableDefinition(TopLevelClass topLevelClass) {
    FullyQualifiedJavaType fqjt =
            new FullyQualifiedJavaType(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
    String fieldName =
            JavaBeansUtil.getValidPropertyName(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
    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()",
            escapeStringForJava(introspectedTable.getFullyQualifiedTable().getDomainObjectName())));
    field.setInitializationString(initializationString.toString());
    return field;
}
 
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: CustomSettingsPlugin.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
/**
 * 配置序列化
 * @author Frodez
 * @date 2019-01-13
 */
private void makeSerializable(TopLevelClass klass, IntrospectedTable table) {
	klass.addImportedType(new FullyQualifiedJavaType("java.io.Serializable"));
	klass.addSuperInterface(new FullyQualifiedJavaType("java.io.Serializable"));
	Field field = new Field("serialVersionUID", new FullyQualifiedJavaType("long"));
	field.setFinal(true);
	field.setInitializationString("1L");
	field.addJavaDocLine("");
	field.setStatic(true);
	field.setVisibility(JavaVisibility.PRIVATE);
	if (table.getTargetRuntime() == TargetRuntime.MYBATIS3_DSQL) {
		context.getCommentGenerator().addFieldAnnotation(field, table, klass.getImportedTypes());
	} else {
		context.getCommentGenerator().addFieldComment(field, table);
	}
	klass.getFields().add(0, field);
}
 
Example 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: CustomCommentGenerator.java    From BlogManagePlatform with Apache License 2.0 5 votes vote down vote up
private void resolveDefaultValue(Field field, IntrospectedTable table, IntrospectedColumn column) {
	String defaultValue = column.getDefaultValue();
	if (EmptyUtil.no(defaultValue)) {
		String typeName = field.getType().getShortName();
		if (typeName.equals("Boolean")) {
			field.setInitializationString(Boolean.valueOf(defaultValue).toString());
		} else if (typeName.equals("Byte")) {
			field.setInitializationString(defaultValue);
		} else if (typeName.equals("Short")) {
			field.setInitializationString(defaultValue);
		} else if (typeName.equals("Integer")) {
			field.setInitializationString(defaultValue);
		} else if (typeName.equals("Long")) {
			field.setInitializationString(defaultValue + "L");
		} else if (typeName.equals("Double")) {
			field.setInitializationString(defaultValue);
		} else if (typeName.equals("Float")) {
			field.setInitializationString(defaultValue + "F");
		} else if (typeName.equals("String")) {
			field.setInitializationString("\"" + defaultValue + "\"");
		} else if (typeName.equals("BigDecimal")) {
			BigDecimal bigDecimal = new BigDecimal(defaultValue);
			if (bigDecimal.equals(BigDecimal.ZERO)) {
				field.setInitializationString("BigDecimal.ZERO");
			} else if (bigDecimal.equals(BigDecimal.ONE)) {
				field.setInitializationString("BigDecimal.ONE");
			} else if (bigDecimal.equals(BigDecimal.TEN)) {
				field.setInitializationString("BigDecimal.TEN");
			} else {
				field.setInitializationString("new BigDecimal(" + defaultValue + ")");
			}
		}
	}
}
 
Example 14
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 15
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;
}