Check that spans multiple java class

Hi,

Can you please let me know if there is way to write a check when it spans across java classes.

For Example: we want to check if there is DB call made in loop, in the below the call from first class is made to a second class. So we want to check if helper method is a call to DB. Is is possible to write a rule for this scenario? Can you please point me to custom rule that checks across class files.

First.java

public class First {
  public void method1(){
       Second secRef = new Second();
       List<String> res = new ArrayList<>();

       for(int i=0;i<n;i++){
            red.add(secRef.helper(i));
       }
  }
}

Second.java

public class Second{
  public String helper(int i){
        //      call database
        
        String result;
        result = DAO.callSQL(i);
        return result;
  }
}

Regards,
Sachin