org.ourbeehive.mbp.util.MapperFormatter.java Source code

Java tutorial

Introduction

Here is the source code for org.ourbeehive.mbp.util.MapperFormatter.java

Source

/**
 * Copyright (C) 2015-2016 OurBeehive(http://ourbeehive.github.io/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * Project Name: MyBatisPioneer
 * File Name: MapperFormatter.java
 * Package Name: org.ourbeehive.mbp.util
 * 
 * Date: Jan 20, 2016
 * Author: Sericloud
 * 
 */

package org.ourbeehive.mbp.util;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.ourbeehive.mbp.exception.AppException;
import org.ourbeehive.mbp.lang.JavaSrcElm;
import org.ourbeehive.mbp.lang.MapperElm;
import org.ourbeehive.mbp.model.ant.AllMapperProfile;
import org.ourbeehive.mbp.model.ant.DsParam;
import org.ourbeehive.mbp.model.ant.InsertConfig;
import org.ourbeehive.mbp.model.ant.MapperArtifact;
import org.ourbeehive.mbp.model.ant.MapperProfile;
import org.ourbeehive.mbp.model.ant.RelConfig;
import org.ourbeehive.mbp.model.ant.ResultMapConfig;
import org.ourbeehive.mbp.model.ant.UpdateConfig;
import org.ourbeehive.mbp.register.OneToOneIdx;
import org.ourbeehive.mbp.register.OneToOneIdxFacade;

public class MapperFormatter {

    private static Logger logger = Logger.getLogger(MapperFormatter.class);

    public static void checkWidth(StringBuffer line) {
        StringHelper.newLine(line, JavaSrcElm.UNIT_OF_INDENT, 3, MapperElm.MAPPER_MAX_WIDTH);
    }

    public static void checkWidth(StringBuffer line, String newLine, int countOfIndents) {

        if (line.length() + newLine.length() > MapperElm.MAPPER_MAX_WIDTH) {
            StringHelper.newLine(line, JavaSrcElm.UNIT_OF_INDENT, countOfIndents);
        }

        line.append(newLine);
    }

    public static void beginWithNewLine(StringBuffer line, String newLine) {
        StringHelper.newLine(line, JavaSrcElm.UNIT_OF_INDENT, 3);
        line.append(newLine);
    }

    public static void beginSetStatement(StringBuffer statement) {
        statement.append(MapperElm.SQL_SET);
        StringHelper.newLine(statement, JavaSrcElm.UNIT_OF_INDENT, 3);
        statement.append(MapperElm.WHITE_SPACE);
        statement.append(MapperElm.WHITE_SPACE);
    }

    public static void beginValuesStatement(StringBuffer statement) {
        StringHelper.newLine(statement, JavaSrcElm.UNIT_OF_INDENT, 3);
        statement.append(MapperElm.SQL_VALUES);
        StringHelper.newLine(statement, JavaSrcElm.UNIT_OF_INDENT, 3);
        statement.append(MapperElm.WHITE_SPACE + MapperElm.LEFT_PARENTHESIS);
    }

    public static void beginFromStatement(StringBuffer statement) {
        StringHelper.newLine(statement, JavaSrcElm.UNIT_OF_INDENT, 3);
        statement.append(MapperElm.SQl_FROM_WHITE_SPACE);
    }

    public static void beginWhereStatement(StringBuffer statement) {
        StringHelper.newLine(statement, JavaSrcElm.UNIT_OF_INDENT, 3);
        statement.append(MapperElm.SQL_WHERE_FULL);
    }

    public static void insertWhereStatement(StringBuffer statement) {
        StringBuffer prefix = new StringBuffer();
        StringHelper.newLine(prefix, JavaSrcElm.UNIT_OF_INDENT, 3);
        prefix.append(MapperElm.SQL_WHERE_FULL);
        statement.insert(0, prefix.toString());
    }

    public static void beginAndStatement(StringBuffer statement) {
        StringHelper.newLine(statement, JavaSrcElm.UNIT_OF_INDENT, 3);
        statement.append(MapperElm.SQL_AND_FULL);
    }

    public static void insertAndStatement(StringBuffer statement) {
        StringBuffer prefix = new StringBuffer();
        StringHelper.newLine(prefix, JavaSrcElm.UNIT_OF_INDENT, 3);
        prefix.append(MapperElm.SQL_AND_FULL);
        statement.insert(0, prefix.toString());
    }

    public static String getDefaultSchema(MapperProfile mapperProfile) {

        AllMapperProfile allMapperProfile = mapperProfile.getAllMapperProfile();
        DsParam dsParam = allMapperProfile.getDsParam();
        String allSchema = dsParam.getSchema();

        if (allSchema.indexOf(MapperElm.COMMA) != -1) {
            String[] schemaArray = StringUtils.split(allSchema, MapperElm.COMMA);
            if (schemaArray.length > 0) {
                return schemaArray[0];
            } else {
                return allSchema;
            }
        } else {
            return allSchema;
        }

    }

    /**
     * ?SchemaTable Alias
     * 
     * @param mapperProfile
     * @param tableName
     * @return
     */
    public static String getTableFullAlias(MapperProfile mapperProfile, String tableName) {
        String tableFullName = getTableFullName(mapperProfile, tableName);
        return StringHelper.replace(tableFullName, JavaSrcElm.DOT, JavaSrcElm.DOUBLE_UNDER_LINE);
    }

    /**
     * SchemaTable Name
     * 
     * @param mapperProfile
     * @param tableName
     * @return
     */
    public static String getTableFullName(MapperProfile mapperProfile, String tableName) {

        // If tableName contain schema name, then use it.
        String schema = null;
        int indexOfDot = tableName.indexOf(MapperElm.DOT);
        if (indexOfDot != -1) {
            return tableName;
        } else {
            schema = getDefaultSchema(mapperProfile);
            return schema + MapperElm.DOT + tableName;
        }

    }

    public static String getTableShortName(String tableName, String tableAlias) {

        // If tableAlias is not null and is not blank, then use it.
        if (StringUtils.isNotBlank(tableAlias) == true) {
            return tableAlias;
        }

        return getTableShortName(tableName);

    }

    /**
     * ??SchemaTable Name
     * 
     * @param tableName
     * @return
     */
    private static String getTableShortName(String tableName) {

        // If tableName contain schema name, then remove it.
        int indexOfDot = tableName.indexOf(MapperElm.DOT);
        if (indexOfDot == -1) {
            return tableName;
        } else {
            return tableName.substring(indexOfDot + 1, tableName.length());
        }

    }

    /**
     * ???????? Table Alias?Table AliasTable Name
     * 
     * @param mapperProfile
     * @param tableName
     * @param tableAlias
     * @return
     */
    public static String getTableNamePair(MapperProfile mapperProfile, String tableName, String tableAlias) {

        String tableFullName = getTableFullName(mapperProfile, tableName);
        if (StringUtils.isNotBlank(tableAlias) == true) {
            return tableFullName + MapperElm.WHITE_SPACE + tableAlias;
        }

        String tableFullAlias = getTableFullAlias(mapperProfile, tableName);
        return tableFullName + MapperElm.WHITE_SPACE + tableFullAlias;

    }

    public static String getTableNamePair(MapperProfile mapperProfile, OneToOneIdx oneToOneIndex, boolean reverse) {

        RelConfig oneToOne = oneToOneIndex.getOneToOne();
        String joinType = oneToOne.getJoinType();

        String leftTableName = OneToOneIdxFacade.getRelLeftTableName(oneToOneIndex);
        String leftTableAlias = OneToOneIdxFacade.getRelLeftTableAlias(oneToOneIndex);
        String leftAttrName = OneToOneIdxFacade.getRelLeftAttrName(oneToOneIndex);
        String leftColumnName = JavaFormatter.getDbStyle(leftAttrName);

        String rightTableName = oneToOneIndex.getSonTableName();
        String rightTableAlias = oneToOneIndex.getSonTableAlias();
        String rightAttrName = oneToOne.getSonAttr();
        String rightColumnName = JavaFormatter.getDbStyle(rightAttrName);

        // Change the table name into full name containing schema.
        String leftTableFullName = getTableFullName(mapperProfile, leftTableName);
        String leftTableFullAlias = getTableFullAlias(mapperProfile, leftTableName);
        String rightTableFullName = getTableFullName(mapperProfile, rightTableName);
        String rightTableFullAlias = getTableFullAlias(mapperProfile, rightTableName);

        // Change the column name into full name containing alias.
        String leftColumnFullName = MapperFormatter.getColumnFullName(mapperProfile, leftTableName, leftTableAlias,
                leftColumnName);
        String rightColumnFullName = MapperFormatter.getColumnFullName(mapperProfile, rightTableName,
                rightTableAlias, rightColumnName);

        // Determine the join statement prefix according to the configured
        // 'joinType' in one to one association.
        String joinPrefix = null;
        if (StringUtils.isNotBlank(joinType) == true) {
            if (joinType.equalsIgnoreCase(MapperElm.SQL_JOIN_LEFT) == true) {
                if (reverse == false) {
                    joinPrefix = MapperElm.SQL_JOIN_LEFT;
                } else {
                    joinPrefix = MapperElm.SQL_JOIN_RIGHT;
                }
            } else if (joinType.equalsIgnoreCase(MapperElm.SQL_JOIN_RIGHT) == true) {
                if (reverse == false) {
                    joinPrefix = MapperElm.SQL_JOIN_RIGHT;
                } else {
                    joinPrefix = MapperElm.SQL_JOIN_LEFT;
                }
            } else if (joinType.equalsIgnoreCase(MapperElm.SQL_JOIN_FULL) == true) {
                joinPrefix = MapperElm.SQL_JOIN_FULL;
            } else {
                joinPrefix = MapperElm.SQL_JOIN_INNER;
            }
        } else {
            joinPrefix = MapperElm.SQL_JOIN_INNER;
        }

        // Append join condition into where clause.
        StringBuffer joinStatement = new StringBuffer();
        joinStatement.append(joinPrefix);
        joinStatement.append(MapperElm.SQL_JOIN);
        if (reverse == false) {
            joinStatement.append(rightTableFullName);
            joinStatement.append(MapperElm.WHITE_SPACE);
            if (StringUtils.isNotBlank(rightTableAlias) == true) {
                joinStatement.append(rightTableAlias);
            } else {
                joinStatement.append(rightTableFullAlias);
            }
            joinStatement.append(MapperElm.SQL_JOIN_ON);
            joinStatement.append(leftColumnFullName);
            joinStatement.append(MapperElm.EQUAL);
            joinStatement.append(rightColumnFullName);
        } else {
            joinStatement.append(leftTableFullName);
            joinStatement.append(MapperElm.WHITE_SPACE);
            if (StringUtils.isNotBlank(leftTableAlias) == true) {
                joinStatement.append(leftTableAlias);
            } else {
                joinStatement.append(leftTableFullAlias);
            }
            joinStatement.append(MapperElm.SQL_JOIN_ON);
            joinStatement.append(rightColumnFullName);
            joinStatement.append(MapperElm.EQUAL);
            joinStatement.append(leftColumnFullName);
        }

        return joinStatement.toString();

    }

    public static String getColumnFullName(MapperProfile mapperProfile, String tableName, String tableAlias,
            String columnName) {

        String colFullName = null;
        if (StringUtils.isNotBlank(tableAlias) == true) {
            colFullName = tableAlias + MapperElm.DOT + columnName;
        } else {
            // // If tableName contain schema name, then remove it.
            // int indexOfDot = tableName.indexOf(MapperElm.DOT);
            // if (indexOfDot != -1) {
            // tableName = tableName.substring(indexOfDot + 1, tableName.length());
            // }
            String tableFullAlias = getTableFullAlias(mapperProfile, tableName);
            colFullName = tableFullAlias + MapperElm.DOT + columnName;
        }

        return colFullName;

    }

    public static String getColumnAlias(MapperProfile mapperProfile, String tableName, String tableAlias,
            String columnName) {

        // If tableName contain schema name, then use it.
        String schema = null;
        int indexOfDot = tableName.indexOf(MapperElm.DOT);
        if (indexOfDot != -1) {
            schema = tableName.substring(0, indexOfDot);
        } else {
            schema = getDefaultSchema(mapperProfile);
        }

        StringBuffer columnAlias = new StringBuffer();
        if (StringUtils.isNotBlank(tableAlias) == true) {
            columnAlias.append(tableAlias);
        } else {
            String tableShortName = getTableShortName(tableName, tableAlias);
            columnAlias.append(schema);
            columnAlias.append(MapperElm.DOUBLE_UNDER_LINE);
            columnAlias.append(tableShortName);
        }
        columnAlias.append(MapperElm.DOUBLE_UNDER_LINE);
        columnAlias.append(columnName);

        return columnAlias.toString();

    }

    public static String getColumnNamePair(MapperProfile mapperProfile, String tableName, String tableAlias,
            String columnName) throws AppException {

        // If tableName contain schema name, then use it.
        String tableFullAlias = getTableFullAlias(mapperProfile, tableName);

        KeyWordsTransformer keyWordsTransformer = KeyWordsTransformer
                .getInstance(mapperProfile.getAllMapperProfile());
        // String schema = null;
        // String dot = MapperElm.DOT;
        // int indexOfDot = tableName.indexOf(dot);
        // if (indexOfDot != -1) {
        // schema = tableName.substring(0, indexOfDot);
        // tableName = tableName.substring(indexOfDot + 1, tableName.length());
        // } else {
        // schema = getDefaultSchema(mapperProfile);
        // }

        StringBuffer colNamePair = new StringBuffer();
        if (StringUtils.isNotBlank(tableAlias) == true) {
            colNamePair.append(tableAlias);
        } else {
            colNamePair.append(tableFullAlias);
        }
        colNamePair.append(MapperElm.DOT);
        colNamePair.append(keyWordsTransformer.getTransferredStr(columnName));
        colNamePair.append(MapperElm.WHITE_SPACE);

        if (StringUtils.isNotBlank(tableAlias) == true) {
            colNamePair.append(tableAlias);
        } else {
            colNamePair.append(tableFullAlias);
        }
        // fullName.append(schema);
        // fullName.append(MapperElm.DOUBLE_UNDER_LINE);
        // if (StringUtils.isNotBlank(tableAlias) == true) {
        // fullName.append(tableAlias);
        // } else {
        // fullName.append(tableName);
        // }
        colNamePair.append(MapperElm.DOUBLE_UNDER_LINE);
        colNamePair.append(columnName);

        return colNamePair.toString();

    }

    public static String getSelectStmtWithPrefix(ResultMapConfig resultMapConfig) {

        StringBuffer id = new StringBuffer();
        id.append(MapperElm.SQL_SELECT);
        String prefix = resultMapConfig.getSelectPrefix();
        if (StringUtils.isNotBlank(prefix)) {
            id.append(prefix);
        }
        id.append(MapperElm.WHITE_SPACE);

        logger.debug("ID: The return value of 'getSelectStmtWithPrefix' is: " + id);
        return id.toString();

    }

    public static String getResultMapIdOfRootTab(ResultMapConfig resultMapConfig) {

        String selectId = getSelIdOfRootTab(resultMapConfig, false);
        String id = selectId + MapperElm.MAPPER_RESULT_MAP;

        logger.debug("ID: The return value of 'getResultMapId' is: " + id);
        return id;

    }

    public static String getResultMapIdOfMultiTab(ResultMapConfig resultMapConfig, List<OneToOneIdx> otoIndexList) {

        String selectId = getSelIdOfMultiTab(resultMapConfig, otoIndexList);
        String id = selectId + MapperElm.MAPPER_RESULT_MAP;

        logger.debug("ID: The return value of 'getResultMapIdOfMultiTabSelect' is: " + id);
        return id.toString();

    }

    public static String getResultMapIdOfIntnlOtm(MapperProfile mapperProfile, MapperArtifact mapperArtifact,
            ResultMapConfig resultMapConfig, String attrName) {

        // Initiate the return value.
        String selectId = getSelIdOfIntnlOtm(mapperProfile, mapperArtifact, resultMapConfig, attrName, false);
        String id = selectId + MapperElm.MAPPER_RESULT_MAP;
        logger.debug("ID: The return value of 'getResultMapIdOfIntnlOTM' is: " + id);
        return id;

    }

    public static String getSqlIdOfRootTabSel(ResultMapConfig resultMapConfig) {

        String selectId = getSelIdOfRootTab(resultMapConfig, false);
        String id = MapperElm.MAPPER_SQL + selectId;
        logger.debug("ID: The return value of 'getSqlIdOfSelectRootTable' is: " + id);
        return id;

    }

    public static String getSqlIdOfMultiTabSel(ResultMapConfig ancesResultMapConfig, List<OneToOneIdx> otoIndexList,
            boolean needPrefix) {

        String selectId = getSelIdOfMultiTab(ancesResultMapConfig, otoIndexList);
        String id = MapperElm.MAPPER_SQL + selectId;
        logger.debug("ID: The return value of 'getSqlIdOfMultiTabSelect' is: " + id);
        return id.toString();

    }

    public static String getSqlIdOfUpdByPK(UpdateConfig updateConfig, boolean isUpdAll, boolean hasTmLck) {

        String updId = getUpdId(updateConfig, isUpdAll, MapperElm.MAPPER_BYPK, hasTmLck);
        String id = MapperElm.MAPPER_SQL + updId;
        logger.debug("ID: The return value of 'getSqlIdOfUpdByPK' is: " + id);
        return id;

    }

    public static String getSqlIdOfUpdBySql(UpdateConfig updateConfig, boolean isUpdAll, boolean hasTmLck) {

        String updId = getUpdId(updateConfig, isUpdAll, MapperElm.MAPPER_BYSQL, hasTmLck);
        String id = MapperElm.MAPPER_SQL + updId;
        logger.debug("ID: The return value of 'getSqlIdOfUpdBySql' is: " + id);
        return id;

    }

    public static String getSqlIdOfDel(UpdateConfig updateConfig) {

        String updId = getDelId(updateConfig, null, false);
        String id = MapperElm.MAPPER_SQL + updId;
        logger.debug("ID: The return value of 'getSqlIdOfDel' is: " + id);
        return id;

    }

    public static String getSqlIdOfDelByPK(UpdateConfig updateConfig, boolean hasTmLck) {

        String updId = getDelId(updateConfig, MapperElm.MAPPER_BYPK, hasTmLck);
        String id = MapperElm.MAPPER_SQL + updId;
        logger.debug("ID: The return value of 'getSqlIdOfDel' is: " + id);
        return id;

    }

    public static String getSqlIdOfDelBySql(UpdateConfig updateConfig, boolean hasTmLck) {

        String updId = getDelId(updateConfig, MapperElm.MAPPER_BYSQL, hasTmLck);
        String id = MapperElm.MAPPER_SQL + updId;
        logger.debug("ID: The return value of 'getSqlIdOfDel' is: " + id);
        return id;

    }

    public static String getSqlIdOfInsertSelCol(InsertConfig insertConfig) {

        String id = getSqlIdOfInsert(insertConfig, false, false) + MapperElm.MAPPER_COL;
        logger.debug("ID: The return value of 'getSqlIdOfInsertSelCol' is: " + id);
        return id;

    }

    public static String getSqlIdOfInsertSelVal(InsertConfig insertConfig) {

        String id = getSqlIdOfInsert(insertConfig, false, false) + MapperElm.MAPPER_VALUE;
        logger.debug("ID: The return value of 'getSqlIdOfInsertSelVal' is: " + id);
        return id;

    }

    public static String getSqlIdOfInsertAllBatchCol(InsertConfig insertConfig, boolean withoutPk) {
        String id = getSqlIdOfInsert(insertConfig, true, true);
        if (withoutPk) {
            id += MapperElm.MAPPER_WITHOUT_PK;
        }
        id += MapperElm.MAPPER_COL;
        logger.debug("ID: The return value of 'getSqlIdOfInsertAllBatchCol' is: " + id);
        return id;

    }

    public static String getSqlIdOfInsertAllBatchVal(InsertConfig insertConfig, boolean withoutPk) {
        String id = getSqlIdOfInsert(insertConfig, true, true);
        if (withoutPk) {
            id += MapperElm.MAPPER_WITHOUT_PK;
        }
        id += MapperElm.MAPPER_VALUE;
        logger.debug("ID: The return value of 'getSqlIdOfInsertAllBatchVal' is: " + id);
        return id;

    }

    public static String getSqlIdOfInsert(InsertConfig insertConfig, boolean isAll, boolean isBatch) {

        String insertId = getInsertId(insertConfig, isAll, isBatch);
        String id = MapperElm.MAPPER_SQL + insertId;
        logger.debug("ID: The return value of 'getSqlIdOfInsert' is: " + id);
        return id;

    }

    public static String getSelIdOfCountBySql(ResultMapConfig resultMapConfig) {

        String tableName = resultMapConfig.getTableName();
        String tableAlias = resultMapConfig.getTableAlias();
        String tableShortName = getTableShortName(tableName, tableAlias);
        String javaName = JavaFormatter.getJavaStyle(tableShortName, true);
        String id = MapperElm.SQL_COUNT + javaName + MapperElm.MAPPER_BYSQL;
        logger.debug("ID: The return value of 'getSelIdOfCountBySql' is: " + id);
        return id;

    }

    public static String getSelIdOfRootTabByPK(ResultMapConfig resultMapConfig) {

        String selectId = getSelIdOfRootTab(resultMapConfig, false);
        String id = selectId + MapperElm.MAPPER_BYPK;
        logger.debug("ID: The return value of 'getSelIdOfSelectRootTableByPK' is: " + id);
        return id;

    }

    public static String getSelIdOfRootTabBySql(ResultMapConfig resultMapConfig) {

        String selectId = getSelIdOfRootTab(resultMapConfig, false);
        String id = selectId + MapperElm.MAPPER_BYSQL;
        logger.debug("ID: The return value of 'getSelIdOfSelectRootTableBySql' is: " + id);
        return id;

    }

    public static String getSelIdOfMultiTabByPK(ResultMapConfig ancesResultMapConfig,
            List<OneToOneIdx> otoIndexList) {

        String selectId = getSelIdOfMultiTab(ancesResultMapConfig, otoIndexList);
        String id = selectId + MapperElm.MAPPER_BYPK;
        logger.debug("ID: The return value of 'getSelIdOfMultiTabSelectByPK' is: " + id);
        return id;

    }

    public static String getSelIdOfMultiTabBySql(ResultMapConfig ancesResultMapConfig,
            List<OneToOneIdx> otoIndexList) {

        String selectId = getSelIdOfMultiTab(ancesResultMapConfig, otoIndexList);
        String id = selectId + MapperElm.MAPPER_BYSQL;
        logger.debug("ID: The return value of 'getSelIdOfPublicSelectBySql' is: " + id);
        return id;

    }

    //
    // String tableName = insertConfig.getTableName();
    // String javaName = JavaFormatter.getJavaStyle(tableName, true);
    // javaName = StringHelper.toUpperCase(javaName, 0);
    //
    // id = MapperElm.MAPPER_SQL + MapperElm.SQL_INSERT + javaName + MapperElm.MAPPER_ALL;
    //
    // logger.debug("ID: The return value of 'getSqlIdOfInsertAll' is: " + id);
    // return id;
    //
    // }

    // public static String getSqlIdOfInsertSelCol(InsertConfig insertConfig) {
    //
    // // Define the return value.
    // String id = new String();
    //
    // // If the given 'insertStatement' attribute is not null, then use it.
    // String insertStatement = insertConfig.getInsertStmt();
    // if (StringUtils.isNotBlank(insertStatement)) {
    // id = MapperElm.MAPPER_SQL + insertStatement + MapperElm.MAPPER_COLUMN;
    // logger.debug("ID: The return value of 'getSqlIdOfInsertSelCol' is: " + id);
    // return id;
    // }
    //
    // String tableName = insertConfig.getTableName();
    // String javaName = JavaFormatter.getJavaStyle(tableName, true);
    // javaName = StringHelper.toUpperCase(javaName, 0);
    //
    // id = MapperElm.MAPPER_SQL + MapperElm.SQL_INSERT + javaName + MapperElm.MAPPER_SEL + MapperElm.MAPPER_COLUMN;
    //
    // logger.debug("ID: The return value of 'getSqlIdOfInsertSelCol' is: " + id);
    // return id;
    //
    // }
    //

    // public static String getInsertIdOfAll(InsertConfig insertConfig) {
    //
    // // Define the return value.
    // String id = new String();
    //
    // // If the given 'insertStatement' attribute is not null, then use it.
    // String insertStmt = insertConfig.getInsertStmt();
    // if (StringUtils.isNotBlank(insertStmt)) {
    // id = insertStmt;
    // logger.debug("ID: The return value of 'getInsertIdOfAll' is: " + id);
    // return id;
    // }
    //
    // String tableName = insertConfig.getTableName();
    // String javaName = JavaFormatter.getJavaStyle(tableName, true);
    // javaName = StringHelper.toUpperCase(javaName, 0);
    //
    // // The default value of id.
    // id = MapperElm.SQL_INSERT + javaName + MapperElm.MAPPER_ALL;
    //
    // logger.debug("ID: The return value of 'getInsertIdOfAll' is: " + id);
    // return id;
    //
    // }
    //
    // public static String getInsertIdOfSel(InsertConfig insertConfig) {
    //
    // // Define the return value.
    // String id = new String();
    //
    // // If the given 'insertStatement' attribute is not null, then use it.
    // String insertStmt = insertConfig.getInsertStmt();
    // if (StringUtils.isNotBlank(insertStmt)) {
    // id = insertStmt;
    // logger.debug("ID: The return value of 'getInsertIdOfSel' is: " + id);
    // return id;
    // }
    //
    // String tableName = insertConfig.getTableName();
    // String javaName = JavaFormatter.getJavaStyle(tableName, true);
    // javaName = StringHelper.toUpperCase(javaName, 0);
    //
    // // The defaut value of id.
    // id = MapperElm.SQL_INSERT + javaName + MapperElm.MAPPER_SEL;
    //
    // logger.debug("ID: The return value of 'getInsertIdOfSel' is: " + id);
    // return id;
    //
    // }

    // public static String getSqlIdOfUpdateAll(UpdateConfig updateConfig) {
    //
    // // Define the return value.
    // String id = new String();
    //
    // // If the given 'updateStatement' attribute is not null, then use it.
    // String updateStatement = updateConfig.getUpdateStmt();
    // if (StringUtils.isNotBlank(updateStatement)) {
    // id = MapperElm.MAPPER_SQL + updateStatement;
    // logger.debug("ID: The return value of 'getSqlIdOfUpdateAll' is: " + id);
    // return id;
    // }
    //
    // id = MapperElm.MAPPER_SQL + MapperElm.MAPPER_UPDATE;
    //
    // logger.debug("ID: The return value of 'getSqlIdOfUpdateAll' is: " + id);
    // return id;
    //
    // }
    //
    // public static String getSqlIdOfUpdateSel(UpdateConfig updateConfig) {
    //
    // String updateNamePrefix = getUpdateId(updateConfig, true, false);
    // String sqlId = updateNamePrefix + MapperElm.MAPPER_SEL;
    //
    // logger.debug("ID: The return value of 'getSqlIdOfUpdateSel' is: " + sqlId);
    // return sqlId;
    //
    // }

    // public static String getUpdateIdOfAll(UpdateConfig updateConfig) {
    //
    // // Define the return value.
    // String id = new String();
    //
    // // If the given 'updateStatement' attribute is not null, then use it.
    // String updateStatement = updateConfig.getUpdateStmt();
    // if (StringUtils.isNotBlank(updateStatement)) {
    // id = updateStatement;
    // logger.debug("ID: The return value of 'getUpdateIdOfAll' is: " + id);
    // return id;
    // }
    //
    // id = MapperElm.MAPPER_STMT_UPD_ALL_BYPK;
    //
    // logger.debug("ID: The return value of 'getUpdateIdOfAll' is: " + id);
    // return id;
    //
    // }

    // public static String getUpdateIdOfSel(UpdateConfig updateElm) {
    //
    // // Define the return value.
    // String id = new String();
    //
    // // If the given 'updateStatement' attribute is not null, then use it.
    // String updateStatement = updateElm.getUpdateStmt();
    // if (StringUtils.isNotBlank(updateStatement)) {
    // id = updateStatement;
    // logger.debug("ID: The return value of 'getUpdateIdOfSelective' is: " + id);
    // return id;
    // }
    //
    // id = MapperElm.MAPPER_STMT_UPD_SEL_BYPK;
    //
    // logger.debug("ID: The return value of 'getUpdateIdOfSelective' is: " + id);
    // return id;
    //
    // }

    public static String getSelIdOfIntnlOtm(MapperProfile mapperProfile, MapperArtifact mapperArtifact,
            ResultMapConfig resultMapConfig, String attrName, boolean useNameSpace) {

        // Initiate the return value.
        StringBuffer id = new StringBuffer();

        // If the given 'selectStmt' attribute is not null, then use it.
        String selectStmt = resultMapConfig.getSelectStmt();
        if (StringUtils.isNotBlank(selectStmt)) {
            if (selectStmt.startsWith(MapperElm.UNDER_LINE) == false) {
                id.append(MapperElm.UNDER_LINE);
            }
            id.append(selectStmt);
        } else {
            id.append(MapperElm.UNDER_LINE);
            id.append(attrName);
        }

        if (useNameSpace == false) {
            logger.debug("ID: The return value of 'getSelIdOfIntnlOTM' is: " + id);
            return id.toString();
        } else {

            // Get the global setting.
            // AllMapperProfile allMapperProfile = mapperProfile.getAllMapperProfile();
            // ComnArtifact comnArtifact = allMapperProfile.getComnArtifact();

            // Get the local setting.
            String nameSpace = mapperArtifact.getMapperNs() + MapperElm.DOT;

            logger.debug("ID: The return value of 'getSelIdOfIntnlOTM' is: " + id);
            return nameSpace + id;

        }

    }

    public static String getUpdIdByPK(UpdateConfig updateConfig, boolean isUpdAll, boolean hasTmLck) {

        String id = getUpdId(updateConfig, isUpdAll, MapperElm.MAPPER_BYPK, hasTmLck);
        logger.debug("ID: The return value of 'getUpdIdByPK' is: " + id);
        return id;

    }

    public static String getUpdIdBySql(UpdateConfig updateConfig, boolean isUpdAll) {

        String id = getUpdId(updateConfig, isUpdAll, MapperElm.MAPPER_BYSQL, false);
        logger.debug("ID: The return value of 'getUpdIdBySql' is: " + id);
        return id;

    }

    //   // TODO 
    //   public static String getDelId(UpdateConfig updateConfig, boolean hasTmLck) {
    //
    //      String id = getDelId(updateConfig, null , hasTmLck);
    //      logger.debug("ID: The return value of 'getDelIdByPK' is: " + id);
    //      return id;
    //
    //   }

    public static String getDelIdByPK(UpdateConfig updateConfig, boolean hasTmLck) {
        String id = getDelId(updateConfig, MapperElm.MAPPER_BYPK, hasTmLck);
        logger.debug("ID: The return value of 'getDelIdByPK' is: " + id);
        return id;

    }

    public static String getDelIdBySql(UpdateConfig updateConfig) {

        String id = getDelId(updateConfig, MapperElm.MAPPER_BYSQL, false);
        logger.debug("ID: The return value of 'getDelIdBySql' is: " + id);
        return id;

    }

    public static String getInsertId(InsertConfig insertConfig, boolean isAll, boolean isBatch) {

        // Define the return value.
        String id = new String();

        // If the given 'insertStmt' attribute is not null, then use it.
        String insertStmt = insertConfig.getInsertStmt();
        if (StringUtils.isNotBlank(insertStmt)) {
            id = insertStmt;
        } else {
            String tableName = insertConfig.getTableName();
            String javaName = JavaFormatter.getJavaStyle(tableName, true);
            javaName = StringHelper.toUpperCase(javaName, 0);
            id = MapperElm.SQL_INSERT + javaName;
        }

        if (isAll == true) {
            id = id + MapperElm.MAPPER_ALL;
        } else {
            id = id + MapperElm.MAPPER_SELECTIVE;
        }

        if (isBatch == true) {
            id = id + MapperElm.MAPPER_BATCH;
        }

        logger.debug("ID: The return value of 'getInsertId' is: " + id);
        return id;

    }

    public static String getAddDtoMethodName(InsertConfig insertConfig) throws AppException {

        // Define the return value.
        String methodName = new String();

        try {

            // If the given 'insertStmt' attribute is not null, then use it.
            String insertStmt = insertConfig.getInsertStmt();
            if (StringUtils.isNotBlank(insertStmt)) {
                methodName = insertStmt;
            } else {
                String dtoClassName = insertConfig.getClassName();
                if (StringUtils.isBlank(dtoClassName) == true) {
                    throw new AppException("The given class name should not be blank.");
                }
                String dtoClassSimpleName = JavaFormatter.getClassSimpleName(dtoClassName);
                methodName = JavaSrcElm.ADD + dtoClassSimpleName;
            }

        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }

        logger.debug("ID: The return value of 'getAddDtoMethodName' is: " + methodName);
        return methodName;

    }

    public static String getChgByPKMethodName(UpdateConfig updStatConfig) throws AppException {

        // Define the return value.
        String methodName = new String();

        try {

            // If the given 'insertStmt' attribute is not null, then use it.
            String updateStmt = updStatConfig.getUpdateStmt();
            if (StringUtils.isNotBlank(updateStmt)) {
                methodName = updateStmt;
            } else {
                String dtoClassName = updStatConfig.getClassName();
                if (StringUtils.isBlank(dtoClassName) == true) {
                    throw new AppException("The given class name should not be blank.");
                }
                String dtoClassSimpleName = JavaFormatter.getClassSimpleName(dtoClassName);
                methodName = JavaSrcElm.CHG + dtoClassSimpleName + MapperElm.MAPPER_BYPK;
            }

        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }

        logger.debug("ID: The return value of 'getChgStatMethodName' is: " + methodName);
        return methodName;

    }

    public static String getDelByPKMethodName(UpdateConfig delByPKConfig) throws AppException {

        // Define the return value.
        String methodName = new String();

        try {

            // If the given 'insertStmt' attribute is not null, then use it.
            String updateStmt = delByPKConfig.getUpdateStmt();
            if (StringUtils.isNotBlank(updateStmt)) {
                methodName = updateStmt;
            } else {
                String dtoClassName = delByPKConfig.getClassName();
                if (StringUtils.isBlank(dtoClassName) == true) {
                    throw new AppException("The given class name should not be blank.");
                }
                String dtoClassSimpleName = JavaFormatter.getClassSimpleName(dtoClassName);
                methodName = JavaSrcElm.DEL + dtoClassSimpleName + MapperElm.MAPPER_BYPK;
            }

        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }

        logger.debug("ID: The return value of 'getDelByPKMethodName' is: " + methodName);
        return methodName;

    }

    public static String getDelBySqlMethodName(UpdateConfig delBySqlConfig) throws AppException {

        // Define the return value.
        String methodName = new String();

        try {

            // If the given 'insertStmt' attribute is not null, then use it.
            String updateStmt = delBySqlConfig.getUpdateStmt();
            if (StringUtils.isNotBlank(updateStmt)) {
                methodName = updateStmt;
            } else {
                String dtoClassName = delBySqlConfig.getClassName();
                if (StringUtils.isBlank(dtoClassName) == true) {
                    throw new AppException("The given class name should not be blank.");
                }
                String dtoClassSimpleName = JavaFormatter.getClassSimpleName(dtoClassName);
                methodName = JavaSrcElm.DEL + dtoClassSimpleName + MapperElm.MAPPER_BYSQL;
            }

        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }

        logger.debug("ID: The return value of 'getDelBySqlMethodName' is: " + methodName);
        return methodName;

    }

    private static String getSelIdOfMultiTab(ResultMapConfig ancesResultMapConfig, List<OneToOneIdx> otoIndexList) {

        String selectStmt = ancesResultMapConfig.getSelectStmt();
        String ancesTableName = ancesResultMapConfig.getTableName();
        String ancesJavaName = null;
        StringBuffer id = new StringBuffer();

        // If the given 'selectStmt' attribute is not null, then use it.
        if (StringUtils.isNotBlank(selectStmt)) {
            id.append(selectStmt);
            logger.debug("ID: The return value of 'getSelIdOfMultiTabSelect' is: " + id);
            return id.toString();
        }

        // TODO 2016.1.25 idselectStmt???
        OneToOneIdx descOtoIdx = null;
        RelConfig descOneToOne = null;
        ResultMapConfig descResultMapElm = null;
        String descTableName = null;
        String descTableAlias = null;

        // Change to Java style.
        ancesJavaName = JavaFormatter.getJavaStyle(ancesTableName, true);
        ancesJavaName = StringHelper.toUpperCase(ancesJavaName, 0);
        id.append(MapperElm.SQL_SELECT);
        id.append(ancesJavaName);

        if (otoIndexList != null) {

            for (int i = 0; i < otoIndexList.size(); i++) {

                descOtoIdx = otoIndexList.get(i);
                descOneToOne = descOtoIdx.getOneToOne();
                descResultMapElm = descOneToOne.getResultMapConfig();
                descTableName = descResultMapElm.getTableName();
                descTableAlias = descResultMapElm.getTableAlias();

                if (StringUtils.isNotBlank(descTableAlias) == true) {
                    // Change to Java style.
                    descTableAlias = JavaFormatter.getJavaStyle(descTableAlias, true);
                    descTableAlias = StringHelper.toUpperCase(descTableAlias, 0);
                    id.append(descTableAlias);
                } else {
                    // Change to Java style.
                    descTableName = JavaFormatter.getJavaStyle(descTableName, true);
                    descTableName = StringHelper.toUpperCase(descTableName, 0);
                    id.append(descTableName);
                }

            }

            // Determine the id of select according to the number of sub OTO or OTM
            if (otoIndexList.size() > 0) {
                id.append(MapperElm.RESULT_MAP_ONE_TO_ONE);
            } else if (ancesResultMapConfig.getOneToMany().size() > 0) {
                id.append(MapperElm.RESULT_MAP_ONE_TO_MANY);
            }

        }

        logger.debug("ID: The return value of 'getSelIdOfMultiTabSelect' is: " + id);
        return id.toString();

    }

    private static String getSelIdOfRootTab(ResultMapConfig resultMapConfig, boolean isCount) {

        // Get attributes from resultMapConfig.
        String tableName = resultMapConfig.getTableName();
        String tableAlias = resultMapConfig.getTableAlias();

        // Change to Java style.
        String tableShortName = getTableShortName(tableName, tableAlias);
        String javaName = JavaFormatter.getJavaStyle(tableShortName, true);

        // Define the return value.
        String id = MapperElm.SQL_SELECT + javaName;

        logger.debug("ID: The return value of 'getSelIdOfRootTab' is: " + id);
        return id;

    }

    private static String getUpdId(UpdateConfig updateConfig, boolean isUpdAll, String whereClause,
            boolean hasTmLck) {

        // Define the return value.
        String id = new String();

        // If the given 'updateStmt' attribute is not null, then use it.
        String updateStmt = updateConfig.getUpdateStmt();
        if (StringUtils.isNotBlank(updateStmt)) {
            id = updateStmt;
        } else {
            String tableName = updateConfig.getTableName();
            String javaName = JavaFormatter.getJavaStyle(tableName, true);
            javaName = StringHelper.toUpperCase(javaName, 0);
            id = MapperElm.SQL_UPDATE + javaName;
        }

        // Update all columns or not.
        if (isUpdAll == true) {
            id = id + MapperElm.MAPPER_ALL;
        } else {
            id = id + MapperElm.MAPPER_SELECTIVE;
        }

        // By primiary key or sql clause.
        id = id + whereClause;

        // With time lock or not.
        if (hasTmLck == true) {
            id = id + MapperElm.MAPPER_TM_LCK;
        }

        logger.debug("ID: The return value of 'getUpdId' is: " + id);
        return id;

    }

    private static String getDelId(UpdateConfig updateConfig, String whereClause, boolean hasTmLck) {

        // Define the return value.
        String id = new String();

        // If the given 'updateStmt' attribute is not null, then use it.
        String updateStmt = updateConfig.getUpdateStmt();
        if (StringUtils.isNotBlank(updateStmt)) {
            id = updateStmt;
        } else {
            String tableName = updateConfig.getTableName();
            String javaName = JavaFormatter.getJavaStyle(tableName, true);
            javaName = StringHelper.toUpperCase(javaName, 0);
            id = MapperElm.SQL_DELETE + javaName;
        }

        // By primiary key or sql clause.
        if (null != whereClause) {
            id = id + whereClause;
        }

        // With time lock or not.
        if (hasTmLck == true) {
            id = id + MapperElm.MAPPER_TM_LCK;
        }

        logger.debug("ID: The return value of 'getDelId' is: " + id);
        return id;

    }

}