Skip to content

Commit ec610e5

Browse files
committed
Android implementation
1 parent 2ea9c3f commit ec610e5

File tree

12 files changed

+367
-25
lines changed

12 files changed

+367
-25
lines changed

firestore/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ set(android_SRCS
9898
src/android/field_path_portable.h
9999
src/android/field_value_android.cc
100100
src/android/field_value_android.h
101+
src/android/filter_android.cc
102+
src/android/filter_android.h
101103
src/android/firestore_android.cc
102104
src/android/firestore_android.h
103105
src/android/firestore_exceptions_android.h

firestore/integration_test_internal/integration_test.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
12CCF1E928FDBD9F00C24941 /* set_options_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 12CCF1DF28FDBD9F00C24941 /* set_options_test.cc */; };
2222
12D513142684C8C200A83FAA /* bundle_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 12D513132684C8C200A83FAA /* bundle_test.cc */; };
2323
12D5131A2684C8D100A83FAA /* bundle_builder.cc in Sources */ = {isa = PBXBuildFile; fileRef = 12D513182684C8D100A83FAA /* bundle_builder.cc */; };
24+
1BAFACA32A449C2B00834979 /* aggregate_query_snapshot_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1BAFACA02A449C2B00834979 /* aggregate_query_snapshot_test.cc */; };
25+
1BAFACA42A449C2B00834979 /* aggregate_query_snapshot_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1BAFACA02A449C2B00834979 /* aggregate_query_snapshot_test.cc */; };
26+
1BAFACA52A449C2B00834979 /* aggregate_count_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1BAFACA12A449C2B00834979 /* aggregate_count_test.cc */; };
27+
1BAFACA62A449C2B00834979 /* aggregate_count_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1BAFACA12A449C2B00834979 /* aggregate_count_test.cc */; };
28+
1BAFACA72A449C2B00834979 /* aggregate_query_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1BAFACA22A449C2B00834979 /* aggregate_query_test.cc */; };
29+
1BAFACA82A449C2B00834979 /* aggregate_query_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1BAFACA22A449C2B00834979 /* aggregate_query_test.cc */; };
30+
1BAFACAA2A449CBD00834979 /* filter_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1BAFACA92A449CBD00834979 /* filter_test.cc */; };
31+
1BAFACAB2A449CBD00834979 /* filter_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1BAFACA92A449CBD00834979 /* filter_test.cc */; };
2432
520BC0391C869159008CFBC3 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 520BC0381C869159008CFBC3 /* GoogleService-Info.plist */; };
2533
5270BB448DF5ECE860FDD68B /* firebase_firestore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAFAF9474EC412ADCC65F2CC /* firebase_firestore.framework */; };
2634
529226D61C85F68000C89379 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 529226D51C85F68000C89379 /* Foundation.framework */; };
@@ -123,6 +131,10 @@
123131
12D513182684C8D100A83FAA /* bundle_builder.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bundle_builder.cc; path = src/util/bundle_builder.cc; sourceTree = "<group>"; };
124132
12D513192684C8D100A83FAA /* bundle_builder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = bundle_builder.h; path = src/util/bundle_builder.h; sourceTree = "<group>"; };
125133
1B3D64B35A22073C76B376D5 /* libPods-integration_test_tvos.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-integration_test_tvos.a"; sourceTree = BUILT_PRODUCTS_DIR; };
134+
1BAFACA02A449C2B00834979 /* aggregate_query_snapshot_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = aggregate_query_snapshot_test.cc; path = src/aggregate_query_snapshot_test.cc; sourceTree = "<group>"; };
135+
1BAFACA12A449C2B00834979 /* aggregate_count_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = aggregate_count_test.cc; path = src/aggregate_count_test.cc; sourceTree = "<group>"; };
136+
1BAFACA22A449C2B00834979 /* aggregate_query_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = aggregate_query_test.cc; path = src/aggregate_query_test.cc; sourceTree = "<group>"; };
137+
1BAFACA92A449CBD00834979 /* filter_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = filter_test.cc; path = src/filter_test.cc; sourceTree = "<group>"; };
126138
3DE393E827F88B06CD3C39CD /* Pods-integration_test_tvos.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-integration_test_tvos.release.xcconfig"; path = "Target Support Files/Pods-integration_test_tvos/Pods-integration_test_tvos.release.xcconfig"; sourceTree = "<group>"; };
127139
4AAFA3E3DA9641C2E3C46C9D /* Pods_integration_test.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_integration_test.framework; sourceTree = BUILT_PRODUCTS_DIR; };
128140
520BC0381C869159008CFBC3 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
@@ -281,6 +293,10 @@
281293
5292271D1C85FB5500C89379 /* src */ = {
282294
isa = PBXGroup;
283295
children = (
296+
1BAFACA92A449CBD00834979 /* filter_test.cc */,
297+
1BAFACA12A449C2B00834979 /* aggregate_count_test.cc */,
298+
1BAFACA02A449C2B00834979 /* aggregate_query_snapshot_test.cc */,
299+
1BAFACA22A449C2B00834979 /* aggregate_query_test.cc */,
284300
12CCF1DF28FDBD9F00C24941 /* set_options_test.cc */,
285301
12CCF1DB28FDBD9E00C24941 /* settings_test.cc */,
286302
12CCF1DC28FDBD9F00C24941 /* source_test.cc */,
@@ -576,12 +592,14 @@
576592
D62CCBC022F367140099BE9F /* gmock-all.cc in Sources */,
577593
D61CFBC126091C3B0035CB2A /* integration_test.cc in Sources */,
578594
D6AAAD532606C22D0025C53B /* includes_test.cc in Sources */,
595+
1BAFACA52A449C2B00834979 /* aggregate_count_test.cc in Sources */,
579596
D6AAAD502606C22D0025C53B /* numeric_transforms_test.cc in Sources */,
580597
D6ED33BE2606CD890058CBF9 /* integration_test_util.cc in Sources */,
581598
D6C179EA22CB322900C2651A /* ios_firebase_test_framework.mm in Sources */,
582599
12CCF1E228FDBD9F00C24941 /* source_test.cc in Sources */,
583600
D6AAAD4C2606C22D0025C53B /* server_timestamp_test.cc in Sources */,
584601
D6AAAD4E2606C22D0025C53B /* firestore_test.cc in Sources */,
602+
1BAFACAA2A449CBD00834979 /* filter_test.cc in Sources */,
585603
D6AAAD452606C22D0025C53B /* document_change_test.cc in Sources */,
586604
D6AAAD472606C22D0025C53B /* document_snapshot_test.cc in Sources */,
587605
D6C179E922CB322900C2651A /* ios_app_framework.mm in Sources */,
@@ -591,7 +609,9 @@
591609
EDEEC7632800CD0000EFBAAF /* leveldb_snappy_test.cc in Sources */,
592610
12CCF1E828FDBD9F00C24941 /* set_options_test.cc in Sources */,
593611
D6AAAD562606C22D0025C53B /* query_network_test.cc in Sources */,
612+
1BAFACA72A449C2B00834979 /* aggregate_query_test.cc in Sources */,
594613
D6AAAD552606C22D0025C53B /* listener_registration_test.cc in Sources */,
614+
1BAFACA32A449C2B00834979 /* aggregate_query_snapshot_test.cc in Sources */,
595615
12D5131A2684C8D100A83FAA /* bundle_builder.cc in Sources */,
596616
D6AAAD4A2606C22D0025C53B /* fields_test.cc in Sources */,
597617
D6AAAD462606C22D0025C53B /* query_test.cc in Sources */,
@@ -610,6 +630,8 @@
610630
isa = PBXSourcesBuildPhase;
611631
buildActionMask = 2147483647;
612632
files = (
633+
1BAFACAB2A449CBD00834979 /* filter_test.cc in Sources */,
634+
1BAFACA62A449C2B00834979 /* aggregate_count_test.cc in Sources */,
613635
BC1D6850267B00EB005DC2DA /* app_framework.cc in Sources */,
614636
BC1D6853267B00EB005DC2DA /* transaction_extra_test.cc in Sources */,
615637
BC1D683E267B00EB005DC2DA /* integration_test_util.cc in Sources */,
@@ -623,6 +645,7 @@
623645
BC1D6848267B00EB005DC2DA /* sanity_test.cc in Sources */,
624646
12CCF1E728FDBD9F00C24941 /* write_batch_test.cc in Sources */,
625647
12CCF1E128FDBD9F00C24941 /* settings_test.cc in Sources */,
648+
1BAFACA82A449C2B00834979 /* aggregate_query_test.cc in Sources */,
626649
BC1D6856267B00EE005DC2DA /* ios_app_framework.mm in Sources */,
627650
BC1D6843267B00EB005DC2DA /* numeric_transforms_test.cc in Sources */,
628651
BC1D6844267B00EB005DC2DA /* array_transform_test.cc in Sources */,
@@ -632,6 +655,7 @@
632655
BC1D684E267B00EB005DC2DA /* includes_test.cc in Sources */,
633656
BC1D684C267B00EB005DC2DA /* document_change_test.cc in Sources */,
634657
BC1D6851267B00EB005DC2DA /* firestore_integration_test.cc in Sources */,
658+
1BAFACA42A449C2B00834979 /* aggregate_query_snapshot_test.cc in Sources */,
635659
BC1D6838267B00EB005DC2DA /* future_test_util.cc in Sources */,
636660
12CCF1E528FDBD9F00C24941 /* validation_test.cc in Sources */,
637661
BC1D6839267B00EB005DC2DA /* type_test.cc in Sources */,

firestore/integration_test_internal/src/aggregate_count_test.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,9 @@
2828
#include "firestore_integration_test.h"
2929
#include "util/event_accumulator.h"
3030

31-
#if defined(__ANDROID__)
32-
#include "firestore/src/android/query_android.h"
33-
#include "firestore/src/common/wrapper_assertions.h"
34-
#endif // defined(__ANDROID__)
35-
3631
#include "Firestore/core/src/util/firestore_exceptions.h"
3732
#include "firebase/firestore/firestore_errors.h"
3833
#include "firebase_test_framework.h"
39-
#include "gmock/gmock.h"
4034
#include "gtest/gtest.h"
4135

4236
namespace firebase {
@@ -757,15 +751,5 @@ TEST_F(AggregateCountTest,
757751
EXPECT_EQ(aggregate_query2, aggregate_snapshot2.query());
758752
}
759753

760-
#if defined(__ANDROID__)
761-
TEST(QueryTestAndroidStub, Construction) {
762-
testutil::AssertWrapperConstructionContract<Query>();
763-
}
764-
765-
TEST(QueryTestAndroidStub, Assignment) {
766-
testutil::AssertWrapperAssignmentContract<Query>();
767-
}
768-
#endif // defined(__ANDROID__)
769-
770754
} // namespace firestore
771755
} // namespace firebase

firestore/integration_test_internal/src/aggregate_query_test.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
#include "firebase/firestore.h"
1818
#include "firestore_integration_test.h"
1919

20+
#if defined(__ANDROID__)
21+
#include "firestore/src/android/aggregate_query_android.h"
22+
#include "firestore/src/common/wrapper_assertions.h"
23+
#endif // defined(__ANDROID__)
24+
2025
#include "gtest/gtest.h"
2126

2227
namespace firebase {
@@ -332,6 +337,16 @@ TEST_F(AggregateQueryTest, TestHashCode) {
332337
AggregateQueryHash(query1.Count()));
333338
}
334339

340+
#if defined(__ANDROID__)
341+
TEST(QueryTestAndroidStub, Construction) {
342+
testutil::AssertWrapperConstructionContract<AggregateQuery>();
343+
}
344+
345+
TEST(QueryTestAndroidStub, Assignment) {
346+
testutil::AssertWrapperAssignmentContract<AggregateQuery>();
347+
}
348+
#endif // defined(__ANDROID__)
349+
335350
} // namespace
336351
} // namespace firestore
337352
} // namespace firebase
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "firestore/src/android/filter_android.h"
18+
19+
#include "firestore/src/android/converter_android.h"
20+
#include "firestore/src/android/firestore_android.h"
21+
#include "firestore/src/android/field_path_android.h"
22+
#include "firestore/src/android/field_value_android.h"
23+
24+
#include "firestore/src/jni/array.h"
25+
#include "firestore/src/jni/array_list.h"
26+
#include "firestore/src/jni/compare.h"
27+
#include "firestore/src/jni/env.h"
28+
#include "firestore/src/jni/loader.h"
29+
30+
namespace firebase {
31+
namespace firestore {
32+
namespace {
33+
34+
using jni::Array;
35+
using jni::ArrayList;
36+
using jni::Env;
37+
using jni::Local;
38+
using jni::StaticMethod;
39+
using jni::Object;
40+
41+
constexpr char kClassName[] =
42+
PROGUARD_KEEP_CLASS "com/google/firebase/firestore/Filter";
43+
StaticMethod<Object> kEqualTo(
44+
"equalTo",
45+
"(Lcom/google/firebase/firestore/FieldPath;Ljava/lang/Object;)"
46+
"Lcom/google/firebase/firestore/Filter;");
47+
StaticMethod<Object> kNotEqualTo(
48+
"notEqualTo",
49+
"(Lcom/google/firebase/firestore/FieldPath;Ljava/lang/Object;)"
50+
"Lcom/google/firebase/firestore/Filter;");
51+
StaticMethod<Object> kLessThan(
52+
"lessThan",
53+
"(Lcom/google/firebase/firestore/FieldPath;Ljava/lang/Object;)"
54+
"Lcom/google/firebase/firestore/Filter;");
55+
StaticMethod<Object> kLessThanOrEqualTo(
56+
"lessThanOrEqualTo",
57+
"(Lcom/google/firebase/firestore/FieldPath;Ljava/lang/Object;)"
58+
"Lcom/google/firebase/firestore/Filter;");
59+
StaticMethod<Object> kGreaterThan(
60+
"greaterThan",
61+
"(Lcom/google/firebase/firestore/FieldPath;Ljava/lang/Object;)"
62+
"Lcom/google/firebase/firestore/Filter;");
63+
StaticMethod<Object> kGreaterThanOrEqualTo(
64+
"greaterThanOrEqualTo",
65+
"(Lcom/google/firebase/firestore/FieldPath;Ljava/lang/Object;)"
66+
"Lcom/google/firebase/firestore/Filter;");
67+
StaticMethod<Object> kArrayContains(
68+
"arrayContains",
69+
"(Lcom/google/firebase/firestore/FieldPath;Ljava/lang/Object;)"
70+
"Lcom/google/firebase/firestore/Filter;");
71+
StaticMethod<Object> kArrayContainsAny(
72+
"arrayContainsAny",
73+
"(Lcom/google/firebase/firestore/FieldPath;Ljava/util/List;)"
74+
"Lcom/google/firebase/firestore/Filter;");
75+
StaticMethod<Object> kIn("in",
76+
"(Lcom/google/firebase/firestore/FieldPath;Ljava/util/List;)"
77+
"Lcom/google/firebase/firestore/Filter;");
78+
StaticMethod<Object> kNotIn(
79+
"notIn",
80+
"(Lcom/google/firebase/firestore/FieldPath;Ljava/util/List;)"
81+
"Lcom/google/firebase/firestore/Filter;");
82+
StaticMethod<Object> kAnd(
83+
"and",
84+
"([Lcom/google/firebase/firestore/Filter;)"
85+
"Lcom/google/firebase/firestore/Filter;");
86+
StaticMethod<Object> kOr(
87+
"or",
88+
"([Lcom/google/firebase/firestore/Filter;)"
89+
"Lcom/google/firebase/firestore/Filter;");
90+
}
91+
92+
void FilterInternal::Initialize(jni::Loader& loader) {
93+
loader.LoadClass(
94+
kClassName, kEqualTo, kNotEqualTo, kLessThan, kLessThanOrEqualTo,
95+
kGreaterThan, kGreaterThanOrEqualTo, kArrayContains, kArrayContainsAny,
96+
kIn, kNotIn, kAnd, kOr);
97+
}
98+
99+
FilterInternal::FilterInternal(jni::Object&& object, bool is_empty)
100+
: object_(object), is_empty_(is_empty) {}
101+
102+
Filter FilterInternal::EqualTo(const FieldPath& field,
103+
const FieldValue& value) {
104+
return Where(field, kEqualTo, value);
105+
}
106+
107+
Filter FilterInternal::NotEqualTo(const FieldPath& field,
108+
const FieldValue& value) {
109+
return Where(field, kNotEqualTo, value);
110+
}
111+
112+
Filter FilterInternal::LessThan(const FieldPath& field,
113+
const FieldValue& value) {
114+
return Where(field, kLessThan, value);
115+
}
116+
117+
Filter FilterInternal::LessThanOrEqualTo(const FieldPath& field,
118+
const FieldValue& value) {
119+
return Where(field, kLessThanOrEqualTo, value);
120+
}
121+
122+
Filter FilterInternal::GreaterThan(const FieldPath& field,
123+
const FieldValue& value) {
124+
return Where(field, kGreaterThan, value);
125+
}
126+
127+
Filter FilterInternal::GreaterThanOrEqualTo(const FieldPath& field,
128+
const FieldValue& value) {
129+
return Where(field, kGreaterThanOrEqualTo, value);
130+
}
131+
132+
Filter FilterInternal::ArrayContains(const FieldPath& field,
133+
const FieldValue& value) {
134+
return Where(field, kArrayContains, value);
135+
}
136+
137+
Filter FilterInternal::ArrayContainsAny(
138+
const FieldPath& field, const std::vector<FieldValue>& values) {
139+
return Where(field, kArrayContainsAny, values);
140+
}
141+
142+
Filter FilterInternal::In(const FieldPath& field,
143+
const std::vector<FieldValue>& values) {
144+
return Where(field, kIn, values);
145+
}
146+
147+
Filter FilterInternal::NotIn(const FieldPath& field,
148+
const std::vector<FieldValue>& values) {
149+
return Where(field, kNotIn, values);
150+
}
151+
152+
Filter FilterInternal::And(const std::vector<const Filter>& filters) {
153+
return Where(kAnd, filters);
154+
}
155+
156+
Filter FilterInternal::Or(const std::vector<const Filter>& filters) {
157+
return Where(kOr, filters);
158+
}
159+
160+
Env FilterInternal::GetEnv() { return FirestoreInternal::GetEnv(); }
161+
162+
Filter FilterInternal::Where(const FieldPath& field,
163+
const StaticMethod<Object>& method,
164+
const FieldValue& value) {
165+
Env env = GetEnv();
166+
Local<Object> java_field = FieldPathConverter::Create(env, field);
167+
Object filter = env.Call(method, java_field, FieldValueInternal::ToJava(value));
168+
return Filter(new FilterInternal(std::move(filter), false));
169+
}
170+
171+
Filter FilterInternal::Where(const FieldPath& field,
172+
const jni::StaticMethod<Object>& method,
173+
const std::vector<FieldValue>& values) {
174+
Env env = GetEnv();
175+
size_t size = values.size();
176+
Local<ArrayList> java_values = ArrayList::Create(env, size);
177+
for (size_t i = 0; i < size; ++i) {
178+
java_values.Add(env, FieldValueInternal::ToJava(values[i]));
179+
}
180+
181+
Local<Object> java_field = FieldPathConverter::Create(env, field);
182+
Object filter = env.Call(method, java_field, java_values);
183+
return Filter(new FilterInternal(std::move(filter), false));
184+
}
185+
186+
Filter FilterInternal::Where(const StaticMethod<Object>& method,
187+
const std::vector<const Filter>& filters) {
188+
Env env = GetEnv();
189+
size_t size = filters.size();
190+
Local<Array<Object>> java_filters = env.NewArray(size, Object::GetClass());
191+
bool is_empty = true;
192+
for (int i = 0; i < size; ++i) {
193+
FilterInternal* internal_filter = filters[i].internal_;
194+
if (!internal_filter->IsEmpty()) {
195+
is_empty = false;
196+
}
197+
java_filters.Set(env, i, internal_filter->object_);
198+
}
199+
Object filter = env.Call(method, java_filters);
200+
return Filter(new FilterInternal(std::move(filter), is_empty));
201+
}
202+
203+
bool operator==(const FilterInternal& lhs, const FilterInternal& rhs) {
204+
return jni::EqualityCompareJni(lhs, rhs);
205+
}
206+
207+
} // namespace firestore
208+
} // namespace firebase

0 commit comments

Comments
 (0)