Class MetaDataProtoEditor
- java.lang.Object
-
- com.apple.foundationdb.record.provider.foundationdb.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MetaDataProtoEditor.AmbiguousTypeNameException
An exception that is thrown if the type of a field is ambiguous.
-
Constructor Summary
Constructors Constructor Description MetaDataProtoEditor()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Descriptors.FileDescriptor
addDefaultUnionIfMissing(Descriptors.FileDescriptor fileDescriptor)
Add a default union to the given records descriptor if missing.static Descriptors.FileDescriptor
addDefaultUnionIfMissing(Descriptors.FileDescriptor fileDescriptor, Descriptors.Descriptor baseUnionDescriptor)
Creates a default union descriptor for the given file descriptor if missing.static void
addField(RecordMetaDataProto.MetaData.Builder metaDataBuilder, String recordType, DescriptorProtos.FieldDescriptorProto field)
Add a field to a record type.static void
addNestedRecordType(RecordMetaDataProto.MetaData.Builder metaDataBuilder, DescriptorProtos.DescriptorProto newRecordType)
Add a newNESTED
record type to the meta-data.static void
addRecordType(RecordMetaDataProto.MetaData.Builder metaDataBuilder, DescriptorProtos.DescriptorProto newRecordType, KeyExpression primaryKey)
Add a new record type to the meta-data.static DescriptorProtos.DescriptorProto.Builder
createSyntheticUnion(Descriptors.FileDescriptor fileDescriptor, Descriptors.Descriptor baseUnionDescriptor)
Creates a default union descriptor for the given file descriptor and a base union descriptor.static void
deprecateField(RecordMetaDataProto.MetaData.Builder metaDataBuilder, String recordType, String fieldName)
Deprecate a field from a record type.static void
deprecateRecordType(RecordMetaDataProto.MetaData.Builder metaDataBuilder, String recordType)
Deprecate a record type from the meta-data.static boolean
hasUnion(Descriptors.FileDescriptor fileDescriptor)
Checks if the file descriptor has a union.static void
renameRecordType(RecordMetaDataProto.MetaData.Builder metaDataBuilder, String recordTypeName, String newRecordTypeName)
Rename a record type.
-
-
-
Method Detail
-
addRecordType
public static void addRecordType(@Nonnull RecordMetaDataProto.MetaData.Builder metaDataBuilder, @Nonnull DescriptorProtos.DescriptorProto newRecordType, @Nonnull KeyExpression primaryKey)
Add a new record type to the meta-data.Adding the record type involves three steps: the message type is added to the file descriptor's list of message types, a field of the given type is added to the union, and its primary key is set. Note that adding
UNION
record types is not allowed. To addNESTED
record types, useaddNestedRecordType(com.apple.foundationdb.record.RecordMetaDataProto.MetaData.Builder, com.google.protobuf.DescriptorProtos.DescriptorProto)
.- Parameters:
metaDataBuilder
- the meta-data buildernewRecordType
- the new record typeprimaryKey
- the primary key of the new record type
-
addNestedRecordType
public static void addNestedRecordType(@Nonnull RecordMetaDataProto.MetaData.Builder metaDataBuilder, @Nonnull DescriptorProtos.DescriptorProto newRecordType)
Add a newNESTED
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 buildernewRecordType
- 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 builderrecordType
- 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, includingNESTED
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 notNESTED
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 builderrecordTypeName
- the name of the existing top-level record typenewRecordTypeName
- the new name to give to the record type
-
addField
public static void addField(@Nonnull RecordMetaDataProto.MetaData.Builder metaDataBuilder, @Nonnull String recordType, @Nonnull DescriptorProtos.FieldDescriptorProto field)
Add a field to a record type.- Parameters:
metaDataBuilder
- the meta-data builderrecordType
- the record type to add the field tofield
- the field to be added
-
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 builderrecordType
- the record type to deprecate the field fromfieldName
- 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 forbaseUnionDescriptor
- the base union descriptor- Returns:
- the builder for the union
-
createSyntheticUnion
@Nonnull @API(INTERNAL) public static DescriptorProtos.DescriptorProto.Builder createSyntheticUnion(@Nonnull Descriptors.FileDescriptor fileDescriptor, @Nonnull Descriptors.Descriptor baseUnionDescriptor)
Creates a default union descriptor for the given file descriptor and a base union descriptor. It adds all of the non-NESTED
message types that exist in the base union to the synthetic union.- Parameters:
fileDescriptor
- the file descriptor to create a union forbaseUnionDescriptor
- 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
-
-