Search in sources :

Example 96 with IntrospectedColumn

use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.

the class UpdateByPrimaryKeyWithoutBLOBsElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    List<IntrospectedColumn> columns;
    if (isSimple) {
        columns = introspectedTable.getNonPrimaryKeyColumns();
    } else {
        columns = introspectedTable.getBaseColumns();
    }
    XmlElement answer = buildUpdateByPrimaryKeyElement(introspectedTable.getUpdateByPrimaryKeyStatementId(), introspectedTable.getBaseRecordType(), columns);
    if (context.getPlugins().sqlMapUpdateByPrimaryKeyWithoutBLOBsElementGenerated(answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 97 with IntrospectedColumn

use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.

the class ObjectFactory method createIntrospectedColumn.

public static IntrospectedColumn createIntrospectedColumn(Context context) {
    String type = context.getIntrospectedColumnImpl();
    if (!stringHasValue(type)) {
        type = IntrospectedColumn.class.getName();
    }
    IntrospectedColumn answer = (IntrospectedColumn) createInternalObject(type);
    answer.setContext(context);
    return answer;
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString)

Example 98 with IntrospectedColumn

use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.

the class ExampleWhereClauseElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    // $NON-NLS-1$
    XmlElement answer = new XmlElement("sql");
    if (isForUpdateByExample) {
        answer.addAttribute(new Attribute("id", // $NON-NLS-1$
        introspectedTable.getMyBatis3UpdateByExampleWhereClauseId()));
    } else {
        answer.addAttribute(new Attribute("id", // $NON-NLS-1$
        introspectedTable.getExampleWhereClauseId()));
    }
    context.getCommentGenerator().addComment(answer);
    // $NON-NLS-1$
    XmlElement whereElement = new XmlElement("where");
    answer.addElement(whereElement);
    // $NON-NLS-1$
    XmlElement outerForEachElement = new XmlElement("foreach");
    if (isForUpdateByExample) {
        outerForEachElement.addAttribute(new Attribute("collection", // $NON-NLS-1$ //$NON-NLS-2$
        "example.oredCriteria"));
    } else {
        outerForEachElement.addAttribute(new Attribute("collection", // $NON-NLS-1$ //$NON-NLS-2$
        "oredCriteria"));
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    outerForEachElement.addAttribute(new Attribute("item", "criteria"));
    // $NON-NLS-1$ //$NON-NLS-2$
    outerForEachElement.addAttribute(new Attribute("separator", "or"));
    whereElement.addElement(outerForEachElement);
    // $NON-NLS-1$
    XmlElement ifElement = new XmlElement("if");
    // $NON-NLS-1$ //$NON-NLS-2$
    ifElement.addAttribute(new Attribute("test", "criteria.valid"));
    outerForEachElement.addElement(ifElement);
    // $NON-NLS-1$
    XmlElement trimElement = new XmlElement("trim");
    // $NON-NLS-1$ //$NON-NLS-2$
    trimElement.addAttribute(new Attribute("prefix", "("));
    // $NON-NLS-1$ //$NON-NLS-2$
    trimElement.addAttribute(new Attribute("suffix", ")"));
    // $NON-NLS-1$ //$NON-NLS-2$
    trimElement.addAttribute(new Attribute("prefixOverrides", "and"));
    ifElement.addElement(trimElement);
    trimElement.addElement(getMiddleForEachElement(null));
    for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
        if (stringHasValue(introspectedColumn.getTypeHandler())) {
            trimElement.addElement(getMiddleForEachElement(introspectedColumn));
        }
    }
    if (context.getPlugins().sqlMapExampleWhereClauseElementGenerated(answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) Attribute(org.mybatis.generator.api.dom.xml.Attribute) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 99 with IntrospectedColumn

use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.

the class UpdateByExampleSelectiveElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    // $NON-NLS-1$
    XmlElement answer = new XmlElement("update");
    answer.addAttribute(new Attribute("id", // $NON-NLS-1$
    introspectedTable.getUpdateByExampleSelectiveStatementId()));
    // $NON-NLS-1$ //$NON-NLS-2$
    answer.addAttribute(new Attribute("parameterType", "map"));
    context.getCommentGenerator().addComment(answer);
    StringBuilder sb = new StringBuilder();
    // $NON-NLS-1$
    sb.append("update ");
    sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));
    // $NON-NLS-1$
    XmlElement dynamicElement = new XmlElement("set");
    answer.addElement(dynamicElement);
    for (IntrospectedColumn introspectedColumn : ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getAllColumns())) {
        sb.setLength(0);
        // $NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty("row."));
        // $NON-NLS-1$
        sb.append(" != null");
        // $NON-NLS-1$
        XmlElement isNotNullElement = new XmlElement("if");
        // $NON-NLS-1$
        isNotNullElement.addAttribute(new Attribute("test", sb.toString()));
        dynamicElement.addElement(isNotNullElement);
        sb.setLength(0);
        sb.append(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
        // $NON-NLS-1$
        sb.append(" = ");
        // $NON-NLS-1$
        sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "row."));
        sb.append(',');
        isNotNullElement.addElement(new TextElement(sb.toString()));
    }
    answer.addElement(getUpdateByExampleIncludeElement());
    if (context.getPlugins().sqlMapUpdateByExampleSelectiveElementGenerated(answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) TextElement(org.mybatis.generator.api.dom.xml.TextElement) Attribute(org.mybatis.generator.api.dom.xml.Attribute) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 100 with IntrospectedColumn

use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.

the class DatabaseIntrospector method calculateExtraColumnInformation.

private void calculateExtraColumnInformation(TableConfiguration tc, Map<ActualTableName, List<IntrospectedColumn>> columns) {
    StringBuilder sb = new StringBuilder();
    Pattern pattern = null;
    String replaceString = null;
    if (tc.getColumnRenamingRule() != null) {
        pattern = Pattern.compile(tc.getColumnRenamingRule().getSearchString());
        replaceString = tc.getColumnRenamingRule().getReplaceString();
        // $NON-NLS-1$
        replaceString = replaceString == null ? "" : replaceString;
    }
    for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns.entrySet()) {
        for (IntrospectedColumn introspectedColumn : entry.getValue()) {
            String calculatedColumnName;
            if (pattern == null) {
                calculatedColumnName = introspectedColumn.getActualColumnName();
            } else {
                Matcher matcher = pattern.matcher(introspectedColumn.getActualColumnName());
                calculatedColumnName = matcher.replaceAll(replaceString);
            }
            if (isTrue(tc.getProperty(PropertyRegistry.TABLE_USE_ACTUAL_COLUMN_NAMES))) {
                introspectedColumn.setJavaProperty(JavaBeansUtil.getValidPropertyName(calculatedColumnName));
            } else if (isTrue(tc.getProperty(PropertyRegistry.TABLE_USE_COMPOUND_PROPERTY_NAMES))) {
                sb.setLength(0);
                sb.append(calculatedColumnName);
                sb.append('_');
                sb.append(JavaBeansUtil.getCamelCaseString(introspectedColumn.getRemarks(), true));
                introspectedColumn.setJavaProperty(JavaBeansUtil.getValidPropertyName(sb.toString()));
            } else {
                introspectedColumn.setJavaProperty(JavaBeansUtil.getCamelCaseString(calculatedColumnName, false));
            }
            FullyQualifiedJavaType fullyQualifiedJavaType = javaTypeResolver.calculateJavaType(introspectedColumn);
            if (fullyQualifiedJavaType != null) {
                introspectedColumn.setFullyQualifiedJavaType(fullyQualifiedJavaType);
                introspectedColumn.setJdbcTypeName(javaTypeResolver.calculateJdbcTypeName(introspectedColumn));
            } else {
                // type cannot be resolved. Check for ignored or overridden
                boolean warn = !tc.isColumnIgnored(introspectedColumn.getActualColumnName());
                ColumnOverride co = tc.getColumnOverride(introspectedColumn.getActualColumnName());
                if (co != null && stringHasValue(co.getJavaType())) {
                    warn = false;
                }
                // if the type is not supported, then we'll report a warning
                if (warn) {
                    introspectedColumn.setFullyQualifiedJavaType(FullyQualifiedJavaType.getObjectInstance());
                    // $NON-NLS-1$
                    introspectedColumn.setJdbcTypeName("OTHER");
                    String warning = getString(// $NON-NLS-1$
                    "Warning.14", Integer.toString(introspectedColumn.getJdbcType()), entry.getKey().toString(), introspectedColumn.getActualColumnName());
                    warnings.add(warning);
                }
            }
            if (context.autoDelimitKeywords() && SqlReservedWords.containsWord(introspectedColumn.getActualColumnName())) {
                introspectedColumn.setColumnNameDelimited(true);
            }
            if (tc.isAllColumnDelimitingEnabled()) {
                introspectedColumn.setColumnNameDelimited(true);
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) ColumnOverride(org.mybatis.generator.config.ColumnOverride) Matcher(java.util.regex.Matcher) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) ArrayList(java.util.ArrayList) List(java.util.List) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)107 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)36 Method (org.mybatis.generator.api.dom.java.Method)33 XmlElement (org.mybatis.generator.api.dom.xml.XmlElement)32 Attribute (org.mybatis.generator.api.dom.xml.Attribute)28 ArrayList (java.util.ArrayList)26 Parameter (org.mybatis.generator.api.dom.java.Parameter)24 TextElement (org.mybatis.generator.api.dom.xml.TextElement)24 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)14 Field (org.mybatis.generator.api.dom.java.Field)11 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)10 CommentGenerator (org.mybatis.generator.api.CommentGenerator)9 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)9 Plugin (org.mybatis.generator.api.Plugin)8 CompilationUnit (org.mybatis.generator.api.dom.java.CompilationUnit)8 JavaBeansUtil.getJavaBeansField (org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField)7 HashSet (java.util.HashSet)6 List (java.util.List)6 HashMap (java.util.HashMap)5 KotlinFunction (org.mybatis.generator.api.dom.kotlin.KotlinFunction)5