4. Managing the data

To actually access the data source, we will write a small class that handles creating the table and doing queries for adding and retrieving friends. RIFE makes it easy: we just extend com.uwyn.rife.database.DbQueryManager, which takes care of a great deal of work, leaving the essential bits for us to implement. The code can be found in src/tutorial/friends/backend/FriendManager.java, and should be pretty clear and comprehensible. There is a bit of code, so we'll walk through the most important bits.

4.1. Using the right data source

In Example 7.3, “Selecting a data source through the configuration system” just above, we added a configuration parameter to select which of the two data sources to use. We can use this parameter to initialize the manager with the right source:

Example 7.5. Using the selected data source

public FriendManager()

Now the query manager will be initialized with the data source that corresponds to the name we entered in the configuration.