Search in sources :

Example 1 with DatabaseId

use of com.google.firebase.firestore.model.DatabaseId in project firebase-android-sdk by firebase.

the class IntegrationTestUtil method testFirestore.

public static FirebaseFirestore testFirestore(String projectId, Logger.Level logLevel, FirebaseFirestoreSettings settings, String persistenceKey) {
    // This unfortunately is a global setting that affects existing Firestore clients.
    Logger.setLogLevel(logLevel);
    Context context = ApplicationProvider.getApplicationContext();
    DatabaseId databaseId = DatabaseId.forDatabase(projectId, DatabaseId.DEFAULT_DATABASE_ID);
    ensureStrictMode();
    AsyncQueue asyncQueue = new AsyncQueue();
    FirebaseFirestore firestore = AccessHelper.newFirebaseFirestore(context, databaseId, persistenceKey, MockCredentialsProvider.instance(), new EmptyAppCheckTokenProvider(), asyncQueue, /*firebaseApp=*/
    null, /*instanceRegistry=*/
    (dbId) -> {
    });
    waitFor(firestore.clearPersistence());
    firestore.setFirestoreSettings(settings);
    firestoreStatus.put(firestore, true);
    return firestore;
}
Also used : Context(android.content.Context) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) DatabaseId(com.google.firebase.firestore.model.DatabaseId) AsyncQueue(com.google.firebase.firestore.util.AsyncQueue)

Example 2 with DatabaseId

use of com.google.firebase.firestore.model.DatabaseId in project firebase-android-sdk by firebase.

the class FirebaseFirestore method newInstance.

@NonNull
static FirebaseFirestore newInstance(@NonNull Context context, @NonNull FirebaseApp app, @NonNull Deferred<InternalAuthProvider> deferredAuthProvider, @NonNull Deferred<InternalAppCheckTokenProvider> deferredAppCheckTokenProvider, @NonNull String database, @NonNull InstanceRegistry instanceRegistry, @Nullable GrpcMetadataProvider metadataProvider) {
    String projectId = app.getOptions().getProjectId();
    if (projectId == null) {
        throw new IllegalArgumentException("FirebaseOptions.getProjectId() cannot be null");
    }
    DatabaseId databaseId = DatabaseId.forDatabase(projectId, database);
    AsyncQueue queue = new AsyncQueue();
    CredentialsProvider<User> authProvider = new FirebaseAuthCredentialsProvider(deferredAuthProvider);
    CredentialsProvider<String> appCheckProvider = new FirebaseAppCheckTokenProvider(deferredAppCheckTokenProvider);
    // Firestore uses a different database for each app name. Note that we don't use
    // app.getPersistenceKey() here because it includes the application ID which is related
    // to the project ID. We already include the project ID when resolving the database,
    // so there is no need to include it in the persistence key.
    String persistenceKey = app.getName();
    FirebaseFirestore firestore = new FirebaseFirestore(context, databaseId, persistenceKey, authProvider, appCheckProvider, queue, app, instanceRegistry, metadataProvider);
    return firestore;
}
Also used : User(com.google.firebase.firestore.auth.User) FirebaseAppCheckTokenProvider(com.google.firebase.firestore.auth.FirebaseAppCheckTokenProvider) DatabaseId(com.google.firebase.firestore.model.DatabaseId) AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) FirebaseAuthCredentialsProvider(com.google.firebase.firestore.auth.FirebaseAuthCredentialsProvider) NonNull(androidx.annotation.NonNull)

Example 3 with DatabaseId

use of com.google.firebase.firestore.model.DatabaseId in project firebase-android-sdk by firebase.

the class MemorySpecTest method initializeComponentProvider.

@Override
protected MemoryComponentProvider initializeComponentProvider(ComponentProvider.Configuration configuration, boolean garbageCollectionEnabled) {
    MemoryComponentProvider provider = new MemoryComponentProvider() {

        @Override
        protected Persistence createPersistence(Configuration configuration) {
            if (garbageCollectionEnabled) {
                return MemoryPersistence.createEagerGcMemoryPersistence();
            } else {
                DatabaseId databaseId = DatabaseId.forProject("projectId");
                LocalSerializer serializer = new LocalSerializer(new RemoteSerializer(databaseId));
                return MemoryPersistence.createLruGcMemoryPersistence(LruGarbageCollector.Params.Default(), serializer);
            }
        }
    };
    provider.initialize(configuration);
    return provider;
}
Also used : RemoteSerializer(com.google.firebase.firestore.remote.RemoteSerializer) MemoryComponentProvider(com.google.firebase.firestore.core.MemoryComponentProvider) DatabaseId(com.google.firebase.firestore.model.DatabaseId) LocalSerializer(com.google.firebase.firestore.local.LocalSerializer)

Example 4 with DatabaseId

use of com.google.firebase.firestore.model.DatabaseId in project firebase-android-sdk by firebase.

the class PersistenceTestHelpers method createLRUMemoryPersistence.

public static MemoryPersistence createLRUMemoryPersistence(LruGarbageCollector.Params params) {
    DatabaseId databaseId = DatabaseId.forProject("projectId");
    LocalSerializer serializer = new LocalSerializer(new RemoteSerializer(databaseId));
    MemoryPersistence persistence = MemoryPersistence.createLruGcMemoryPersistence(params, serializer);
    persistence.start();
    return persistence;
}
Also used : RemoteSerializer(com.google.firebase.firestore.remote.RemoteSerializer) DatabaseId(com.google.firebase.firestore.model.DatabaseId)

Example 5 with DatabaseId

use of com.google.firebase.firestore.model.DatabaseId in project firebase-android-sdk by firebase.

the class PersistenceTestHelpers method openSQLitePersistence.

private static SQLitePersistence openSQLitePersistence(int version, String name, LruGarbageCollector.Params params) {
    DatabaseId databaseId = DatabaseId.forProject("projectId");
    LocalSerializer serializer = new LocalSerializer(new RemoteSerializer(databaseId));
    Context context = ApplicationProvider.getApplicationContext();
    SQLitePersistence persistence = new SQLitePersistence(serializer, params, new SQLitePersistence.OpenHelper(context, serializer, databaseName(name, databaseId), version));
    persistence.start();
    return persistence;
}
Also used : Context(android.content.Context) RemoteSerializer(com.google.firebase.firestore.remote.RemoteSerializer) DatabaseId(com.google.firebase.firestore.model.DatabaseId)

Aggregations

DatabaseId (com.google.firebase.firestore.model.DatabaseId)10 RemoteSerializer (com.google.firebase.firestore.remote.RemoteSerializer)5 Context (android.content.Context)3 AsyncQueue (com.google.firebase.firestore.util.AsyncQueue)2 NonNull (androidx.annotation.NonNull)1 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)1 UserDataReader (com.google.firebase.firestore.UserDataReader)1 FirebaseAppCheckTokenProvider (com.google.firebase.firestore.auth.FirebaseAppCheckTokenProvider)1 FirebaseAuthCredentialsProvider (com.google.firebase.firestore.auth.FirebaseAuthCredentialsProvider)1 User (com.google.firebase.firestore.auth.User)1 MemoryComponentProvider (com.google.firebase.firestore.core.MemoryComponentProvider)1 LocalSerializer (com.google.firebase.firestore.local.LocalSerializer)1 DocumentKey (com.google.firebase.firestore.model.DocumentKey)1 ObjectValue (com.google.firebase.firestore.model.ObjectValue)1 ArrayValue (com.google.firestore.v1.ArrayValue)1 Value (com.google.firestore.v1.Value)1 Before (org.junit.Before)1 Test (org.junit.Test)1