I have created a ContentProvider for my main Sqlite table, pretty much following NotePad example from SDK (although I am not sure whether I will ever be exposing my data to other apps). However, I need to create lots of other, non-trivial queries on that and other tables and views. A good example would be queries to extract some statistics from the base data, averages, totals etc.
So what’s the best place for this code in an Android project? How it should be related and connected to the Uri-based data access exposed by a Provider? Any good examples out there?
From the point of view of maintainabillty I think that the provider model is the cleanest way to abstract the data access code. And from experience having worked on a large application, eventually the application will grow to the point where some data must be exposed via the provider model (e.g. introducing services to the application). That said exposing many different views of your data can be a lot of work in the provider model.
If you were to go the route I would think carefully how you exposed the data through URLs, and usually some of the complexity you talk of can be managed with use of sub-directories representing different views of the data (similar to a REST approach).
If you wish to avoid the provider model, then implementing a DA class is fairly straight forward. Typically a SQLiteOpenHelper is creatd as an inner class to the DA class (the open helper also providers basic versioning support) and an instance of this class is used to create database connections in the DA functions.
There are many examples in the Android Source code. Look at any of the provider implementations, with MediaProvider.java probably being the most relevant as it uses quite complex searches for a provider. For example from the source code that is not a content provider see DbSSLSessionCache.java