Java Code Examples for org.mybatis.generator.api.IntrospectedColumn#getJavaProperty()

The following examples show how to use org.mybatis.generator.api.IntrospectedColumn#getJavaProperty() . 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: JavaBeansUtil.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
private static Method getBasicJavaBeansGetter(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method(getGetterMethodName(property, fqjt));
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(fqjt);

    StringBuilder sb = new StringBuilder();
    sb.append("return ");
    sb.append(property);
    sb.append(';');
    method.addBodyLine(sb.toString());

    return method;
}
 
Example 2
Source File: RootClassInfo.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
public boolean containsProperty(IntrospectedColumn introspectedColumn) {
    if (propertyDescriptors == null) {
        return false;
    }

    boolean found = false;
    String propertyName = introspectedColumn.getJavaProperty();
    String propertyType = introspectedColumn.getFullyQualifiedJavaType()
            .getFullyQualifiedName();

    // get method names from class and check against this column definition.
    // better yet, have a map of method Names. check against it.
    for (int i = 0; i < propertyDescriptors.length; i++) {
        PropertyDescriptor propertyDescriptor = propertyDescriptors[i];

        if (hasProperty(propertyName, propertyType, propertyDescriptor)) {
            found = true;
            break;
        }
    }

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

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(fqjt);
    method.setName(getGetterMethodName(property, fqjt));
    context.getCommentGenerator().addGetterComment(method,
            introspectedTable, introspectedColumn);

    StringBuilder sb = new StringBuilder();
    sb.append("return "); //$NON-NLS-1$
    sb.append(property);
    sb.append(';');
    method.addBodyLine(sb.toString());

    return method;
}
 
Example 4
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 5
Source File: AbstractJavaGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
public Method getJavaBeansGetter(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(fqjt);
    method.setName(getGetterMethodName(property, fqjt));
    context.getCommentGenerator().addGetterComment(method,
            introspectedTable, introspectedColumn);

    StringBuilder sb = new StringBuilder();
    sb.append("return "); //$NON-NLS-1$
    sb.append(property);
    sb.append(';');
    method.addBodyLine(sb.toString());

    return method;
}
 
Example 6
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 7
Source File: JavaBeansUtil.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
private static Method getBasicJavaBeansSetter(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method(getSetterMethodName(property));
    method.setVisibility(JavaVisibility.PUBLIC);
    method.addParameter(new Parameter(fqjt, property));

    StringBuilder sb = new StringBuilder();
    if (introspectedColumn.isStringColumn() && isTrimStringsEnabled(introspectedColumn)) {
        sb.append("this.");
        sb.append(property);
        sb.append(" = ");
        sb.append(property);
        sb.append(" == null ? null : ");
        sb.append(property);
        sb.append(".trim();");
        method.addBodyLine(sb.toString());
    } else {
        sb.append("this.");
        sb.append(property);
        sb.append(" = ");
        sb.append(property);
        sb.append(';');
        method.addBodyLine(sb.toString());
    }

    return method;
}
 
Example 8
Source File: AbstractMethodGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
public static String calculateFieldName(String tableFieldName, IntrospectedColumn column) {
    String fieldName = column.getJavaProperty();
    if (fieldName.equals(tableFieldName)) {
        // name collision, no shortcut generated
        fieldName = tableFieldName + "." + fieldName;
    }
    return fieldName;
}
 
Example 9
Source File: JavaBeansUtil.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the java beans setter.
 *
 * @param introspectedColumn
 *            the introspected column
 * @param context
 *            the context
 * @param introspectedTable
 *            the introspected table
 * @return the java beans setter
 */
public static Method getJavaBeansSetter(IntrospectedColumn introspectedColumn,
        Context context,
        IntrospectedTable introspectedTable) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getSetterMethodName(property));
    method.addParameter(new Parameter(fqjt, property));
    context.getCommentGenerator().addSetterComment(method,
            introspectedTable, introspectedColumn);

    StringBuilder sb = new StringBuilder();
    if (isTrimStringsEnabled(context) && introspectedColumn.isStringColumn()) {
        sb.append("this."); //$NON-NLS-1$
        sb.append(property);
        sb.append(" = "); //$NON-NLS-1$
        sb.append(property);
        sb.append(" == null ? null : "); //$NON-NLS-1$
        sb.append(property);
        sb.append(".trim();"); //$NON-NLS-1$
        method.addBodyLine(sb.toString());
    } else {
        sb.append("this."); //$NON-NLS-1$
        sb.append(property);
        sb.append(" = "); //$NON-NLS-1$
        sb.append(property);
        sb.append(';');
        method.addBodyLine(sb.toString());
    }

    return method;
}
 
Example 10
Source File: AbstractJavaGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public Field getJavaBeansField(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

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

    return field;
}
 
Example 11
Source File: AbstractJavaGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public Method getJavaBeansSetter(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getSetterMethodName(property));
    method.addParameter(new Parameter(fqjt, property));
    context.getCommentGenerator().addSetterComment(method,
            introspectedTable, introspectedColumn);

    StringBuilder sb = new StringBuilder();
    if (isTrimStringsEnabled() && introspectedColumn.isStringColumn()) {
        sb.append("this."); //$NON-NLS-1$
        sb.append(property);
        sb.append(" = "); //$NON-NLS-1$
        sb.append(property);
        sb.append(" == null ? null : "); //$NON-NLS-1$
        sb.append(property);
        sb.append(".trim();"); //$NON-NLS-1$
        method.addBodyLine(sb.toString());
    } else {
        sb.append("this."); //$NON-NLS-1$
        sb.append(property);
        sb.append(" = "); //$NON-NLS-1$
        sb.append(property);
        sb.append(';');
        method.addBodyLine(sb.toString());
    }

    return method;
}
 
Example 12
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 13
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);
	}
}
 
Example 14
Source File: RootClassInfo.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
public boolean containsProperty(IntrospectedColumn introspectedColumn) {
    if (propertyDescriptors == null) {
        return false;
    }

    boolean found = false;
    String propertyName = introspectedColumn.getJavaProperty();
    String propertyType = introspectedColumn.getFullyQualifiedJavaType()
            .getFullyQualifiedName();

    // get method names from class and check against this column definition.
    // better yet, have a map of method Names. check against it.
    for (int i = 0; i < propertyDescriptors.length; i++) {
        PropertyDescriptor propertyDescriptor = propertyDescriptors[i];

        if (propertyDescriptor.getName().equals(propertyName)) {
            // property name is in the rootClass...

            // Is it the proper type?
            String introspectedPropertyType = propertyDescriptor.getPropertyType().getName();
            if (genericMode && introspectedPropertyType.equals("java.lang.Object")) { //$NON-NLS-1$
                // OK - but add a warning
                warnings.add(getString("Warning.28", //$NON-NLS-1$
                        propertyName, className));
            } else if (!introspectedPropertyType.equals(propertyType)) {
                warnings.add(getString("Warning.21", //$NON-NLS-1$
                        propertyName, className, propertyType));
                break;
            }

            // Does it have a getter?
            if (propertyDescriptor.getReadMethod() == null) {
                warnings.add(getString("Warning.22", //$NON-NLS-1$
                        propertyName, className));
                break;
            }

            // Does it have a setter?
            if (propertyDescriptor.getWriteMethod() == null) {
                warnings.add(getString("Warning.23", //$NON-NLS-1$
                        propertyName, className));
                break;
            }

            found = true;
            break;
        }
    }

    return found;
}
 
Example 15
Source File: RootClassInfo.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
public boolean containsProperty(IntrospectedColumn introspectedColumn) {
    if (propertyDescriptors == null) {
        return false;
    }

    boolean found = false;
    String propertyName = introspectedColumn.getJavaProperty();
    String propertyType = introspectedColumn.getFullyQualifiedJavaType()
            .getFullyQualifiedName();

    // get method names from class and check against this column definition.
    // better yet, have a map of method Names. check against it.
    for (int i = 0; i < propertyDescriptors.length; i++) {
        PropertyDescriptor propertyDescriptor = propertyDescriptors[i];

        if (propertyDescriptor.getName().equals(propertyName)) {
            // property is in the rootClass...

            // Is it the proper type?
            if (!propertyDescriptor.getPropertyType().getName().equals(
                    propertyType)) {
                warnings.add(getString("Warning.21", //$NON-NLS-1$
                        propertyName, className, propertyType));
                break;
            }

            // Does it have a getter?
            if (propertyDescriptor.getReadMethod() == null) {
                warnings.add(getString("Warning.22", //$NON-NLS-1$
                        propertyName, className));
                break;
            }

            // Does it have a setter?
            if (propertyDescriptor.getWriteMethod() == null) {
                warnings.add(getString("Warning.23", //$NON-NLS-1$
                        propertyName, className));
                break;
            }

            found = true;
            break;
        }
    }

    return found;
}