use of com.abubusoft.kripton.processor.sqlite.model.SQLProperty in project kripton by xcesco.
the class JQLBuilder method extractFieldsFromAnnotation.
/**
* @param method
* @param annotationClazz
* @param includePrimaryKey
* @param dao
* @param entity
* @return
*/
private static <A extends Annotation> LinkedHashSet<String> extractFieldsFromAnnotation(final SQLiteModelMethod method, Class<A> annotationClazz, final boolean includePrimaryKey) {
final SQLiteDaoDefinition dao = method.getParent();
final SQLiteEntity entity = method.getParent().getEntity();
List<String> annotatedFieldValues = AnnotationUtility.extractAsStringArray(method.getElement(), annotationClazz, AnnotationAttributeType.FIELDS);
List<String> annotatedExcludedFieldValues = AnnotationUtility.extractAsStringArray(method.getElement(), annotationClazz, AnnotationAttributeType.EXCLUDED_FIELDS);
CollectionUtils.trim(annotatedFieldValues);
CollectionUtils.trim(annotatedExcludedFieldValues);
final One<Integer> count = new One<>(0);
// extract properties from managed bean
final Set<String> allFields = new LinkedHashSet<>();
forEachFields(dao, new OnPropertyListener() {
@Override
public void onProperty(SQLProperty item) {
if (!item.isPrimaryKey() || (item.isPrimaryKey() && includePrimaryKey)) {
allFields.add(item.getName());
}
if (TypeUtility.isEquals(item.getPropertyType().getTypeName(), typeName(entity.getElement()))) {
count.value0++;
}
}
});
// properties from selected set.
if (annotatedFieldValues.size() == 0 && annotatedExcludedFieldValues.size() == 0) {
// if no fields was selected, select all
annotatedFieldValues.clear();
annotatedFieldValues.addAll(allFields);
} else if (annotatedExcludedFieldValues.size() > 0) {
for (String fieldName : annotatedExcludedFieldValues) {
if (!entity.contains(fieldName)) {
AssertKripton.failUnknownPropertyInJQLException(method, annotationClazz, AnnotationAttributeType.EXCLUDED_FIELDS, fieldName);
}
}
allFields.removeAll(annotatedExcludedFieldValues);
annotatedFieldValues.clear();
annotatedFieldValues.addAll(allFields);
}
LinkedHashSet<String> result = new LinkedHashSet<>();
result.addAll(annotatedFieldValues);
return result;
}
Aggregations