Skip to content

Commit f5e2499

Browse files
committed
add multiple binding function samples
1 parent 08f2348 commit f5e2499

File tree

4 files changed

+110
-4
lines changed

4 files changed

+110
-4
lines changed

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,5 +360,9 @@ __azurite_db*__.json
360360
# Python virtual environment
361361
.venv
362362

363-
# Mac OS X
364-
.DS_Store
363+
# Mac OS X
364+
.DS_Store
365+
366+
# Java build files
367+
repo/
368+
target/

samples/samples-java/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Build output
2-
target/
3-
repo/
42
*.class
53

64
# Log file
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.function.Common.Product;
10+
import com.microsoft.azure.functions.HttpMethod;
11+
import com.microsoft.azure.functions.HttpRequestMessage;
12+
import com.microsoft.azure.functions.HttpResponseMessage;
13+
import com.microsoft.azure.functions.HttpStatus;
14+
import com.microsoft.azure.functions.OutputBinding;
15+
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
16+
import com.microsoft.azure.functions.annotation.FunctionName;
17+
import com.microsoft.azure.functions.annotation.HttpTrigger;
18+
import com.microsoft.azure.functions.sql.annotation.SQLInput;
19+
import com.microsoft.azure.functions.sql.annotation.SQLOutput;
20+
21+
import java.util.Optional;
22+
23+
/**
24+
* This function uses a SQL input binding to get products from the Products table
25+
* and upsert those products to the ProductsWithIdentity table.
26+
*/
27+
public class GetAndAddProducts {
28+
@FunctionName("GetAndAddProducts")
29+
public HttpResponseMessage run(
30+
@HttpTrigger(
31+
name = "req",
32+
methods = {HttpMethod.GET},
33+
authLevel = AuthorizationLevel.ANONYMOUS,
34+
route = "getandaddproducts/{cost}")
35+
HttpRequestMessage<Optional<String>> request,
36+
@SQLInput(
37+
name = "products",
38+
commandText = "SELECT * FROM Products WHERE Cost = @Cost",
39+
commandType = "Text",
40+
parameters = "@Cost={cost}",
41+
connectionStringSetting = "SqlConnectionString")
42+
Product[] products,
43+
@SQLOutput(
44+
name = "productsWithIdentity",
45+
commandText = "ProductsWithIdentity",
46+
connectionStringSetting = "SqlConnectionString")
47+
OutputBinding<Product[]> productsWithIdentity) {
48+
49+
productsWithIdentity.setValue(products);
50+
51+
return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(products).build();
52+
}
53+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.function.Common.Product;
10+
import com.microsoft.azure.functions.HttpMethod;
11+
import com.microsoft.azure.functions.HttpRequestMessage;
12+
import com.microsoft.azure.functions.HttpResponseMessage;
13+
import com.microsoft.azure.functions.HttpStatus;
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.SQLInput;
18+
19+
import java.util.Optional;
20+
21+
public class GetProductsFromTwoTables {
22+
@FunctionName("GetProductsFromTwoTables")
23+
public HttpResponseMessage run(
24+
@HttpTrigger(
25+
name = "req",
26+
methods = {HttpMethod.GET},
27+
authLevel = AuthorizationLevel.ANONYMOUS,
28+
route = "getproductsfromtwotables/{cost}")
29+
HttpRequestMessage<Optional<String>> request,
30+
@SQLInput(
31+
name = "products",
32+
commandText = "SELECT * FROM Products WHERE Cost = @Cost",
33+
commandType = "Text",
34+
parameters = "@Cost={cost}",
35+
connectionStringSetting = "SqlConnectionString")
36+
Product[] products,
37+
@SQLInput(
38+
name = "productsWithIdentity",
39+
commandText = "SELECT * FROM ProductsWithIdentity WHERE Cost = @Cost",
40+
commandType = "Text",
41+
parameters = "@Cost={cost}",
42+
connectionStringSetting = "SqlConnectionString")
43+
Product[] productsWithIdentity) {
44+
45+
Product[] allProducts = new Product[products.length + productsWithIdentity.length];
46+
System.arraycopy(products, 0, allProducts, 0, products.length);
47+
System.arraycopy(productsWithIdentity, 0, allProducts, products.length, productsWithIdentity.length);
48+
49+
return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(allProducts).build();
50+
}
51+
}

0 commit comments

Comments
 (0)