Class RecordMetaDataBuilder

    • Method Detail

      • setRecords

        @Nonnull
        public RecordMetaDataBuilder setRecords​(@Nonnull
                                                Descriptors.FileDescriptor fileDescriptor,
                                                boolean processExtensionOptions)
        Adds the root file descriptor of the RecordMetaData.
        Parameters:
        fileDescriptor - the file descriptor of the record meta-data
        processExtensionOptions - whether to add primary keys and indexes based on extensions in the protobuf
        Returns:
        this builder
      • updateRecords

        public void updateRecords​(@Nonnull
                                  Descriptors.FileDescriptor recordsDescriptor)
        Update the records descriptor of the record meta-data.

        This involves adding new record types and updating descriptors for the existing record types and union fields. By contract, the extension options will be processed for all of the new record types and will not be processed for any of the old record types. Also, it is not allowed to call this method when the local file descriptor is set.

        See updateRecords(Descriptors.FileDescriptor, boolean) for more information.

        Parameters:
        recordsDescriptor - the new record descriptor
      • updateRecords

        public void updateRecords​(@Nonnull
                                  Descriptors.FileDescriptor newRecordsDescriptor,
                                  boolean processExtensionOptions)
        Update the records descriptor of the record meta-data.

        This adds any new record types and updates the descriptors for existing record types. By contract, the extension options will not be processed for the old record types. If processExtensionOptions is set, extension options will be processed only for the new record types. Also, this method may not be called when localFileDescriptor is set. This method bumps the meta-data version and sets the since version for the new record types (and their indexes).

        To avoid accidental changes, this method only updates the record types (i.e., updates the message descriptors of the old record types and adds new record types with their primary keys and indexes). This method does not process schema options. To update the schema options, use setSplitLongRecords(boolean) and setStoreRecordVersions(boolean).

        Parameters:
        newRecordsDescriptor - the new record descriptor
        processExtensionOptions - whether to add primary keys and indexes using the extensions in the protobuf (only for the new record types)
      • setLocalFileDescriptor

        @Nonnull
        public RecordMetaDataBuilder setLocalFileDescriptor​(@Nonnull
                                                            Descriptors.FileDescriptor localFileDescriptor)
        Sets the local file descriptor. A local meta-data file descriptor may contain newer versions of record types or indexes.

        This method is handy when two versions of the record meta-data are compatible (i.e., they follow the Record Layer guidelines on schema evolution), but their descriptors are not equal, e.g., a statically-generated proto and its serialized version stored in a meta-data store (i.e., FDBMetaDataStore). A record store created using the meta-data store may not be able to store a record created by the statically-generated proto file because the meta-data and record have mismatched descriptors. Using this method, the meta-data can use the same version of the descriptor as the record.

        This should only be used when the records descriptor is set through a meta-data Protobuf message (i.e, it is followed by a call to setRecords(RecordMetaDataProto.MetaData) or setRecords(RecordMetaDataProto.MetaData, boolean)). This will not work if the records are set using a file descriptor. Note also that once the local file descriptor is set, the RecordMetaData object that is produced from this builder may differ from the original Protobuf definition in ways that make serializing the meta-data back to Protobuf unsafe. As a result, calling toProto() on the produced RecordMetaData is disallowed.

        To verify that the file descriptor supplied here and the file descriptor included in the meta-data proto are compatible, the two descriptors are compared using a MetaDataEvolutionValidator. The user may provide their own validator by calling setEvolutionValidator(MetaDataEvolutionValidator). By default, this will use that class's default instance.

        Parameters:
        localFileDescriptor - a file descriptor that contains updated record types
        Returns:
        this builder
      • addIndex

        public void addIndex​(@Nullable
                             RecordTypeIndexesBuilder recordType,
                             @Nonnull
                             Index index)
        Adds a new index. This index can either be a universal index or an index for a single record type.
        Parameters:
        recordType - if null this index will exist for all record types
        index - the index to be added
      • addIndex

        public void addIndex​(@Nonnull
                             String recordType,
                             @Nonnull
                             Index index)
        Adds a new index.
        Parameters:
        recordType - name of the record type
        index - the index to be added
      • addIndex

        public void addIndex​(@Nonnull
                             String recordType,
                             @Nonnull
                             String indexName,
                             @Nonnull
                             KeyExpression indexExpression)
        Adds a new index.
        Parameters:
        recordType - name of the record type
        indexName - the name of the new index
        indexExpression - the root expression of the new index
      • addIndex

        public void addIndex​(@Nonnull
                             String recordType,
                             @Nonnull
                             String indexName,
                             @Nonnull
                             String fieldName)
        Adds a new index.
        Parameters:
        recordType - name of the record type
        indexName - the name of the new index
        fieldName - the record field to be indexed
      • addIndex

        public void addIndex​(@Nonnull
                             String recordType,
                             @Nonnull
                             String fieldName)
        Adds a new index on a single field.
        Parameters:
        recordType - name of the record type
        fieldName - the record field to be indexed
      • addMultiTypeIndex

        public void addMultiTypeIndex​(@Nullable
                                      List<? extends RecordTypeIndexesBuilder> recordTypes,
                                      @Nonnull
                                      Index index)
        Adds a new index that contains multiple record types. If the list is null or empty, the resulting index will include all record types. If the list has one element it will just be a normal single record type index.
        Parameters:
        recordTypes - a list of record types that the index will include
        index - the index to be added
      • addUniversalIndex

        public void addUniversalIndex​(@Nonnull
                                      Index index)
        Adds a new index on all record types.
        Parameters:
        index - the index to be added
      • isSplitLongRecords

        public boolean isSplitLongRecords()
      • setSplitLongRecords

        public void setSplitLongRecords​(boolean splitLongRecords)
      • isStoreRecordVersions

        public boolean isStoreRecordVersions()
      • setStoreRecordVersions

        public void setStoreRecordVersions​(boolean storeRecordVersions)
      • setRecordCountKey

        @Deprecated
        @API(DEPRECATED)
        public void setRecordCountKey​(KeyExpression recordCountKey)
        Deprecated.
        use COUNT type indexes instead
        Set the key used for maintaining record counts.
        Parameters:
        recordCountKey - grouping key for counting
      • getVersion

        public int getVersion()
      • setVersion

        public void setVersion​(int version)
      • enableCounterBasedSubspaceKeys

        @Nonnull
        public RecordMetaDataBuilder enableCounterBasedSubspaceKeys()
        Enable counter-based subspace keys assignment.

        If enabled, index subspace keys will be set using a counter instead of defaulting to the indexes' names. This must be called prior to setting the records descriptor (for example setRecords(Descriptors.FileDescriptor)).

        Existing clients should be careful about enabling this feature. The name of an index is the default value of its subspace key when counter-based subspace keys are disabled. If a subspace key was not set explicitly before, enabling the counter-based scheme will change the index's subspace key. Note that it is important that the subspace key of an index that has data does not change. See Index.setSubspaceKey(Object) for more details.

        Returns:
        this builder
      • usesSubspaceKeyCounter

        public boolean usesSubspaceKeyCounter()
        Checks if counter-based subspace key assignment is used.
        Returns:
        true if the subspace key counter is used
      • getSubspaceKeyCounter

        public long getSubspaceKeyCounter()
        Get the current value of the index subspace key counter. If it is not enabled, the value will be 0.
        Returns:
        the current value of the index subspace key counter
        See Also:
        enableCounterBasedSubspaceKeys()
      • setSubspaceKeyCounter

        @Nonnull
        public RecordMetaDataBuilder setSubspaceKeyCounter​(long subspaceKeyCounter)
        Set the initial value of the subspace key counter. This method can be handy when users want to assign subspace keys using a counter, but their indexes already have subspace keys that may conflict with the counter-based assignment.

        Note that the new counter must be greater than the current value. Also, users must first enable this feature by calling enableCounterBasedSubspaceKeys() before updating the counter value.

        Parameters:
        subspaceKeyCounter - the new value
        Returns:
        this builder
        See Also:
        enableCounterBasedSubspaceKeys()
      • getOnlyRecordType

        @Nonnull
        public RecordTypeBuilder getOnlyRecordType()
        If there is only one record type, get it.
        Returns:
        the only type defined for this store.
      • getIndexMaintainerRegistry

        @Nonnull
        public IndexMaintainerRegistry getIndexMaintainerRegistry()
        Get the index registry used for validation.
        Returns:
        the index maintainer registry
      • build

        @Nonnull
        public RecordMetaData build()
        Build and validate meta-data.
        Returns:
        new validated meta-data
      • build

        @Nonnull
        public RecordMetaData build​(boolean validate)
        Build and validate meta-data with specific index registry.
        Parameters:
        validate - true to validate the new meta-data
        Returns:
        new meta-data