Return to Video

Efficient Updates Inserts - Developing Android Apps

  • 0:00 - 0:03
    Let's take the look at the
    implementation, of an optional method,
  • 0:03 - 0:05
    we've got in the content provider.
  • 0:05 - 0:07
    Anyone out there who has
    done work with SQLite,
  • 0:07 - 0:10
    knows that putting a bunch of
    inserts into a single transaction is
  • 0:10 - 0:13
    much faster than inserting
    them individually.
  • 0:13 - 0:15
    BulkInsert allows us to do that.
  • 0:15 - 0:19
    The default implementation,
    just calls insert a bunch of times.
  • 0:19 - 0:23
    But, we can wrap it in a transaction,
    if we implement it ourselves.
  • 0:23 - 0:26
    Note that we've only added support for
    weather forecast transactions here,
  • 0:26 - 0:29
    since they are the only
    ones we insert in bulk.
  • 0:29 - 0:32
    We start by calling db.beginTransaction.
  • 0:32 - 0:37
    For each of the content values
    passed in, we insert and
  • 0:37 - 0:39
    update the number of records inserted.
  • 0:39 - 0:43
    When we're done,
    we set the transaction to be successful.
  • 0:43 - 0:46
    And then rely on the finally
    statement endTransaction.
  • 0:46 - 0:49
    Note, that if we do not set
    the transaction to be successful,
  • 0:49 - 0:52
    the records will not be committed
    when we call endTransaction.
Title:
Efficient Updates Inserts - Developing Android Apps
Description:

more » « less
Video Language:
English
Team:
Udacity
Project:
UD853 - Developing Android Apps
Duration:
0:53

English subtitles

Revisions Compare revisions