Java Code Examples for com.google.cloud.firestore.FirestoreOptions#getService()

The following examples show how to use com.google.cloud.firestore.FirestoreOptions#getService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FirestoreDataSink.java    From daq with Apache License 2.0 5 votes vote down vote up
public FirestoreDataSink() {
  try {
    Credentials projectCredentials = getProjectCredentials();
    FirestoreOptions firestoreOptions =
        FirestoreOptions.getDefaultInstance().toBuilder()
            .setCredentials(projectCredentials)
            .setProjectId(projectId)
            .setTimestampsInSnapshotsEnabled(true)
            .build();

    db = firestoreOptions.getService();
  } catch (Exception e) {
    throw new RuntimeException("While creating Firestore connection to " + projectId, e);
  }
}
 
Example 2
Source File: Quickstart.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public Quickstart(String projectId) throws Exception {
  // [START fs_initialize_project_id]
  FirestoreOptions firestoreOptions =
      FirestoreOptions.getDefaultInstance().toBuilder()
          .setProjectId(projectId)
          .setCredentials(GoogleCredentials.getApplicationDefault())
          .build();
  Firestore db = firestoreOptions.getService();
  // [END fs_initialize_project_id]
  this.db = db;
}
 
Example 3
Source File: BaseIntegrationTest.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void baseSetup() throws Exception {
  projectId = getEnvVar("FIRESTORE_PROJECT_ID");
  FirestoreOptions firestoreOptions = FirestoreOptions.getDefaultInstance().toBuilder()
      .setCredentials(GoogleCredentials.getApplicationDefault())
      .setProjectId(projectId)
      .build();
  db = firestoreOptions.getService();
  deleteAllDocuments(db);
}
 
Example 4
Source File: GcpFirestoreAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public Firestore firestore(FirestoreOptions firestoreOptions) {
	return firestoreOptions.getService();
}