Skip to content

Need more example in Transaction Insert and Query #44

Open

Description

@GulajavaMinistudio

From this documentation, there are several transaction in ObjectBox
http://objectbox.io/documentation/transactions/

The class BoxStore offers the following methods to perform explicit transactions:
runInTx: Runs the given runnable inside a transaction.
runInReadTx: Runs the given runnable inside a read(-only) transaction. Unlike write transactions, multiple read transactions can run at the same time.
runInTxAsync: Runs the given Runnable as a transaction in a separate thread. Once the transaction completes the given callback is called (callback may be null).
callInTx: Like runInTx(Runnable), but allows returning a value and throwing an exception.

But I found little confused for runInTxAsync implementation. Any good example about how to implementation those transaction ?

Activity

  1. greenrobot-team commented on Jun 19, 2018

    @greenrobot-team
    Member

    I suppose looking at the implementation of BoxStore.runInTxAsync can clear things up for you? It's basically the same as runInTx, except the Runnable is submitted to a thread pool and you get a callback once the transaction is done.

    Simple example:

    boxStore.runInTxAsync(new Runnable() {
        @Override
        public void run() {
            notesBox.put(note);
            ...
        }
    }, new TxCallback<Void>() {
        @Override
        public void txFinished(@Nullable Void result, @Nullable Throwable error) {
            // transaction is done! do something?
        }
    });

    We maybe could add examples for this.
    -ut

  2. GulajavaMinistudio commented on Jun 24, 2018

    @GulajavaMinistudio
    Author

    Thank you for response. Yes there's need addition in Documentation and Examples about every Transactions methods .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions