public final int storeSession(final Session session,final boolean invalidateActive){
  if (session == null) {
    Log.e(TAG,"Error storing session: Session is null");
    return 0;
  }
  if (invalidateActive) {
    invalidateActiveSessions();
  }
  final Cursor cursor=contentResolver.query(ContentUris.withAppendedId(ContentProvider.CONTENT_URI_SESSION,session.getId()),null,null,null,null);
  if (!cursor.moveToNext()) {
    storeSession(session);
    cursor.close();
    return 1;
  }
 else {
    Log.d(TAG,"Updating existing session " + session.getId());
    final ContentValues values=new ContentValues();
    values.put(Schema.COL_CREATED_AT,session.getCreatedAt());
    values.put(Schema.COL_LAST_UPDATED,session.getLastUpdated());
    values.put(Schema.COL_DESCRIPTION,session.getDescription());
    values.put(Schema.COL_HAS_BEEN_EXPORTED,session.hasBeenExported());
    values.put(Schema.COL_IS_ACTIVE,session.isActive());
    values.put(Schema.COL_NUMBER_OF_CELLS,session.getCellsCount());
    values.put(Schema.COL_NUMBER_OF_WIFIS,session.getWifisCount());
    values.put(Schema.COL_NUMBER_OF_WAYPOINTS,session.getWaypointsCount());
    cursor.close();
    return contentResolver.update(ContentProvider.CONTENT_URI_SESSION,values,Schema.COL_ID + " = ?",new String[]{String.valueOf(session.getId())});
  }
}

public final int storeSession ( final Session session , final boolean invalidateActive ) { if ( session == null ) { Log . e ( TAG , "Error storing session: Session is null" ) ; return 0 ; } if ( invalidateActive ) { invalidateActiveSessions ( ) ; } final Cursor cursor = contentResolver . query ( ContentUris . withAppendedId ( ContentProvider . CONTENT_URI_SESSION , session . getId ( ) ) , null , null , null , null ) ; if ( ! cursor . moveToNext ( ) ) { storeSession ( session ) ; cursor . close ( ) ; return 1 ; } else { Log . d ( TAG , "Updating existing session " + session . getId ( ) ) ; final ContentValues values = new ContentValues ( ) ; values . put ( Schema . COL_CREATED_AT , session . getCreatedAt ( ) ) ; values . put ( Schema . COL_LAST_UPDATED , session . getLastUpdated ( ) ) ; values . put ( Schema . COL_DESCRIPTION , session . getDescription ( ) ) ; values . put ( Schema . COL_HAS_BEEN_EXPORTED , session . hasBeenExported ( ) ) ; values . put ( Schema . COL_IS_ACTIVE , session . isActive ( ) ) ; values . put ( Schema . COL_NUMBER_OF_CELLS , session . getCellsCount ( ) ) ; values . put ( Schema . COL_NUMBER_OF_WIFIS , session . getWifisCount ( ) ) ; values . put ( Schema . COL_NUMBER_OF_WAYPOINTS , session . getWaypointsCount ( ) ) ; cursor . close ( ) ; return contentResolver . update ( ContentProvider . CONTENT_URI_SESSION , values , Schema . COL_ID + " = ?" , new String [ ] { String . valueOf ( session . getId ( ) ) } ) ; } }
persists given session in database . if session already exists , session is updated , otherwise new session is created
