Search in sources :

Example 21 with AbstractParameterHost

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

the class JavaDataPreparerOfTableViewSpProcessor method buildViewHost.

private ViewHost buildViewHost(CodeGenContext context, GenTaskByTableViewSp tableViewSp, DatabaseCategory dbCategory, String viewName) throws Exception {
    JavaCodeGenContext ctx = (JavaCodeGenContext) context;
    if (!DbUtils.viewExists(tableViewSp.getAllInOneName(), viewName)) {
        return null;
    }
    ViewHost vhost = new ViewHost();
    String className = viewName.replace("_", "");
    className = getPojoClassName(tableViewSp.getPrefix(), tableViewSp.getSuffix(), className);
    vhost.setPackageName(ctx.getNamespace());
    vhost.setDatabaseCategory(getDatabaseCategory(tableViewSp.getAllInOneName()));
    vhost.setDbSetName(tableViewSp.getDatabaseSetName());
    vhost.setPojoClassName(className);
    vhost.setViewName(viewName);
    // vhost.setLength(tableViewSp.getLength());
    List<String> primaryKeyNames = DbUtils.getPrimaryKeyNames(tableViewSp.getAllInOneName(), viewName);
    List<AbstractParameterHost> params = DbUtils.getAllColumnNames(tableViewSp.getAllInOneName(), viewName, new JavaColumnNameResultSetExtractor(tableViewSp.getAllInOneName(), viewName, dbCategory));
    List<JavaParameterHost> realParams = new ArrayList<>();
    if (params == null || params.size() == 0) {
        throw new Exception(String.format("The column names of view[%s, %s] is null", tableViewSp.getAllInOneName(), viewName));
    }
    for (AbstractParameterHost p : params) {
        JavaParameterHost jHost = (JavaParameterHost) p;
        if (primaryKeyNames.contains(jHost.getName())) {
            jHost.setPrimary(true);
        }
        realParams.add(jHost);
    }
    vhost.setFields(realParams);
    return vhost;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) SQLException(java.sql.SQLException) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 22 with AbstractParameterHost

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

the class CsharpGivenSqlResultSetExtractor method extract.

@Override
public List<AbstractParameterHost> extract(ResultSet rs) throws SQLException {
    List<AbstractParameterHost> hosts = new ArrayList<>();
    if (rs == null) {
        return hosts;
    }
    ResultSetMetaData metaData = rs.getMetaData();
    int count = metaData.getColumnCount();
    for (int i = 1; i <= count; i++) {
        CSharpParameterHost host = new CSharpParameterHost();
        String columnName = metaData.getColumnLabel(i);
        host.setName(columnName);
        String typeName = metaData.getColumnTypeName(i);
        boolean isUnsigned = DbUtils.isColumnUnsigned(typeName);
        int dataType = metaData.getColumnType(i);
        int length = metaData.getColumnDisplaySize(i);
        // 特殊处理
        DbType dbType = DbUtils.getDotNetDbType(typeName, dataType, length, isUnsigned, dbCategory);
        host.setDbType(dbType);
        String type = DbType.getCSharpType(host.getDbType());
        host.setType(type);
        host.setIdentity(false);
        host.setNullable(metaData.isNullable(i) == 1 ? true : false);
        host.setPrimary(false);
        host.setLength(length);
        host.setValueType(Consts.CSharpValueTypes.contains(host.getType()));
        hosts.add(host);
    }
    return hosts;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) ArrayList(java.util.ArrayList) DbType(com.ctrip.platform.dal.daogen.enums.DbType)

Example 23 with AbstractParameterHost

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

the class JavaGivenSqlResultSetExtractor method extract.

@Override
public List<AbstractParameterHost> extract(ResultSet rs) throws SQLException {
    ResultSetMetaData rsmd = rs.getMetaData();
    List<AbstractParameterHost> paramHosts = new ArrayList<>();
    for (int i = 1; i <= rsmd.getColumnCount(); i++) {
        JavaParameterHost paramHost = new JavaParameterHost();
        paramHost.setName(rsmd.getColumnLabel(i));
        paramHost.setSqlType(rsmd.getColumnType(i));
        Class<?> javaClass = null;
        try {
            javaClass = Class.forName(rsmd.getColumnClassName(i));
        } catch (Exception e) {
            e.printStackTrace();
            javaClass = Consts.jdbcSqlTypeToJavaClass.get(paramHost.getSqlType());
        }
        paramHost.setJavaClass(javaClass);
        paramHost.setIdentity(false);
        paramHost.setNullable(rsmd.isNullable(i) == 1 ? true : false);
        paramHost.setPrimary(false);
        paramHost.setLength(rsmd.getColumnDisplaySize(i));
        paramHosts.add(paramHost);
    }
    return paramHosts;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException)

Example 24 with AbstractParameterHost

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

the class CsharpSpParamResultSetExtractor method extract.

@Override
public List<AbstractParameterHost> extract(ResultSet rs) throws SQLException {
    List<AbstractParameterHost> parameters = new ArrayList<>();
    while (rs.next()) {
        int paramMode = rs.getShort("COLUMN_TYPE");
        if (!DbUtils.validMode.contains(paramMode)) {
            continue;
        }
        CSharpParameterHost host = new CSharpParameterHost();
        DbType dbType = DbUtils.getDotNetDbType(rs.getString("TYPE_NAME"), rs.getInt("DATA_TYPE"), rs.getInt("LENGTH"), false, null);
        host.setDbType(dbType);
        host.setNullable(rs.getShort("NULLABLE") == DatabaseMetaData.columnNullable);
        if (paramMode == DatabaseMetaData.procedureColumnIn) {
            host.setDirection(ParameterDirection.Input);
        } else if (paramMode == DatabaseMetaData.procedureColumnInOut) {
            host.setDirection(ParameterDirection.InputOutput);
        } else {
            host.setDirection(ParameterDirection.Output);
        }
        host.setName(rs.getString("COLUMN_NAME"));
        host.setType(DbType.getCSharpType(host.getDbType()));
        host.setNullable(rs.getShort("NULLABLE") == DatabaseMetaData.columnNullable);
        if (host.getType() == null) {
            host.setType("string");
            host.setDbType(DbType.AnsiString);
        }
        parameters.add(host);
    }
    return parameters;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) ArrayList(java.util.ArrayList) DbType(com.ctrip.platform.dal.daogen.enums.DbType)

Example 25 with AbstractParameterHost

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

the class CSharpDataPreparerOfTableViewSpProcessor method buildSpHost.

private CSharpTableHost buildSpHost(CodeGenContext codeGenCtx, GenTaskByTableViewSp tableViewSp, DatabaseCategory dbCategory, String spName) throws Exception {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    String schema = "dbo";
    String realSpName = spName;
    if (spName.contains(".")) {
        String[] splitSp = StringUtils.split(spName, '.');
        schema = splitSp[0];
        realSpName = splitSp[1];
    }
    StoredProcedure currentSp = new StoredProcedure();
    currentSp.setSchema(schema);
    currentSp.setName(realSpName);
    if (!DbUtils.spExists(tableViewSp.getAllInOneName(), currentSp)) {
        throw new Exception(String.format("存储过程 %s 不存在,请修改DAO后再试!", currentSp.getName()));
    }
    List<AbstractParameterHost> params = DbUtils.getSpParams(tableViewSp.getAllInOneName(), currentSp, new CsharpSpParamResultSetExtractor());
    List<CSharpParameterHost> realParams = new ArrayList<CSharpParameterHost>();
    for (AbstractParameterHost p : params) {
        realParams.add((CSharpParameterHost) p);
    }
    CSharpTableHost tableHost = new CSharpTableHost();
    tableHost.setNameSpace(ctx.getNamespace());
    tableHost.setDatabaseCategory(dbCategory);
    tableHost.setDbSetName(tableViewSp.getDatabaseSetName());
    tableHost.setClassName(getPojoClassName(tableViewSp.getPrefix(), tableViewSp.getSuffix(), realSpName.replace("_", "")));
    tableHost.setTable(false);
    tableHost.setSpName(spName);
    tableHost.setSpParams(realParams);
    tableHost.setApi_list(tableViewSp.getApi_list());
    return tableHost;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) StoredProcedure(com.ctrip.platform.dal.daogen.domain.StoredProcedure) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) SQLException(java.sql.SQLException)

Aggregations

AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)28 ArrayList (java.util.ArrayList)16 SQLException (java.sql.SQLException)13 ResultSetMetaData (java.sql.ResultSetMetaData)8 DbType (com.ctrip.platform.dal.daogen.enums.DbType)6 StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)5 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)3 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)3 JavaParameterHost (com.ctrip.platform.dal.daogen.host.java.JavaParameterHost)3 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)2 DatabaseCategory (com.ctrip.platform.dal.daogen.enums.DatabaseCategory)2 Matcher (java.util.regex.Matcher)2 DalHints (com.ctrip.platform.dal.dao.DalHints)1 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)1 Parameter (com.ctrip.platform.dal.daogen.entity.Parameter)1 JavaColumnNameResultSetExtractor (com.ctrip.platform.dal.daogen.host.java.JavaColumnNameResultSetExtractor)1 JavaGivenSqlResultSetExtractor (com.ctrip.platform.dal.daogen.host.java.JavaGivenSqlResultSetExtractor)1 JavaMethodHost (com.ctrip.platform.dal.daogen.host.java.JavaMethodHost)1 JavaSelectFieldResultSetExtractor (com.ctrip.platform.dal.daogen.host.java.JavaSelectFieldResultSetExtractor)1 HashMap (java.util.HashMap)1