[aerogear-dev] [aerogear-android] DataManager API inconsistency + solution

Tadeas Kriz tkriz at redhat.com
Wed Jan 8 05:53:47 EST 2014


Forgot to include the link to gist: https://gist.github.com/TadeasKriz/499e8ae51102887a38ae
—
Tadeas Kriz
tkriz at redhat.com

On 08 Jan 2014, at 11:51, Tadeas Kriz <tkriz at redhat.com> wrote:

> Hey everyone,
> 
> I’ve been recently going through the DataManager API in aerogear-android. In this email, I’d like to suggest addiction of two method (or possibly three) into the `Store<T>` interface. These would be:
> 
> ```java
> /**
> * If store is open, it can be read or written to.
> */
> boolean isOpen();
> 
> /**
> * Opens store in current thread (blocking).
> */
> Store<T> open();
> 
> /**
> * Opens store in background thread and then callback#onSuccess is called.
> */
> void open(Callback<Store<T>> callback);
> ```
> 
> From my point of view, this makes sense to be in the `Store<T>` so I can switch between stores easily during development with no need to change other code. Also, if `read` or `write` operations are done with closed store, there are two possible workflows. First one is, that I’d fail and throw an exception. Second (and for me a preferred one) is, that all those methods would internally check if the store is open and if not, they’d call the `open` method. This also leads me to another API change for `Store<T>`.
> 
> ```java
> /**
> * Reads all the data from the underlying storage system asynchronously.
> */
> void readAll(Callback<Collection<T>> callback);
> 
> /**
> * Reads a specific object/record from the underlying storage system asynchronously.
> */
> void read(Serializable id, Callback<T> callback);
> 
> /**
> * Search for objects/records from the underlying storage system asynchronously.
> */
> void readWithFilter(ReadFilter filter, Callback<List<T>> callback);
> 
> /**
> * Saves the given object in the underlying storage system asynchronously.
> */
> void save(T item, Callback<Void> callback);
> 
> /**
> * Resets the entire storage system asynchronously.
> */
> void reset(Callback<Void> callback);
> 
> /**
> * Removes a specific object/record from the underlying storage system asynchronously.
> */
> void remove(Serializable id, Callback<Void> callback);
> 
> /**
> * Checks if the storage system contains no stored elements asynchronously.
> */
> void isEmpty(Callback<Boolean> callback);
> ```
> 
> That’s right, async methods for easy access to the storage from background thread, without the pain of writing it myself (for example, it makes no sense if I want to just call `store.save(..)` and I’d have to write all the `AsyncTask` boilerplate).
> 
> So, what do you think?
> 
> PS: You can find the whole text with highlighted syntax here: 
> 
>> Tadeas Kriz
> tkriz at redhat.com
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/aerogear-dev/attachments/20140108/decd35da/attachment.html 


More information about the aerogear-dev mailing list