use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.
the class CSharpDataPreparerOfSqlBuilderProcessor method prepareSqlBuilder.
private List<Callable<ExecuteResult>> prepareSqlBuilder(CodeGenContext context) {
final CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
final Progress progress = ctx.getProgress();
List<Callable<ExecuteResult>> results = new ArrayList<>();
Queue<GenTaskBySqlBuilder> sqlBuilders = ctx.getSqlBuilders();
final Queue<CSharpTableHost> tableViewHosts = ctx.getTableViewHosts();
if (sqlBuilders.size() > 0) {
Map<String, GenTaskBySqlBuilder> tempSqlBuildres = sqlBuilderBroupBy(sqlBuilders);
for (final Map.Entry<String, GenTaskBySqlBuilder> sqlBuilder : tempSqlBuildres.entrySet()) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Build Extral SQL[" + sqlBuilder.getValue().getAllInOneName() + "." + sqlBuilder.getKey() + "] Host");
progress.setOtherMessage(result.getTaskName());
CSharpTableHost extraTableHost;
try {
extraTableHost = buildExtraSqlBuilderHost(ctx, sqlBuilder.getValue());
if (null != extraTableHost) {
tableViewHosts.add(extraTableHost);
}
result.setSuccessal(true);
} catch (Throwable e) {
throw new Exception(String.format("Task Id[%s]:%s\r\n", sqlBuilder.getValue().getId(), e.getMessage()), e);
}
return result;
}
};
results.add(worker);
}
}
return results;
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.
the class AbstractCSharpDataPreparer method buildInsertMethodHosts.
private List<CSharpMethodHost> buildInsertMethodHosts(List<CSharpParameterHost> allColumns, List<GenTaskBySqlBuilder> currentTableBuilders) throws Exception {
List<CSharpMethodHost> methods = new ArrayList<>();
for (GenTaskBySqlBuilder builder : currentTableBuilders) {
if (!builder.getCrud_type().equals("insert")) {
continue;
}
CSharpMethodHost method = new CSharpMethodHost();
method.setCrud_type(builder.getCrud_type());
method.setName(builder.getMethod_name());
method.setSql(builder.getSql_content());
method.setScalarType(builder.getScalarType());
method.setPaging(builder.getPagination());
List<CSharpParameterHost> parameters = new ArrayList<>();
if (method.getCrud_type().equals("insert")) {
String[] fields = StringUtils.split(builder.getFields(), ",");
for (String field : fields) {
for (CSharpParameterHost pHost : allColumns) {
if (pHost.getName().equals(field)) {
parameters.add(pHost);
break;
}
}
}
}
method.setParameters(parameters);
methods.add(method);
}
return methods;
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder 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;
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.
the class AbstractCSharpDataPreparer method buildDeleteMethodHosts.
private List<CSharpMethodHost> buildDeleteMethodHosts(List<CSharpParameterHost> allColumns, List<GenTaskBySqlBuilder> currentTableBuilders) throws Exception {
List<CSharpMethodHost> methods = new ArrayList<>();
for (GenTaskBySqlBuilder builder : currentTableBuilders) {
if (!builder.getCrud_type().equals("delete")) {
continue;
}
CSharpMethodHost method = new CSharpMethodHost();
method.setCrud_type(builder.getCrud_type());
method.setName(builder.getMethod_name());
method.setSql(builder.getSql_content());
method.setScalarType(builder.getScalarType());
method.setPaging(builder.getPagination());
List<CSharpParameterHost> whereParams = buildMethodParameterHost4SqlConditin(builder, allColumns);
method.setParameters(buildSqlParamName(whereParams, method.getSql()));
methods.add(method);
}
return methods;
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.
the class DaoBySqlBuilder method getVersionById.
public int getVersionById(int id) throws SQLException {
DalHints hints = DalHints.createIfAbsent(null);
GenTaskBySqlBuilder entity = client.queryByPk(id, hints);
if (entity == null)
return 0;
return entity.getVersion();
}
Aggregations