use of com.amplifyframework.core.model.query.predicate.QueryPredicate in project amplify-android by aws-amplify.
the class InMemoryStorageAdapter method query.
@Override
public void query(@NonNull String modelName, @NonNull QueryOptions options, @NonNull Consumer<Iterator<? extends Model>> onSuccess, @NonNull Consumer<DataStoreException> onError) {
final List<Model> result = new ArrayList<>();
final QueryPredicate predicate = options.getQueryPredicate();
for (Model item : items) {
if (modelName.equals(item.getClass().getSimpleName()) && predicate.evaluate(item)) {
// TODO, add tests for new query method.
result.add(item);
}
}
onSuccess.accept(result.iterator());
}
use of com.amplifyframework.core.model.query.predicate.QueryPredicate in project amplify-android by aws-amplify.
the class InMemoryStorageAdapter method query.
// (T) item *is* checked, via isAssignableFrom().
@SuppressWarnings("unchecked")
@Override
public <T extends Model> void query(@NonNull final Class<T> itemClass, @NonNull final QueryOptions options, @NonNull final Consumer<Iterator<T>> onSuccess, @NonNull final Consumer<DataStoreException> onError) {
final List<T> result = new ArrayList<>();
final QueryPredicate predicate = options.getQueryPredicate();
for (Model item : items) {
if (itemClass.isAssignableFrom(item.getClass()) && predicate.evaluate(item)) {
result.add((T) item);
}
}
onSuccess.accept(result.iterator());
}
use of com.amplifyframework.core.model.query.predicate.QueryPredicate in project amplify-android by aws-amplify.
the class SQLCommandProcessorTest method executeExistsReturnsFalseWhenItemDoesntExist.
/**
* Create a BlogOwner, but don't insert it. Then verify that executeExists returns false.
* @throws AmplifyException on failure to create ModelSchema from class.
*/
@Test
public void executeExistsReturnsFalseWhenItemDoesntExist() throws AmplifyException {
// Create a BlogOwner, but don't insert it
ModelSchema blogOwnerSchema = ModelSchema.fromModelClass(BlogOwner.class);
BlogOwner abigailMcGregor = BlogOwner.builder().name("Abigail McGregor").build();
QueryPredicate predicate = BlogOwner.ID.eq(abigailMcGregor.getId());
SqlCommand existsCommand = sqlCommandFactory.existsFor(blogOwnerSchema, predicate);
assertFalse(sqlCommandProcessor.executeExists(existsCommand));
}
use of com.amplifyframework.core.model.query.predicate.QueryPredicate in project amplify-android by aws-amplify.
the class SQLPredicateTest method testContainsForStringField.
/**
* Test contains in the context of a String field.
* @throws DataStoreException Not thrown.
*/
@Test
public void testContainsForStringField() throws DataStoreException {
QueryPredicate predicate = Where.matches(Blog.NAME.contains("something")).getQueryPredicate();
SQLPredicate sqlPredicate = new SQLPredicate(predicate);
validateSQLExpressionForContains(sqlPredicate, "name");
}
use of com.amplifyframework.core.model.query.predicate.QueryPredicate in project amplify-android by aws-amplify.
the class SQLPredicateTest method testNotContainsForStringField.
/**
* Test notContains in the context of a String field.
* @throws DataStoreException Not thrown.
*/
@Test
public void testNotContainsForStringField() throws DataStoreException {
QueryPredicate predicate = Where.matches(Blog.NAME.notContains("something")).getQueryPredicate();
SQLPredicate sqlPredicate = new SQLPredicate(predicate);
validateSQLExpressionForNotContains(sqlPredicate, "name");
}
Aggregations