So, I wrote an interface that meets my requirements, with two implementations: for Android and J2ME.
Here's what the interface looks like:
public interface ISDataStore { public int getNumRecords() throws SDataStoreException; public int getRecordSize(int record_id) throws SDataStoreException; public void getRecord(int record_id, byte[] data, int offset) throws SDataStoreException; public byte[] getRecord(int record_id) throws SDataStoreException; public boolean isRecordExists(int record_id) throws SDataStoreException; public boolean setRecord(int record_id, byte[] data, int offset, int length) throws SDataStoreException; public boolean deleteRecord(int record_id) throws SDataStoreException; public void deleteAll() throws SDataStoreException; public void close() throws SDataStoreException; }
There is also a factory for data warehouses:
public interface ISDataStoreFactory { public ISDataStore getDataStore(Object dataStoreId) throws SDataStoreException; public void destroyDataStore(Object dataStoreId) throws SDataStoreException; }
Documents created with Doxygen can be found here .
A mercury repository with an interface and all implementations can be found here .
How to use it:
As I said in my question, I have an Android app and a J2ME app, both of these apps do a similar thing. (if anyone is interested, they communicate via Bluetooth with a remote built-in device)
Both applications have a common low-level part, which performs the main task.
I have an interface IMainApp , something like this:
public interface IMainApp { public ISDataStoreFactory getDataStoreFactory(); }
Both applications (for Android and J2ME) have their own implementations of this interface, and they transmit a link to a low-level part. When the low-level part wants to open some data store, it uses the ISDataStoreFactory returned by IMainApp.getDataStoreFactory . It works the way I want it to work.
Hope this is helpful to everyone.