use of com.ctrip.platform.dal.daogen.host.AbstractParameterHost in project dal by ctripcorp.
the class JavaSelectFieldResultSetExtractor method extractData.
@Override
public List<AbstractParameterHost> extractData(ResultSet rs) throws SQLException {
ResultSetMetaData rsMeta = rs.getMetaData();
List<AbstractParameterHost> hosts = new ArrayList<>();
for (int i = 1; i <= rsMeta.getColumnCount(); i++) {
JavaParameterHost paramHost = new JavaParameterHost();
paramHost.setName(rsMeta.getColumnLabel(i));
paramHost.setSqlType(rsMeta.getColumnType(i));
Class<?> javaClass = null;
try {
javaClass = Class.forName(rsMeta.getColumnClassName(i));
} catch (Exception e) {
log.warn(e.getMessage(), e);
javaClass = Consts.jdbcSqlTypeToJavaClass.get(paramHost.getSqlType());
}
paramHost.setJavaClass(javaClass);
paramHost.setIdentity(false);
paramHost.setNullable(rsMeta.isNullable(i) == 1 ? true : false);
paramHost.setPrimary(false);
paramHost.setLength(rsMeta.getColumnDisplaySize(i));
hosts.add(paramHost);
}
return hosts;
}
use of com.ctrip.platform.dal.daogen.host.AbstractParameterHost in project dal by ctripcorp.
the class CsharpColumnNameResultSetExtractor method extractData.
@Override
public List<AbstractParameterHost> extractData(ResultSet rs) throws SQLException {
List<AbstractParameterHost> allColumns = new ArrayList<>();
if (rs == null) {
return allColumns;
}
Map<String, String> columnComment;
try {
columnComment = DbUtils.getSqlserverColumnComment(allInOneName, tableName);
} catch (Exception e) {
throw new SQLException(e.getMessage(), e);
}
while (rs.next()) {
CSharpParameterHost host = new CSharpParameterHost();
String columnName = rs.getString(COLUMN_NAME);
host.setName(columnName);
String typeName = rs.getString(TYPE_NAME);
boolean isUnsigned = DbUtils.isColumnUnsigned(typeName);
int dataType = rs.getInt(DATA_TYPE);
host.setDataType(dataType);
int length = rs.getInt(COLUMN_SIZE);
// 特殊处理
DbType dbType = DbUtils.getDotNetDbType(typeName, dataType, length, isUnsigned, dbCategory);
host.setDbType(dbType);
String remark = rs.getString(REMARKS);
if (remark == null) {
String description = columnComment.get(columnName.toLowerCase());
remark = description == null ? "" : description;
}
host.setComment(remark.replace("\n", " "));
String type = DbType.getCSharpType(host.getDbType());
host.setType(type);
host.setIdentity(rs.getString(IS_AUTOINCREMENT).equalsIgnoreCase("YES"));
host.setNullable(rs.getShort(NULLABLE) == DatabaseMetaData.columnNullable);
host.setValueType(Consts.CSharpValueTypes.contains(host.getType()));
// 仅获取String类型的长度
if ("string".equalsIgnoreCase(host.getType()))
host.setLength(length);
host.setDefaultValue(rs.getString(COLUMN_DEF));
host.setDbCategory(dbCategory);
allColumns.add(host);
}
return allColumns;
}
use of com.ctrip.platform.dal.daogen.host.AbstractParameterHost in project dal by ctripcorp.
the class CsharpSpParamResultSetExtractor method extractData.
@Override
public List<AbstractParameterHost> extractData(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 GenTaskBySqlBuilderResource method getTableColumnSqlType.
/**
* @param set_name
* @param table_name
* @return <column alias, sqltype>
*/
private Map<String, Integer> getTableColumnSqlType(String set_name, String table_name, String modeType) throws Exception {
String dbName = AllInOneNameUtils.getAllInOneName(set_name, modeType);
DatabaseCategory dbCategory = DbUtils.getDatabaseCategory(dbName);
List<AbstractParameterHost> paramsHost = DbUtils.getAllColumnNames(dbName, table_name, new JavaColumnNameResultSetExtractor(dbName, table_name, dbCategory));
Map<String, Integer> map = new HashMap<>();
if (paramsHost != null) {
for (int i = 0; i < paramsHost.size(); i++) {
JavaParameterHost paramHost = (JavaParameterHost) paramsHost.get(i);
map.put(paramHost.getAlias().toLowerCase(), paramHost.getSqlType());
}
}
return map;
}
use of com.ctrip.platform.dal.daogen.host.AbstractParameterHost in project dal by ctripcorp.
the class JavaDataPreparerOfTableViewSpProcessor method buildSpHost.
private SpHost buildSpHost(CodeGenContext context, GenTaskByTableViewSp tableViewSp, String spName) throws Exception {
JavaCodeGenContext ctx = (JavaCodeGenContext) context;
String schema = "dbo";
String realSpName = spName;
if (spName.contains(".")) {
String[] splitSp = StringUtils.split(spName, '.');
schema = splitSp[0];
realSpName = splitSp[1];
}
StoredProcedure sp = new StoredProcedure();
sp.setSchema(schema);
sp.setName(realSpName);
if (!DbUtils.spExists(tableViewSp.getAllInOneName(), sp)) {
throw new Exception(String.format("The store procedure[%s, %s] doesn't exist, pls check", tableViewSp.getAllInOneName(), sp.getName()));
}
SpHost host = new SpHost();
String className = realSpName.replace("_", "");
className = getPojoClassName(tableViewSp.getPrefix(), tableViewSp.getSuffix(), className);
host.setPackageName(ctx.getNamespace());
host.setDatabaseCategory(getDatabaseCategory(tableViewSp.getAllInOneName()));
host.setDbName(tableViewSp.getDatabaseSetName());
host.setPojoClassName(className);
host.setSpName(spName);
// host.setLength(tableViewSp.getLength());
List<AbstractParameterHost> params = DbUtils.getSpParams(tableViewSp.getAllInOneName(), sp, new JavaSpParamResultSetExtractor(tableViewSp.getAllInOneName(), sp.getName()));
List<JavaParameterHost> realParams = new ArrayList<>();
String callParams = "";
if (params == null) {
throw new Exception(String.format("The sp[%s, %s] parameters is null", tableViewSp.getAllInOneName(), sp.getName()));
}
for (AbstractParameterHost p : params) {
callParams += "?,";
realParams.add((JavaParameterHost) p);
}
host.setCallParameters(StringUtils.removeEnd(callParams, ","));
host.setFields(realParams);
return host;
}
Aggregations