@API(value=EXPERIMENTAL) public class MetaDataProtoEditor extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
MetaDataProtoEditor.AmbiguousTypeNameException
An exception that is thrown if the type of a field is ambiguous.
|
Constructor and Description |
---|
MetaDataProtoEditor() |
Modifier and Type | Method and 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 new
NESTED 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.
|
public static void addRecordType(@Nonnull RecordMetaDataProto.MetaData.Builder metaDataBuilder, @Nonnull DescriptorProtos.DescriptorProto newRecordType, @Nonnull KeyExpression primaryKey)
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 add NESTED
record types, use addNestedRecordType(com.apple.foundationdb.record.RecordMetaDataProto.MetaData.Builder, com.google.protobuf.DescriptorProtos.DescriptorProto)
.
metaDataBuilder
- the meta-data buildernewRecordType
- the new record typeprimaryKey
- the primary key of the new record typepublic static void addNestedRecordType(@Nonnull RecordMetaDataProto.MetaData.Builder metaDataBuilder, @Nonnull DescriptorProtos.DescriptorProto newRecordType)
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.metaDataBuilder
- the meta-data buildernewRecordType
- the new record typepublic static void deprecateRecordType(@Nonnull RecordMetaDataProto.MetaData.Builder metaDataBuilder, @Nonnull String recordType)
metaDataBuilder
- the meta-data builderrecordType
- the record type to be deprecatedpublic static void renameRecordType(@Nonnull RecordMetaDataProto.MetaData.Builder metaDataBuilder, @Nonnull String recordTypeName, @Nonnull String newRecordTypeName)
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).metaDataBuilder
- the meta-data builderrecordTypeName
- the name of the existing top-level record typenewRecordTypeName
- the new name to give to the record typepublic static void addField(@Nonnull RecordMetaDataProto.MetaData.Builder metaDataBuilder, @Nonnull String recordType, @Nonnull DescriptorProtos.FieldDescriptorProto field)
metaDataBuilder
- the meta-data builderrecordType
- the record type to add the field tofield
- the field to be addedpublic static void deprecateField(@Nonnull RecordMetaDataProto.MetaData.Builder metaDataBuilder, @Nonnull String recordType, @Nonnull String fieldName)
metaDataBuilder
- the meta-data builderrecordType
- the record type to deprecate the field fromfieldName
- the name of the field to be deprecated@Nonnull public static Descriptors.FileDescriptor addDefaultUnionIfMissing(@Nonnull Descriptors.FileDescriptor fileDescriptor)
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.
fileDescriptor
- the records descriptor of the record meta-data@Nonnull public static Descriptors.FileDescriptor addDefaultUnionIfMissing(@Nonnull Descriptors.FileDescriptor fileDescriptor, @Nonnull Descriptors.Descriptor baseUnionDescriptor)
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.
fileDescriptor
- the file descriptor to create a union forbaseUnionDescriptor
- the base union descriptor@Nonnull @API(value=INTERNAL) public static DescriptorProtos.DescriptorProto.Builder createSyntheticUnion(@Nonnull Descriptors.FileDescriptor fileDescriptor, @Nonnull Descriptors.Descriptor baseUnionDescriptor)
NESTED
message types that exist in the base union to the synthetic union.fileDescriptor
- the file descriptor to create a union forbaseUnionDescriptor
- the base union descriptorpublic static boolean hasUnion(@Nonnull Descriptors.FileDescriptor fileDescriptor)
fileDescriptor
- the file descriptor