use of com.apple.foundationdb.record.metadata.SyntheticRecordTypeBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilder method build.
/**
* Build and validate meta-data with specific index registry.
* @param validate {@code true} to validate the new meta-data
* @return new meta-data
*/
@Nonnull
public RecordMetaData build(boolean validate) {
Map<String, RecordType> builtRecordTypes = Maps.newHashMapWithExpectedSize(recordTypes.size());
Map<String, SyntheticRecordType<?>> builtSyntheticRecordTypes = Maps.newHashMapWithExpectedSize(syntheticRecordTypes.size());
RecordMetaData metaData = new RecordMetaData(recordsDescriptor, getUnionDescriptor(), unionFields, builtRecordTypes, builtSyntheticRecordTypes, indexes, universalIndexes, formerIndexes, splitLongRecords, storeRecordVersions, version, subspaceKeyCounter, usesSubspaceKeyCounter, recordCountKey, localFileDescriptor != null);
for (RecordTypeBuilder recordTypeBuilder : recordTypes.values()) {
KeyExpression primaryKey = recordTypeBuilder.getPrimaryKey();
if (primaryKey != null) {
builtRecordTypes.put(recordTypeBuilder.getName(), recordTypeBuilder.build(metaData));
for (Index index : recordTypeBuilder.getIndexes()) {
index.setPrimaryKeyComponentPositions(buildPrimaryKeyComponentPositions(index.getRootExpression(), primaryKey));
}
} else {
throw new MetaDataException("Record type " + recordTypeBuilder.getName() + " must have a primary key");
}
}
if (!syntheticRecordTypes.isEmpty()) {
DescriptorProtos.FileDescriptorProto.Builder fileBuilder = DescriptorProtos.FileDescriptorProto.newBuilder();
fileBuilder.setName("_synthetic");
fileBuilder.addDependency(unionDescriptor.getFile().getName());
syntheticRecordTypes.values().forEach(recordTypeBuilder -> recordTypeBuilder.buildDescriptor(fileBuilder));
final Descriptors.FileDescriptor fileDescriptor;
try {
final Descriptors.FileDescriptor[] dependencies = new Descriptors.FileDescriptor[] { unionDescriptor.getFile() };
fileDescriptor = Descriptors.FileDescriptor.buildFrom(fileBuilder.build(), dependencies);
} catch (Descriptors.DescriptorValidationException ex) {
throw new MetaDataException("Could not build synthesized file descriptor", ex);
}
for (SyntheticRecordTypeBuilder<?> recordTypeBuilder : syntheticRecordTypes.values()) {
builtSyntheticRecordTypes.put(recordTypeBuilder.getName(), recordTypeBuilder.build(metaData, fileDescriptor));
}
}
if (validate) {
final MetaDataValidator validator = new MetaDataValidator(metaData, indexMaintainerRegistry);
validator.validate();
}
return metaData;
}
Aggregations