public final class

SetSchemaRequest.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.appsearch.app.SetSchemaRequest.Builder

Overview

Builder for SetSchemaRequest objects.

Summary

Constructors
publicBuilder()

Methods
public SetSchemaRequest.BuilderaddDocumentClasses(java.lang.Class<java.lang.Object> documentClasses[])

Adds one or more Document annotated classes to the schema.

public SetSchemaRequest.BuilderaddDocumentClasses(java.util.Collection<java.lang.Class> documentClasses)

Adds a collection of Document annotated classes to the schema.

public SetSchemaRequest.BuilderaddSchemas(AppSearchSchema schemas[])

Adds one or more AppSearchSchema types to the schema.

public SetSchemaRequest.BuilderaddSchemas(java.util.Collection<AppSearchSchema> schemas)

Adds a collection of AppSearchSchema objects to the schema.

public SetSchemaRequestbuild()

Builds a new SetSchemaRequest object.

public SetSchemaRequest.BuildersetDocumentClassDisplayedBySystem(java.lang.Class<java.lang.Object> documentClass, boolean displayed)

Sets whether or not documents from the provided Document annotated class will be displayed and visible on any system UI surface.

public SetSchemaRequest.BuildersetDocumentClassVisibilityForPackage(java.lang.Class<java.lang.Object> documentClass, boolean visible, PackageIdentifier packageIdentifier)

Sets whether or not documents from the provided Document annotated class can be read by the specified package.

public SetSchemaRequest.BuildersetForceOverride(boolean forceOverride)

Sets whether or not to override the current schema in the AppSearchSession database.

public SetSchemaRequest.BuildersetMigrator(java.lang.String schemaType, Migrator migrator)

Sets the Migrator associated with the given SchemaType.

public SetSchemaRequest.BuildersetMigrators(java.util.Map<java.lang.String, Migrator> migrators)

Sets a Map of Migrators.

public SetSchemaRequest.BuildersetSchemaTypeDisplayedBySystem(java.lang.String schemaType, boolean displayed)

Sets whether or not documents from the provided schemaType will be displayed and visible on any system UI surface.

public SetSchemaRequest.BuildersetSchemaTypeVisibilityForPackage(java.lang.String schemaType, boolean visible, PackageIdentifier packageIdentifier)

Sets whether or not documents from the provided schemaType can be read by the specified package.

public SetSchemaRequest.BuildersetVersion(int version)

Sets the version number of the overall AppSearchSchema in the database.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Methods

public SetSchemaRequest.Builder addSchemas(AppSearchSchema schemas[])

Adds one or more AppSearchSchema types to the schema.

An AppSearchSchema object represents one type of structured data.

Any documents of these types will be displayed on system UI surfaces by default.

public SetSchemaRequest.Builder addSchemas(java.util.Collection<AppSearchSchema> schemas)

Adds a collection of AppSearchSchema objects to the schema.

An AppSearchSchema object represents one type of structured data.

public SetSchemaRequest.Builder addDocumentClasses(java.lang.Class<java.lang.Object> documentClasses[])

Adds one or more Document annotated classes to the schema.

Parameters:

documentClasses: classes annotated with Document.

public SetSchemaRequest.Builder addDocumentClasses(java.util.Collection<java.lang.Class> documentClasses)

Adds a collection of Document annotated classes to the schema.

Parameters:

documentClasses: classes annotated with Document.

public SetSchemaRequest.Builder setSchemaTypeDisplayedBySystem(java.lang.String schemaType, boolean displayed)

Sets whether or not documents from the provided schemaType will be displayed and visible on any system UI surface.

This setting applies to the provided schemaType only, and does not persist across AppSearchSession.setSchema(SetSchemaRequest) calls.

The default behavior, if this method is not called, is to allow types to be displayed on system UI surfaces.

Parameters:

schemaType: The name of an AppSearchSchema within the same SetSchemaRequest, which will be configured.
displayed: Whether documents of this type will be displayed on system UI surfaces.

public SetSchemaRequest.Builder setSchemaTypeVisibilityForPackage(java.lang.String schemaType, boolean visible, PackageIdentifier packageIdentifier)

Sets whether or not documents from the provided schemaType can be read by the specified package.

Each package is represented by a PackageIdentifier, containing a package name and a byte array of type android.content.pm.PackageManager.

To opt into one-way data sharing with another application, the developer will need to explicitly grant the other application’s package name and certificate Read access to its data.

For two-way data sharing, both applications need to explicitly grant Read access to one another.

By default, data sharing between applications is disabled.

Parameters:

schemaType: The schema type to set visibility on.
visible: Whether the schemaType will be visible or not.
packageIdentifier: Represents the package that will be granted visibility.

public SetSchemaRequest.Builder setMigrator(java.lang.String schemaType, Migrator migrator)

Sets the Migrator associated with the given SchemaType.

The Migrator migrates all GenericDocuments under given schema type from the current version number stored in AppSearch to the final version set via SetSchemaRequest.Builder.setVersion(int).

A Migrator will be invoked if the current version number stored in AppSearch is different from the final version set via SetSchemaRequest.Builder.setVersion(int) and Migrator.shouldMigrate(int, int) returns true.

The target schema type of the output GenericDocument of Migrator.onUpgrade(int, int, GenericDocument) or Migrator.onDowngrade(int, int, GenericDocument) must exist in this SetSchemaRequest.

Parameters:

schemaType: The schema type to set migrator on.
migrator: The migrator translates a document from its current version to the final version set via SetSchemaRequest.Builder.setVersion(int).

See also: SetSchemaRequest.Builder.setVersion(int), SetSchemaRequest.Builder.addSchemas(AppSearchSchema...), AppSearchSession.setSchema(SetSchemaRequest)

public SetSchemaRequest.Builder setMigrators(java.util.Map<java.lang.String, Migrator> migrators)

Sets a Map of Migrators.

The key of the map is the schema type that the Migrator value applies to.

The Migrator migrates all GenericDocuments under given schema type from the current version number stored in AppSearch to the final version set via SetSchemaRequest.Builder.setVersion(int).

A Migrator will be invoked if the current version number stored in AppSearch is different from the final version set via SetSchemaRequest.Builder.setVersion(int) and Migrator.shouldMigrate(int, int) returns true.

The target schema type of the output GenericDocument of Migrator.onUpgrade(int, int, GenericDocument) or Migrator.onDowngrade(int, int, GenericDocument) must exist in this SetSchemaRequest.

Parameters:

migrators: A java.util.Map of migrators that translate a document from it's current version to the final version set via SetSchemaRequest.Builder.setVersion(int). The key of the map is the schema type that the Migrator value applies to.

See also: SetSchemaRequest.Builder.setVersion(int), SetSchemaRequest.Builder.addSchemas(AppSearchSchema...), AppSearchSession.setSchema(SetSchemaRequest)

public SetSchemaRequest.Builder setDocumentClassDisplayedBySystem(java.lang.Class<java.lang.Object> documentClass, boolean displayed)

Sets whether or not documents from the provided Document annotated class will be displayed and visible on any system UI surface.

This setting applies to the provided Document annotated class only, and does not persist across AppSearchSession.setSchema(SetSchemaRequest) calls.

The default behavior, if this method is not called, is to allow types to be displayed on system UI surfaces.

Parameters:

documentClass: A class annotated with Document, the visibility of which will be configured
displayed: Whether documents of this type will be displayed on system UI surfaces.

public SetSchemaRequest.Builder setDocumentClassVisibilityForPackage(java.lang.Class<java.lang.Object> documentClass, boolean visible, PackageIdentifier packageIdentifier)

Sets whether or not documents from the provided Document annotated class can be read by the specified package.

Each package is represented by a PackageIdentifier, containing a package name and a byte array of type android.content.pm.PackageManager.

To opt into one-way data sharing with another application, the developer will need to explicitly grant the other application’s package name and certificate Read access to its data.

For two-way data sharing, both applications need to explicitly grant Read access to one another.

By default, app data sharing between applications is disabled.

Parameters:

documentClass: The Document class to set visibility on.
visible: Whether the documentClass will be visible or not.
packageIdentifier: Represents the package that will be granted visibility.

public SetSchemaRequest.Builder setForceOverride(boolean forceOverride)

Sets whether or not to override the current schema in the AppSearchSession database.

Call this method whenever backward incompatible changes need to be made by setting forceOverride to true. As a result, during execution of the setSchema operation, all documents that are incompatible with the new schema will be deleted and the new schema will be saved and persisted.

By default, this is false.

public SetSchemaRequest.Builder setVersion(int version)

Sets the version number of the overall AppSearchSchema in the database.

The AppSearchSession database can only ever hold documents for one version at a time.

Setting a version number that is different from the version number currently stored in AppSearch will result in AppSearch calling the Migrators provided to AppSearchSession.setSchema(SetSchemaRequest) to migrate the documents already in AppSearch from the previous version to the one set in this request. The version number can be updated without any other changes to the set of schemas.

The version number can stay the same, increase, or decrease relative to the current version number that is already stored in the AppSearchSession database.

The version of an empty database will always be 0. You cannot set version to the SetSchemaRequest, if it doesn't contains any AppSearchSchema.

Parameters:

version: A positive integer representing the version of the entire set of schemas represents the version of the whole schema in the AppSearchSession database, default version is 1.

See also: AppSearchSession.setSchema(SetSchemaRequest), Migrator, SetSchemaRequest.Builder.setMigrator(String, Migrator)

public SetSchemaRequest build()

Builds a new SetSchemaRequest object.