From 8a082f950b0813cd96d01b0261ddb84fd57d2057 Mon Sep 17 00:00:00 2001 From: Diego Medina Date: Fri, 7 Jul 2017 14:03:25 -0300 Subject: [PATCH 1/2] Added the ability to fetch a single entity with sql conditions --- .../xmartlabs/bigbang/core/controller/EntityDao.java | 11 +++++++++++ .../bigbang/dbflow/controller/DbFlowController.java | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/core/src/main/java/com/xmartlabs/bigbang/core/controller/EntityDao.java b/core/src/main/java/com/xmartlabs/bigbang/core/controller/EntityDao.java index afe825e0..0e6a784c 100644 --- a/core/src/main/java/com/xmartlabs/bigbang/core/controller/EntityDao.java +++ b/core/src/main/java/com/xmartlabs/bigbang/core/controller/EntityDao.java @@ -44,6 +44,17 @@ public interface EntityDao { @NonNull Maybe getEntity(@NonNull Id id); + /** + * Retrieves the entity that satisfies the conditions, if any + * If more than one entity satisfy the conditions, the first one will be returned + * + * @param conditions to find the entity + * @return + */ + @CheckResult + @NonNull + Maybe getEntity(@NonNull Condition... conditions); + /** * Creates the {@code entity} and returns it. * diff --git a/dbflow/src/main/java/com/xmartlabs/bigbang/dbflow/controller/DbFlowController.java b/dbflow/src/main/java/com/xmartlabs/bigbang/dbflow/controller/DbFlowController.java index 23692a01..287c05d3 100644 --- a/dbflow/src/main/java/com/xmartlabs/bigbang/dbflow/controller/DbFlowController.java +++ b/dbflow/src/main/java/com/xmartlabs/bigbang/dbflow/controller/DbFlowController.java @@ -81,6 +81,18 @@ public Maybe getEntity(@NonNull Id id) { .subscribeOn(Schedulers.io()); } + @CheckResult + @NonNull + @Override + public Maybe getEntity(@NonNull SQLOperator... conditions) { + return Maybe + .fromCallable(() -> new Select() + .from(getModelClass()) + .where(conditions) + .querySingle()) + .subscribeOn(Schedulers.io()); + } + @CheckResult @NonNull @Override From 8c1397c5e5b4d2a3e20039f71f232dbb396398c2 Mon Sep 17 00:00:00 2001 From: Diego Medina Date: Thu, 27 Jul 2017 11:53:33 -0300 Subject: [PATCH 2/2] PR comment --- .../java/com/xmartlabs/bigbang/core/controller/EntityDao.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/xmartlabs/bigbang/core/controller/EntityDao.java b/core/src/main/java/com/xmartlabs/bigbang/core/controller/EntityDao.java index 0e6a784c..b0ce7a49 100644 --- a/core/src/main/java/com/xmartlabs/bigbang/core/controller/EntityDao.java +++ b/core/src/main/java/com/xmartlabs/bigbang/core/controller/EntityDao.java @@ -49,7 +49,7 @@ public interface EntityDao { * If more than one entity satisfy the conditions, the first one will be returned * * @param conditions to find the entity - * @return + * @return the entity, if exists */ @CheckResult @NonNull