Food getFood(String name);
List<Food> getFoodsWhoseNameContains(String name, int maxResults);
void createFood(String name, double price, int quantity);
int removeStock(String name, int quantity);
The Inventory interface provides methods for adding and removing food from the
database, searching for food in the database, and finding out how much food there is
in the database. In a more complex application, you might want to expose more com-
plex queries as well. You haven't exposed the fact that you're using JPA in your inter-
face. This keeps things more flexible and decoupled, and it can be particularly handy
when it comes to unit testing.
Modularity, rebuilding, and split packages
You may be wondering why you're rebuilding bundles you wrote earlier. After all, OSGi
is all about modularity, and modularity definitely doesn't mean rebuilding existing
bundles every time you add new function to your application. Our excuse is that you'd
normally do a bit more up-front design work rather than build an application up one
chapter at a time!
But, if you don't like the idea of rebuilding the API bundle, feel free to add a new bun-
dle instead. Our one caution is that you must choose a different package name for
Inventory . Packages are closely associated with bundles in OSGi, and splitting a
package across multiple bundles is best avoided. For one thing, it's not very modular!
More seriously, by default OSGi will only wire importing bundles to one of the export-
ing bundles, leaving some of your interfaces inaccessible.
The Blueprint for the persistence service
In the cases where you're not unit testing, it's most convenient to allow the Blueprint
and JPA containers to do most of the work to set up and manage the instances of
You'll be relieved to see that the Blueprint for setting up the managed persistence
is much shorter than the Blueprint for setting up the datasource, even though it's
arguably achieving a great deal more, as shown in the following listing.
The blueprint.xml for the persistence bundle
Two new namespaces
Search WWH ::