Search in sources :

Example 1 with SynchronousStorageAdapter

use of com.amplifyframework.datastore.storage.SynchronousStorageAdapter in project amplify-android by aws-amplify.

the class TestStorageAdapter method create.

/**
 * Creates an instance of the {@link SynchronousStorageAdapter}, which has been initialized
 * so that it can be used with the given models. The {@link SynchronousStorageAdapter}
 * is backed by an {@link SQLiteStorageAdapter}. The caller of this method
 * should do due diligence to ensure that any resources created by
 * {@link SQLiteStorageAdapter#initialize(Context, Consumer, Consumer)} have been cleaned up.
 * @return An initialized instance of the {@link SynchronousStorageAdapter}
 */
static SynchronousStorageAdapter create(ModelProvider modelProvider) {
    SchemaRegistry schemaRegistry = SchemaRegistry.instance();
    schemaRegistry.clear();
    try {
        schemaRegistry.register(modelProvider.models());
    } catch (AmplifyException modelSchemaLoadingFailure) {
        throw new RuntimeException(modelSchemaLoadingFailure);
    }
    SQLiteStorageAdapter sqLiteStorageAdapter = SQLiteStorageAdapter.forModels(schemaRegistry, modelProvider);
    SynchronousStorageAdapter synchronousStorageAdapter = SynchronousStorageAdapter.delegatingTo(sqLiteStorageAdapter);
    Context context = ApplicationProvider.getApplicationContext();
    try {
        synchronousStorageAdapter.initialize(context);
    } catch (DataStoreException initializationFailure) {
        throw new RuntimeException(initializationFailure);
    }
    return synchronousStorageAdapter;
}
Also used : Context(android.content.Context) DataStoreException(com.amplifyframework.datastore.DataStoreException) AmplifyException(com.amplifyframework.AmplifyException) SynchronousStorageAdapter(com.amplifyframework.datastore.storage.SynchronousStorageAdapter) SchemaRegistry(com.amplifyframework.core.model.SchemaRegistry)

Aggregations

Context (android.content.Context)1 AmplifyException (com.amplifyframework.AmplifyException)1 SchemaRegistry (com.amplifyframework.core.model.SchemaRegistry)1 DataStoreException (com.amplifyframework.datastore.DataStoreException)1 SynchronousStorageAdapter (com.amplifyframework.datastore.storage.SynchronousStorageAdapter)1