Search in sources :

Example 1 with StoredProcedure

use of com.ctrip.platform.dal.daogen.domain.StoredProcedure in project dal by ctripcorp.

the class CSharpSpaOperationHost method getSpaOperation.

public static CSharpSpaOperationHost getSpaOperation(String dbName, String tableName, List<StoredProcedure> spNames, String operation) {
    CSharpSpaOperationHost host = new CSharpSpaOperationHost();
    StoredProcedure expectSpa = new StoredProcedure();
    expectSpa.setName(String.format("spA_%s_%s", tableName, operation));
    StoredProcedure expectSp3 = new StoredProcedure();
    expectSp3.setName(String.format("sp3_%s_%s", tableName, operation));
    StoredProcedure currentSp = null;
    int index = -1;
    if ((index = spNames.indexOf(expectSpa)) > 0) {
        host.exist = true;
        host.methodName = expectSpa.getName();
        currentSp = spNames.get(index);
    } else if ((index = spNames.indexOf(expectSp3)) > 0) {
        host.exist = true;
        host.methodName = expectSp3.getName();
        currentSp = spNames.get(index);
    } else {
        host.exist = false;
    }
    if (host.exist) {
        List<AbstractParameterHost> parameters = DbUtils.getSpParams(dbName, currentSp, new CsharpSpParamResultSetExtractor());
        List<CSharpParameterHost> realParams = new ArrayList<CSharpParameterHost>();
        for (AbstractParameterHost _host : parameters) {
            realParams.add((CSharpParameterHost) _host);
        }
        host.setParameters(realParams);
    }
    return host;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) StoredProcedure(com.ctrip.platform.dal.daogen.domain.StoredProcedure) ArrayList(java.util.ArrayList)

Example 2 with StoredProcedure

use of com.ctrip.platform.dal.daogen.domain.StoredProcedure in project dal by ctripcorp.

the class DatabaseResource method filterSP.

private List<StoredProcedure> filterSP(List<String> tables, List<StoredProcedure> sps) {
    List<StoredProcedure> result = new ArrayList<>();
    if (tables != null && sps != null && tables.size() > 0 && sps.size() > 0) {
        for (StoredProcedure sp : sps) {
            String spName = sp.getName() != null ? sp.getName().toLowerCase() : null;
            boolean isSpAOrSp3orSpT = false;
            for (String tableName : tables) {
                tableName = tableName.toLowerCase();
                if (spName == null || "".equals(spName)) {
                    isSpAOrSp3orSpT = true;
                    break;
                }
                if (spName.indexOf(String.format("spa_%s", tableName)) > -1 || spName.indexOf(String.format("sp3_%s", tableName)) > -1 || spName.indexOf(String.format("spt_%s", tableName)) > -1) {
                    isSpAOrSp3orSpT = true;
                    break;
                }
            }
            if (!isSpAOrSp3orSpT) {
                result.add(sp);
            }
        }
    }
    return result;
}
Also used : StoredProcedure(com.ctrip.platform.dal.daogen.domain.StoredProcedure)

Example 3 with StoredProcedure

use of com.ctrip.platform.dal.daogen.domain.StoredProcedure in project dal by ctripcorp.

the class AbstractCSharpDataPreparer method buildTableHost.

protected CSharpTableHost buildTableHost(CodeGenContext codeGenCtx, GenTaskByTableViewSp tableViewSp, String table, DatabaseCategory dbCategory, List<StoredProcedure> allSpNames) throws Exception {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    if (!DbUtils.tableExists(tableViewSp.getAllInOneName(), table)) {
        throw new Exception(String.format("表 %s 不存在,请编辑DAO再生成", table));
    }
    // 主键及所有列
    List<AbstractParameterHost> allColumnsAbstract = DbUtils.getAllColumnNames(tableViewSp.getAllInOneName(), table, new CsharpColumnNameResultSetExtractor(tableViewSp.getAllInOneName(), table, dbCategory));
    List<String> primaryKeyNames = DbUtils.getPrimaryKeyNames(tableViewSp.getAllInOneName(), table);
    List<CSharpParameterHost> allColumns = new ArrayList<>();
    for (AbstractParameterHost h : allColumnsAbstract) {
        allColumns.add((CSharpParameterHost) h);
    }
    List<CSharpParameterHost> primaryKeys = new ArrayList<>();
    for (CSharpParameterHost h : allColumns) {
        if (primaryKeyNames.contains(h.getName())) {
            h.setPrimary(true);
            primaryKeys.add(h);
        }
    }
    Queue<GenTaskBySqlBuilder> _sqlBuilders = ctx.getSqlBuilders();
    List<GenTaskBySqlBuilder> currentTableBuilders = filterExtraMethods(_sqlBuilders, tableViewSp.getAllInOneName(), table);
    List<CSharpMethodHost> methods = buildSqlBuilderMethodHost(allColumns, currentTableBuilders);
    CSharpTableHost tableHost = new CSharpTableHost();
    tableHost.setExtraMethods(methods);
    tableHost.setNameSpace(ctx.getNamespace());
    tableHost.setDatabaseCategory(dbCategory);
    tableHost.setDbSetName(tableViewSp.getDatabaseSetName());
    tableHost.setTableName(table);
    tableHost.setClassName(CommonUtils.normalizeVariable(getPojoClassName(tableViewSp.getPrefix(), tableViewSp.getSuffix(), table)));
    tableHost.setTable(true);
    tableHost.setSpa(tableViewSp.isCud_by_sp());
    // SP方式增删改
    if (tableHost.isSpa()) {
        tableHost.setSpaInsert(CSharpSpaOperationHost.getSpaOperation(tableViewSp.getAllInOneName(), table, allSpNames, "i"));
        tableHost.setSpaUpdate(CSharpSpaOperationHost.getSpaOperation(tableViewSp.getAllInOneName(), table, allSpNames, "u"));
        tableHost.setSpaDelete(CSharpSpaOperationHost.getSpaOperation(tableViewSp.getAllInOneName(), table, allSpNames, "d"));
    }
    tableHost.setPrimaryKeys(primaryKeys);
    tableHost.setColumns(allColumns);
    tableHost.setHasPagination(tableViewSp.isPagination());
    StoredProcedure expectSptI = new StoredProcedure();
    expectSptI.setName(String.format("spT_%s_i", table));
    StoredProcedure expectSptU = new StoredProcedure();
    expectSptU.setName(String.format("spT_%s_u", table));
    StoredProcedure expectSptD = new StoredProcedure();
    expectSptD.setName(String.format("spT_%s_d", table));
    tableHost.setHasSptI(allSpNames.contains(expectSptI));
    tableHost.setHasSptU(allSpNames.contains(expectSptU));
    tableHost.setHasSptD(allSpNames.contains(expectSptD));
    tableHost.setHasSpt(tableHost.isHasSptI() || tableHost.isHasSptU() || tableHost.isHasSptD());
    tableHost.setApi_list(tableViewSp.getApi_list());
    return tableHost;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder) StoredProcedure(com.ctrip.platform.dal.daogen.domain.StoredProcedure)

Example 4 with StoredProcedure

use of com.ctrip.platform.dal.daogen.domain.StoredProcedure in project dal by ctripcorp.

the class CSharpDataPreparerOfSqlBuilderProcessor method buildExtraSqlBuilderHost.

private CSharpTableHost buildExtraSqlBuilderHost(CodeGenContext codeGenCtx, 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("");
    DatabaseCategory dbCategory = DatabaseCategory.SqlServer;
    String dbType = DbUtils.getDbType(sqlBuilder.getAllInOneName());
    if (dbType != null && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
        dbCategory = DatabaseCategory.MySql;
    }
    List<StoredProcedure> allSpNames = DbUtils.getAllSpNames(sqlBuilder.getAllInOneName());
    return buildTableHost(codeGenCtx, tableViewSp, sqlBuilder.getTable_name(), dbCategory, allSpNames);
}
Also used : DatabaseCategory(com.ctrip.platform.dal.daogen.enums.DatabaseCategory) StoredProcedure(com.ctrip.platform.dal.daogen.domain.StoredProcedure) GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)

Example 5 with StoredProcedure

use of com.ctrip.platform.dal.daogen.domain.StoredProcedure in project dal by ctripcorp.

the class SpOperationHost method getSpaOperation.

public static SpOperationHost getSpaOperation(String dbName, String tableName, List<StoredProcedure> spNames, String operation) {
    SpOperationHost host = new SpOperationHost();
    host.exist = true;
    StoredProcedure expectSpa = new StoredProcedure();
    expectSpa.setName(String.format("spA_%s_%s", tableName, operation));
    StoredProcedure expectSp3 = new StoredProcedure();
    expectSp3.setName(String.format("sp3_%s_%s", tableName, operation));
    StoredProcedure currentSp = null;
    int index = -1;
    if ((index = spNames.indexOf(expectSpa)) > -1 && spNames.indexOf(expectSp3) > -1) {
        //spA、sp3都存在
        host.setBasicSpName(expectSpa.getName());
        host.setBatchSpName(expectSp3.getName());
        host.setType("sp3");
        currentSp = spNames.get(index);
    } else if ((index = spNames.indexOf(expectSpa)) > -1 && spNames.indexOf(expectSp3) < 0) {
        //只存在spA
        host.setBasicSpName(expectSpa.getName());
        host.setType("spA");
        currentSp = spNames.get(index);
    } else if (spNames.indexOf(expectSpa) < 0 && (index = spNames.indexOf(expectSp3)) > -1) {
        //只存在sp3
        host.setBasicSpName(expectSp3.getName());
        host.setBatchSpName(expectSp3.getName());
        host.setType("sp3");
        currentSp = spNames.get(index);
    } else {
        host.exist = false;
    }
    if (host.exist) {
        List<AbstractParameterHost> params = DbUtils.getSpParams(dbName, currentSp, new JavaSpParamResultSetExtractor(dbName, currentSp.getName()));
        List<JavaParameterHost> realParams = new ArrayList<>();
        for (AbstractParameterHost p : params) {
            realParams.add((JavaParameterHost) p);
        }
        host.parameters = realParams;
    }
    return host;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) StoredProcedure(com.ctrip.platform.dal.daogen.domain.StoredProcedure) ArrayList(java.util.ArrayList)

Aggregations

StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)9 AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)5 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)2 ArrayList (java.util.ArrayList)2 Status (com.ctrip.platform.dal.daogen.domain.Status)1 TableSpNames (com.ctrip.platform.dal.daogen.domain.TableSpNames)1 ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)1 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)1 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)1 DatabaseCategory (com.ctrip.platform.dal.daogen.enums.DatabaseCategory)1 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SQLException (java.sql.SQLException)1 Callable (java.util.concurrent.Callable)1