Search in sources :

Example 1 with DatabaseCategory

use of com.ctrip.platform.dal.daogen.enums.DatabaseCategory in project dal by ctripcorp.

the class GenTaskBySqlBuilderResource method getDatabaseCategory.

@POST
@Path("getDatabaseCategory")
public Status getDatabaseCategory(@FormParam("db_set_name") String db_set_name, @FormParam("mode_type") String modeType) throws SQLException {
    Status status = Status.OK();
    String connectionString = AllInOneNameUtils.getAllInOneName(db_set_name, modeType);
    try {
        DatabaseCategory category = DbUtils.getDatabaseCategory(connectionString);
        if (DatabaseCategory.MySql == category) {
            status.setInfo("MySql");
        } else {
            status.setInfo("SqlServer");
        }
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DatabaseCategory(com.ctrip.platform.dal.daogen.enums.DatabaseCategory)

Example 2 with DatabaseCategory

use of com.ctrip.platform.dal.daogen.enums.DatabaseCategory in project dal by ctripcorp.

the class GenTaskByTableViewResource method getApiList.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("apiList")
public Status getApiList(@FormParam("db_name") String db_set_name, @FormParam("table_names") String table_names, @FormParam("sql_style") String sql_style) {
    Status status = Status.OK();
    try {
        String connectionString = AllInOneNameUtils.getAllInOneNameByNameOnly(db_set_name);
        List<DalApi> apis = null;
        DatabaseCategory dbCategory = DbUtils.getDatabaseCategory(connectionString);
        if ("csharp".equalsIgnoreCase(sql_style)) {
            if (dbCategory == DatabaseCategory.MySql) {
                apis = BeanGetter.getDalApiDao().getDalApiByLanguageAndDbtype("csharp", "MySQL");
            } else {
                apis = BeanGetter.getDalApiDao().getDalApiByLanguageAndDbtype("csharp", "SQLServer");
            }
        } else {
            if (dbCategory == DatabaseCategory.MySql) {
                apis = BeanGetter.getDalApiDao().getDalApiByLanguageAndDbtype("java", "MySQL");
            } else {
                // SpType spType =
                // spType(databaseSetEntry.getConnectionString(),
                // table_names);
                // apis =
                // BeanGetter.getDalApiDao().getDalApiByLanguageAndDbtypeAndSptype("java",
                // "SQLServer", spType.getValue());
                apis = BeanGetter.getDalApiDao().getDalApiByLanguageAndDbtype("java", "SQLServer");
            }
        }
        for (DalApi api : apis) {
            String method_declaration = api.getMethod_declaration();
            method_declaration = method_declaration.replaceAll("<", "&lt;");
            method_declaration = method_declaration.replaceAll(">", "&gt;");
            api.setMethod_declaration(method_declaration);
        }
        java.util.Collections.sort(apis, new Comparator<DalApi>() {

            @Override
            public int compare(DalApi o1, DalApi o2) {
                return o1.getMethod_declaration().compareToIgnoreCase(o2.getMethod_declaration());
            }
        });
        status.setInfo(mapper.writeValueAsString(apis));
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DatabaseCategory(com.ctrip.platform.dal.daogen.enums.DatabaseCategory) DalApi(com.ctrip.platform.dal.daogen.entity.DalApi)

Example 3 with DatabaseCategory

use of com.ctrip.platform.dal.daogen.enums.DatabaseCategory in project dal by ctripcorp.

the class JavaDataPreparerOfSqlBuilderProcessor method buildExtraSqlBuilderHost.

private JavaTableHost buildExtraSqlBuilderHost(CodeGenContext context, GenTaskBySqlBuilder sqlBuilder) throws Exception {
    GenTaskByTableViewSp tableViewSp = new GenTaskByTableViewSp();
    tableViewSp.setCud_by_sp(false);
    tableViewSp.setPagination(false);
    tableViewSp.setAllInOneName(sqlBuilder.getAllInOneName());
    tableViewSp.setDatabaseSetName(sqlBuilder.getDatabaseSetName());
    tableViewSp.setPrefix("");
    tableViewSp.setSuffix("");
    // tableViewSp.setLength(sqlBuilder.getLength());
    DatabaseCategory dbCategory = DatabaseCategory.SqlServer;
    String dbType = DbUtils.getDbType(sqlBuilder.getAllInOneName());
    if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
        dbCategory = DatabaseCategory.MySql;
    }
    return buildTableHost(context, tableViewSp, sqlBuilder.getTable_name(), dbCategory);
}
Also used : DatabaseCategory(com.ctrip.platform.dal.daogen.enums.DatabaseCategory) GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)

Example 4 with DatabaseCategory

use of com.ctrip.platform.dal.daogen.enums.DatabaseCategory in project dal by ctripcorp.

the class CSharpDataPreparerOfTableViewSpProcessor method prepareTableViewSp.

private List<Callable<ExecuteResult>> prepareTableViewSp(CodeGenContext context) throws Exception {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
    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 5 with DatabaseCategory

use of com.ctrip.platform.dal.daogen.enums.DatabaseCategory in project dal by ctripcorp.

the class JavaDataPreparerOfTableViewSpProcessor method prepareTableViewSp.

private List<Callable<ExecuteResult>> prepareTableViewSp(CodeGenContext context) throws Exception {
    final JavaCodeGenContext ctx = (JavaCodeGenContext) context;
    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 sqlBuilder : sqlBuilderTasks) {
        sqlBuilders.add(sqlBuilder);
    }
    final Queue<JavaTableHost> tableHosts = ctx.getTableHosts();
    final Queue<ViewHost> viewHosts = ctx.getViewHosts();
    final Queue<SpHost> spHosts = ctx.getSpHosts();
    final Map<String, SpDbHost> spHostMaps = ctx.getSpHostMaps();
    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;
        }
        try {
            results.addAll(prepareTable(ctx, progress, tableHosts, tableViewSp, tableNames, dbCategory));
            results.addAll(prepareView(ctx, progress, viewHosts, tableViewSp, viewNames, dbCategory));
            results.addAll(prepareSp(ctx, progress, spHosts, spHostMaps, tableViewSp, spNames));
        } catch (Throwable e) {
            throw e;
        }
    }
    return results;
}
Also used : GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder) Callable(java.util.concurrent.Callable) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext) Progress(com.ctrip.platform.dal.daogen.entity.Progress) DatabaseCategory(com.ctrip.platform.dal.daogen.enums.DatabaseCategory)

Aggregations

DatabaseCategory (com.ctrip.platform.dal.daogen.enums.DatabaseCategory)11 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)4 Status (com.ctrip.platform.dal.daogen.domain.Status)2 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)2 Progress (com.ctrip.platform.dal.daogen.entity.Progress)2 AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)2 Callable (java.util.concurrent.Callable)2 StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)1 DalApi (com.ctrip.platform.dal.daogen.entity.DalApi)1 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)1 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)1 JavaColumnNameResultSetExtractor (com.ctrip.platform.dal.daogen.host.java.JavaColumnNameResultSetExtractor)1 JavaParameterHost (com.ctrip.platform.dal.daogen.host.java.JavaParameterHost)1 HashMap (java.util.HashMap)1