SetSchemaRequest
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 |
|---|
class SetSchemaRequest.BuilderBuilder for |
Public functions |
|
|---|---|
Boolean |
|
(Mutable)Map<String!, Migrator!> |
Returns the map of |
(Mutable)Map<String!, PackageIdentifier!> |
Returns a mapping of publicly visible schemas to the |
(Mutable)Map<String!, (Mutable)Set<(Mutable)Set<Int!>!>!> |
Returns a mapping of schema types to the Map of |
(Mutable)Set<AppSearchSchema!> |
Returns the |
(Mutable)Set<String!> |
Returns all the schema types that are opted out of being displayed and visible on any system UI surface. |
(Mutable)Map<String!, (Mutable)Set<SchemaVisibilityConfig!>!> |
Returns a mapping of schema types to the set of |
(Mutable)Map<String!, (Mutable)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)
const val READ_ASSISTANT_APP_SEARCH_DATA = 6: Int
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)
const val READ_CALENDAR = 2: Int
The READ_CALENDAR AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility
READ_CONTACTS
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
const val READ_CONTACTS = 3: Int
The READ_CONTACTS AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility
READ_EXTERNAL_STORAGE
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
const val READ_EXTERNAL_STORAGE = 4: Int
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)
const val READ_HOME_APP_SEARCH_DATA = 5: Int
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)
const val READ_SMS = 1: Int
The READ_SMS AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility
Public functions
getMigrators
fun getMigrators(): (Mutable)Map<String!, Migrator!>
Returns the map of Migrator, the key will be the schema type of the Migrator associated with.
getPubliclyVisibleSchemas
fun getPubliclyVisibleSchemas(): (Mutable)Map<String!, PackageIdentifier!>
Returns a mapping of publicly visible schemas to the PackageIdentifier specifying the package the schemas are from.
getRequiredPermissionsForSchemaTypeVisibility
fun getRequiredPermissionsForSchemaTypeVisibility(): (Mutable)Map<String!, (Mutable)Set<(Mutable)Set<Int!>!>!>
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 | |
|---|---|
(Mutable)Map<String!, (Mutable)Set<(Mutable)Set<Int!>!>!> |
The map contains schema type and all combinations of required permission for querier to access it. The supported Permission are |
getSchemas
fun getSchemas(): (Mutable)Set<AppSearchSchema!>
Returns the AppSearchSchema types that are part of this request.
getSchemasNotDisplayedBySystem
fun getSchemasNotDisplayedBySystem(): (Mutable)Set<String!>
Returns all the schema types that are opted out of being displayed and visible on any system UI surface.
getSchemasVisibleToConfigs
fun getSchemasVisibleToConfigs(): (Mutable)Map<String!, (Mutable)Set<SchemaVisibilityConfig!>!>
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
fun getSchemasVisibleToPackages(): (Mutable)Map<String!, (Mutable)Set<PackageIdentifier!>!>
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
fun getVersion(): @IntRange(from = 1) Int
Returns the database overall schema version.
isForceOverride
fun isForceOverride(): Boolean
Returns whether this request will force the schema to be overridden.