All Downloads are FREE. Search and download functionalities are using the official Maven repository.

group.rober.dataform.model.DataFormParser Maven / Gradle / Ivy

There is a newer version: 3.2.2
Show newest version
package group.rober.dataform.model;


import group.rober.runtime.kit.StringKit;
import group.rober.runtime.kit.ValidateKit;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * DataForm解析转换工具
 * Created by tisir [email protected] on 2017-05-29
 */
public class DataFormParser {
    protected DataForm dataForm;
    protected String querySql;
    protected Map fieldsMap = new LinkedHashMap();
    protected Map summaryFieldsMap = new LinkedHashMap();
//    protected NameConverter nameConverter;
//    protected NameConverter summaryNameConverter ;
    protected Map summaryExpression = new LinkedHashMap();

    public DataFormParser(DataForm dataForm) {
        this.dataForm = dataForm;
    }
    public void parse(){
        ValidateKit.notNull(dataForm,"解析DataForm对象上的SQL出错,DataForm对象为空");
        ValidateKit.notNull(dataForm.getQuery(),"解析DataForm对象上的SQL出错,DataForm.query对象为空");

//        final Map nameConvertMap = MapKit.newHashMap();
//        final Map summaryNameConvertMap = MapKit.newHashMap();
        //第一个是总数列,PaginationQuery的查询规范是这样制订的
        summaryFieldsMap.put(1,"totalCount");
        int summaryIndex = 2;
        StringBuilder columnsClause = new StringBuilder();

        List elements = dataForm.getElements();
        for(int i=0;i0)columnsClause.deleteCharAt(0);

        //处理掉以前的select * 部分
        String fromClause = dataForm.getQuery().buildQuerySql();
        fromClause = fromClause.replaceAll("(?u)^\\s*select\\s+\\*\\s+", "");
        StringBuffer sbSQL = new StringBuffer("SELECT ");
        sbSQL.append(columnsClause).append(" ").append(fromClause);

        querySql = sbSQL.toString();
//        nameConverter = new NameConverter() {
//            public String getPropertyName(String columnName) {
//                return null;
//            }
//            public String getPropertyName(int column) {
//                return nameConvertMap.get(column);
//            }
//            public String getColumnName(String propertyName) {
//                return null;
//            }
//            public String getClassName(String tableName) {
//                return null;
//            }
//            public String getTableName(Class clazz) {
//                return null;
//            }
//        };
//        summaryNameConverter = new NameConverter() {
//            public String getPropertyName(String columnName) {
//                return null;
//            }
//            public String getPropertyName(int column) {
//                if(column == 1)return "totalCount";
//                return summaryNameConvertMap.get(column);
//            }
//            public String getColumnName(String propertyName) {
//                return null;
//            }
//            public String getClassName(String tableName) {
//                return null;
//            }
//            public String getTableName(Class clazz) {
//                return null;
//            }
//        };

    }

    public String getQuerySql() {
        return querySql;
    }

//    public NameConverter getNameConverter() {
//        return nameConverter;
//    }
//
//    public NameConverter getSummaryNameConverter() {
//        return summaryNameConverter;
//    }

    public Map getSummaryExpression() {
        return summaryExpression;
    }

    public Map getFieldsMap() {
        return fieldsMap;
    }

    public Map getSummaryFieldsMap() {
        return summaryFieldsMap;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy