66import org .osgl .$ ;
77import org .osgl .Osgl ;
88import org .osgl .exception .NotAppliedException ;
9+ import org .osgl .inject .BeanSpec ;
10+ import org .osgl .inject .Injector ;
911import org .osgl .util .E ;
1012import org .osgl .util .S ;
1113
14+ import java .beans .Transient ;
1215import java .lang .annotation .Annotation ;
1316import java .lang .reflect .Field ;
1417import java .lang .reflect .InvocationTargetException ;
@@ -78,6 +81,16 @@ public interface AdaptiveRecord<ID_TYPE, MODEL_TYPE extends AdaptiveRecord> exte
7881 */
7982 Set <Map .Entry <String , Object >> entrySet ();
8083
84+ /**
85+ * Returns a set of entries stored in the active record. For
86+ * field entries, use the field filter specified to check
87+ * if it needs to be added into the return set
88+ * @param fieldFilter the function that returns `true` or `false` for
89+ * bean spec of a certain field declared in the class
90+ * @return the entry set with field filter applied
91+ */
92+ Set <Map .Entry <String , Object >> entrySet ($ .Function <BeanSpec , Boolean > fieldFilter );
93+
8194 /**
8295 * Returns a Map typed object backed by this active record
8396 * @return a Map backed by this active record
@@ -88,13 +101,14 @@ public interface AdaptiveRecord<ID_TYPE, MODEL_TYPE extends AdaptiveRecord> exte
88101 * Returns the meta info of this AdaptiveRecord
89102 * @return
90103 */
104+ @ Transient
91105 MetaInfo metaInfo ();
92106
93107 class MetaInfo {
94108 private Class <? extends AdaptiveRecord > arClass ;
95109 public String className ;
96110 private Class <? extends Annotation > transientAnnotationType ;
97- public Set < Field > fields ;
111+ public Map < String , BeanSpec > fieldSpecs ;
98112 public Map <String , Type > fieldTypes ;
99113 public Map <String , $ .Function > fieldGetters ;
100114 public Map <String , $ .Func2 > fieldSetters ;
@@ -112,13 +126,14 @@ public Type fieldType(String fieldName) {
112126
113127 private void discoverFields (Class <? extends AdaptiveRecord > clazz ) {
114128 List <Field > list = $ .fieldsOf (arClass , $ .F .NON_STATIC_FIELD /*.and($.F.fieldWithAnnotation(transientAnnotationType)).negate()*/ );
115- fields = new HashSet <Field >();
116- fieldTypes = new HashMap <String , Type >();
117- fieldGetters = new HashMap <String , Osgl .Function >();
118- fieldSetters = new HashMap <String , Osgl .Func2 >();
129+ fieldSpecs = new HashMap <>();
130+ fieldTypes = new HashMap <>();
131+ fieldGetters = new HashMap <>();
132+ fieldSetters = new HashMap <>();
133+ Injector injector = Act .app ().injector ();
119134 for (Field f : list ) {
120135 //if (!f.isAnnotationPresent(transientAnnotationType)) {
121- fields . add ( f );
136+ fieldSpecs . put ( f . getName (), BeanSpec . of ( f , injector ) );
122137 fieldTypes .put (f .getName (), f .getGenericType ());
123138 fieldGetters .put (f .getName (), fieldGetter (f , clazz ));
124139 fieldSetters .put (f .getName (), fieldSetter (f , clazz ));
@@ -211,7 +226,7 @@ public static class Repository extends AppServicePlugin {
211226 protected void applyTo (App app ) {
212227 }
213228
214- private ConcurrentMap <Class <?>, MetaInfo > map = new ConcurrentHashMap <Class <?>, MetaInfo >();
229+ private ConcurrentMap <Class <?>, MetaInfo > map = new ConcurrentHashMap <>();
215230
216231 public MetaInfo get (Class <? extends AdaptiveRecord > clazz , $ .Function <Class <? extends AdaptiveRecord >, MetaInfo > factory ) {
217232 MetaInfo info = map .get (clazz );
0 commit comments