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;
}
Aggregations