@@ -294,32 +294,37 @@ private static void initSet(AmpActivityVersion out, Field field){
294294 */
295295 public static AmpActivityVersion initializeActivity (AmpActivityVersion act ) throws DgException , IllegalArgumentException ,
296296 IllegalAccessException , InvocationTargetException {
297- Session session = PersistenceManager .getRequestDBSession ();
298- Method [] methods = AmpActivityVersion .class .getDeclaredMethods ();
299- for (int i = 0 ; i < methods .length ; i ++) {
300- if (methods [i ].getName ().contains ("get" ) && methods [i ].getReturnType ().getName ().contains ("java.util.Set" )) {
301- Object methodValue = methods [i ].invoke (act , null );
302- Collection auxColl = (Collection ) methodValue ;
303- if (auxColl != null ) {
304- auxColl .size ();
305- Iterator iInner = auxColl .iterator ();
306- while (iInner .hasNext ()) {
307- Object auxInnerObject = iInner .next ();
308- Method [] innerMethods = auxInnerObject .getClass ().getDeclaredMethods ();
309- for (int j = 0 ; j < innerMethods .length ; j ++) {
310- if (innerMethods [j ].getName ().contains ("get" )
311- && innerMethods [j ].getReturnType ().getName ().contains ("java.util.Set" )) {
312- Object innerMethodValue = innerMethods [j ].invoke (auxInnerObject , null );
313- Collection auxInnerColl = (Collection ) innerMethodValue ;
314- if (auxInnerColl != null ) {
315- auxInnerColl .size ();
316- }
317- }
318- }
319- }
320- }
297+ initializeCollectionGetters (act , 1 );
298+ return act ;
299+ }
300+
301+ private static void initializeCollectionGetters (Object source , int nestedDepth )
302+ throws InvocationTargetException , IllegalAccessException {
303+ if (source == null ) {
304+ return ;
305+ }
306+
307+ Method [] methods = source .getClass ().getMethods ();
308+ for (Method method : methods ) {
309+ if (!method .getName ().startsWith ("get" )
310+ || method .getParameterTypes ().length != 0
311+ || !Collection .class .isAssignableFrom (method .getReturnType ())) {
312+ continue ;
313+ }
314+
315+ Collection <?> collection = (Collection <?>) method .invoke (source , (Object []) null );
316+ if (collection == null ) {
317+ continue ;
318+ }
319+
320+ collection .size ();
321+ if (nestedDepth <= 0 ) {
322+ continue ;
323+ }
324+
325+ for (Object nestedObject : collection ) {
326+ initializeCollectionGetters (nestedObject , nestedDepth - 1 );
321327 }
322328 }
323- return act ;
324329 }
325330}
0 commit comments