Package com.apple.foundationdb.record
Class RecordMetaData
- java.lang.Object
-
- com.apple.foundationdb.record.RecordMetaData
-
- All Implemented Interfaces:
RecordMetaDataProvider
@API(MAINTAINED) public class RecordMetaData extends Object implements RecordMetaDataProvider
Meta-data for Record Layer record stores. Records are represented using ProtobufMessage
s. Each messageDescriptors.Descriptor
corresponds to aRecordType
. All message types in the database come from a singleDescriptors.FileDescriptor
. The Protobuf file must also define a union message type (conventionally namedRecordTypeUnion
) with fields for each of the possible record types. When serializing, the record is put in the corresponding field and the whole saved as a byte string. Then when deserializing, the returned record can be of any of the allowed types. Meta-data can also define any number of secondaryIndex
es for record types.- See Also:
RecordMetaDataBuilder
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RecordMetaData(Descriptors.FileDescriptor recordsDescriptor, Descriptors.Descriptor unionDescriptor, Map<Descriptors.Descriptor,Descriptors.FieldDescriptor> unionFields, Map<String,RecordType> recordTypes, Map<String,SyntheticRecordType<?>> syntheticRecordTypes, Map<String,Index> indexes, Map<String,Index> universalIndexes, List<FormerIndex> formerIndexes, boolean splitLongRecords, boolean storeRecordVersions, int version, long subspaceKeyCounter, boolean usesSubspaceKeyCounter, KeyExpression recordCountKey, boolean usesLocalRecordsDescriptor)
-
Method Summary
-
-
-
Constructor Detail
-
RecordMetaData
protected RecordMetaData(@Nonnull Descriptors.FileDescriptor recordsDescriptor, @Nonnull Descriptors.Descriptor unionDescriptor, @Nonnull Map<Descriptors.Descriptor,Descriptors.FieldDescriptor> unionFields, @Nonnull Map<String,RecordType> recordTypes, @Nonnull Map<String,SyntheticRecordType<?>> syntheticRecordTypes, @Nonnull Map<String,Index> indexes, @Nonnull Map<String,Index> universalIndexes, @Nonnull List<FormerIndex> formerIndexes, boolean splitLongRecords, boolean storeRecordVersions, int version, long subspaceKeyCounter, boolean usesSubspaceKeyCounter, @Nullable KeyExpression recordCountKey, boolean usesLocalRecordsDescriptor)
-
-
Method Detail
-
newBuilder
@Nonnull public static RecordMetaDataBuilder newBuilder()
Creates an instance ofRecordMetaDataBuilder
.- Returns:
- a new builder
-
getRecordsDescriptor
@Nonnull public Descriptors.FileDescriptor getRecordsDescriptor()
-
getUnionDescriptor
@Nonnull public Descriptors.Descriptor getUnionDescriptor()
-
getUnionFieldForRecordType
@Nonnull public Descriptors.FieldDescriptor getUnionFieldForRecordType(@Nonnull RecordType recordType)
-
getRecordTypes
@Nonnull public Map<String,RecordType> getRecordTypes()
-
getRecordType
@Nonnull public RecordType getRecordType(@Nonnull String name)
-
getRecordTypeForDescriptor
@Nonnull public RecordType getRecordTypeForDescriptor(@Nonnull Descriptors.Descriptor descriptor)
-
getRecordTypeFromRecordTypeKey
@Nonnull public RecordType getRecordTypeFromRecordTypeKey(@Nonnull Object recordTypeKey)
Get the record type that uses the given record type key.- Parameters:
recordTypeKey
- the key used as a prefix for some record type- Returns:
- the record type
- Throws:
MetaDataException
- if the given key does not correspond to any record type
-
getSyntheticRecordTypes
@Nonnull @API(EXPERIMENTAL) public Map<String,SyntheticRecordType<?>> getSyntheticRecordTypes()
-
getSyntheticRecordType
@Nonnull @API(EXPERIMENTAL) public SyntheticRecordType<?> getSyntheticRecordType(@Nonnull String name)
-
getSyntheticRecordTypeFromRecordTypeKey
@Nonnull @API(EXPERIMENTAL) public SyntheticRecordType<?> getSyntheticRecordTypeFromRecordTypeKey(@Nonnull Object recordTypeKey)
-
getIndexableRecordType
public RecordType getIndexableRecordType(@Nonnull String name)
Get a record type or synthetic record type by name as used in an index.- Parameters:
name
- the name of the record type- Returns:
- the possibly synthetic record type
-
getIndexFromSubspaceKey
@Nonnull public Index getIndexFromSubspaceKey(@Nonnull Object subspaceKey)
Get the index that uses the given subspace key.- Parameters:
subspaceKey
- the key used as a prefix for some index- Returns:
- the index
- Throws:
MetaDataException
- if the given key does not correspond to any index
-
getFormerIndexes
public List<FormerIndex> getFormerIndexes()
-
isSplitLongRecords
public boolean isSplitLongRecords()
-
isStoreRecordVersions
public boolean isStoreRecordVersions()
-
getVersion
public int getVersion()
-
getSubspaceKeyCounter
public long getSubspaceKeyCounter()
Get value of the counter used for index subspace keys if the counter-based assignment is used.- Returns:
- the value of the counter
- See Also:
RecordMetaDataBuilder.enableCounterBasedSubspaceKeys()
-
usesSubspaceKeyCounter
public boolean usesSubspaceKeyCounter()
Checks if counter-based subspace key assignment is used.- Returns:
true
if the subspace key counter is used- See Also:
RecordMetaDataBuilder.enableCounterBasedSubspaceKeys()
-
getFormerIndexesSince
public List<FormerIndex> getFormerIndexesSince(int version)
-
getIndexesSince
public Map<Index,List<RecordType>> getIndexesSince(int version)
-
recordTypesForIndex
@Nonnull public Collection<RecordType> recordTypesForIndex(@Nonnull Index index)
-
getRecordCountKey
@Nullable @API(DEPRECATED) public KeyExpression getRecordCountKey()
-
primaryKeyHasRecordTypePrefix
public boolean primaryKeyHasRecordTypePrefix()
Determine whether every record type in this meta-data hasRecordType.primaryKeyHasRecordTypePrefix()
. If so, records are strictly partitioned by record type.- Returns:
true
if every record type has a record type prefix on the primary key
-
commonPrimaryKey
@Nullable public KeyExpression commonPrimaryKey()
Determine whether every record type in this meta-data has the same primary key.- Returns:
- the common primary key or
null
-
commonPrimaryKey
@Nullable public static KeyExpression commonPrimaryKey(@Nonnull Collection<RecordType> recordTypes)
-
getRecordMetaData
@Nonnull public RecordMetaData getRecordMetaData()
Get thisRecordMetaData
instance.- Specified by:
getRecordMetaData
in interfaceRecordMetaDataProvider
- Returns:
- this
RecordMetaData
instance
-
build
@Nonnull public static RecordMetaData build(@Nonnull Descriptors.FileDescriptor descriptor)
-
build
@Nonnull public static RecordMetaData build(@Nonnull RecordMetaDataProto.MetaData proto)
Factory method to deserialize a record meta-data proto. It assumes that the proto contains all of the dependencies and does not process extension options.- Parameters:
proto
- the serialized proto message of theRecordMetaData
- Returns:
- the
RecordMetaData
object
-
toProto
@Nonnull public RecordMetaDataProto.MetaData toProto()
Serializes the record meta-data to aMetaData
proto message. By default, it includes all of the dependencies exceptTupleFieldsProto
,RecordMetaDataOptionsProto
andRecordMetaDataProto
.Note that if this record meta-data object was created with a local file descriptor, then serializing the meta-data to a proto message is disallowed. This is because setting a local file descriptor can change the meta-data in ways that would change its serialization, but it also will not update the meta-data version. This means that if the meta-data were then saved to disk, existing clients would not be informed that the meta-data had been updated.
- Returns:
- the serialized
MetaData
proto message - Throws:
KeyExpression.SerializationException
- on any serialization failuresMetaDataException
- if thisRecordMetaData
was initialized with a local file descriptor
-
toProto
@Nonnull public RecordMetaDataProto.MetaData toProto(@Nullable Descriptors.FileDescriptor[] excludedDependencies) throws KeyExpression.SerializationException
Serializes the record meta-data to aMetaData
proto message. This operates liketoProto()
except that any dependency in the excluded list is not included in the serialized proto message. If the list is set tonull
, then all dependencies will be serialized to the proto message including those that are execluded by default.- Parameters:
excludedDependencies
- a list of dependencies not to include in the serialized proto- Returns:
- the serialized
MetaData
proto message - Throws:
KeyExpression.SerializationException
- on any serialization failuresMetaDataException
- if thisRecordMetaData
was initialized with a local file descriptor- See Also:
toProto()
-
-