1717package com .google .cloud .firestore ;
1818
1919import com .google .api .core .InternalApi ;
20- import com .google .api .gax .core .CredentialsProvider ;
21- import com .google .api .gax .core .GoogleCredentialsProvider ;
22- import com .google .api .gax .grpc .InstantiatingGrpcChannelProvider ;
23- import com .google .api .gax .rpc .TransportChannelProvider ;
2420import com .google .cloud .ServiceDefaults ;
2521import com .google .cloud .ServiceOptions ;
2622import com .google .cloud .TransportOptions ;
3026import com .google .cloud .grpc .GrpcTransportOptions ;
3127import com .google .common .collect .ImmutableSet ;
3228import java .io .IOException ;
33- import java .util .Objects ;
3429import java .util .Set ;
3530import javax .annotation .Nonnull ;
3631
@@ -43,12 +38,11 @@ public final class FirestoreOptions extends ServiceOptions<Firestore, FirestoreO
4338 .add ("https://www.googleapis.com/auth/cloud-platform" )
4439 .add ("https://www.googleapis.com/auth/datastore" )
4540 .build ();
46-
47- private static final long serialVersionUID = -5853552236134770089L ;
41+ private static final String DEFAULT_HOST = FirestoreSettings .getDefaultEndpoint ();
42+ private static final String DEFAULT_DATABASE_ID = "(default)" ;
43+ private static final long serialVersionUID = -5853552236134770088L ;
4844
4945 private final String databaseId ;
50- private final TransportChannelProvider channelProvider ;
51- private final CredentialsProvider credentialsProvider ;
5246
5347 public static class DefaultFirestoreFactory implements FirestoreFactory {
5448
@@ -88,129 +82,53 @@ protected boolean projectIdRequired() {
8882
8983 @ Override
9084 protected String getDefaultHost () {
91- return FirestoreDefaults . INSTANCE . getHost () ;
85+ return DEFAULT_HOST ;
9286 }
9387
9488 public String getDatabaseId () {
9589 return databaseId ;
9690 }
9791
98- public CredentialsProvider getCredentialsProvider () {
99- return credentialsProvider ;
100- }
101-
102- public TransportChannelProvider getTransportChannelProvider () {
103- return channelProvider ;
104- }
105-
10692 public static class Builder extends ServiceOptions .Builder <Firestore , FirestoreOptions , Builder > {
10793
108- private String databaseId = FirestoreDefaults .INSTANCE .getDatabaseId ();
109- private TransportChannelProvider channelProvider =
110- FirestoreDefaults .INSTANCE .getDefaultTransportChannelProvider ();
111- private CredentialsProvider credentialsProvider =
112- FirestoreDefaults .INSTANCE .getDefaultCredentialsProvider ();
94+ private String databaseId = DEFAULT_DATABASE_ID ;
11395
11496 private Builder () {}
11597
11698 private Builder (FirestoreOptions options ) {
11799 super (options );
118- this .databaseId = options .databaseId ;
119- this .channelProvider = options .channelProvider ;
120- this .credentialsProvider = options .credentialsProvider ;
121100 }
122101
123- /**
124- * Sets the {@link TransportOptions} to use with this Firestore client.
125- *
126- * @param transportOptions A GrpcTransportOptions object that defines the transport options for
127- * this client.
128- */
129102 @ Nonnull
130103 @ Override
131104 public Builder setTransportOptions (@ Nonnull TransportOptions transportOptions ) {
132105 if (!(transportOptions instanceof GrpcTransportOptions )) {
133106 throw new IllegalArgumentException (
134- "Only GRPC transport is allowed for " + API_SHORT_NAME + "." );
107+ "Only grpc transport is allowed for " + API_SHORT_NAME + "." );
135108 }
136109 return super .setTransportOptions (transportOptions );
137110 }
138111
139- /**
140- * Sets the {@link TransportChannelProvider} to use with this Firestore client.
141- *
142- * @param channelProvider A InstantiatingGrpcChannelProvider object that defines the transport
143- * provider for this client.
144- */
145- @ Nonnull
146- public Builder setChannelProvider (@ Nonnull TransportChannelProvider channelProvider ) {
147- if (!(channelProvider instanceof InstantiatingGrpcChannelProvider )) {
148- throw new IllegalArgumentException (
149- "Only GRPC channels are allowed for " + API_SHORT_NAME + "." );
150- }
151- this .channelProvider = channelProvider ;
152- return this ;
153- }
154-
155- /**
156- * Sets the {@link CredentialsProvider} to use with this Firestore client.
157- *
158- * @param credentialsProvider A CredentialsProvider object that defines the credential provider
159- * for this client.
160- */
112+ @ Override
161113 @ Nonnull
162- public Builder setCredentialsProvider (@ Nonnull CredentialsProvider credentialsProvider ) {
163- this .credentialsProvider = credentialsProvider ;
164- return this ;
114+ public FirestoreOptions build () {
115+ return new FirestoreOptions (this );
165116 }
166117
167- /**
168- * Sets the database ID to use with this Firestore client.
169- *
170- * @param databaseId The Firestore database ID to use with this client.
171- */
172118 public Builder setDatabaseId (String databaseId ) {
173119 this .databaseId = databaseId ;
174120 return this ;
175121 }
176-
177- @ Override
178- @ Nonnull
179- public FirestoreOptions build () {
180- return new FirestoreOptions (this );
181- }
182122 }
183123
184124 @ InternalApi ("This class should only be extended within google-cloud-java" )
185125 protected FirestoreOptions (Builder builder ) {
186126 super (FirestoreFactory .class , FirestoreRpcFactory .class , builder , new FirestoreDefaults ());
187127
188128 this .databaseId = builder .databaseId ;
189- this .channelProvider = builder .channelProvider ;
190- this .credentialsProvider = builder .credentialsProvider ;
191129 }
192130
193131 private static class FirestoreDefaults implements ServiceDefaults <Firestore , FirestoreOptions > {
194- private static final FirestoreDefaults INSTANCE = new FirestoreDefaults ();
195-
196- private final String HOST = FirestoreSettings .getDefaultEndpoint ();
197- private final String DATABASE_ID = "(default)" ;
198- private final TransportOptions TRANSPORT_OPTIONS =
199- getDefaultTransportOptionsBuilder ().build ();
200- private final TransportChannelProvider CHANNEL_PROVIDER =
201- getDefaultTransportChannelProviderBuilder ().build ();
202- private final CredentialsProvider CREDENTIALS_PROVIDER =
203- getDefaultCredentialsProviderBuilder ().build ();
204-
205- @ Nonnull
206- String getHost () {
207- return HOST ;
208- }
209-
210- @ Nonnull
211- String getDatabaseId () {
212- return DATABASE_ID ;
213- }
214132
215133 @ Nonnull
216134 @ Override
@@ -227,34 +145,13 @@ public FirestoreRpcFactory getDefaultRpcFactory() {
227145 @ Nonnull
228146 @ Override
229147 public TransportOptions getDefaultTransportOptions () {
230- return TRANSPORT_OPTIONS ;
148+ return getDefaultGrpcTransportOptions () ;
231149 }
232-
233- @ Nonnull
234- TransportChannelProvider getDefaultTransportChannelProvider () {
235- return CHANNEL_PROVIDER ;
236- }
237-
238- @ Nonnull
239- CredentialsProvider getDefaultCredentialsProvider () {
240- return CREDENTIALS_PROVIDER ;
241- }
242- }
243-
244- @ Nonnull
245- public static GrpcTransportOptions .Builder getDefaultTransportOptionsBuilder () {
246- return GrpcTransportOptions .newBuilder ();
247150 }
248151
249152 @ Nonnull
250- public static InstantiatingGrpcChannelProvider .Builder
251- getDefaultTransportChannelProviderBuilder () {
252- return FirestoreSettings .defaultGrpcTransportProviderBuilder ();
253- }
254-
255- @ Nonnull
256- public static GoogleCredentialsProvider .Builder getDefaultCredentialsProviderBuilder () {
257- return FirestoreSettings .defaultCredentialsProviderBuilder ();
153+ public static GrpcTransportOptions getDefaultGrpcTransportOptions () {
154+ return GrpcTransportOptions .newBuilder ().build ();
258155 }
259156
260157 @ Override
@@ -267,22 +164,13 @@ FirestoreRpc getFirestoreRpc() {
267164 }
268165
269166 @ Override
270- public boolean equals (Object o ) {
271- if (this == o ) {
272- return true ;
273- }
274- if (o == null || getClass () != o .getClass ()) {
275- return false ;
276- }
277- FirestoreOptions that = (FirestoreOptions ) o ;
278- return Objects .equals (databaseId , that .databaseId )
279- && Objects .equals (channelProvider , that .channelProvider )
280- && baseEquals (that );
167+ public boolean equals (Object obj ) {
168+ return obj instanceof FirestoreOptions && baseEquals ((FirestoreOptions ) obj );
281169 }
282170
283171 @ Override
284172 public int hashCode () {
285- return Objects . hash ( databaseId , channelProvider , baseHashCode () );
173+ return baseHashCode ();
286174 }
287175
288176 @ Nonnull
0 commit comments