Skip to content

Commit 8683de1

Browse files
authored
Allowing for better mapping of accessor methods
Allowing for mapping the getter and setter methods through the Java object hierarchy in a recursive way that can cater for inherited class attributes and methods
1 parent 6712470 commit 8683de1

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

src/main/java/io/jsondb/CollectionMetaData.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,14 @@ public CollectionMetaData(String collectionName, Class<?> clazz, String schemaVe
7171
this.collectionLock = new ReentrantReadWriteLock();
7272

7373
//Populate the class metadata
74-
List<Field[]> fields = new ArrayList<>();
75-
Field[] startFields = clazz.getDeclaredFields();
76-
int totalFields = startFields.length;
77-
fields.add(startFields);
78-
while (clazz.getSuperclass() != Object.class) {
79-
clazz = clazz.getSuperclass();
80-
Field[] toAdd = clazz.getDeclaredFields();
81-
totalFields += toAdd.length;
82-
fields.add(toAdd);
83-
}
74+
setupClassMetadata(clazz);
8475

85-
int x = 0;
86-
Field[] fs = new Field[totalFields];
87-
for (Field[] field : fields) {
88-
for (Field value : field) {
89-
fs[x] = value;
90-
x++;
91-
}
92-
}
76+
this.idAnnotatedFieldGetterMethod = getterMethodMap.get(idAnnotatedFieldName);
77+
this.idAnnotatedFieldSetterMethod = setterMethodMap.get(idAnnotatedFieldName);
78+
}
9379

80+
private void setupClassMetadata(final Class<?> clazz) {
81+
Field[] fs = clazz.getDeclaredFields();
9482
Method[] ms = clazz.getDeclaredMethods();
9583
for (Field f : fs) {
9684
String fieldName = f.getName();
@@ -119,8 +107,7 @@ public CollectionMetaData(String collectionName, Class<?> clazz, String schemaVe
119107
}
120108
}
121109
}
122-
this.idAnnotatedFieldGetterMethod = getterMethodMap.get(idAnnotatedFieldName);
123-
this.idAnnotatedFieldSetterMethod = setterMethodMap.get(idAnnotatedFieldName);
110+
if (clazz.getSuperclass() != Object.class) setupClassMetadata(clazz.getSuperclass());
124111
}
125112

126113
protected ReentrantReadWriteLock getCollectionLock() {

0 commit comments

Comments
 (0)