title: Database(SQLite) transaction for downstream operators with rxJava
body: <p>Assuming i have some stream of items:</p>
  
  <pre><code>Observable&lt;Item&gt; stream = ...
  </code></pre>
  
  <p>What am i trying to achieve? </p>
  
  <ul>
  <li>Stream has any amount of operations. All operations before beginning a transaction should be run outside of the transaction</li>
  <li>Somehow start transaction in the middle of the stream <code>db.beginTransaction()</code></li>
  <li>All operators after starting transaction should be run inside the transaction</li>
  <li>Transaction have to be completed in case of successful operations <code>db.setTransactionSuccessful</code></li>
  <li>Transaction have to be always ended <code>db.endTransaction</code></li>
  <li>It will be great to have both snippets : open <strong>one</strong> transaction for all items in downstream operations; open and close transaction for <strong>each</strong> item in the stream</li>
  </ul>
  
  <blockquote>
    <p></p>
  </blockquote>
  
  <pre><code>//some upstream operators
  stream.doOnNext(i -&gt; ...)
      .map(i -&gt; ...)
      //somehow start transaction here
      //operator inside transaction. All database changes will be reverted in case error
      .doOnNext(i -&gt; /*database ops*/)
      .subscribe()
  </code></pre>
  
  <p>PS: db is application scoped instance of writable <code>SQLiteDatabase</code></p>
  
  <p>I have a solution now. But maybe you have any suggestions about more cleaner way?        </p>