private void PopulateUpsertResourceCommand(SqlCommandWrapper sqlCommandWrapper, ResourceWrapper resource, ResourceMetadata resourceMetadata, bool allowCreate, bool keepHistory, int?eTag, RecyclableMemoryStream stream) { long baseResourceSurrogateId = ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(resource.LastModified.UtcDateTime); short resourceTypeId = _model.GetResourceTypeId(resource.ResourceTypeName); if (_schemaInformation.Current >= SchemaVersionConstants.SearchParameterHashSchemaVersion) { VLatest.UpsertResource.PopulateCommand( sqlCommandWrapper, baseResourceSurrogateId: ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(resource.LastModified.UtcDateTime), resourceTypeId: _model.GetResourceTypeId(resource.ResourceTypeName), resourceId: resource.ResourceId, eTag: eTag, allowCreate: allowCreate, isDeleted: resource.IsDeleted, keepHistory: keepHistory, requestMethod: resource.Request.Method, searchParamHash: resource.SearchParameterHash, rawResource: stream, tableValuedParameters: _upsertResourceTvpGeneratorVLatest.Generate(new List <ResourceWrapper> { resource })); } else if (_schemaInformation.Current >= SchemaVersionConstants.SupportForReferencesWithMissingTypeVersion) { V7.UpsertResource.PopulateCommand( sqlCommandWrapper, baseResourceSurrogateId: baseResourceSurrogateId, resourceTypeId: resourceTypeId, resourceId: resource.ResourceId, eTag: eTag, allowCreate: allowCreate, isDeleted: resource.IsDeleted, keepHistory: keepHistory, requestMethod: resource.Request.Method, rawResource: stream, tableValuedParameters: _upsertResourceTvpGeneratorV7.Generate(resourceMetadata)); } else { V6.UpsertResource.PopulateCommand( sqlCommandWrapper, baseResourceSurrogateId: baseResourceSurrogateId, resourceTypeId: resourceTypeId, resourceId: resource.ResourceId, eTag: eTag, allowCreate: allowCreate, isDeleted: resource.IsDeleted, keepHistory: keepHistory, requestMethod: resource.Request.Method, rawResource: stream, tableValuedParameters: _upsertResourceTvpGeneratorV6.Generate(resourceMetadata)); } }
public IEnumerable <BulkReindexResourceTableTypeV1Row> GenerateRows(IReadOnlyList <ResourceWrapper> input) { for (var index = 0; index < input.Count; index++) { ResourceWrapper resource = input[index]; var resourceTypeId = _model.GetResourceTypeId(resource.ResourceTypeName); var resourceId = resource.ResourceId; int etag = 0; if (resource.Version != null && !int.TryParse(resource.Version, out etag)) { // Set the etag to a sentinel value to enable expected failure paths when updating with both existing and nonexistent resources. etag = -1; } yield return(new BulkReindexResourceTableTypeV1Row( index, resourceTypeId, resourceId, resource.Version == null ? null : etag, resource.SearchParameterHash)); } }