BasicDatastore is a huge class, which contains virtually all the logic to manage the MVCC semantics of the database. AttachmentManager breaks out some attachment logic, but really it's all still driven from BasicDatastore. What I'd like to do is to break up BasicDatastore into smaller components, which hopefully can have simpler tasks and can each be understood as a single unit doing a single task. Latterly, we might even be able to start testing things individually.
I think of this a bit like the operations in objective-cloudant -- each SQLCallable is a logical MVCC operation or perhaps lower level database operation. I'm not sure yet whether we want to more formally layer the MVCC semantics vs the database SQL semantics (which would allow us to more easily swap out storage layers later).
For example, https://github.com/cloudant/sync-android/pull/219 pulls out the work of inserting a single revision into the revs table. This might be too small a thing, but the logic is required by several of the higher level operations -- creating, updating and deleting -- so it makes sense to have separately.
Further from that, extracting the database interaction from the BasicDatastore "orchestration" logic would be a good thing. In the first instance, that won't really be possible. The first piece of work will be pulling out all the higher-level things like "create a document" into their own classes, which will do things like checking for MVCC validity (e.g., my update has the right revId of a current leaf node). It'd be nice long term if the database operations could be separated from the business logic.
For example, #219 is a storage level operation, almost. It might actually be slightly too low-level, perhaps it should have some more logic of its own, but we'll see. At least we'll hopefully get to a stage where it's easier to conceptually see what's going on when we have separate classes. If not, then at least we learned that just making classes, however well encapsulated, doesn't help.
From @mikerhodes:
Note that
BasicDatastore
is nowDatastoreImpl
.