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

The following examples show how to use org.mybatis.generator.api.dom.java.Field#setStatic() . 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: 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 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: 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);
	}
}