use of com.abubusoft.kripton.processor.exceptions.PropertyInAnnotationNotFoundException in project kripton by xcesco.
the class SqlAnalyzer method execute.
/**
* Extract from value string every placeholder ${}, replace it with ? and then convert every field typeName with column typeName. The result is a pair: the first value is the elaborated string. The second is the list of parameters associated to
* ?. This second parameter is the list of parameters and replaced with ?.
*/
public void execute(Elements elementUtils, SQLiteModelMethod method, String sqlStatement) {
SQLiteDaoDefinition daoDefinition = method.getParent();
SQLiteEntity entity = daoDefinition.getEntity();
usedMethodParameters = new HashSet<String>();
paramNames = new ArrayList<String>();
paramGetters = new ArrayList<String>();
usedBeanPropertyNames = new ArrayList<String>();
paramTypeNames = new ArrayList<TypeName>();
// replace placeholder ${ } with ?
{
Matcher matcher = PARAMETER.matcher(sqlStatement);
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(buffer, "?");
paramNames.add(matcher.group(1));
}
matcher.appendTail(buffer);
sqlStatement = buffer.toString();
}
// replace property typeName to column typeName
{
Matcher matcher = WORD.matcher(sqlStatement);
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
SQLProperty property = entity.findPropertyByName(matcher.group(1));
if (property != null) {
matcher.appendReplacement(buffer, property.columnName);
}
}
matcher.appendTail(buffer);
sqlStatement = buffer.toString();
}
TypeName rawNameType;
// analyze parametersName
String effectiveName;
for (String rawName : paramNames) {
JQLParameterName pName = JQLParameterName.parse(rawName);
if (!pName.isNested()) {
effectiveName = method.findParameterNameByAlias(pName.getValue());
rawNameType = method.findParameterTypeByAliasOrName(effectiveName);
if (rawNameType == null) {
throw new MethodParameterNotFoundException(method, effectiveName);
}
paramGetters.add(effectiveName);
paramTypeNames.add(rawNameType);
usedMethodParameters.add(effectiveName);
usedBeanPropertyNames.add(null);
} else {
if (method.findParameterTypeByAliasOrName(pName.getBeanName()) == null) {
throw new MethodParameterNotFoundException(method, pName.getBeanName());
}
if (TypeUtility.isEquals(method.findParameterTypeByAliasOrName(pName.getBeanName()), entity) && entity.contains(pName.getValue())) {
// there are nested property invocation
paramGetters.add(method.findParameterNameByAlias(pName.getBeanName()) + "." + getter(entity.findPropertyByName(pName.getValue())));
usedBeanPropertyNames.add(pName.getValue());
paramTypeNames.add(TypeUtility.typeName(entity.findPropertyByName(pName.getValue()).getElement().asType()));
usedMethodParameters.add(method.findParameterNameByAlias(pName.getBeanName()));
} else {
throw (new PropertyInAnnotationNotFoundException(method, pName.getValue()));
}
}
// } else {
// throw (new PropertyInAnnotationNotFoundException(method, rawName));
// }
}
this.sqlStatement = sqlStatement;
}
Aggregations