|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for |
| 4 | + * license information. |
| 5 | + */ |
| 6 | + |
| 7 | +package com.function; |
| 8 | + |
| 9 | +import com.microsoft.azure.functions.HttpMethod; |
| 10 | +import com.microsoft.azure.functions.HttpRequestMessage; |
| 11 | +import com.microsoft.azure.functions.HttpResponseMessage; |
| 12 | +import com.microsoft.azure.functions.HttpStatus; |
| 13 | +import com.microsoft.azure.functions.OutputBinding; |
| 14 | +import com.microsoft.azure.functions.annotation.AuthorizationLevel; |
| 15 | +import com.microsoft.azure.functions.annotation.FunctionName; |
| 16 | +import com.microsoft.azure.functions.annotation.HttpTrigger; |
| 17 | +import com.microsoft.azure.functions.sql.annotation.SQLOutput; |
| 18 | +import com.function.Common.ProductDefaultPKAndDifferentColumnOrder; |
| 19 | + |
| 20 | +import java.util.Optional; |
| 21 | + |
| 22 | +/** |
| 23 | + * This shows an example of a SQL Output binding where the target table has a default primary key |
| 24 | + * of type uniqueidentifier and the column is not included in the output object. The order of the |
| 25 | + * properties in the POCO is different from the order of the columns in the SQL table. A new row will |
| 26 | + * be inserted and the uniqueidentifier will be generated by the engine. |
| 27 | + */ |
| 28 | +public class AddProductDefaultPKAndDifferentColumnOrder { |
| 29 | + @FunctionName("AddProductDefaultPKAndDifferentColumnOrder") |
| 30 | + public HttpResponseMessage run( |
| 31 | + @HttpTrigger( |
| 32 | + name = "req", |
| 33 | + methods = {HttpMethod.GET}, |
| 34 | + authLevel = AuthorizationLevel.ANONYMOUS, |
| 35 | + route = "addproductdefaultpkanddifferentcolumnorder") |
| 36 | + HttpRequestMessage<Optional<String>> request, |
| 37 | + @SQLOutput( |
| 38 | + name = "product", |
| 39 | + commandText = "dbo.ProductsWithDefaultPK", |
| 40 | + connectionStringSetting = "SqlConnectionString") |
| 41 | + OutputBinding<ProductDefaultPKAndDifferentColumnOrder> product) { |
| 42 | + |
| 43 | + ProductDefaultPKAndDifferentColumnOrder p = new ProductDefaultPKAndDifferentColumnOrder( |
| 44 | + 100, |
| 45 | + "test"); |
| 46 | + product.setValue(p); |
| 47 | + |
| 48 | + return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(product).build(); |
| 49 | + } |
| 50 | +} |
0 commit comments