SetSchemaRequest
public
final
class
SetSchemaRequest
extends Object
| java.lang.Object | |
| ↳ | android.app.appsearch.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 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
SetSchemaRequest.Builder#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 it's old schema version to the new version. Migrated types will be set into bothSetSchemaResponse#getIncompatibleTypes()andSetSchemaResponse.getMigratedTypes(). See the migration section below.
Summary
Nested classes | |
|---|---|
class |
SetSchemaRequest.Builder
Builder for |
Public methods | |
|---|---|
Map<String, Migrator>
|
getMigrators()
Returns the map of |
Set<AppSearchSchema>
|
getSchemas()
Returns the |
Set<String>
|
getSchemasNotDisplayedBySystem()
Returns all the schema types that are opted out of being displayed and visible on any system UI surface. |
Map<String, Set<PackageIdentifier>>
|
getSchemasVisibleToPackages()
Returns a mapping of schema types to the set of packages that have access to that schema type. |
int
|
getVersion()
Returns the database overall schema version. |
boolean
|
isForceOverride()
Returns whether this request will force the schema to be overridden. |
Inherited methods | |
|---|---|
Public methods
getMigrators
public Map<String, Migrator> getMigrators ()
Returns the map of Migrator, the key will be the schema type of the Migrator
associated with.
| Returns | |
|---|---|
Map<String, Migrator> |
This value cannot be null. |
getSchemas
public Set<AppSearchSchema> getSchemas ()
Returns the AppSearchSchema types that are part of this request.
| Returns | |
|---|---|
Set<AppSearchSchema> |
This value cannot be null. |
getSchemasNotDisplayedBySystem
public Set<String> getSchemasNotDisplayedBySystem ()
Returns all the schema types that are opted out of being displayed and visible on any system UI surface.
| Returns | |
|---|---|
Set<String> |
This value cannot be null. |
getSchemasVisibleToPackages
public 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.
| Returns | |
|---|---|
Map<String, Set<PackageIdentifier>> |
This value cannot be null. |
getVersion
public int getVersion ()
Returns the database overall schema version.
| Returns | |
|---|---|
int |
Value is 1 or greater |
isForceOverride
public boolean isForceOverride ()
Returns whether this request will force the schema to be overridden.
| Returns | |
|---|---|
boolean |
|
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-05-18 UTC.