SetSchemaRequest

public final class SetSchemaRequest
extends Object

java.lang.Object
   ↳ androidx.appsearch.app.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 AppSearchSchema types
  • Addition of new properties to an existing AppSearchSchema type
  • Changing the cardinality of a property to be less restrictive

The following types of schema changes are not backwards compatible:

  • Removal of an existing AppSearchSchema type
  • Removal of a property from an existing AppSearchSchema type
  • 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 :

Summary

Nested classes

class SetSchemaRequest.Builder

Builder for SetSchemaRequest objects. 

Public methods

Map<String, Migrator> getMigrators()

Returns the map of Migrator, the key will be the schema type of the Migrator associated with.

Set<AppSearchSchema> getSchemas()

Returns the AppSearchSchema types that are part of this request.

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>

getSchemas

public Set<AppSearchSchema> getSchemas ()

Returns the AppSearchSchema types that are part of this request.

Returns
Set<AppSearchSchema>

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>

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>>

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