Search in sources :

Example 11 with GenTaskBySqlBuilder

use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.

the class CSharpDataPreparerOfSqlBuilderProcessor method prepareSqlBuilder.

private List<Callable<ExecuteResult>> prepareSqlBuilder(CodeGenContext context) {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
    final Progress progress = ctx.getProgress();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    Queue<GenTaskBySqlBuilder> sqlBuilders = ctx.getSqlBuilders();
    final Queue<CSharpTableHost> tableViewHosts = ctx.getTableViewHosts();
    if (sqlBuilders.size() > 0) {
        Map<String, GenTaskBySqlBuilder> tempSqlBuildres = sqlBuilderBroupBy(sqlBuilders);
        for (final Map.Entry<String, GenTaskBySqlBuilder> sqlBuilder : tempSqlBuildres.entrySet()) {
            Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

                @Override
                public ExecuteResult call() throws Exception {
                    ExecuteResult result = new ExecuteResult("Build Extral SQL[" + sqlBuilder.getValue().getAllInOneName() + "." + sqlBuilder.getKey() + "] Host");
                    progress.setOtherMessage(result.getTaskName());
                    CSharpTableHost extraTableHost;
                    try {
                        extraTableHost = buildExtraSqlBuilderHost(ctx, sqlBuilder.getValue());
                        if (null != extraTableHost) {
                            tableViewHosts.add(extraTableHost);
                        }
                        result.setSuccessal(true);
                    } catch (Throwable e) {
                        throw new Exception(String.format("Task Id[%s]:%s\r\n", sqlBuilder.getValue().getId(), e.getMessage()), e);
                    }
                    return result;
                }
            };
            results.add(worker);
        }
    }
    return results;
}
Also used : Progress(com.ctrip.platform.dal.daogen.entity.Progress) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) Callable(java.util.concurrent.Callable) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder) CSharpTableHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult)

Example 12 with GenTaskBySqlBuilder

use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.

the class AbstractCSharpDataPreparer method buildInsertMethodHosts.

private List<CSharpMethodHost> buildInsertMethodHosts(List<CSharpParameterHost> allColumns, List<GenTaskBySqlBuilder> currentTableBuilders) throws Exception {
    List<CSharpMethodHost> methods = new ArrayList<>();
    for (GenTaskBySqlBuilder builder : currentTableBuilders) {
        if (!builder.getCrud_type().equals("insert")) {
            continue;
        }
        CSharpMethodHost method = new CSharpMethodHost();
        method.setCrud_type(builder.getCrud_type());
        method.setName(builder.getMethod_name());
        method.setSql(builder.getSql_content());
        method.setScalarType(builder.getScalarType());
        method.setPaging(builder.getPagination());
        List<CSharpParameterHost> parameters = new ArrayList<>();
        if (method.getCrud_type().equals("insert")) {
            String[] fields = StringUtils.split(builder.getFields(), ",");
            for (String field : fields) {
                for (CSharpParameterHost pHost : allColumns) {
                    if (pHost.getName().equals(field)) {
                        parameters.add(pHost);
                        break;
                    }
                }
            }
        }
        method.setParameters(parameters);
        methods.add(method);
    }
    return methods;
}
Also used : GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)

Example 13 with GenTaskBySqlBuilder

use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder 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)

Example 14 with GenTaskBySqlBuilder

use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.

the class AbstractCSharpDataPreparer method buildDeleteMethodHosts.

private List<CSharpMethodHost> buildDeleteMethodHosts(List<CSharpParameterHost> allColumns, List<GenTaskBySqlBuilder> currentTableBuilders) throws Exception {
    List<CSharpMethodHost> methods = new ArrayList<>();
    for (GenTaskBySqlBuilder builder : currentTableBuilders) {
        if (!builder.getCrud_type().equals("delete")) {
            continue;
        }
        CSharpMethodHost method = new CSharpMethodHost();
        method.setCrud_type(builder.getCrud_type());
        method.setName(builder.getMethod_name());
        method.setSql(builder.getSql_content());
        method.setScalarType(builder.getScalarType());
        method.setPaging(builder.getPagination());
        List<CSharpParameterHost> whereParams = buildMethodParameterHost4SqlConditin(builder, allColumns);
        method.setParameters(buildSqlParamName(whereParams, method.getSql()));
        methods.add(method);
    }
    return methods;
}
Also used : GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)

Example 15 with GenTaskBySqlBuilder

use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.

the class DaoBySqlBuilder method getVersionById.

public int getVersionById(int id) throws SQLException {
    DalHints hints = DalHints.createIfAbsent(null);
    GenTaskBySqlBuilder entity = client.queryByPk(id, hints);
    if (entity == null)
        return 0;
    return entity.getVersion();
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)

Aggregations

GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)18 DalHints (com.ctrip.platform.dal.dao.DalHints)5 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)4 Progress (com.ctrip.platform.dal.daogen.entity.Progress)4 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)4 Callable (java.util.concurrent.Callable)4 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)3 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)3 ArrayList (java.util.ArrayList)3 ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)2 DatabaseCategory (com.ctrip.platform.dal.daogen.enums.DatabaseCategory)2 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)2 AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 FreeUpdateSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder)1 SelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)1 StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)1 CSharpTableHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost)1 JavaParameterHost (com.ctrip.platform.dal.daogen.host.java.JavaParameterHost)1