private static < A extends Annotation > LinkedHashSet < String > extractFieldsFromAnnotation ( final SQLiteModelMethod method , Class < A > annotationClazz , final boolean includePrimaryKey ) { final SQLiteEntity entity = method . 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 ( method , 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 ++ ; } } } ) ; // use attribute includedFields and excludedFields to mantain or remove // 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 ; }
Extract fields from annotation .