use of com.abubusoft.kripton.processor.sqlite.grammars.jql.JQLReplacerListenerImpl in project kripton by xcesco.
the class InsertRawHelper method generateJavaDoc.
/**
* @param methodBuilder
* @param method
* @param returnType
* @return string sql
*/
public String generateJavaDoc(MethodSpec.Builder methodBuilder, final SQLiteModelMethod method, TypeName returnType) {
final SQLiteDaoDefinition daoDefinition = method.getParent();
final SQLiteEntity entity = daoDefinition.getEntity();
final One<Boolean> inColumnValues = new One<Boolean>(false);
final List<Pair<String, TypeName>> methodParamsUsedAsColumnValue = new ArrayList<>();
final List<Pair<String, TypeName>> methodParamsUsedAsParameter = new ArrayList<>();
// transform JQL to SQL
String sqlInsert = JQLChecker.getInstance().replace(method, method.jql, new JQLReplacerListenerImpl(method) {
@Override
public void onColumnValueSetBegin(Column_value_setContext ctx) {
inColumnValues.value0 = true;
}
@Override
public void onColumnValueSetEnd(Column_value_setContext ctx) {
inColumnValues.value0 = false;
}
@Override
public String onColumnName(String columnName) {
Set<SQLProperty> property = currentSchema.getPropertyBySimpleName(columnName);
AssertKripton.assertTrueOrUnknownPropertyInJQLException(property != null, method, columnName);
SQLProperty tempProperty = property.iterator().next();
AssertKripton.assertTrueOrUnknownPropertyInJQLException(tempProperty != null, method, columnName);
return tempProperty.columnName;
}
@Override
public String onBindParameter(String bindParameterName) {
String resolvedParamName = method.findParameterNameByAlias(bindParameterName);
if (inColumnValues.value0) {
methodParamsUsedAsColumnValue.add(new Pair<>(resolvedParamName, method.findParameterType(resolvedParamName)));
} else {
methodParamsUsedAsParameter.add(new Pair<>(resolvedParamName, method.findParameterType(resolvedParamName)));
}
return "${" + resolvedParamName + "}";
}
});
methodBuilder.addJavadoc("<h2>SQL insert</h2>\n");
methodBuilder.addJavadoc("<pre>$L</pre>\n", sqlInsert);
methodBuilder.addJavadoc("\n");
if (methodParamsUsedAsColumnValue.size() > 0) {
// list of inserted fields
methodBuilder.addJavadoc("<h2>Inserted columns:</strong></h2>\n");
methodBuilder.addJavadoc("<dl>\n");
for (Pair<String, TypeName> property : methodParamsUsedAsColumnValue) {
// String resolvedName = method.findParameterAliasByName(property.value0);
String resolvedName = method.findParameterNameByAlias(property.value0);
/*SQLProperty prop = entity.get(resolvedName);
if (prop == null)
throw (new PropertyNotFoundException(method, property.value0, property.value1));*/
methodBuilder.addJavadoc("\t<dt>$L</dt>", property.value0);
methodBuilder.addJavadoc("<dd>is binded to query's parameter <strong>$L</strong> and method's parameter <strong>$L</strong></dd>\n", "${" + property.value0 + "}", resolvedName);
}
methodBuilder.addJavadoc("</dl>\n\n");
}
// list of parameters
if (methodParamsUsedAsParameter.size() > 0) {
methodBuilder.addJavadoc("<h2>Method parameters used as sql parameters</h2>\n");
methodBuilder.addJavadoc("<dl>\n");
for (Pair<String, TypeName> property : methodParamsUsedAsParameter) {
String resolvedName = method.findParameterNameByAlias(property.value0);
methodBuilder.addJavadoc("\t<dt>$L</dt>", resolvedName);
methodBuilder.addJavadoc("<dd>is binded to query's parameter <strong>$${$L}</strong></dd>\n", property.value0);
}
methodBuilder.addJavadoc("</dl>\n\n");
}
for (Pair<String, TypeName> param : method.getParameters()) {
if (methodParamsUsedAsColumnValue.contains(param)) {
methodBuilder.addJavadoc("@param $L\n", param.value0);
if (entity.get(method.findParameterAliasByName(param.value0)) != null) {
methodBuilder.addJavadoc("\tis binded to column value <strong>$L</strong>\n", entity.get(method.findParameterAliasByName(param.value0)).columnName);
} else {
// in case of JQL explicit, you can declare name of parameter
methodBuilder.addJavadoc("\tis binded to query parameter <strong>$L</strong>\n", param.value0);
}
}
if (methodParamsUsedAsParameter.contains(param)) {
methodBuilder.addJavadoc("@param $L\n", param.value0);
methodBuilder.addJavadoc("\tis used as parameter\n");
}
}
generateJavaDocReturnType(methodBuilder, returnType);
return sqlInsert;
}
Aggregations