源码学习-mybatis_generator-03-配置解析类(2)

配置解析类

  • MyBatisGeneratorConfigurationParser.java
  • 解析满足org/mybatis/generator/config/xml/mybatis-generator-config_1_0.dtd的xml文件
  • 总体思路:
    • 将节点元素转化为properties读取
    • 遍历子节点,读取节点元素
    • 将读取的配置存入Configuration
generatorConfiguration
<!--根节点generatorConfiguration -->
<!ELEMENT generatorConfiguration (properties?, classPathEntry*, context+)>
 //解析根节点generatorConfiguration
Configuration configuration = new Configuration();
NodeList nodeList = rootNode.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
	Node childNode = nodeList.item(i);
	if (childNode.getNodeType() != Node.ELEMENT_NODE) {
	    continue;
	}
	if ("properties".equals(childNode.getNodeName())) {
	    parseProperties(configuration, childNode);
	} else if ("classPathEntry".equals(childNode.getNodeName())) {
	    parseClassPathEntry(configuration, childNode);
	} else if ("context".equals(childNode.getNodeName())) { 
	    parseContext(configuration, childNode);
	}
}
公共方法:node解析为properties
	//主要功能
    //将node转变为properties
    protected Properties parseAttributes(Node node) {
        Properties attributes = new Properties();
        NamedNodeMap nnm = node.getAttributes();
        for (int i = 0; i < nnm.getLength(); i++) {
            Node attribute = nnm.item(i);
            //将node的内容取出,将${}内的内容替换
            String value = parsePropertyTokens(attribute.getNodeValue());
            attributes.put(attribute.getNodeName(), value);
        }
        return attributes;
    }
    //将node的内容取出,将${}内的内容替换
    private String parsePropertyTokens(String string) {
        final String OPEN = "${"; 
        final String CLOSE = "}";
        String newString = string;
        if (newString != null) {
            int start = newString.indexOf(OPEN);
            int end = newString.indexOf(CLOSE);
            while (start > -1 && end > start) {
                String prepend = newString.substring(0, start);
                String append = newString.substring(end + CLOSE.length());
                //${}内部内容
                String propName = newString.substring(start + OPEN.length(), end);
                String propValue = resolveProperty(propName);
                if (propValue != null) {
                    //替换合并
                    newString = prepend + propValue + append;
                }
                start = newString.indexOf(OPEN, end);
                end = newString.indexOf(CLOSE, end);
            }
        }
        return newString;
    }

    //通过key值替换,先找本地系统内部,没有继续找配置文件内
    private String resolveProperty(String key) {
        String property = null;
        property = System.getProperty(key);
        if (property == null) {
            property = configurationProperties.getProperty(key);
        }
        if (property == null) {
            property = extraProperties.getProperty(key);
        }
        return property;
    }
generatorConfiguration下节点properties
<!--properties节点 -->
<!ELEMENT properties EMPTY>
<!ATTLIST properties
  resource CDATA #IMPLIED
  url CDATA #IMPLIED>
//Properties节点解析,
//将url或resource配置的文件读取并存入configurationProperties以替换${}内容
Properties attributes = parseAttributes(node);
String resource = attributes.getProperty("resource"); 
String url = attributes.getProperty("url"); 
if (!stringHasValue(resource) && !stringHasValue(url)) {
    throw new XMLParserException(Messages.getString("RuntimeError.14"));
}
if (stringHasValue(resource) && stringHasValue(url)) {
    throw new XMLParserException(Messages.getString("RuntimeError.14")); 
}
URL resourceUrl;
try {
    if (stringHasValue(resource)) {
        resourceUrl = ObjectFactory.getResource(resource);
        if (resourceUrl == null) {
            throw new XMLParserException(Messages.getString("RuntimeError.15", resource));
        }
    } else {
        resourceUrl = new URL(url);
    }
    InputStream inputStream = resourceUrl.openConnection().getInputStream();
    configurationProperties.load(inputStream);
    inputStream.close();
}
generatorConfiguration下节点classPathEntry
<!--配置数据库驱动位置-->
    <!ELEMENT classPathEntry EMPTY>
    <!ATTLIST classPathEntry
      location CDATA #REQUIRED>
    //解析ClassPathEntry(数据库驱动路径)
    protected void parseClassPathEntry(Configuration configuration, Node node) {
        Properties attributes = parseAttributes(node);
        configuration.addClasspathEntry(attributes.getProperty("location"));
    }
generatorConfiguration下节点context
<!--context配置定义-->
 <!ELEMENT context (property*, plugin*, commentGenerator?, (connectionFactory | jdbcConnection), javaTypeResolver?,
                         javaModelGenerator, sqlMapGenerator?, javaClientGenerator?, table+)>
<!ATTLIST context id ID #REQUIRED
  defaultModelType CDATA #IMPLIED
  targetRuntime CDATA #IMPLIED
  introspectedColumnImpl CDATA #IMPLIED>
    //解析context
    private void parseContext(Configuration configuration, Node node) {
        Properties attributes = parseAttributes(node);
        String defaultModelType = attributes.getProperty("defaultModelType");
        String targetRuntime = attributes.getProperty("targetRuntime");
        String introspectedColumnImpl = attributes.getProperty("introspectedColumnImpl");
        String id = attributes.getProperty("id");
        ModelType mt = defaultModelType == null ? null : ModelType.getModelType(defaultModelType);
        Context context = new Context(mt);
        context.setId(id);
        if (StringUtility.stringHasValue(introspectedColumnImpl)) {
            context.setIntrospectedColumnImpl(introspectedColumnImpl);
        }
        if (StringUtility.stringHasValue(targetRuntime)) {
            context.setTargetRuntime(targetRuntime);
        }
        configuration.addContext(context);
        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())) {
                parseProperty(context, childNode);
            } else if ("plugin".equals(childNode.getNodeName())) {
                parsePlugin(context, childNode);
            } else if ("commentGenerator".equals(childNode.getNodeName())) {
                parseCommentGenerator(context, childNode);
            } else if ("jdbcConnection".equals(childNode.getNodeName())) {
                parseJdbcConnection(context, childNode);
            } else if ("connectionFactory".equals(childNode.getNodeName())) {
                parseConnectionFactory(context, childNode);
            } else if ("javaModelGenerator".equals(childNode.getNodeName())) {
                parseJavaModelGenerator(context, childNode);
            } else if ("javaTypeResolver".equals(childNode.getNodeName())) {
                parseJavaTypeResolver(context, childNode);
            } else if ("sqlMapGenerator".equals(childNode.getNodeName())) {
                parseSqlMapGenerator(context, childNode);
            } else if ("javaClientGenerator".equals(childNode.getNodeName())) {
                parseJavaClientGenerator(context, childNode);
            } else if ("table".equals(childNode.getNodeName())) { 
                parseTable(context, childNode);
            }
        }
    }
context节点下property
<!-- property,多个node共用-->
    <!ELEMENT property EMPTY>
    <!ATTLIST property
        name CDATA #REQUIRED
        value CDATA #REQUIRED>
    //property解析,多个node共用
    protected void parseProperty(PropertyHolder propertyHolder, Node node) {
        Properties attributes = parseAttributes(node);
        String name = attributes.getProperty("name"); 
        String value = attributes.getProperty("value"); 
        propertyHolder.addProperty(name, value);
    }
context节点下plugin
<!ELEMENT plugin (property*)>
<!ATTLIST plugin
  type CDATA #REQUIRED>
private void parsePlugin(Context context, Node node) {
    PluginConfiguration pluginConfiguration = new PluginConfiguration();
    context.addPluginConfiguration(pluginConfiguration);
    Properties attributes = parseAttributes(node);
    String type = attributes.getProperty("type");
    pluginConfiguration.setConfigurationType(type);
    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);
        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        //存在节点property,使用解析property节点方法解析即可
        if ("property".equals(childNode.getNodeName())) {
            parseProperty(pluginConfiguration, childNode);
        }
    }
}
context节下commentGenerator
<!ELEMENT commentGenerator (property*)>
 <!ATTLIST commentGenerator
   type CDATA #IMPLIED>  

    protected void parseCommentGenerator(Context context, Node node) {
        CommentGeneratorConfiguration commentGeneratorConfiguration = new CommentGeneratorConfiguration();
        context.setCommentGeneratorConfiguration(commentGeneratorConfiguration);
        Properties attributes = parseAttributes(node);
        String type = attributes.getProperty("type");
        if (StringUtility.stringHasValue(type)) {
            commentGeneratorConfiguration.setConfigurationType(type);
        }
        NodeList nodeList = node.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node childNode = nodeList.item(i);
            if (childNode.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            //存在节点property,使用解析property节点方法解析即可
            if ("property".equals(childNode.getNodeName())) {
                parseProperty(commentGeneratorConfiguration, childNode);
            }
        }
    }
context下jdbcConnection
<!ELEMENT jdbcConnection (property*)>
<!ATTLIST jdbcConnection 
  driverClass CDATA #REQUIRED
  connectionURL CDATA #REQUIRED
  userId CDATA #IMPLIED
  password CDATA #IMPLIED>
    protected void parseJdbcConnection(Context context, Node node) {
        JDBCConnectionConfiguration jdbcConnectionConfiguration = new JDBCConnectionConfiguration();
        context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);
        Properties attributes = parseAttributes(node);
        String driverClass = attributes.getProperty("driverClass"); 
        String connectionURL = attributes.getProperty("connectionURL"); 
        jdbcConnectionConfiguration.setDriverClass(driverClass);
        jdbcConnectionConfiguration.setConnectionURL(connectionURL);
        String userId = attributes.getProperty("userId"); 
        if (StringUtility.stringHasValue(userId)) {
            jdbcConnectionConfiguration.setUserId(userId);
        }
        String password = attributes.getProperty("password"); 
        if (StringUtility.stringHasValue(password)) {
            jdbcConnectionConfiguration.setPassword(password);
        }
        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(jdbcConnectionConfiguration, childNode);
            }
        }
    }
context下connectionFactory
    <!ELEMENT connectionFactory (property*)>
    <!ATTLIST connectionFactory
      type CDATA #IMPLIED>
protected void parseConnectionFactory(Context context, Node node) {
   ConnectionFactoryConfiguration connectionFactoryConfiguration = new ConnectionFactoryConfiguration();
   context.setConnectionFactoryConfiguration(connectionFactoryConfiguration);
   Properties attributes = parseAttributes(node);
   String type = attributes.getProperty("type"); 
   if (StringUtility.stringHasValue(type)) {
       connectionFactoryConfiguration.setConfigurationType(type);
   }
   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())) { 
           parseProperty(connectionFactoryConfiguration, childNode);
       }
   }
}
context下javaModelGenerator
<!ELEMENT javaModelGenerator (property*)>
<!ATTLIST javaModelGenerator
  targetPackage CDATA #REQUIRED
  targetProject CDATA #REQUIRED>

protected void parseJavaModelGenerator(Context context, Node node) {
	JavaModelGeneratorConfiguration javaModelGeneratorConfiguration = new JavaModelGeneratorConfiguration();
	context.setJavaModelGeneratorConfiguration(javaModelGeneratorConfiguration);
	Properties attributes = parseAttributes(node);
	String targetPackage = attributes.getProperty("targetPackage"); 
	String targetProject = attributes.getProperty("targetProject");
	javaModelGeneratorConfiguration.setTargetPackage(targetPackage);
	javaModelGeneratorConfiguration.setTargetProject(targetProject);
	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())) { 
	       parseProperty(javaModelGeneratorConfiguration, childNode);
	   }
	}
}
context下javaTypeResolver
<!ELEMENT javaTypeResolver (property*)>
<!ATTLIST javaTypeResolver
  type CDATA #IMPLIED>        
protected void parseJavaTypeResolver(Context context, Node node) {
    JavaTypeResolverConfiguration javaTypeResolverConfiguration = new JavaTypeResolverConfiguration();
    context.setJavaTypeResolverConfiguration(javaTypeResolverConfiguration);
    Properties attributes = parseAttributes(node);
    String type = attributes.getProperty("type"); 
    if (StringUtility.stringHasValue(type)) {
        javaTypeResolverConfiguration.setConfigurationType(type);
    }
    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())) { 
            parseProperty(javaTypeResolverConfiguration, childNode);
        }
    }
}
context下sqlMapGenerator
<!ELEMENT sqlMapGenerator (property*)>
<!ATTLIST sqlMapGenerator
  targetPackage CDATA #REQUIRED
  targetProject CDATA #REQUIRED>
protected void parseSqlMapGenerator(Context context, Node node) {
    SqlMapGeneratorConfiguration sqlMapGeneratorConfiguration = new SqlMapGeneratorConfiguration();
    context.setSqlMapGeneratorConfiguration(sqlMapGeneratorConfiguration);
    Properties attributes = parseAttributes(node);
    String targetPackage = attributes.getProperty("targetPackage");
    String targetProject = attributes.getProperty("targetProject");
    sqlMapGeneratorConfiguration.setTargetPackage(targetPackage);
    sqlMapGeneratorConfiguration.setTargetProject(targetProject);
    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())) { 
            parseProperty(sqlMapGeneratorConfiguration, childNode);
        }
    }
}
context下javaClientGenerator
<!ELEMENT javaClientGenerator (property*)>
<!ATTLIST javaClientGenerator
  type CDATA #REQUIRED
  targetPackage CDATA #REQUIRED
  targetProject CDATA #REQUIRED
  implementationPackage CDATA #IMPLIED>
private void parseJavaClientGenerator(Context context, Node node) {
    JavaClientGeneratorConfiguration javaClientGeneratorConfiguration = new JavaClientGeneratorConfiguration();
    context.setJavaClientGeneratorConfiguration(javaClientGeneratorConfiguration);
    Properties attributes = parseAttributes(node);
    String type = attributes.getProperty("type"); 
    String targetPackage = attributes.getProperty("targetPackage"); 
    String targetProject = attributes.getProperty("targetProject"); 
    String implementationPackage = attributes.getProperty("implementationPackage");
    javaClientGeneratorConfiguration.setConfigurationType(type);
    javaClientGeneratorConfiguration.setTargetPackage(targetPackage);
    javaClientGeneratorConfiguration.setTargetProject(targetProject);
    javaClientGeneratorConfiguration.setImplementationPackage(implementationPackage);
    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())) { 
            parseProperty(javaClientGeneratorConfiguration, childNode);
        }
    }
}
context 下 table
<!ELEMENT table (property*, generatedKey?, domainObjectRenamingRule?, columnRenamingRule?, (columnOverride | ignoreColumn | ignoreColumnsByRegex)*) >
<!ATTLIST table
  catalog CDATA #IMPLIED
  schema CDATA #IMPLIED
  tableName CDATA #REQUIRED
  alias CDATA #IMPLIED
  domainObjectName CDATA #IMPLIED
  mapperName CDATA #IMPLIED
  sqlProviderName CDATA #IMPLIED
  enableInsert CDATA #IMPLIED
  enableSelectByPrimaryKey CDATA #IMPLIED
  enableSelectByExample CDATA #IMPLIED
  enableUpdateByPrimaryKey CDATA #IMPLIED
  enableDeleteByPrimaryKey CDATA #IMPLIED
  enableDeleteByExample CDATA #IMPLIED
  enableCountByExample CDATA #IMPLIED
  enableUpdateByExample CDATA #IMPLIED
  selectByPrimaryKeyQueryId CDATA #IMPLIED
  selectByExampleQueryId CDATA #IMPLIED
  modelType CDATA #IMPLIED
  escapeWildcards CDATA #IMPLIED
  delimitIdentifiers CDATA #IMPLIED
  delimitAllColumns CDATA #IMPLIED>
protected void parseTable(Context context, Node node) {
    TableConfiguration tc = new TableConfiguration(context);
    context.addTableConfiguration(tc);
    Properties attributes = parseAttributes(node);
    String catalog = attributes.getProperty("catalog");
    if (StringUtility.stringHasValue(catalog)) {
        tc.setCatalog(catalog);
    }
    String schema = attributes.getProperty("schema");
    if (StringUtility.stringHasValue(schema)) {
        tc.setSchema(schema);
    }
    String tableName = attributes.getProperty("tableName");
    if (StringUtility.stringHasValue(tableName)) {
        tc.setTableName(tableName);
    }
    String domainObjectName = attributes.getProperty("domainObjectName");
    if (StringUtility.stringHasValue(domainObjectName)) {
        tc.setDomainObjectName(domainObjectName);
    }
    String alias = attributes.getProperty("alias");
    if (StringUtility.stringHasValue(alias)) {
        tc.setAlias(alias);
    }
    String enableInsert = attributes.getProperty("enableInsert");
    if (StringUtility.stringHasValue(enableInsert)) {
        tc.setInsertStatementEnabled(StringUtility.isTrue(enableInsert));
    }
    String enableSelectByPrimaryKey = attributes.getProperty("enableSelectByPrimaryKey");
    if (StringUtility.stringHasValue(enableSelectByPrimaryKey)) {
        tc.setSelectByPrimaryKeyStatementEnabled(StringUtility.isTrue(enableSelectByPrimaryKey));
    }
    String enableSelectByExample = attributes.getProperty("enableSelectByExample");
    if (StringUtility.stringHasValue(enableSelectByExample)) {
        tc.setSelectByExampleStatementEnabled(
                StringUtility.isTrue(enableSelectByExample));
    }
    String enableUpdateByPrimaryKey = attributes.getProperty("enableUpdateByPrimaryKey");
    if (StringUtility.stringHasValue(enableUpdateByPrimaryKey)) {
        tc.setUpdateByPrimaryKeyStatementEnabled(
                StringUtility.isTrue(enableUpdateByPrimaryKey));
    }
    String enableDeleteByPrimaryKey = attributes.getProperty("enableDeleteByPrimaryKey");
    if (StringUtility.stringHasValue(enableDeleteByPrimaryKey)) {
        tc.setDeleteByPrimaryKeyStatementEnabled(
                StringUtility.isTrue(enableDeleteByPrimaryKey));
    }
    String enableDeleteByExample = attributes.getProperty("enableDeleteByExample");
    if (StringUtility.stringHasValue(enableDeleteByExample)) {
        tc.setDeleteByExampleStatementEnabled(
                StringUtility.isTrue(enableDeleteByExample));
    }
    String enableCountByExample = attributes.getProperty("enableCountByExample");
    if (StringUtility.stringHasValue(enableCountByExample)) {
        tc.setCountByExampleStatementEnabled(
                StringUtility.isTrue(enableCountByExample));
    }
    String enableUpdateByExample = attributes.getProperty("enableUpdateByExample");
    if (StringUtility.stringHasValue(enableUpdateByExample)) {
        tc.setUpdateByExampleStatementEnabled(
                StringUtility.isTrue(enableUpdateByExample));
    }
    String selectByPrimaryKeyQueryId = attributes.getProperty("selectByPrimaryKeyQueryId");
    if (StringUtility.stringHasValue(selectByPrimaryKeyQueryId)) {
        tc.setSelectByPrimaryKeyQueryId(selectByPrimaryKeyQueryId);
    }
    String selectByExampleQueryId = attributes.getProperty("selectByExampleQueryId");
    if (StringUtility.stringHasValue(selectByExampleQueryId)) {
        tc.setSelectByExampleQueryId(selectByExampleQueryId);
    }
    String modelType = attributes.getProperty("modelType");
    if (StringUtility.stringHasValue(modelType)) {
        tc.setConfiguredModelType(modelType);
    }
    String escapeWildcards = attributes.getProperty("escapeWildcards");
    if (StringUtility.stringHasValue(escapeWildcards)) {
        tc.setWildcardEscapingEnabled(StringUtility.isTrue(escapeWildcards));
    }
    String delimitIdentifiers = attributes.getProperty("delimitIdentifiers");
    if (StringUtility.stringHasValue(delimitIdentifiers)) {
        tc.setDelimitIdentifiers(StringUtility.isTrue(delimitIdentifiers));
    }
    String delimitAllColumns = attributes.getProperty("delimitAllColumns");
    if (StringUtility.stringHasValue(delimitAllColumns)) {
        tc.setAllColumnDelimitingEnabled(StringUtility.isTrue(delimitAllColumns));
    }
    String mapperName = attributes.getProperty("mapperName");
    if (StringUtility.stringHasValue(mapperName)) {
        tc.setMapperName(mapperName);
    }
    String sqlProviderName = attributes.getProperty("sqlProviderName");
    if (StringUtility.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())) {
            parseProperty(tc, childNode);
        } else if ("columnOverride".equals(childNode.getNodeName())) {
            parseColumnOverride(tc, childNode);
        } else if ("ignoreColumn".equals(childNode.getNodeName())) {
            parseIgnoreColumn(tc, childNode);
        } else if ("ignoreColumnsByRegex".equals(childNode.getNodeName())) {
            parseIgnoreColumnByRegex(tc, childNode);
        } else if ("generatedKey".equals(childNode.getNodeName())) {
            parseGeneratedKey(tc, childNode);
        } else if ("domainObjectRenamingRule".equals(childNode.getNodeName())) {
            parseDomainObjectRenamingRule(tc, childNode);
        } else if ("columnRenamingRule".equals(childNode.getNodeName())) {
            parseColumnRenamingRule(tc, childNode);
        }
    }
}
table下columnOverride
<!ELEMENT columnOverride (property*)>
<!ATTLIST columnOverride
  column CDATA #REQUIRED
  property CDATA #IMPLIED
  javaType CDATA #IMPLIED
  jdbcType CDATA #IMPLIED
  typeHandler CDATA #IMPLIED
  isGeneratedAlways CDATA #IMPLIED
  delimitedColumnName CDATA #IMPLIED>
 private void parseColumnOverride(TableConfiguration tc, Node node) {
     Properties attributes = parseAttributes(node);
     String column = attributes.getProperty("column");
     ColumnOverride co = new ColumnOverride(column);
     String property = attributes.getProperty("property");
     if (StringUtility.stringHasValue(property)) {
         co.setJavaProperty(property);
     }
     String javaType = attributes.getProperty("javaType");
     if (StringUtility.stringHasValue(javaType)) {
         co.setJavaType(javaType);
     }
     String jdbcType = attributes.getProperty("jdbcType"); 
     if (StringUtility.stringHasValue(jdbcType)) {
         co.setJdbcType(jdbcType);
     }
     String typeHandler = attributes.getProperty("typeHandler"); 
     if (StringUtility.stringHasValue(typeHandler)) {
         co.setTypeHandler(typeHandler);
     }
     String delimitedColumnName = attributes
             .getProperty("delimitedColumnName"); 
     if (StringUtility.stringHasValue(delimitedColumnName)) {
         co.setColumnNameDelimited(StringUtility.isTrue(delimitedColumnName));
     }
     String isGeneratedAlways = attributes.getProperty("isGeneratedAlways"); 
     if (StringUtility.stringHasValue(isGeneratedAlways)) {
         co.setGeneratedAlways(Boolean.parseBoolean(isGeneratedAlways));
     }
     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())) { 
             parseProperty(co, childNode);
         }
     }
     tc.addColumnOverride(co);
 }
table下ignoreColumn
<!ELEMENT ignoreColumn EMPTY>
<!ATTLIST ignoreColumn
  column CDATA #REQUIRED
  delimitedColumnName CDATA #IMPLIED>
    private void parseIgnoreColumn(TableConfiguration tc, Node node) {
        Properties attributes = parseAttributes(node);
        String column = attributes.getProperty("column");
        String delimitedColumnName = attributes.getProperty("delimitedColumnName");
        IgnoredColumn ic = new IgnoredColumn(column);
        if (StringUtility.stringHasValue(delimitedColumnName)) {
            ic.setColumnNameDelimited(StringUtility.isTrue(delimitedColumnName));
        }
        tc.addIgnoredColumn(ic);
    }
table下ignoreColumnsByRegex
 <!ELEMENT ignoreColumnsByRegex (except*)>
 <!ATTLIST ignoreColumnsByRegex
   pattern CDATA #REQUIRED>
 private void parseIgnoreColumnByRegex(TableConfiguration tc, Node node) {
     Properties attributes = parseAttributes(node);
     String pattern = attributes.getProperty("pattern");
     IgnoredColumnPattern icPattern = new IgnoredColumnPattern(pattern);
     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 ("except".equals(childNode.getNodeName())) { 
             parseException(icPattern, childNode);
         }
     }
     tc.addIgnoredColumnPattern(icPattern);
 }

####### ignoreColumnsByRegex 下except

<!ELEMENT except EMPTY>
<!ATTLIST except
 column CDATA #REQUIRED
 delimitedColumnName CDATA #IMPLIED>
private void parseException(IgnoredColumnPattern icPattern, Node node) {
   Properties attributes = parseAttributes(node);
   String column = attributes.getProperty("column"); 
   String delimitedColumnName = attributes.getProperty("delimitedColumnName"); 
   IgnoredColumnException exception = new IgnoredColumnException(column);
   if (StringUtility.stringHasValue(delimitedColumnName)) {
       exception.setColumnNameDelimited(StringUtility.isTrue(delimitedColumnName));
   }
   icPattern.addException(exception);
}
table下generatedKey
<!ELEMENT generatedKey EMPTY>
<!ATTLIST generatedKey
  column CDATA #REQUIRED
  sqlStatement CDATA #REQUIRED
  identity CDATA #IMPLIED
  type CDATA #IMPLIED>
private void parseGeneratedKey(TableConfiguration tc, Node node) {
    Properties attributes = parseAttributes(node);
    String column = attributes.getProperty("column"); 
    boolean identity = StringUtility.isTrue(attributes.getProperty("identity")); 
    String sqlStatement = attributes.getProperty("sqlStatement"); 
    String type = attributes.getProperty("type");
    GeneratedKey gk = new GeneratedKey(column, sqlStatement, identity, type);
    tc.setGeneratedKey(gk);
}
table下domainObjectRenameingRule
<!ELEMENT domainObjectRenamingRule EMPTY>
<!ATTLIST domainObjectRenamingRule
  searchString CDATA #REQUIRED
  replaceString CDATA #IMPLIED>
private void parseDomainObjectRenamingRule(TableConfiguration tc, Node node) {
    Properties attributes = parseAttributes(node);
    String searchString = attributes.getProperty("searchString"); 
    String replaceString = attributes.getProperty("replaceString"); 
    DomainObjectRenamingRule dorr = new DomainObjectRenamingRule();
    dorr.setSearchString(searchString);
    if (StringUtility.stringHasValue(replaceString)) {
        dorr.setReplaceString(replaceString);
    }
    tc.setDomainObjectRenamingRule(dorr);
}
table下columnRenamingRule
<!ELEMENT columnRenamingRule EMPTY>
<!ATTLIST columnRenamingRule
  searchString CDATA #REQUIRED
  replaceString CDATA #IMPLIED>
private void parseColumnRenamingRule(TableConfiguration tc, Node node) {
    Properties attributes = parseAttributes(node);
    String searchString = attributes.getProperty("searchString");
    String replaceString = attributes.getProperty("replaceString"); 
    ColumnRenamingRule crr = new ColumnRenamingRule();
    crr.setSearchString(searchString);
    if (StringUtility.stringHasValue(replaceString)) {
        crr.setReplaceString(replaceString);
    }
    tc.setColumnRenamingRule(crr);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值