# Transaction

# Transaction


```
public class Transaction
```

<br />

*** ** * ** ***

The Transaction class encapsulates the functionality needed to perform a transaction on the data at a location. To run a transaction, provide a `https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Handler` to `https://firebase.google.com/docs/reference/android/com/google/firebase/database/DatabaseReference#runTransaction(com.google.firebase.database.Transaction.Handler)`. That handler will be passed the current data at the location, and must return a `https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Result`. A `https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Result` can be created using either `https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction#success(com.google.firebase.database.MutableData)` or `https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction#abort()`.

## Summary

| ### Nested types |
|---|
| `public interface https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Handler` An object implementing this interface is used to run a transaction, and will be notified of the results of the transaction. |
| `public class https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Result` Instances of this class represent the desired outcome of a single run of a `https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Handler`'s doTransaction method. |

| ### Public constructors |
|---|
| `https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction#Transaction()()` |

| ### Public methods |
|---|---|
| `static @https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Result` | `https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction#abort()()` |
| `static @https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Result` | `https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction#success(com.google.firebase.database.MutableData)(@https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html https://firebase.google.com/docs/reference/android/com/google/firebase/database/MutableData resultData)` |

## Public constructors

### Transaction

```
public Transaction()
```

## Public methods

### abort

```
public static @NonNull Transaction.Result abort()
```

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Result` | A `https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Result` that aborts the transaction |

### success

```
public static @NonNull Transaction.Result success(@NonNull MutableData resultData)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html https://firebase.google.com/docs/reference/android/com/google/firebase/database/MutableData resultData` | The desired data at the location |

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Result` | A `https://firebase.google.com/docs/reference/android/com/google/firebase/database/Transaction.Result` indicating the new data to be stored at the location |