Example usage for android.database Cursor getLong

List of usage examples for android.database Cursor getLong

Introduction

In this page you can find the example usage for android.database Cursor getLong.

Prototype

long getLong(int columnIndex);

Source Link

Document

Returns the value of the requested column as a long.

Usage

From source file:com.task.krabiysok.sunshine.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city//  ww  w  . j a v  a 2  s . co  m
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
public long addLocation(String locationSetting, String cityName, double lat, double lon) {
    long locationId;
    // Students: First, check if the location with this city name exists in the db
    Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.LOCATION_SETTING + " =?", new String[] { locationSetting }, null);
    // If it exists, return the current ID
    if (locationCursor.moveToFirst()) {
        int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(locationIdIndex);
    } else {
        // Otherwise, insert it using the content resolver and the base URI
        ContentValues locationValues = new ContentValues();

        // Then add the data, along with the corresponding name of the data type,
        // so the content provider knows what kind of value is being inserted.
        locationValues.put(WeatherContract.LocationEntry.CITY_NAME, cityName);
        locationValues.put(WeatherContract.LocationEntry.LOCATION_SETTING, locationSetting);
        locationValues.put(WeatherContract.LocationEntry.COORD_LAT, lat);
        locationValues.put(WeatherContract.LocationEntry.COORD_LONG, lon);

        // Finally, insert location data into the database.
        Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                locationValues);

        // The resulting URI contains the ID for the row.  Extract the locationId from the Uri.
        locationId = ContentUris.parseId(insertedUri);
    }

    locationCursor.close();
    // Wait, that worked?  Yes!
    return locationId;
}

From source file:org.mythtv.service.dvr.v27.RecordedHelperV27.java

private int load(final Context context, final LocationProfile locationProfile, final Program[] programs)
        throws RemoteException, OperationApplicationException {
    Log.d(TAG, "load : enter");

    if (null == context)
        throw new RuntimeException("RecordedHelperV27 is not initialized");

    processProgramGroups(context, locationProfile, programs);

    String tag = UUID.randomUUID().toString();
    int processed = -1;
    int count = 0;

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    boolean inError;

    List<Integer> channelsChecked = new ArrayList<Integer>();

    for (Program program : programs) {

        if (null != program.getRecording() && "livetv".equalsIgnoreCase(program.getRecording().getRecGroup())
                && !"deleted".equalsIgnoreCase(program.getRecording().getRecGroup())) {
            Log.w(TAG,//from ww w.j a v  a2s . co m
                    "load : program has no recording or program is in livetv or deleted recording groups:"
                            + program.getTitle() + ":" + program.getSubTitle() + ":"
                            + program.getChannel().getChanId() + ":" + program.getStartTime() + ":"
                            + program.getHostName() + " ("
                            + (null == program.getRecording() ? "No Recording"
                                    : ("livetv".equalsIgnoreCase(program.getRecording().getRecGroup())
                                            ? "LiveTv"
                                            : "Deleted"))
                            + ")");

            continue;
        }

        if (null == program.getStartTime() || null == program.getEndTime()) {
            Log.w(TAG, "load : null starttime and or endtime");

            inError = true;
        } else {
            inError = false;
        }

        ProgramHelperV27.getInstance().processProgram(context, locationProfile,
                ProgramConstants.CONTENT_URI_RECORDED, ProgramConstants.TABLE_NAME_RECORDED, ops, program, tag);
        count++;

        if (null != program.getChannel()) {

            if (!channelsChecked.contains(program.getChannel().getChanId())) {

                if (null == mChannelDaoHelper.findByChannelId(context, locationProfile,
                        Long.parseLong(String.valueOf(program.getChannel().getChanId())))) {

                    ChannelHelperV27.getInstance().processChannel(context, locationProfile, ops,
                            program.getChannel());
                    count++;

                }

                channelsChecked.add(program.getChannel().getChanId());

            }

        }

        if (!inError && null != program.getRecording()) {

            if (program.getRecording().getRecordId() > 0) {

                RecordingHelperV27.getInstance().processRecording(context, locationProfile, ops,
                        RecordingConstants.ContentDetails.RECORDED, program, tag);
                count++;

            }

        }

        if (count > BATCH_COUNT_LIMIT) {
            Log.i(TAG, "load : applying batch for '" + count + "' transactions");

            processBatch(context, ops, processed, count);

            count = 0;

        }

    }

    if (!ops.isEmpty()) {
        Log.i(TAG, "load : applying final batch for '" + count + "' transactions");

        processBatch(context, ops, processed, count);
    }

    ProgramHelperV27.getInstance().findAllPrograms(context, locationProfile,
            ProgramConstants.CONTENT_URI_RECORDED, ProgramConstants.TABLE_NAME_RECORDED);

    Log.v(TAG, "load : remove deleted recording live streams");
    String[] deletedProjection = new String[] { ProgramConstants.FIELD_CHANNEL_ID,
            ProgramConstants.FIELD_START_TIME, ProgramConstants.FIELD_TITLE, ProgramConstants.FIELD_SUB_TITLE,
            ProgramConstants.FIELD_LAST_MODIFIED_DATE };
    String deletedSelection = "not " + ProgramConstants.TABLE_NAME_RECORDED + "."
            + ProgramConstants.FIELD_LAST_MODIFIED_TAG + " = ?";
    String[] deletedSelectionArgs = new String[] { tag };

    deletedSelection = appendLocationHostname(context, locationProfile, deletedSelection,
            ProgramConstants.TABLE_NAME_RECORDED);

    int deleteCount = 0;
    Cursor deletedCursor = context.getContentResolver().query(ProgramConstants.CONTENT_URI_RECORDED,
            deletedProjection, deletedSelection, deletedSelectionArgs, null);
    while (deletedCursor.moveToNext()) {

        long channelId = deletedCursor.getLong(deletedCursor.getColumnIndex(ProgramConstants.FIELD_CHANNEL_ID));
        long startTime = deletedCursor.getLong(deletedCursor.getColumnIndex(ProgramConstants.FIELD_START_TIME));

        // Delete any live stream details
        String liveStreamSelection = LiveStreamConstants.FIELD_CHAN_ID + " = ? AND "
                + LiveStreamConstants.FIELD_START_TIME + " = ?";
        String[] liveStreamSelectionArgs = new String[] { String.valueOf(channelId),
                String.valueOf(startTime) };

        liveStreamSelection = appendLocationHostname(context, locationProfile, liveStreamSelection,
                LiveStreamConstants.TABLE_NAME);

        Cursor liveStreamCursor = context.getContentResolver().query(LiveStreamConstants.CONTENT_URI, null,
                liveStreamSelection, liveStreamSelectionArgs, null);
        if (liveStreamCursor.moveToFirst()) {
            Log.v(TAG, "load : remove live stream");

            int liveStreamId = liveStreamCursor.getInt(liveStreamCursor
                    .getColumnIndex(LiveStreamConstants.TABLE_NAME + "." + LiveStreamConstants.FIELD_ID));

            RemoveStreamTask removeStreamTask = new RemoveStreamTask(context, locationProfile);
            removeStreamTask.execute(liveStreamId);
        }
        liveStreamCursor.close();

        deleteCount++;
    }
    deletedCursor.close();
    Log.v(TAG, "load : queued deleted programs - " + deleteCount);

    ProgramHelperV27.getInstance().deletePrograms(context, locationProfile,
            ProgramConstants.CONTENT_URI_RECORDED, ProgramConstants.TABLE_NAME_RECORDED, tag);
    //      RecordingHelperV27.getInstance().deleteRecordings( context, locationProfile, ops, RecordingConstants.ContentDetails.RECORDED, lastModified );

    if (!ops.isEmpty()) {
        Log.i(TAG, "load : applying delete batch for transactions");

        processBatch(context, ops, processed, count);
    }

    //      Log.v( TAG, "load : exit" );
    return processed;
}

From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java

private void mergeDbs() {
    Log.d(LOG_TAG, "update received - juggling dbs");
    // Get main database, attach temp db to it.
    SQLiteDatabase mainDb = dataService.getHelper().getWritableDatabase();
    mainDb.execSQL("attach database ? as ka_temp",
            new Object[] { dataService.getDatabasePath("ka_temp").getAbsolutePath() });

    mainDb.beginTransaction();//from w  w  w. j a v  a  2s. co m
    try {

        // Maintain download status.
        String sql = "select max(download_status), dlm_id, youtube_id from video where download_status != ? group by youtube_id";
        Cursor c = mainDb.rawQuery(sql, new String[] { "" + Video.DL_STATUS_NOT_STARTED });
        Cursor c1;
        String[] videoIds = new String[c.getCount()];
        int i = 0;
        while (c.moveToNext()) {
            String youtube_id = c.getString(c.getColumnIndex("youtube_id"));
            String download_status = c.getString(c.getColumnIndex("max(download_status)"));
            long dlm_id = c.getLong(c.getColumnIndex("dlm_id"));
            videoIds[i++] = youtube_id;
            ContentValues v = new ContentValues();
            v.put("download_status", download_status);
            v.put("dlm_id", dlm_id);
            String[] idArg = new String[] { youtube_id };
            mainDb.update("ka_temp.video", v, "youtube_id = ?", idArg);

            // cursor over parent topics of this video
            sql = "select ka_temp.topic._id from ka_temp.topic, ka_temp.topicvideo, ka_temp.video where ka_temp.video.youtube_id=? and ka_temp.topicvideo.video_id=ka_temp.video.readable_id and ka_temp.topicvideo.topic_id=ka_temp.topic._id";
            c1 = mainDb.rawQuery(sql, idArg);
            Log.d(LOG_TAG, String.format("updating counts for %d topics", c1.getCount()));
            while (c1.moveToNext()) {
                String topicId = c1.getString(c1.getColumnIndex("_id"));
                DatabaseHelper.incrementDownloadedVideoCounts(mainDb, topicId, "ka_temp.topic");
            }
            c1.close();
        }
        c.close();

        mainDb.execSQL("delete from topic");
        mainDb.execSQL("insert into topic select * from ka_temp.topic");

        mainDb.execSQL("delete from topicvideo");
        mainDb.execSQL("insert into topicvideo select * from ka_temp.topicvideo");

        mainDb.execSQL("delete from video");
        mainDb.execSQL("insert into video select * from ka_temp.video");

        mainDb.setTransactionSuccessful();
    } finally {
        mainDb.endTransaction();
        mainDb.execSQL("detach database ka_temp");
    }

    Log.d(LOG_TAG, "finished juggling");
}

From source file:app.com.example.manu.sunshine.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city/*from  ww w  . j a v  a  2  s  . c o m*/
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
long addLocation(String locationSetting, String cityName, double lat, double lon) {
    // Students: First, check if the location with this city name exists in the db
    // If it exists, return the current ID
    // Otherwise, insert it using the content resolver and the base URI

    long locationId;

    // First, check if the location with this city name exists in the db
    Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);

    if (locationCursor.moveToFirst()) {
        int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(locationIdIndex);
    } else {
        // Now that the content provider is set up, inserting rows of data is pretty simple.
        // First create a ContentValues object to hold the data you want to insert.
        ContentValues locationValues = new ContentValues();

        // Then add the data, along with the corresponding name of the data type,
        // so the content provider knows what kind of value is being inserted.
        locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        // Finally, insert location data into the database.
        Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                locationValues);

        // The resulting URI contains the ID for the row.  Extract the locationId from the Uri.
        locationId = ContentUris.parseId(insertedUri);
    }

    locationCursor.close();
    // Wait, that worked?  Yes!
    return locationId;

}

From source file:com.samknows.measurement.storage.DBHelper.java

public JSONObject getArchiveDataSummary() {
    synchronized (sync) {
        List<Integer> batches = getTestBatchesByPassiveMetric(getPassiveMetricsFilter());

        open();//ww  w  . j ava  2 s . c  om
        JSONObject ret = new JSONObject();
        // test batch counter
        String counterColumn = "COUNT(*)";
        String minDate = "MIN(" + SKSQLiteHelper.TB_COLUMN_DTIME + ")";
        String maxDate = "MAX(" + SKSQLiteHelper.TB_COLUMN_DTIME + ")";
        String[] columns = { counterColumn, minDate, maxDate };
        Cursor cursor = database.query(SKSQLiteHelper.TABLE_TESTBATCH, columns, null, null, null, null, null);
        cursor.moveToFirst();

        String counter = cursor.getLong(0) + "";
        String min = cursor.getLong(1) + "";
        String max = cursor.getLong(2) + "";
        cursor.close();
        // test results counter
        columns = new String[] { SKSQLiteHelper.TR_COLUMN_TYPE, counterColumn };
        String groupBy = SKSQLiteHelper.TR_COLUMN_TYPE;
        String selection = getInClause(SKSQLiteHelper.TR_COLUMN_BATCH_ID, batches);
        cursor = database.query(SKSQLiteHelper.TABLE_TESTRESULT, columns, selection, null, groupBy, null, null);
        cursor.moveToFirst();
        JSONObject test_counter = new JSONObject();
        while (!cursor.isAfterLast()) {
            try {
                test_counter.put(TestResult.testStringToId(cursor.getString(0)) + "", cursor.getInt(1) + "");
            } catch (JSONException je) {
                Logger.e(this, "Error in creating a JSONObject: " + je.getMessage());
            }
            cursor.moveToNext();
        }
        cursor.close();
        try {
            ret.put(ARCHIVEDATASUMMARY_COUNTER, counter);
            ret.put(ARCHIVEDATASUMMARY_STARTDATE, min);
            ret.put(ARCHIVEDATASUMMARY_ENDDATE, max);
            ret.put(ARCHIVEDATASUMMARY_TESTCOUNTER, test_counter);
        } catch (JSONException je) {
            Logger.e(this, "Error in creating a JSONObject: " + je.getMessage());
        }
        close();
        return ret;
    }
}

From source file:com.nonninz.robomodel.RoboManager.java

public long[] getSelectedModelIds(String selection, String[] selectionArgs, String groupBy, String having,
        String orderBy) {//ww w  . jav  a 2s. c  om
    final SQLiteDatabase db = mDatabaseManager.openOrCreateDatabase(getDatabaseName());

    final String columns[] = new String[] { BaseColumns._ID };
    Cursor query;

    /*
     * Try the query. If the Table doesn't exist, fix the DB and re-run the query.
     */
    try {
        query = db.query(getTableName(), columns, selection, selectionArgs, groupBy, having, orderBy);
    } catch (final SQLiteException e) {
        prepareTable(db);
        query = db.query(getTableName(), columns, selection, selectionArgs, groupBy, having, orderBy);
    }

    final int columnIndex = query.getColumnIndex(BaseColumns._ID);
    final long result[] = new long[query.getCount()];
    for (query.moveToFirst(); !query.isAfterLast(); query.moveToNext()) {
        result[query.getPosition()] = query.getLong(columnIndex);
    }

    return result;
}

From source file:com.ericsender.android_nanodegree.popmovie.com.ericsender.android_nanodegree.popmovie.data.TestProvider.java

public void testGettingMovieAndMaybeFavorite() {
    mContext.getContentResolver().delete(MovieContract.FavoriteEntry.CONTENT_URI, null, null);
    Map<Long, ContentValues> listContentValues = TestUtilities.createSortedMovieValues(getContext(), "popular");

    ContentValues[] arr = (ContentValues[]) listContentValues.values().toArray(new ContentValues[0]);

    mContext.getContentResolver().bulkInsert(MovieContract.MovieEntry.CONTENT_URI, arr);

    ContentValues[] movie_ids = new ContentValues[arr.length];
    for (int i = 0; i < arr.length; i++)
        (movie_ids[i] = new ContentValues()).put(MovieContract.RatingEntry.COLUMN_MOVIE_ID,
                arr[i].getAsLong(MovieContract.MovieEntry.COLUMN_MOVIE_ID));

    mContext.getContentResolver().bulkInsert(MovieContract.FavoriteEntry.CONTENT_URI, movie_ids);

    TestUtilities.verifyFavoriteValuesInDatabase(listContentValues, mContext);

    Long expected = movie_ids[0].getAsLong(MovieContract.MovieEntry.COLUMN_MOVIE_ID);
    Cursor c = mContext.getContentResolver().query(MovieContract.MovieEntry.buildUriUnionFavorite(expected),
            null, null, null, null);/* w  ww.j a  v  a 2  s. c  o  m*/

    assertTrue(c.moveToFirst());
    assertEquals(2, c.getCount());
    assertEquals(expected.longValue(), c.getLong(0));
    assertTrue(c.moveToNext());
    assertTrue(c.getBlob(1).length > 0);
    c.close();

    mContext.getContentResolver().delete(MovieContract.FavoriteEntry.buildUri(),
            MovieContract.FavoriteEntry.COLUMN_MOVIE_ID + "=?", new String[] { expected.toString() });

    c = mContext.getContentResolver().query(MovieContract.MovieEntry.buildUriUnionFavorite(expected), null,
            null, null, null);

    assertTrue(c.moveToFirst());
    assertEquals(1, c.getCount());
    assertTrue(c.getBlob(1).length > 0);
}

From source file:com.example.diokey.sunshine.app.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city/*  ww  w. j a  v a2s.  c o  m*/
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
long addLocation(String locationSetting, String cityName, double lat, double lon) {
    // Students: First, check if the location with this city name exists in the db
    long locationId;
    Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);
    // If it exists, return the current ID
    if (locationCursor.moveToFirst()) {
        int locationIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(locationIndex);
    } else {
        // Otherwise, insert it using the content resolver and the base URI
        ContentValues contentValues = new ContentValues();
        contentValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        Uri locationUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                contentValues);

        locationId = ContentUris.parseId(locationUri);
    }

    return locationId;
}

From source file:com.whalesocks.sunshine.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city/*from  w  ww. j a v  a  2s .com*/
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
long addLocation(String locationSetting, String cityName, double lat, double lon) {
    // Students: First, check if the location with this city name exists in the db
    long locationId = 0;

    Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);

    if (locationCursor.moveToFirst()) {
        //Location found
        int localIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(localIndex);
    } else {
        ContentValues locationValues = new ContentValues();
        locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        Uri locationInsertUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                locationValues);
        if (locationInsertUri != null) {
            // inserted correctly
            locationId = ContentUris.parseId(locationInsertUri);
        }
    }
    locationCursor.close();
    // If it exists, return the current ID
    // Otherwise, insert it using the content resolver and the base URI
    return locationId;
}

From source file:edu.stanford.mobisocial.dungbeetle.MessagingManagerThread.java

@Override
public void run() {
    ProfileScanningObjHandler profileScanningObjHandler = new ProfileScanningObjHandler();
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    Set<Long> notSendingObjects = new HashSet<Long>();
    if (DBG)/*  w  w  w. j  av a2 s  .  co  m*/
        Log.i(TAG, "Running...");
    mMessenger.init();
    long max_sent = -1;
    while (!interrupted()) {
        mOco.waitForChange();
        mOco.clearChanged();
        Cursor objs = mHelper.queryUnsentObjects(max_sent);
        try {
            Log.i(TAG, "Sending " + objs.getCount() + " objects...");
            if (objs.moveToFirst())
                do {
                    Long objId = objs.getLong(objs.getColumnIndexOrThrow(DbObject._ID));
                    String jsonSrc = objs.getString(objs.getColumnIndexOrThrow(DbObject.JSON));

                    max_sent = objId.longValue();
                    JSONObject json = null;
                    if (jsonSrc != null) {
                        try {
                            json = new JSONObject(jsonSrc);
                        } catch (JSONException e) {
                            Log.e(TAG, "bad json", e);
                        }
                    } else {
                        json = new JSONObject();
                    }

                    if (json != null) {
                        /*
                         * if you update latest feed here then there is a
                         * race condition between when you put a message
                         * into your db, when you actually have a connection
                         * to send the message (which is here) when other
                         * people send you messages the processing gets all
                         * out of order, so instead we update latest
                         * immediately when you add messages into your db
                         * inside DBHelper.java addToFeed();
                         */
                        // mFeedModifiedObjHandler.handleObj(mContext,
                        // feedUri, objId);

                        // TODO: Don't be fooled! This is not truly an
                        // EncodedObj
                        // and does not yet have a hash.
                        DbObj signedObj = App.instance().getMusubi().objForId(objId);
                        if (signedObj == null) {
                            Log.e(TAG, "Error, object " + objId + " not found in database");
                            notSendingObjects.add(objId);
                            continue;
                        }
                        DbEntryHandler h = DbObjects.getObjHandler(json);
                        h.afterDbInsertion(mContext, signedObj);

                        // TODO: Constraint error thrown for now b/c local
                        // user not in contacts
                        profileScanningObjHandler.handleObj(mContext, h, signedObj);
                    }

                    OutgoingMessage m = new OutgoingMsg(objs);
                    if (m.contents().getRecipients().isEmpty()) {
                        Log.w(TAG, "No addressees for direct message " + objId);
                        notSendingObjects.add(objId);
                    } else {
                        mMessenger.sendMessage(m);
                    }
                } while (objs.moveToNext());
            if (notSendingObjects.size() > 0) {
                if (DBG)
                    Log.d(TAG, "Marking " + notSendingObjects.size() + " objects sent");
                mHelper.markObjectsAsSent(notSendingObjects);
                notSendingObjects.clear();
            }
        } catch (Exception e) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
                Log.wtf(TAG, "error running notify loop", e);
            } else {
                Log.e(TAG, "error running notify loop", e);
            }
        } finally {
            objs.close();
        }
    }
    mHelper.close();
}