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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations