RequestBatch
open class RequestBatch : ObjectBase, @unchecked Sendable
Encapsulates an OData batch request.
Example using proxy classes
open func processBatchExample() throws -> Void {
let service = self.service
let supplier1 = try service.fetchSupplier(matching: DataQuery().top(1))
let supplier2 = supplier1.copy()
let supplier3 = supplier1.copy()
let supplier4 = supplier1.copy()
supplier2.companyName = "Alpha Inc."
supplier3.companyName = "Beta Inc."
try service.createEntity(supplier2)
try service.createEntity(supplier3)
supplier3.companyName = "Gamma Inc."
let product1 = try service.fetchProduct(matching: DataQuery().top(1))
let product2 = product1.copy()
product2.productName = "Delta Cake"
let batch = RequestBatch()
let changes = ChangeSet()
changes.createEntity(supplier4)
changes.updateEntity(supplier3)
changes.deleteEntity(supplier2)
changes.createEntity(product2)
changes.createLink(from: product2, property: Product.supplier, to: supplier4)
changes.updateLink(from: product2, property: Product.supplier, to: supplier3)
changes.deleteLink(from: product2, property: Product.supplier, to: supplier3)
let query = DataQuery().from(NorthwindServiceMetadata.EntitySets.suppliers)
batch.addChanges(changes)
batch.addQuery(query)
try service.processBatch(batch)
let suppliers = try Supplier.array(from: batch.queryResult(for: query)
.entityList())
try Example.show("There are now ", Example.formatInt(suppliers.count), " suppliers.")
}
Example using dynamic API
open func processBatchExample() throws -> Void {
let service = self.service
let suppliersEntitySet = service.entitySet(withName: "Suppliers")
let productsEntitySet = service.entitySet(withName: "Products")
let supplierEntityType = suppliersEntitySet.entityType
let companyNameProperty = supplierEntityType.property(withName: "CompanyName")
let productEntityType = productsEntitySet.entityType
let productNameProperty = productEntityType.property(withName: "ProductName")
let supplierProperty = productEntityType.property(withName: "Supplier")
let supplier1 = try service.executeQuery(DataQuery().from(suppliersEntitySet)
.top(1))
.requiredEntity()
let supplier2 = supplier1.copyEntity()
let supplier3 = supplier1.copyEntity()
let supplier4 = supplier1.copyEntity()
companyNameProperty.setStringValue(in: supplier2, to: "Alpha Inc.")
companyNameProperty.setStringValue(in: supplier3, to: "Beta Inc.")
try service.createEntity(supplier2)
try service.createEntity(supplier3)
companyNameProperty.setStringValue(in: supplier3, to: "Gamma Inc.")
let product1 = try service.executeQuery(DataQuery().from(productsEntitySet)
.top(1))
.requiredEntity()
let product2 = product1.copyEntity()
productNameProperty.setStringValue(in: product2, to: "Delta Cake")
let batch = RequestBatch()
let changes = ChangeSet()
changes.createEntity(supplier4)
changes.updateEntity(supplier3)
changes.deleteEntity(supplier2)
changes.createEntity(product2)
changes.createLink(from: product2, property: supplierProperty, to: supplier4)
let query = DataQuery().from(suppliersEntitySet)
batch.addChanges(changes)
batch.addQuery(query)
try service.processBatch(batch)
let suppliers = try batch.queryResult(for: query).entityList()
try Example.show("There are now ", Example.formatInt(suppliers.length), " suppliers.")
}
-
Should the server continue executing all requests in a batch if one or more of the requests returns an error status. Defaults to
true.Declaration
Swift
final public var continueOnError: Bool -
Default initializer.
Declaration
Swift
override public init() -
Declaration
Swift
open func actionResult(for call: DataQuery, at index: Int = Int(Int32.min)) -> QueryResultParameters
callDataQuerycontaining the action call.indexFrom zero to
size - 1. Index for the query. Omit if unknown, in which case the query will be located by a linear search.Return Value
The
QueryResultfor an action call. -
Add an action call to this request batch.
Example using proxy classes
open func invokeActionsInBatch() throws -> Void { let service = self.service let batch = RequestBatch() let action1 = DataQuery() let action2 = DataQuery() try service.deleteVideosInCategory("Romance", query: action1.deferExecution()) try service.deleteVideosInCategory("Suspense", query: action2.deferExecution()) batch.addAction(call: action1) batch.addAction(call: action2) try service.processBatch(batch) batch.checkActionResult(for: action1) batch.checkActionResult(for: action2) }Declaration
Swift
open func addAction(call: DataQuery, headers: HTTPHeaders? = nil, options: RequestOptions? = nil)Parameters
callQuery with non-null
DataQuery.methodCallfor an action method.headersAction call headers.
optionsAction call options.
-
Add a change set to this request batch.
Declaration
Swift
open func addChanges(_ changes: ChangeSet, headers: HTTPHeaders? = nil, options: RequestOptions? = nil)Parameters
changesChange set.
headersChange set headers.
optionsChange set options.
-
Add a function call to this request batch.
Example using proxy classes
open func invokeFunctionsInBatch() throws -> Void { let service = self.service let batch = RequestBatch() let query1 = DataQuery() let query2 = DataQuery() _ = try service.videosInCategory("Romance", query: query1.deferExecution()) _ = try service.videosInCategory("Suspense", query: query2.deferExecution()) batch.addFunction(call: query1) batch.addFunction(call: query2) try service.processBatch(batch) let videos1 = try Video.array(from: batch.functionResult(for: query1) .entityList()) let videos2 = try Video.array(from: batch.functionResult(for: query2) .entityList()) self.showVideos(videos1) self.showVideos(videos2) }Declaration
Swift
open func addFunction(call: DataQuery, headers: HTTPHeaders? = nil, options: RequestOptions? = nil)Parameters
callQuery with non-null
DataQuery.methodCallfor a function method.headersFunction call headers.
optionsFunction call options.
-
Add a data query to this request batch.
Declaration
Swift
open func addQuery(_ query: DataQuery, headers: HTTPHeaders? = nil, options: RequestOptions? = nil)Parameters
queryData query.
headersData query headers.
optionsData query options.
-
Add a query result to this request batch.
Declaration
Swift
open func addQueryResult(query: DataQuery, result: QueryResult, index: Int = Int(Int32.min))Parameters
queryData query, which must have been previously added to this batch using
addQuery.indexFrom zero to
size - 1. Index for the query. Omit if unknown, in which case the query will be located by a linear search.resultQuery result.
-
Declaration
Swift
open func changeSet(at index: Int) -> ChangeSetParameters
indexFrom zero to
size - 1.Return Value
The change set, if
isChangeSet(index)istrue; otherwise throwsundefined. -
Call
QueryResult.checkon theQueryResultfor an action call. ThrowsDataServiceExceptionif the action failed.Declaration
Swift
open func checkActionResult(for call: DataQuery, at index: Int = Int(Int32.min))Parameters
callDataQuerycontaining the action call.indexFrom zero to
size - 1. Index for the query. Omit if unknown, in which case the query will be located by a linear search. -
Declaration
Swift
open func dataQuery(at index: Int) -> DataQueryParameters
indexFrom zero to
size - 1.Return Value
The data query, if
isDataQuery(index)istrue; otherwise throwsundefined. -
Add a “download media” query to the batch, to obtain a stream for downloading the content of a media entity from the target system. Caution: streams are often used for large content that may not fit (all at once) in available application memory. Having too many threads simultaneously downloading streams, or using
ByteStream.readAndClose, may result in out-of-memory conditions on memory-constrained devices.See also
QueryResult.getByteStream,QueryResult.getCharStream.Declaration
Swift
open func downloadMedia(entity: EntityValue, headers: HTTPHeaders? = nil, options: RequestOptions? = nil) -> DataQueryParameters
entityEntity whose content is to be downloaded.
headersRequest-specific headers.
optionsRequest-specific options.
Return Value
A data query representing the media download request.
-
Add a “download stream” query to the batch, to obtain a stream for downloading the content of a stream property from the target system. Caution: streams are often used for large content that may not fit (all at once) in available application memory. Having too many threads simultaneously downloading streams, or using
ByteStream.readAndClose, may result in out-of-memory conditions on memory-constrained devices.See also
QueryResult.getByteStream,QueryResult.getCharStream.Declaration
Swift
open func downloadStream(entity: EntityValue, link: StreamLink, headers: HTTPHeaders? = nil, options: RequestOptions? = nil) -> DataQueryParameters
entityEntity containing the stream property whose content is to be downloaded.
linkStream link for the stream to be downloaded.
headersRequest-specific headers.
optionsRequest-specific options.
Return Value
A data query representing the stream download request.
-
Error if
statusdoes not represent a successful response.Declaration
Swift
@inline(__always) public final var error: DataServiceError? { get set } -
Declaration
Swift
open func functionResult(for call: DataQuery, at index: Int = Int(Int32.min)) -> QueryResultParameters
callDataQuerycontaining the function call.indexFrom zero to
size - 1. Index for the query. Omit if unknown, in which case the query will be located by a linear search.Return Value
The
QueryResultfor a function call. -
Declaration
Swift
open func headers(at index: Int) -> HTTPHeadersParameters
indexFrom zero to
size - 1.Return Value
The HTTP headers for the request at
index. -
Add a function call to the batch.
See also
DataQuery.bindandDataQuery.from, for setting the binding parameter for a bound function (either can be applied to the returned query).Declaration
Swift
open func invokeFunction(method: DataMethod, parameters: ParameterList = ParameterList.empty, headers: HTTPHeaders? = nil, options: RequestOptions? = nil) -> DataQueryParameters
methodFunction to be called.
parametersFunction call parameters.
headersFunction call headers.
optionsFunction call options.
Return Value
A data query representing the function call.
-
Declaration
Swift
open func isAction(at index: Int) -> BoolParameters
indexFrom zero to
size - 1Return Value
trueifindexis a valid change index, and the request at that index is for an action call. -
Declaration
Swift
open func isChangeSet(at index: Int) -> BoolParameters
indexFrom zero to
size - 1.Return Value
trueifindexis a valid request index, and the request at that index is aChangeSet; otherwisefalse. -
Declaration
Swift
open func isDataQuery(at index: Int) -> BoolParameters
indexFrom zero to
size - 1.Return Value
trueifindexis a valid request index, and the request at that index is aDataQuery; otherwisefalse. -
True if
sizeis zero.Declaration
Swift
open var isEmpty: Bool { get } -
Declaration
Swift
open func isFunction(at index: Int) -> BoolParameters
indexFrom zero to
size - 1Return Value
trueifindexis a valid change index, and the request at that index is for a function call. -
True if
sizeis non-zero.Declaration
Swift
open var isNotEmpty: Bool { get } -
Declaration
Swift
open func options(at index: Int) -> RequestOptionsParameters
indexFrom zero to
size - 1.Return Value
The request options for the request at
index. -
See also
addQuery.Declaration
Swift
open func queryResult(for query: DataQuery, index: Int = Int(Int32.min)) -> QueryResultParameters
queryData query.
indexFrom zero to
size - 1. Index for the query. Omit if unknown, in which case the query will be located by a linear search.Return Value
The result of a data query within this batch.
-
Replace the request headers for a previously added request.
Declaration
Swift
open func replaceHeaders(at index: Int, headers: HTTPHeaders)Parameters
indexFrom zero to
size - 1.headersUpdated request headers.
-
Replace the request options for a previously added request.
Declaration
Swift
open func replaceOptions(at index: Int, options: RequestOptions)Parameters
indexFrom zero to
size - 1.optionsUpdated request options.
-
The number of requests in this request batch.
Declaration
Swift
open var size: Int { get } -
Response status (e.g. HTTP status code 200 = OK).
Declaration
Swift
@inline(__always) public final var status: Int { get set }