Skip to content

Instantly share code, notes, and snippets.

@aruld
Created October 17, 2010 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aruld/630971 to your computer and use it in GitHub Desktop.
Save aruld/630971 to your computer and use it in GitHub Desktop.
@Path("/sakila")
public class SakilaResource {
@Context
private SearchContext searchContext;
List<Actor> actors = new ArrayList<Actor>();
List<Film> films = new ArrayList<Film>();
List<Rental> rentals = new ArrayList<Rental>();
public SakilaResource() {
// JPA Plumbing omitted for clarity.
}
@GET
@Produces("application/xml")
@Path("searchActors")
public List<Actor> searchActors() {
SearchCondition<Actor> sc = searchContext.getCondition(Actor.class);
if (sc == null) {
throw new NotFoundException("Invalid search query.");
}
System.out.println(sc.toSQL("actor"));
List<Actor> found = sc.findAll(actors);
if (found.size() == 0) {
throw new NotFoundException("No matching actor found.");
}
return found;
}
@GET
@Produces("application/xml")
@Path("searchFilms")
public List<Film> searchFilms() {
SearchCondition<Film> sc = searchContext.getCondition(Film.class);
if (sc == null) {
throw new NotFoundException("Invalid search query.");
}
System.out.println(sc.toSQL("film"));
List<Film> found = sc.findAll(films);
if (found.size() == 0) {
throw new NotFoundException("No matching film found.");
}
return found;
}
@GET
@Produces("application/xml")
@Path("searchRentals")
public List<Rental> searchRentals() {
SearchCondition<Rental> sc = searchContext.getCondition(Rental.class);
if (sc == null) {
throw new NotFoundException("Invalid search query.");
}
System.out.println(sc.toSQL("rental"));
List<Rental> found = sc.findAll(rentals);
if (found.size() == 0) {
throw new NotFoundException("No matching rental found.");
}
return found;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment