use of com.ctrip.platform.dal.daogen.host.AbstractParameterHost in project dal by ctripcorp.
the class JavaDataPreparerOfFreeSqlProcessor method processMethodHost.
private void processMethodHost(GenTaskByFreeSql task, String namespace, List<JavaMethodHost> methods, Map<String, JavaMethodHost> freeSqlPojoHosts, String userName) throws Exception {
JavaMethodHost method = new JavaMethodHost();
method.setSql(task.getSql_content());
method.setName(task.getMethod_name());
method.setPackageName(namespace);
method.setScalarType(task.getScalarType());
method.setPojoType(task.getPojoType());
method.setPaging(task.getPagination());
method.setCrud_type(task.getCrud_type());
method.setComments(task.getComment());
method.setUserName(userName);
if (task.getPojo_name() != null && !task.getPojo_name().isEmpty())
method.setPojoClassName(WordUtils.capitalize(task.getPojo_name() + "Pojo"));
List<JavaParameterHost> params = new ArrayList<>();
for (String param : StringUtils.split(task.getParameters(), ";")) {
String[] splitedParam = StringUtils.split(param, ",");
JavaParameterHost p = new JavaParameterHost();
p.setName(splitedParam[0]);
p.setSqlType(Integer.valueOf(splitedParam[1]));
p.setJavaClass(Consts.jdbcSqlTypeToJavaClass.get(p.getSqlType()));
p.setValidationValue(DbUtils.mockATest(p.getSqlType()));
boolean sensitive = splitedParam.length >= 3 ? Boolean.parseBoolean(splitedParam[2]) : false;
p.setSensitive(sensitive);
params.add(p);
}
SqlBuilder.rebuildJavaInClauseSQL(task.getSql_content(), params);
method.setParameters(params);
method.setHints(task.getHints());
methods.add(method);
if (method.getPojoClassName() != null && !method.getPojoClassName().isEmpty() && !freeSqlPojoHosts.containsKey(method.getPojoClassName()) && !"update".equalsIgnoreCase(method.getCrud_type())) {
List<JavaParameterHost> paramHosts = new ArrayList<>();
for (AbstractParameterHost _ahost : DbUtils.testAQuerySql(task.getAllInOneName(), task.getSql_content(), task.getParameters(), new JavaGivenSqlResultSetExtractor())) {
paramHosts.add((JavaParameterHost) _ahost);
}
method.setFields(paramHosts);
freeSqlPojoHosts.put(method.getPojoClassName(), method);
} else if ("update".equalsIgnoreCase(method.getCrud_type())) {
DbUtils.testUpdateSql(task.getAllInOneName(), task.getSql_content(), task.getParameters());
}
}
use of com.ctrip.platform.dal.daogen.host.AbstractParameterHost in project dal by ctripcorp.
the class CSharpDataPreparerOfFreeSqlProcessor method buildFreeSqlPojoHost.
private CSharpFreeSqlPojoHost buildFreeSqlPojoHost(CSharpCodeGenContext codeGenCtx, GenTaskByFreeSql task) throws Exception {
CSharpFreeSqlPojoHost freeSqlHost = new CSharpFreeSqlPojoHost();
List<CSharpParameterHost> pHosts = new ArrayList<>();
DatabaseCategory dbCategory = DatabaseCategory.SqlServer;
String dbType = DbUtils.getDbType(task.getAllInOneName());
if (dbType != null && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
dbCategory = DatabaseCategory.MySql;
}
List<AbstractParameterHost> list = DbUtils.testAQuerySql(task.getAllInOneName(), task.getSql_content(), task.getParameters(), new CsharpGivenSqlResultSetExtractor(dbCategory));
for (AbstractParameterHost _ahost : list) {
pHosts.add((CSharpParameterHost) _ahost);
}
freeSqlHost.setColumns(pHosts);
freeSqlHost.setTableName("");
String className = task.getPojo_name();
if (className.equalsIgnoreCase("简单类型")) {
freeSqlHost.setClassName(task.getMethod_name().substring(0, 1).toUpperCase() + task.getMethod_name().substring(1));
} else {
freeSqlHost.setClassName(CommonUtils.normalizeVariable(WordUtils.capitalize(task.getPojo_name())));
}
freeSqlHost.setNameSpace(codeGenCtx.getNamespace());
return freeSqlHost;
}
use of com.ctrip.platform.dal.daogen.host.AbstractParameterHost 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