Search in sources :

Example 1 with TableConfiguration

use of org.mybatis.generator.config.TableConfiguration in project generator by mybatis.

the class MyBatisGeneratorConfigurationParser method parseTable.

protected void parseTable(Context context, Node node) {
    TableConfiguration tc = new TableConfiguration(context);
    context.addTableConfiguration(tc);
    Properties attributes = parseAttributes(node);
    //$NON-NLS-1$
    String catalog = attributes.getProperty("catalog");
    //$NON-NLS-1$
    String schema = attributes.getProperty("schema");
    //$NON-NLS-1$
    String tableName = attributes.getProperty("tableName");
    //$NON-NLS-1$
    String domainObjectName = attributes.getProperty("domainObjectName");
    //$NON-NLS-1$
    String alias = attributes.getProperty("alias");
    //$NON-NLS-1$
    String enableInsert = attributes.getProperty("enableInsert");
    String enableSelectByPrimaryKey = attributes.getProperty(//$NON-NLS-1$
    "enableSelectByPrimaryKey");
    String enableSelectByExample = attributes.getProperty(//$NON-NLS-1$
    "enableSelectByExample");
    String enableUpdateByPrimaryKey = attributes.getProperty(//$NON-NLS-1$
    "enableUpdateByPrimaryKey");
    String enableDeleteByPrimaryKey = attributes.getProperty(//$NON-NLS-1$
    "enableDeleteByPrimaryKey");
    String enableDeleteByExample = attributes.getProperty(//$NON-NLS-1$
    "enableDeleteByExample");
    String enableCountByExample = attributes.getProperty(//$NON-NLS-1$
    "enableCountByExample");
    String enableUpdateByExample = attributes.getProperty(//$NON-NLS-1$
    "enableUpdateByExample");
    String selectByPrimaryKeyQueryId = attributes.getProperty(//$NON-NLS-1$
    "selectByPrimaryKeyQueryId");
    String selectByExampleQueryId = attributes.getProperty(//$NON-NLS-1$
    "selectByExampleQueryId");
    //$NON-NLS-1$
    String modelType = attributes.getProperty("modelType");
    //$NON-NLS-1$
    String escapeWildcards = attributes.getProperty("escapeWildcards");
    String delimitIdentifiers = attributes.getProperty(//$NON-NLS-1$
    "delimitIdentifiers");
    //$NON-NLS-1$
    String delimitAllColumns = attributes.getProperty("delimitAllColumns");
    //$NON-NLS-1$
    String mapperName = attributes.getProperty("mapperName");
    //$NON-NLS-1$
    String sqlProviderName = attributes.getProperty("sqlProviderName");
    if (stringHasValue(catalog)) {
        tc.setCatalog(catalog);
    }
    if (stringHasValue(schema)) {
        tc.setSchema(schema);
    }
    if (stringHasValue(tableName)) {
        tc.setTableName(tableName);
    }
    if (stringHasValue(domainObjectName)) {
        tc.setDomainObjectName(domainObjectName);
    }
    if (stringHasValue(alias)) {
        tc.setAlias(alias);
    }
    if (stringHasValue(enableInsert)) {
        tc.setInsertStatementEnabled(isTrue(enableInsert));
    }
    if (stringHasValue(enableSelectByPrimaryKey)) {
        tc.setSelectByPrimaryKeyStatementEnabled(isTrue(enableSelectByPrimaryKey));
    }
    if (stringHasValue(enableSelectByExample)) {
        tc.setSelectByExampleStatementEnabled(isTrue(enableSelectByExample));
    }
    if (stringHasValue(enableUpdateByPrimaryKey)) {
        tc.setUpdateByPrimaryKeyStatementEnabled(isTrue(enableUpdateByPrimaryKey));
    }
    if (stringHasValue(enableDeleteByPrimaryKey)) {
        tc.setDeleteByPrimaryKeyStatementEnabled(isTrue(enableDeleteByPrimaryKey));
    }
    if (stringHasValue(enableDeleteByExample)) {
        tc.setDeleteByExampleStatementEnabled(isTrue(enableDeleteByExample));
    }
    if (stringHasValue(enableCountByExample)) {
        tc.setCountByExampleStatementEnabled(isTrue(enableCountByExample));
    }
    if (stringHasValue(enableUpdateByExample)) {
        tc.setUpdateByExampleStatementEnabled(isTrue(enableUpdateByExample));
    }
    if (stringHasValue(selectByPrimaryKeyQueryId)) {
        tc.setSelectByPrimaryKeyQueryId(selectByPrimaryKeyQueryId);
    }
    if (stringHasValue(selectByExampleQueryId)) {
        tc.setSelectByExampleQueryId(selectByExampleQueryId);
    }
    if (stringHasValue(modelType)) {
        tc.setConfiguredModelType(modelType);
    }
    if (stringHasValue(escapeWildcards)) {
        tc.setWildcardEscapingEnabled(isTrue(escapeWildcards));
    }
    if (stringHasValue(delimitIdentifiers)) {
        tc.setDelimitIdentifiers(isTrue(delimitIdentifiers));
    }
    if (stringHasValue(delimitAllColumns)) {
        tc.setAllColumnDelimitingEnabled(isTrue(delimitAllColumns));
    }
    if (stringHasValue(mapperName)) {
        tc.setMapperName(mapperName);
    }
    if (stringHasValue(sqlProviderName)) {
        tc.setSqlProviderName(sqlProviderName);
    }
    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);
        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        if ("property".equals(childNode.getNodeName())) {
            //$NON-NLS-1$
            parseProperty(tc, childNode);
        } else if ("columnOverride".equals(childNode.getNodeName())) {
            //$NON-NLS-1$
            parseColumnOverride(tc, childNode);
        } else if ("ignoreColumn".equals(childNode.getNodeName())) {
            //$NON-NLS-1$
            parseIgnoreColumn(tc, childNode);
        } else if ("ignoreColumnsByRegex".equals(childNode.getNodeName())) {
            //$NON-NLS-1$
            parseIgnoreColumnByRegex(tc, childNode);
        } else if ("generatedKey".equals(childNode.getNodeName())) {
            //$NON-NLS-1$
            parseGeneratedKey(tc, childNode);
        } else if ("columnRenamingRule".equals(childNode.getNodeName())) {
            //$NON-NLS-1$
            parseColumnRenamingRule(tc, childNode);
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) Properties(java.util.Properties) TableConfiguration(org.mybatis.generator.config.TableConfiguration)

Example 2 with TableConfiguration

use of org.mybatis.generator.config.TableConfiguration in project generator by mybatis.

the class JavaBeansUtil method isTrimStringsEnabled.

/**
     * Checks if is trim strings enabled.
     *
     * @param table
     *            the table
     * @return true, if is trim strings enabled
     */
private static boolean isTrimStringsEnabled(IntrospectedTable table) {
    TableConfiguration tableConfiguration = table.getTableConfiguration();
    String trimSpaces = tableConfiguration.getProperties().getProperty(PropertyRegistry.MODEL_GENERATOR_TRIM_STRINGS);
    if (trimSpaces != null) {
        return isTrue(trimSpaces);
    }
    return isTrimStringsEnabled(table.getContext());
}
Also used : TableConfiguration(org.mybatis.generator.config.TableConfiguration)

Aggregations

TableConfiguration (org.mybatis.generator.config.TableConfiguration)2 Properties (java.util.Properties)1 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1