Search in sources :

Example 6 with CSharpCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.

the class AbstractCSharpDataPreparer method addDatabaseSet.

protected void addDatabaseSet(CodeGenContext codeGenCtx, String databaseSetName) {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    List<DatabaseSet> sets = daoOfDatabaseSet.getAllDatabaseSetByName(databaseSetName);
    if (null == sets || sets.isEmpty()) {
        // exist", databaseSetName));
        return;
    }
    DalConfigHost dalConfigHost = ctx.getDalConfigHost();
    dalConfigHost.addDatabaseSet(sets);
    for (DatabaseSet databaseSet : sets) {
        List<DatabaseSetEntry> entries = daoOfDatabaseSet.getAllDatabaseSetEntryByDbsetid(databaseSet.getId());
        if (null == entries || entries.isEmpty()) {
            // any entries", databaseSet.getId()));
            continue;
        }
        dalConfigHost.addDatabaseSetEntry(entries);
    }
}
Also used : DaoOfDatabaseSet(com.ctrip.platform.dal.daogen.dao.DaoOfDatabaseSet) DatabaseSet(com.ctrip.platform.dal.daogen.entity.DatabaseSet) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost) DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)

Example 7 with CSharpCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.

the class CSharpDataPreparerOfTableViewSpProcessor method prepareTableViewSp.

private List<Callable<ExecuteResult>> prepareTableViewSp(CodeGenContext codeGenCtx) throws Exception {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    int projectId = ctx.getProjectId();
    boolean regenerate = ctx.isRegenerate();
    final Progress progress = ctx.getProgress();
    List<GenTaskByTableViewSp> tableViewSpTasks;
    List<GenTaskBySqlBuilder> sqlBuilderTasks;
    if (regenerate) {
        tableViewSpTasks = daoByTableViewSp.updateAndGetAllTasks(projectId);
        sqlBuilderTasks = daoBySqlBuilder.updateAndGetAllTasks(projectId);
        prepareDbFromTableViewSp(ctx, tableViewSpTasks, sqlBuilderTasks);
    } else {
        tableViewSpTasks = daoByTableViewSp.updateAndGetTasks(projectId);
        sqlBuilderTasks = daoBySqlBuilder.updateAndGetTasks(projectId);
        prepareDbFromTableViewSp(ctx, daoByTableViewSp.getTasksByProjectId(projectId), daoBySqlBuilder.getTasksByProjectId(projectId));
    }
    if (!ctx.isIgnoreApproveStatus() && tableViewSpTasks != null && tableViewSpTasks.size() > 0) {
        Iterator<GenTaskByTableViewSp> ite = tableViewSpTasks.iterator();
        while (ite.hasNext()) {
            int approved = ite.next().getApproved();
            if (approved != 2 && approved != 0) {
                ite.remove();
            }
        }
    }
    if (!ctx.isIgnoreApproveStatus() && sqlBuilderTasks != null && sqlBuilderTasks.size() > 0) {
        Iterator<GenTaskBySqlBuilder> ite = sqlBuilderTasks.iterator();
        while (ite.hasNext()) {
            int approved = ite.next().getApproved();
            if (approved != 2 && approved != 0) {
                ite.remove();
            }
        }
    }
    Queue<GenTaskBySqlBuilder> _sqlBuilders = ctx.getSqlBuilders();
    for (GenTaskBySqlBuilder _t : sqlBuilderTasks) {
        _sqlBuilders.add(_t);
    }
    final Queue<CSharpTableHost> _spHosts = ctx.getSpHosts();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    for (final GenTaskByTableViewSp tableViewSp : tableViewSpTasks) {
        final String[] viewNames = StringUtils.split(tableViewSp.getView_names(), ",");
        final String[] tableNames = StringUtils.split(tableViewSp.getTable_names(), ",");
        final String[] spNames = StringUtils.split(tableViewSp.getSp_names(), ",");
        final DatabaseCategory dbCategory;
        String dbType = DbUtils.getDbType(tableViewSp.getAllInOneName());
        if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
            dbCategory = DatabaseCategory.MySql;
        } else {
            dbCategory = DatabaseCategory.SqlServer;
        }
        final Queue<CSharpTableHost> _tableViewHosts = ctx.getTableViewHosts();
        results.addAll(prepareTable(ctx, progress, tableViewSp, tableNames, dbCategory, _tableViewHosts));
        results.addAll(prepareView(ctx, progress, tableViewSp, viewNames, dbCategory, _tableViewHosts));
        results.addAll(prepareSp(ctx, progress, _spHosts, tableViewSp, spNames, dbCategory));
    }
    return results;
}
Also used : Progress(com.ctrip.platform.dal.daogen.entity.Progress) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder) Callable(java.util.concurrent.Callable) DatabaseCategory(com.ctrip.platform.dal.daogen.enums.DatabaseCategory)

Example 8 with CSharpCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.

the class CSharpDataPreparerOfTableViewSpProcessor method buildViewHost.

private CSharpTableHost buildViewHost(CodeGenContext codeGenCtx, GenTaskByTableViewSp tableViewSp, DatabaseCategory dbCategory, String view) throws Exception {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    if (!DbUtils.viewExists(tableViewSp.getAllInOneName(), view)) {
        throw new Exception(String.format("视图 %s 不存在,请编辑DAO再生成", view));
    }
    List<AbstractParameterHost> allColumnsAbstract = DbUtils.getAllColumnNames(tableViewSp.getAllInOneName(), view, new CsharpColumnNameResultSetExtractor(tableViewSp.getAllInOneName(), view, dbCategory));
    List<CSharpParameterHost> allColumns = new ArrayList<>();
    for (AbstractParameterHost h : allColumnsAbstract) {
        allColumns.add((CSharpParameterHost) h);
    }
    CSharpTableHost tableHost = new CSharpTableHost();
    tableHost.setNameSpace(ctx.getNamespace());
    tableHost.setDatabaseCategory(dbCategory);
    tableHost.setDbSetName(tableViewSp.getDatabaseSetName());
    tableHost.setTableName(view);
    tableHost.setClassName(CommonUtils.normalizeVariable(getPojoClassName(tableViewSp.getPrefix(), tableViewSp.getSuffix(), view)));
    tableHost.setTable(false);
    tableHost.setSpa(false);
    tableHost.setColumns(allColumns);
    tableHost.setHasPagination(tableViewSp.isPagination());
    return tableHost;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)

Example 9 with CSharpCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.

the class CSharpDataPreparerOfTableViewSpProcessor method prepareDbFromTableViewSp.

private void prepareDbFromTableViewSp(CodeGenContext codeGenCtx, List<GenTaskByTableViewSp> tableViewSps, List<GenTaskBySqlBuilder> sqlBuilders) throws Exception {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    Set<String> existsTable = new HashSet<>();
    Set<String> _tableDaos = ctx.getTableDaos();
    Set<String> _spDaos = ctx.getSpDaos();
    Map<String, DatabaseHost> _dbHosts = ctx.getDbHosts();
    for (GenTaskByTableViewSp task : tableViewSps) {
        for (String table : StringUtils.split(task.getTable_names(), ",")) {
            _tableDaos.add(getPojoClassName(task.getPrefix(), task.getSuffix(), table));
            existsTable.add(table);
        }
        for (String table : StringUtils.split(task.getView_names(), ",")) {
            _tableDaos.add(getPojoClassName(task.getPrefix(), task.getSuffix(), table));
        }
        for (String table : StringUtils.split(task.getSp_names(), ",")) {
            String realSpName = table;
            if (table.contains(".")) {
                String[] splitSp = StringUtils.split(table, '.');
                realSpName = splitSp[1];
            }
            _spDaos.add(getPojoClassName(task.getPrefix(), task.getSuffix(), realSpName.replace("_", "")));
        }
        addDatabaseSet(ctx, task.getDatabaseSetName());
        if (!_dbHosts.containsKey(task.getAllInOneName())) {
            String provider = "sqlProvider";
            String dbType = DbUtils.getDbType(task.getAllInOneName());
            if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
                provider = "mySqlProvider";
            }
            DatabaseHost host = new DatabaseHost();
            host.setAllInOneName(task.getAllInOneName());
            host.setProviderType(provider);
            host.setDatasetName(host.getAllInOneName());
            _dbHosts.put(task.getAllInOneName(), host);
        }
    }
    for (GenTaskBySqlBuilder task : sqlBuilders) {
        if (!existsTable.contains(task.getTable_name())) {
            _tableDaos.add(getPojoClassName("", "", task.getTable_name()));
        }
        addDatabaseSet(ctx, task.getDatabaseSetName());
        if (!_dbHosts.containsKey(task.getAllInOneName())) {
            String provider = "sqlProvider";
            String dbType = DbUtils.getDbType(task.getAllInOneName());
            if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
                provider = "mySqlProvider";
            }
            DatabaseHost host = new DatabaseHost();
            host.setAllInOneName(task.getAllInOneName());
            host.setProviderType(provider);
            host.setDatasetName(host.getAllInOneName());
            _dbHosts.put(task.getAllInOneName(), host);
        }
    }
}
Also used : CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)

Example 10 with CSharpCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.

the class CSharpDataPreparerOfSqlBuilderProcessor method prepareSqlBuilder.

private List<Callable<ExecuteResult>> prepareSqlBuilder(CodeGenContext codeGenCtx) {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    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> _table : _TempSqlBuildres.entrySet()) {
            Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

                @Override
                public ExecuteResult call() throws Exception {
                    /*progress.setOtherMessage("正在整理表 "
                                + _table.getValue().getClass_name());*/
                    ExecuteResult result = new ExecuteResult("Build Extral SQL[" + _table.getValue().getAllInOneName() + "." + _table.getKey() + "] Host");
                    progress.setOtherMessage(result.getTaskName());
                    CSharpTableHost extraTableHost;
                    try {
                        extraTableHost = buildExtraSqlBuilderHost(ctx, _table.getValue());
                        if (null != extraTableHost) {
                            _tableViewHosts.add(extraTableHost);
                        }
                        result.setSuccessal(true);
                    } catch (Exception e) {
                        log.error(result.getTaskName() + " exception.", 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)

Aggregations

CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)20 Callable (java.util.concurrent.Callable)9 Progress (com.ctrip.platform.dal.daogen.entity.Progress)8 ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)5 File (java.io.File)5 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)4 CSharpTableHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost)4 VelocityContext (org.apache.velocity.VelocityContext)4 AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)3 ArrayList (java.util.ArrayList)3 CodeGenContext (com.ctrip.platform.dal.daogen.CodeGenContext)2 DalGenerator (com.ctrip.platform.dal.daogen.DalGenerator)2 StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)2 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)2 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)2 CSharpDalGenerator (com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator)2 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)2 JavaDalGenerator (com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator)2 DalConfigHost (com.ctrip.platform.dal.daogen.host.DalConfigHost)2 CSharpFreeSqlHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost)2