Class MetaDataProtoEditor


  • @API(EXPERIMENTAL)
    public class MetaDataProtoEditor
    extends Object
    A helper class for mutating the meta-data proto.

    This class contains several helper methods for modifying a serialized meta-data, e.g., adding a new record type to the meta-data. FDBMetaDataStore.mutateMetaData(Consumer) is one example of where these methods can be useful. That method modifies the stored meta-data using a mutation callback and saves it back to the meta-data store.

    • Constructor Detail

      • MetaDataProtoEditor

        public MetaDataProtoEditor()
    • Method Detail

      • addNestedRecordType

        public static void addNestedRecordType​(@Nonnull
                                               RecordMetaDataProto.MetaData.Builder metaDataBuilder,
                                               @Nonnull
                                               DescriptorProtos.DescriptorProto newRecordType)
        Add a new NESTED record type to the meta-data. This can be used to define fields in other record types, but it does not add the new record type to the union.
        Parameters:
        metaDataBuilder - the meta-data builder
        newRecordType - the new record type
      • deprecateRecordType

        public static void deprecateRecordType​(@Nonnull
                                               RecordMetaDataProto.MetaData.Builder metaDataBuilder,
                                               @Nonnull
                                               String recordType)
        Deprecate a record type from the meta-data. The record is still defined in the record definition, but any occurrences of the field in the union descriptor are deprecated. If there are any top-level record types that are defined as nested messages within the deprecated record type, those fields in the union will also be deprecated.
        Parameters:
        metaDataBuilder - the meta-data builder
        recordType - the record type to be deprecated
      • renameRecordType

        public static void renameRecordType​(@Nonnull
                                            RecordMetaDataProto.MetaData.Builder metaDataBuilder,
                                            @Nonnull
                                            String recordTypeName,
                                            @Nonnull
                                            String newRecordTypeName)
        Rename a record type. This can be used to update any top-level record type defined within the meta-data's records descriptor, including NESTED records or the union descriptor. However, it cannot be used to rename nested messages (i.e., messages defined within other messages) or records defined in imported files. In addition to updating the file descriptor, if the record type is not NESTED or the union descriptor, update any other references to the record type within the meta-data (such as within index definitions).
        Parameters:
        metaDataBuilder - the meta-data builder
        recordTypeName - the name of the existing top-level record type
        newRecordTypeName - the new name to give to the record type
      • deprecateField

        public static void deprecateField​(@Nonnull
                                          RecordMetaDataProto.MetaData.Builder metaDataBuilder,
                                          @Nonnull
                                          String recordType,
                                          @Nonnull
                                          String fieldName)
        Deprecate a field from a record type.
        Parameters:
        metaDataBuilder - the meta-data builder
        recordType - the record type to deprecate the field from
        fieldName - the name of the field to be deprecated
      • addDefaultUnionIfMissing

        @Nonnull
        public static Descriptors.FileDescriptor addDefaultUnionIfMissing​(@Nonnull
                                                                          Descriptors.FileDescriptor fileDescriptor)
        Add a default union to the given records descriptor if missing.

        This method is a no-op if the union is present. Otherwise, the method will add a union to the records descriptor. The union descriptor will be filled in with all of the record types defined in the file except NESTED record types.

        Parameters:
        fileDescriptor - the records descriptor of the record meta-data
        Returns:
        the resulting records descriptor
      • addDefaultUnionIfMissing

        @Nonnull
        public static Descriptors.FileDescriptor addDefaultUnionIfMissing​(@Nonnull
                                                                          Descriptors.FileDescriptor fileDescriptor,
                                                                          @Nonnull
                                                                          Descriptors.Descriptor baseUnionDescriptor)
        Creates a default union descriptor for the given file descriptor if missing.

        If the given file descriptor is missing a union message, this method will add one before updating the meta-data. The generated union descriptor is constructed by adding any non-NESTED types in the file descriptor to the union descriptor from the currently stored meta-data. A new field is not added if a field of the given type already exists, and the order of any existing fields is preserved. Note that types are identified by name, so renaming top-level message types may result in validation errors when trying to update the record descriptor.

        Parameters:
        fileDescriptor - the file descriptor to create a union for
        baseUnionDescriptor - the base union descriptor
        Returns:
        the builder for the union
      • hasUnion

        public static boolean hasUnion​(@Nonnull
                                       Descriptors.FileDescriptor fileDescriptor)
        Checks if the file descriptor has a union.
        Parameters:
        fileDescriptor - the file descriptor
        Returns:
        true if the file descriptor has a union