helun/Ektorp

DocumentChange.getDocAsNode() returning "null" value for "doc" key

bundeeteddee opened this issue · 0 comments

Hi there,

I've just started seeing this problem which wasn't there (as far as i know) in older version of the library. I am currently using the latest codebase of ektorp. First, the code in attaching change feed to the database connector

Creating ChangesCommand and ChangesFeedAsyncTask

ChangesCommand changesCmd = new ChangesCommand.Builder()
    .includeDocs(true)
    .continuous(true)
    .build();
if (mChangesFeedTask != null &&
                        mChangesFeedTask.getStatus() != AsyncTask.Status.FINISHED) {
    mChangesFeedTask.cancel(true);
}
    mChangesFeedTask = (new ChangesFeedAsyncTask(getCouchDbConnector(), changesCmd));
    mChangesFeedTask.execute();

ChangesFeedAsyncTask

private class ChangesFeedAsyncTask extends AsyncTask<Void, DocumentChange, Object> {
        protected CouchDbConnector couchDbConnector;
        protected ChangesCommand changesCommand;
        protected ChangesFeed changesFeed;

        /**
         * Create a ChangesFeedAsynTask with the provided CouchDbConnector and ChangesCommand
         *
         * @param couchDbConnector the couchDbConnector to use
         * @param changesCommand the changeCommand to execute
         */
        public ChangesFeedAsyncTask(CouchDbConnector couchDbConnector, ChangesCommand changesCommand) {
            this.couchDbConnector = couchDbConnector;
            this.changesCommand = changesCommand;
        }

        @Override
        protected Object doInBackground(Void... params) {
            Object result = null;

            changesFeed = getCouchDbConnector().changesFeed(changesCommand);

            //Keep loop running and listen to doc changes
            while(!isCancelled() && changesFeed.isAlive()) {
                try {
                    DocumentChange change = changesFeed.next();

                    //More fine grain control on database change notification
                    KLog.e(TAG, "ChangesFeedAsyncTask >> include docs? " + changesCommand.includeDocs, Severity.WTF);
                    JsonNode pJson = change.getDocAsNode();
                    KLog.e(TAG, "DatabaseEvent >>>>> " + change.toString() + " " + pJson.toString(), KLog.Severity.WTF);


                } catch(DbAccessException dbAccesException) {
                    result = dbAccesException;
                } catch(InterruptedException interruptedException) {
                    cancel(false);
                }

                //A quick sleep to throttle events a bit
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            return result;
        }

        @Override
        protected void onCancelled() {
            if(changesFeed != null) {
                changesFeed.cancel();
            }
        }

        @Override
        protected void onPostExecute(Object result) {
            if(result == null) {
                onSuccess();
            }
            else if(result instanceof DbAccessException) {
                onDbAccessException((DbAccessException)result);
            }

        }

        /**
         * Called when the changes feed has returned all applicable changes without Exception
         */
        protected void onSuccess() {

        }

        /**
         * By default, we rethrow this exception
         * @param dbAccessException
         */
        protected void onDbAccessException(DbAccessException dbAccessException) {
            throw dbAccessException;
        }
    }

For each DocumentChange coming in, i can see something like:
DatabaseEvent >>>>> {"seq":5898,"doc":null,"id":"bcb5a88ef0c513aa565ecc1bcc6fe202","changes":[{"rev":"1-fed669a85a38696fe9fe71e8e6dd7405"}]} null

So my question is why change.getDocAsNode() returns a null doc key when it was specified in the ChangesCommand to includeDocs(true) ? Does my code look right?