A real-world domain object can have quite a few fields, for example:
Code:
public class Car {
private Make make;
private Model model;
private String VIN;
private Colour colour;
private Date purchaseDate;
private Warranty warranty;
private int kilometres;
}
Imagine you've been asked to implement a search screen in which the user can search by all seven of these fields at once (not such an unusual requirement). If you try this Roo command:
Code:
finder list --class ~.Car --depth 7
... the Roo shell will die with an OutOfMemoryError, quite understandable given that the possible combinations of finders for seven fields is mind-bogglingly huge (there's a PhD thesis for someone).
The solution is to list the finders at a depth of one, like this:
Code:
finder list --class ~.Car
... which will output this:
Code:
findCarsByColour(Colour colour)
findCarsByKilometres(Integer kilometres)
findCarsByKilometresBetween(Integer minKilometres, Integer maxKilometres)
findCarsByKilometresEquals(Integer kilometres)
findCarsByKilometresGreaterThan(Integer kilometres)
findCarsByKilometresGreaterThanEquals(Integer kilometres)
findCarsByKilometresIsNotNull()
findCarsByKilometresIsNull()
findCarsByKilometresLessThan(Integer kilometres)
findCarsByKilometresLessThanEquals(Integer kilometres)
findCarsByKilometresNotEquals(Integer kilometres)
findCarsByMake(Make make)
findCarsByModel(Model model)
findCarsByPurchaseDate(Date purchaseDate)
findCarsByPurchaseDateBetween(Date minPurchaseDate, Date maxPurchaseDate)
findCarsByPurchaseDateEquals(Date purchaseDate)
findCarsByPurchaseDateGreaterThan(Date purchaseDate)
findCarsByPurchaseDateGreaterThanEquals(Date purchaseDate)
findCarsByPurchaseDateIsNotNull()
findCarsByPurchaseDateIsNull()
findCarsByPurchaseDateLessThan(Date purchaseDate)
findCarsByPurchaseDateLessThanEquals(Date purchaseDate)
findCarsByPurchaseDateNotEquals(Date purchaseDate)
findCarsByVIN(String VIN)
findCarsByVINEquals(String VIN)
findCarsByVINIsNotNull()
findCarsByVINIsNull()
findCarsByVINLike(String VIN)
findCarsByVINNotEquals(String VIN)
findCarsByWarranty(Warranty warranty)
Copy and paste that list into a text editor, then hack it around until you get a valid finder name that matches your business requirements, for example:
Code:
findCarsByColourAndKilometresBetweenAndMakeAndModelAndPurchaseDateBetweenAndVINLikeAndWarranty
Open your Car.java file, and change this line:
To include the above finder name:
Code:
@RooEntity(finders = {"findCarsByColourAndKilometresBetweenAndMakeAndModelAndPurchaseDateBetweenAndVINLikeAndWarranty"})
(Note that until Roo 1.0.2, you need to include the curly braces because of ROO-618.)
Save the Car.java file. Next time you run the Roo shell, it will output this:
Code:
Created SRC_MAIN_JAVA\com\example\car\Car_Roo_Finder.aj
Open that AspectJ ITD and you will see your new finder in all its glory. If you want to modify it, you can push it into Car.java as with any other introduced method.
If the finder name you came up with is invalid, Roo will tell you there's no such finder available, in which case fix the name and try again.
Hope this helps someone...