SetSchemaRequest
public final class SetSchemaRequest
Encapsulates a request to update the schema of an AppSearchSession database.
The schema is composed of a collection of AppSearchSchema objects, each of which defines a unique type of data.
The first call to SetSchemaRequest will set the provided schema and store it within the AppSearchSession database.
Subsequent calls will compare the provided schema to the previously saved schema, to determine how to treat existing documents.
The following types of schema modifications are always safe and are made without deleting any existing documents:
- Addition of new
AppSearchSchematypes - Addition of new properties to an existing
AppSearchSchematype - Changing the cardinality of a property to be less restrictive
The following types of schema changes are not backwards compatible:
- Removal of an existing
AppSearchSchematype - Removal of a property from an existing
AppSearchSchematype - Changing the data type of an existing property
- Changing the cardinality of a property to be more restrictive
Providing a schema with incompatible changes, will throw an androidx.appsearch.exceptions.AppSearchException, with a message describing the incompatibility. As a result, the previously set schema will remain unchanged.
Backward incompatible changes can be made by :
- setting
setForceOverridemethod totrue. This deletes all documents that are incompatible with the new schema. The new schema is then saved and persisted to disk. - Add a
Migratorfor each incompatible type and make no deletion. The migrator will migrate documents from its old schema version to the new version. Migrated types will be set into bothgetIncompatibleTypesandgetMigratedTypes. See the migration section below.
| See also | |
|---|---|
setSchemaAsync |
|
Migrator |
Summary
Nested types |
|---|
public final class SetSchemaRequest.BuilderBuilder for |
Public methods |
|
|---|---|
boolean |
|
@NonNull Map<String, Migrator> |
Returns the map of |
@NonNull Map<String, PackageIdentifier> |
Returns a mapping of publicly visible schemas to the |
@NonNull Map<String, Set<Set<Integer>>> |
Returns a mapping of schema types to the Map of |
@NonNull Set<AppSearchSchema> |
Returns the |
@NonNull Set<String> |
Returns all the schema types that are opted out of being displayed and visible on any system UI surface. |
@NonNull Map<String, Set<SchemaVisibilityConfig>> |
Returns a mapping of schema types to the set of |
@NonNull Map<String, Set<PackageIdentifier>> |
Returns a mapping of schema types to the set of packages that have access to that schema type. |
@IntRange(from = 1) int |
Returns the database overall schema version. |
int |
hashCode() |
boolean |
Returns whether this request will force the schema to be overridden. |
Constants
READ_ASSISTANT_APP_SEARCH_DATA
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_ASSISTANT_APP_SEARCH_DATA = 6
The READ_ASSISTANT_APP_SEARCH_DATA AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility
READ_CALENDAR
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_CALENDAR = 2
The READ_CALENDAR AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility
READ_CONTACTS
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_CONTACTS = 3
The READ_CONTACTS AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility
READ_EXTERNAL_STORAGE
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_EXTERNAL_STORAGE = 4
The READ_EXTERNAL_STORAGE AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility
READ_HOME_APP_SEARCH_DATA
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_HOME_APP_SEARCH_DATA = 5
The READ_HOME_APP_SEARCH_DATA AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility
READ_SMS
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_SMS = 1
The READ_SMS AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility
Public methods
getMigrators
public @NonNull Map<String, Migrator> getMigrators()
Returns the map of Migrator, the key will be the schema type of the Migrator associated with.
getPubliclyVisibleSchemas
public @NonNull Map<String, PackageIdentifier> getPubliclyVisibleSchemas()
Returns a mapping of publicly visible schemas to the PackageIdentifier specifying the package the schemas are from.
getRequiredPermissionsForSchemaTypeVisibility
public @NonNull Map<String, Set<Set<Integer>>> getRequiredPermissionsForSchemaTypeVisibility()
Returns a mapping of schema types to the Map of android.Manifest.permission combinations that querier must hold to access that schema type.
The querier could read the GenericDocument objects under the schemaType if they holds ALL required permissions of ANY of the individual value sets.
For example, if the Map contains {{permissionA, PermissionB},
{PermissionC, PermissionD}, {PermissionE}}.
- A querier holds both PermissionA and PermissionB has access.
- A querier holds both PermissionC and PermissionD has access.
- A querier holds only PermissionE has access.
- A querier holds both PermissionA and PermissionE has access.
- A querier holds only PermissionA doesn't have access.
- A querier holds both PermissionA and PermissionC doesn't have access.
It’s inefficient to call this method repeatedly.
| Returns | |
|---|---|
@NonNull Map<String, Set<Set<Integer>>> |
The map contains schema type and all combinations of required permission for querier to access it. The supported Permission are |
getSchemas
public @NonNull Set<AppSearchSchema> getSchemas()
Returns the AppSearchSchema types that are part of this request.
getSchemasNotDisplayedBySystem
public @NonNull Set<String> getSchemasNotDisplayedBySystem()
Returns all the schema types that are opted out of being displayed and visible on any system UI surface.
getSchemasVisibleToConfigs
public @NonNull Map<String, Set<SchemaVisibilityConfig>> getSchemasVisibleToConfigs()
Returns a mapping of schema types to the set of SchemaVisibilityConfig that have access to that schema type.
It’s inefficient to call this method repeatedly.
| See also | |
|---|---|
addSchemaTypeVisibleToConfig |
getSchemasVisibleToPackages
public @NonNull Map<String, Set<PackageIdentifier>> getSchemasVisibleToPackages()
Returns a mapping of schema types to the set of packages that have access to that schema type.
It’s inefficient to call this method repeatedly.
getVersion
public @IntRange(from = 1) int getVersion()
Returns the database overall schema version.
isForceOverride
public boolean isForceOverride()
Returns whether this request will force the schema to be overridden.