Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observe query #1470

Merged
merged 35 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7d2b358
Adding observe query api to datastore plugin. Work in progress.
poojamat Aug 23, 2021
15ef5cb
Moving queryProcessor instantiation inside thread.
poojamat Aug 24, 2021
c68bec7
Added code for ObserveQueryManager
poojamat Aug 26, 2021
afee334
Added code for ObserveQueryManager
poojamat Aug 29, 2021
c485ef6
Added code for ObserveQueryManager
poojamat Aug 30, 2021
047e782
Merge branch 'main' into observe-query
poojamat Aug 30, 2021
40a624d
Added collect and debounce based on time and record size. Added filte…
poojamat Sep 1, 2021
5b3a568
Added debounce based on time for item changed.
poojamat Sep 2, 2021
64506cf
Added complete item map to deal with deletes.
poojamat Sep 3, 2021
ecd555e
Added logic for sync status and passes in max records and lapse time …
poojamat Sep 8, 2021
0ac5e50
Small fixes.
poojamat Sep 10, 2021
e6a62f6
Adding logic for sorting.
poojamat Sep 14, 2021
bcfd3a4
Some fixes
poojamat Sep 17, 2021
b1c7853
Changes to support recent changes to observe query api. DataSnapshot …
poojamat Sep 23, 2021
302f839
check style changes.
poojamat Sep 24, 2021
d5f4be2
Adding observeQuery to kotlin facade and RxBindings.
poojamat Sep 24, 2021
be3262f
More unit tests.
poojamat Sep 28, 2021
230c11f
More unit tests.
poojamat Sep 28, 2021
2921ff8
PR suggestions and checkstyle changes.
poojamat Sep 28, 2021
725790a
PR suggestions.
poojamat Sep 29, 2021
6726067
Merge branch 'observe-query-main' into observe-query
poojamat Sep 29, 2021
90bf875
Merging master.
poojamat Sep 29, 2021
42ef92b
Lint error fix.
poojamat Sep 29, 2021
9928e24
Lint error fix.
poojamat Sep 29, 2021
8f46339
Lint error fix.
poojamat Sep 29, 2021
e4a8a39
unit test fix
poojamat Sep 29, 2021
992688e
Fix for unit test timing out
poojamat Sep 29, 2021
9c4e080
Integration test fix.
poojamat Sep 30, 2021
c9c9d23
Integration test fix.
poojamat Sep 30, 2021
3e68c0d
Merge branch 'main' into observe-query
poojamat Sep 30, 2021
6d85eb9
Integration test fix.
poojamat Sep 30, 2021
f40eb87
Merge branch 'observe-query' of https://github.com/aws-amplify/amplif…
poojamat Sep 30, 2021
1ac68c1
unit test fix.
poojamat Sep 30, 2021
f6b3dc6
unit test fix adding longer wait for latch to countdown.
poojamat Sep 30, 2021
e75e96c
unit test fix adding longer wait for latch to countdown.
poojamat Sep 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand All @@ -18,14 +18,19 @@
import android.content.Context;
import androidx.annotation.NonNull;

import com.amplifyframework.core.Action;
import com.amplifyframework.core.Consumer;
import com.amplifyframework.core.async.Cancelable;
import com.amplifyframework.core.model.Model;
import com.amplifyframework.core.model.ModelSchema;
import com.amplifyframework.core.model.query.ObserveQueryOptions;
import com.amplifyframework.core.model.query.QueryOptions;
import com.amplifyframework.core.model.query.Where;
import com.amplifyframework.core.model.query.predicate.QueryPredicate;
import com.amplifyframework.core.model.query.predicate.QueryPredicates;
import com.amplifyframework.datastore.DataStoreConfiguration;
import com.amplifyframework.datastore.DataStoreException;
import com.amplifyframework.datastore.DataStoreQuerySnapshot;
import com.amplifyframework.testutils.Await;
import com.amplifyframework.testutils.VoidResult;

Expand Down Expand Up @@ -93,8 +98,20 @@ public static SynchronousStorageAdapter create(
public List<ModelSchema> initialize(@NonNull Context context) throws DataStoreException {
return Await.result(
operationTimeoutMs,
(Consumer<List<ModelSchema>> onResult, Consumer<DataStoreException> onError) ->
asyncDelegate.initialize(context, onResult, onError)
(Consumer<List<ModelSchema>> onResult, Consumer<DataStoreException> onError) -> {
try {
asyncDelegate.initialize(context,
onResult,
onError,
DataStoreConfiguration.builder()
.syncInterval(2L, TimeUnit.MINUTES)
.observeQueryMaxRecords(2)
.observeQueryMaxTime(0)
.build());
} catch (DataStoreException exception) {
onError.accept(exception);
}
}
);
}

Expand Down Expand Up @@ -206,6 +223,31 @@ public <T extends Model> List<T> query(@NonNull Class<T> modelClass, @NonNull Qu
return resultSet;
}

/**
* Query the storage adapter for models of a given class, and considering some additional criteria
* that each model must meet.
* @param modelClass Class of models being queried
* @param options Query options with predicate and pagination info
* @param <T> Type of model being queried
* @param onObservationStarted callback for canceling the subscription
* @param onQuerySnapshot callback for DataStoreQuerySnapshot
* @param onObservationError callback for DataStoreException
* @param onObservationComplete callback for onObservationComplete
*/
public <T extends Model> void observeQuery(@NonNull Class<T> modelClass,
@NonNull ObserveQueryOptions options,
@NonNull Consumer<Cancelable> onObservationStarted,
@NonNull Consumer<DataStoreQuerySnapshot<T>> onQuerySnapshot,
@NonNull Consumer<DataStoreException> onObservationError,
@NonNull Action onObservationComplete) {
asyncDelegate.observeQuery(modelClass,
options,
onObservationStarted,
onQuerySnapshot,
onObservationError,
onObservationComplete);
}

/**
* Delete a model, unconditionally. Expect success.
* @param model A model to be deleted
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand All @@ -19,9 +19,11 @@
import androidx.test.core.app.ApplicationProvider;

import com.amplifyframework.AmplifyException;
import com.amplifyframework.core.Amplify;
import com.amplifyframework.core.Consumer;
import com.amplifyframework.core.model.ModelSchema;
import com.amplifyframework.core.model.SchemaRegistry;
import com.amplifyframework.datastore.DataStoreConfiguration;
import com.amplifyframework.datastore.DataStoreException;
import com.amplifyframework.datastore.StrictMode;
import com.amplifyframework.datastore.model.CompoundModelProvider;
Expand Down Expand Up @@ -105,8 +107,16 @@ public void modelVersionStoredCorrectlyBeforeAndAfterUpgrade() throws AmplifyExc
sqliteStorageAdapter = SQLiteStorageAdapter.forModels(schemaRegistry, modelProvider);
List<ModelSchema> firstResults = Await.result(
SQLITE_OPERATION_TIMEOUT_MS,
(Consumer<List<ModelSchema>> onResult, Consumer<DataStoreException> onError) ->
sqliteStorageAdapter.initialize(context, onResult, onError)
(Consumer<List<ModelSchema>> onResult, Consumer<DataStoreException> onError) -> {
try {
sqliteStorageAdapter.initialize(context, onResult, onError,
DataStoreConfiguration.builder()
.syncInterval(2L, TimeUnit.MINUTES)
.build());
} catch (DataStoreException exception) {
Amplify.Logging.forNamespace("amplify:aws-datastore").warn(exception.toString());
}
}
);
// Assert if initialize succeeds.
assertFalse(Empty.check(firstResults));
Expand Down Expand Up @@ -135,8 +145,16 @@ public void modelVersionStoredCorrectlyBeforeAndAfterUpgrade() throws AmplifyExc
// Now, initialize storage adapter with the new models
List<ModelSchema> secondResults = Await.result(
SQLITE_OPERATION_TIMEOUT_MS,
(Consumer<List<ModelSchema>> onResult, Consumer<DataStoreException> onError) ->
sqliteStorageAdapter.initialize(context, onResult, onError)
(Consumer<List<ModelSchema>> onResult, Consumer<DataStoreException> onError) -> {
try {
sqliteStorageAdapter.initialize(context, onResult, onError,
DataStoreConfiguration.builder()
.syncInterval(2L, TimeUnit.MINUTES)
.build());
} catch (DataStoreException exception) {
Amplify.Logging.forNamespace("amplify:aws-datastore").warn(exception.toString());
}
}
);
assertFalse(Empty.check(secondResults));

Expand Down
Loading