KimB
KimB

Reputation: 63

Spring ROO custom finder

I use Spring ROO , I success to generate finders. the problem is that every property is in its own menu, I want to generate a custom finder in one form.

I started by adding a method in my entity, here is the method

  public static TypedQuery<com.keyrus.outside.business.entity.Candidate> findCandidatesByCustomDataLike(String principalSkills, String university) {
    if (principalSkills != null) {
        principalSkills = principalSkills.replace('*', '%');
        if (principalSkills.charAt(0) != '%') {
            principalSkills = "%" + principalSkills;
        }
        if (principalSkills.charAt(principalSkills.length() - 1) != '%') {
            principalSkills = principalSkills + "%";
        }
    }
    if (university != null) {
        university = university.replace('*', '%');
        if (university.charAt(0) != '%') {
            university = "%" + university;
        }
        if (university.charAt(university.length() - 1) != '%') {
            university = university + "%";
        }
    }
    EntityManager em = Candidate.entityManager();
    TypedQuery<Candidate> q = em.createQuery("SELECT o FROM Candidate AS o WHERE LOWER(o.principalSkills) LIKE LOWER(:principalSkills)" + 
    " AND LOWER(o.university) LIKE LOWER(:university)", Candidate.class);
    q.setParameter("principalSkills", principalSkills);
    q.setParameter("university", university);
    return q;
}

how do I could generate it in the *.aj file?

Thanks

Upvotes: 1

Views: 1821

Answers (1)

C&#232;sar
C&#232;sar

Reputation: 1246

If I understand you correctly you would like to add a new method to the AspectJ IDT file related to your entitiy, which is generated by Spring Roo.

If that is the case I advise you to keep your changes in the entity .java file. This is the way Spring Roo works, it generates code in the .aj files, and you write your own code in the .java files. If you modify the .aj file, it will get overwritten by Roo.

You can have more information about how it works in the Spring Roo reference documentation, as well as the recommended practices.

If what you want is to add a new functionality, which could be incorporated into any entity, you may develop your own Roo addons, which then would generate their own .aj files adding the new methods you need.

Upvotes: 3

Related Questions