/**
  * Queries uncompleted partUpload tasks of a multipart upload and constructs a UploadPartRequest
  * for each task. It's used when resuming a multipart upload
  *
  * @param mainUploadId The mainUploadId of a multipart upload task
  * @param multipartId The multipartId of a multipart upload task
  * @return A list of UploadPartRequest
  */
 public List<UploadPartRequest> getNonCompletedPartRequestsFromDB(
     int mainUploadId, String multipartId) {
   ArrayList<UploadPartRequest> list = new ArrayList<UploadPartRequest>();
   Cursor c = transferDBBase.query(getPartUri(mainUploadId), null, null, null, null);
   while (c.moveToNext()) {
     if (TransferState.PART_COMPLETED.equals(
         TransferState.getState(
             c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_STATE))))) {
       continue;
     }
     UploadPartRequest putPartRequest =
         new UploadPartRequest()
             .withId(c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_ID)))
             .withMainUploadId(
                 c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_MAIN_UPLOAD_ID)))
             .withBucketName(
                 c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_BUCKET_NAME)))
             .withKey(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_KEY)))
             .withUploadId(multipartId)
             .withFile(new File(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_FILE))))
             .withFileOffset(c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_FILE_OFFSET)))
             .withPartNumber(c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_PART_NUM)))
             .withPartSize(c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_BYTES_TOTAL)))
             .withLastPart(
                 1 == c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_IS_LAST_PART)));
     list.add(putPartRequest);
   }
   c.close();
   return list;
 }
 /**
  * Queries the transfer record specified by main upload id.
  *
  * @param mainUploadId The mainUploadId of a multipart upload task
  * @return The bytes already uploaded for this multipart upload task
  */
 public long queryBytesTransferredByMainUploadId(int mainUploadId) {
   Cursor c = transferDBBase.query(getPartUri(mainUploadId), null, null, null, null);
   long bytesTotal = 0;
   while (c.moveToNext()) {
     String state = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_STATE));
     if (TransferState.PART_COMPLETED.equals(TransferState.getState(state))) {
       bytesTotal += c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_BYTES_TOTAL));
     }
   }
   c.close();
   return bytesTotal;
 }