Search in sources :

Example 1 with JavaSelectFieldResultSetExtractor

use of com.ctrip.platform.dal.daogen.host.java.JavaSelectFieldResultSetExtractor in project dal by ctripcorp.

the class AbstractCSharpDataPreparer method buildSelectMethodHosts.

private List<CSharpMethodHost> buildSelectMethodHosts(List<CSharpParameterHost> allColumns, List<GenTaskBySqlBuilder> currentTableBuilders) throws Exception {
    List<CSharpMethodHost> methods = new ArrayList<>();
    for (GenTaskBySqlBuilder builder : currentTableBuilders) {
        if (!builder.getCrud_type().equals("select")) {
            continue;
        }
        CSharpMethodHost method = new CSharpMethodHost();
        method.setCrud_type(builder.getCrud_type());
        method.setName(builder.getMethod_name());
        String sql = builder.getSql_content();
        int index = 0;
        if (builder.getPagination()) {
            sql = SqlBuilder.pagingQuerySql(sql, getDatabaseCategory(builder.getAllInOneName()), CurrentLanguage.CSharp);
            index += 2;
        }
        Matcher m = CSharpCodeGenContext.inRegxPattern.matcher(builder.getSql_content());
        while (m.find()) {
            sql = sql.replace(m.group(1), String.format("({%d}) ", index));
            index++;
        }
        method.setSql(sql);
        method.setScalarType(builder.getScalarType());
        method.setPaging(builder.getPagination());
        List<AbstractParameterHost> paramAbstractHosts = DbUtils.getSelectFieldHosts(builder.getAllInOneName(), builder.getSql_content(), new JavaSelectFieldResultSetExtractor());
        List<JavaParameterHost> paramHosts = new ArrayList<>();
        for (AbstractParameterHost phost : paramAbstractHosts) {
            paramHosts.add((JavaParameterHost) phost);
        }
        method.setFields(paramHosts);
        List<CSharpParameterHost> whereParams = buildMethodParameterHost4SqlConditin(builder, allColumns);
        method.setParameters(buildSqlParamName(whereParams, method.getSql()));
        String orderBy = builder.getOrderby();
        if (orderBy != null && !orderBy.trim().isEmpty() && orderBy.indexOf("-1,") != 0) {
            String[] str = orderBy.split(",");
            String odyExp = "p => p." + str[0] + ", ";
            odyExp = "asc".equalsIgnoreCase(str[1]) ? odyExp + "true" : odyExp + "false";
            method.setOrderByExp(odyExp);
        }
        methods.add(method);
    }
    return methods;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) Matcher(java.util.regex.Matcher) JavaSelectFieldResultSetExtractor(com.ctrip.platform.dal.daogen.host.java.JavaSelectFieldResultSetExtractor) JavaParameterHost(com.ctrip.platform.dal.daogen.host.java.JavaParameterHost) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)

Aggregations

GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)1 AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)1 JavaParameterHost (com.ctrip.platform.dal.daogen.host.java.JavaParameterHost)1 JavaSelectFieldResultSetExtractor (com.ctrip.platform.dal.daogen.host.java.JavaSelectFieldResultSetExtractor)1 Matcher (java.util.regex.Matcher)1