use of com.ctrip.platform.dal.daogen.host.java.JavaSelectFieldResultSetExtractor in project dal by ctripcorp.
the class AbstractCSharpDataPreparer method buildSelectMethodHosts.
private List<CSharpMethodHost> buildSelectMethodHosts(List<CSharpParameterHost> allColumns, List<GenTaskBySqlBuilder> currentTableBuilders) throws Exception {
List<CSharpMethodHost> methods = new ArrayList<>();
for (GenTaskBySqlBuilder builder : currentTableBuilders) {
if (!builder.getCrud_type().equals("select")) {
continue;
}
CSharpMethodHost method = new CSharpMethodHost();
method.setCrud_type(builder.getCrud_type());
method.setName(builder.getMethod_name());
String sql = builder.getSql_content();
int index = 0;
if (builder.getPagination()) {
sql = SqlBuilder.pagingQuerySql(sql, getDatabaseCategory(builder.getAllInOneName()), CurrentLanguage.CSharp);
index += 2;
}
Matcher m = CSharpCodeGenContext.inRegxPattern.matcher(builder.getSql_content());
while (m.find()) {
sql = sql.replace(m.group(1), String.format("({%d}) ", index));
index++;
}
method.setSql(sql);
method.setScalarType(builder.getScalarType());
method.setPaging(builder.getPagination());
List<AbstractParameterHost> paramAbstractHosts = DbUtils.getSelectFieldHosts(builder.getAllInOneName(), builder.getSql_content(), new JavaSelectFieldResultSetExtractor());
List<JavaParameterHost> paramHosts = new ArrayList<>();
for (AbstractParameterHost phost : paramAbstractHosts) {
paramHosts.add((JavaParameterHost) phost);
}
method.setFields(paramHosts);
List<CSharpParameterHost> whereParams = buildMethodParameterHost4SqlConditin(builder, allColumns);
method.setParameters(buildSqlParamName(whereParams, method.getSql()));
String orderBy = builder.getOrderby();
if (orderBy != null && !orderBy.trim().isEmpty() && orderBy.indexOf("-1,") != 0) {
String[] str = orderBy.split(",");
String odyExp = "p => p." + str[0] + ", ";
odyExp = "asc".equalsIgnoreCase(str[1]) ? odyExp + "true" : odyExp + "false";
method.setOrderByExp(odyExp);
}
methods.add(method);
}
return methods;
}
Aggregations