Created
October 17, 2010 16:10
-
-
Save aruld/630971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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