<BlockSwitcher>
<Block name="Java">

```java
QueryOptions queryOptions = null;
try {
    queryOptions = Where.identifier(Post.class, "123");
} catch (AmplifyException e) {
    Log.e("MyAmplifyApp", "Failed to construct QueryOptions with provided values for Where.identifier", e);
}

if (queryOptions != null) {
    Amplify.DataStore.query(Post.class, queryOptions,
        matches -> {
            if (matches.hasNext()) {
                Post original = matches.next();
                Post edited = original.copyOfBuilder()
                    .title("New Title")
                    .build();
                Amplify.DataStore.save(edited,
                    updated -> Log.i("MyAmplifyApp", "Updated a post."),
                    failure -> Log.e("MyAmplifyApp", "Update failed.", failure)
                );
            }
        },
        failure -> Log.e("MyAmplifyApp", "Query failed.", failure)
    );
} 
```

</Block>
<Block name="Kotlin - Callbacks">

```kotlin
Amplify.DataStore.query(Post::class.java, Where.identifier(Post::class.java, "123"),
    { matches ->
        if (matches.hasNext()) {
            val original = matches.next()
            val edited = original.copyOfBuilder()
                .title("New Title")
                .build()
            Amplify.DataStore.save(edited,
                { Log.i("MyAmplifyApp", "Updated a post") },
                { Log.e("MyAmplifyApp", "Update failed", it) }
            )
        }
    },
    { Log.e("MyAmplifyApp", "Query failed", it) }
)
```

</Block>
<Block name="Kotlin - Coroutines">

```kotlin
Amplify.DataStore.query(Post::class, Where.identifier(Post::class.java, "123"))
    .catch { Log.e("MyAmplifyApp", "Query failed", it) }
    .map { it.copyOfBuilder().title("New Title").build() }
    .onEach { Amplify.DataStore.save(it) }
    .catch { Log.e("MyAmplifyApp", "Update failed", it) }
    .collect { Log.i("MyAmplifyApp", "Updated a post") }
```

</Block>
<Block name="RxJava">

```java
QueryOptions queryOptions = null;
try {
    queryOptions = Where.identifier(Post.class, "123");
} catch (AmplifyException e) {
    Log.e("MyAmplifyApp", "Failed to construct QueryOptions with provided values for Where.identifier", e);
}

if (queryOptions != null) {
    RxAmplify.DataStore.query(Post.class, queryOptions)
        .map(matchingPost -> matchingPost.copyOfBuilder()
            .title("New Title")
            .build()
        )
        .flatMapCompletable(RxAmplify.DataStore::save)
        .subscribe(
            () -> Log.i("MyAmplifyApp", "Query and update succeeded."),
            failure -> Log.e("MyAmplifyApp", "Update failed.", failure)
        );
}
```

</Block>
</BlockSwitcher>

<Callout>

Models in DataStore are *immutable*. Instead of directly modifying the fields on a Model, you must use the `.copyOfBuilder()` method to create a new representation of the model.

</Callout>
