Skip to content

Commit 7bcae01

Browse files
Merge branch 'main' into chgagnon/triggerbindingsmerge
# Conflicts: # README.md
2 parents 5c37c5d + f06252e commit 7bcae01

File tree

128 files changed

+4311
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+4311
-93
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,7 @@ __queuestorage__
358358
__azurite_db*__.json
359359

360360
# Python virtual environment
361-
.venv
361+
.venv
362+
363+
# Mac OS X
364+
.DS_Store

Directory.Packages.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@
1818
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
1919
<PackageVersion Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
2020
<PackageVersion Include="BenchmarkDotNet" Version="0.13.1" />
21+
<PackageVersion Include="Microsoft.Azure.Functions.Worker" Version="1.10.0" />
22+
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
23+
<PackageVersion Include="System.Net.NameResolution" Version="4.3.0" />
24+
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
25+
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.0" />
2126
</ItemGroup>
2227
</Project>

README.md

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Azure SQL bindings for Azure Functions are supported for:
1616
- .NET functions (C# in-process)
1717
- NodeJS functions (JavaScript/TypeScript)
1818
- Python functions
19+
- Java functions
1920

2021
## Table of Contents
2122

@@ -40,6 +41,9 @@ Azure SQL bindings for Azure Functions are supported for:
4041
- [Python functions](#python-functions)
4142
- [Input Binding Tutorial](#input-binding-tutorial-2)
4243
- [Output Binding Tutorial](#output-binding-tutorial-2)
44+
- [Java functions](#java-functions)
45+
- [Input Binding Tutorial](#input-binding-tutorial-3)
46+
- [Output Binding Tutorial](#output-binding-tutorial-3)
4347
- [Configuration](#configuration)
4448
- [Trigger Binding Configuration](#trigger-binding-configuration)
4549
- [Sql_Trigger_BatchSize](#sql_trigger_batchsize)
@@ -122,7 +126,7 @@ These steps can be done in the Terminal/CLI or with PowerShell.
122126

123127
1. Install [Azure Functions Core Tools](https://docs.microsoft.com/azure/azure-functions/functions-run-local)
124128

125-
2. Create a function app for .NET, JavaScript, TypeScript or Python.
129+
2. Create a function app for .NET, JavaScript, TypeScript, Python, or Java.
126130

127131
**.NET**
128132
```bash
@@ -154,6 +158,13 @@ These steps can be done in the Terminal/CLI or with PowerShell.
154158
func init --worker-runtime python
155159
```
156160

161+
**Java**
162+
```bash
163+
mkdir MyApp
164+
cd MyApp
165+
func init --worker-runtime java
166+
```
167+
157168
3. Enable SQL bindings on the function app. More information can be found [in Microsoft Docs](https://docs.microsoft.com/azure/azure-functions/functions-bindings-azure-sql).
158169

159170
**.NET:** Install the extension.
@@ -190,6 +201,24 @@ These steps can be done in the Terminal/CLI or with PowerShell.
190201
"PYTHON_ISOLATE_WORKER_DEPENDENCIES": "1"
191202
```
192203

204+
**Java:**
205+
Update the `host.json` file to the preview extension bundle.
206+
```json
207+
"extensionBundle": {
208+
"id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
209+
"version": "[4.*, 5.0.0)"
210+
}
211+
```
212+
213+
Add the `azure-functions-java-library-sql` dependency to the pom.xml file.
214+
```xml
215+
<dependency>
216+
<groupId>com.microsoft.azure.functions</groupId>
217+
<artifactId>azure-functions-java-library-sql</artifactId>
218+
<version>0.1.0</version>
219+
</dependency>
220+
```
221+
193222
### Configure Function App
194223

195224
Once you have your Function App you need to configure it for use with Azure SQL bindings for Azure Functions.
@@ -565,6 +594,132 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
565594
- Hit 'F5' to run your code. Click the link to upsert the output array values in your SQL table. Your upserted values should launch in the browser.
566595
- Congratulations! You have successfully created your first SQL output binding! Checkout [Output Binding](#Output-Binding) for more information on how to use it and explore on your own!
567596
597+
### Java functions
598+
599+
#### Input Binding Tutorial
600+
601+
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](#Create-a-SQL-Server).
602+
603+
- Open your app that you created in [Create a Function App](#create-a-function-app) in VSCode
604+
- Press 'F1' and search for 'Azure Functions: Create Function'
605+
- Choose HttpTrigger -> (Provide a package name) -> (Provide a function name) -> anonymous
606+
- In the file that opens, replace the `public HttpResponseMessage run` block with the below code.
607+
608+
```java
609+
public HttpResponseMessage run(
610+
@HttpTrigger(
611+
name = "req",
612+
methods = {HttpMethod.GET, HttpMethod.POST},
613+
authLevel = AuthorizationLevel.ANONYMOUS,
614+
route = "getemployees")
615+
HttpRequestMessage<Optional<String>> request,
616+
@SQLInput(
617+
commandText = "SELECT * FROM Employees",
618+
commandType = "Text",
619+
connectionStringSetting = "SqlConnectionString")
620+
Employee[] employees) {
621+
return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(employees).build();
622+
}
623+
```
624+
625+
*In the above, "select * from Employees" is the SQL script run by the input binding. The CommandType on the line below specifies whether the first line is a query or a stored procedure. On the next line, the ConnectionStringSetting specifies that the app setting that contains the SQL connection string used to connect to the database is "SqlConnectionString." For more information on this, see the [Input Binding](#Input-Binding) section*
626+
627+
- Add 'import com.microsoft.azure.functions.sql.annotation.SQLInput;'
628+
- Create a new file and call it 'Employee.java'
629+
- Paste the below in the file. These are the column names of our SQL table.
630+
631+
```java
632+
package com.function.Common;
633+
public class Employee {
634+
private int EmployeeId;
635+
private String LastName;
636+
private String FirstName;
637+
private String Company;
638+
private String Team;
639+
public Employee() {
640+
}
641+
public Employee(int employeeId, String lastName, String firstName, String company, String team) {
642+
EmployeeId = employeeId;
643+
LastName = lastName;
644+
FirstName = firstName;
645+
Company = company;
646+
Team = team;
647+
}
648+
public int getEmployeeId() {
649+
return EmployeeId;
650+
}
651+
public void setEmployeeId(int employeeId) {
652+
this.EmployeeId = employeeId;
653+
}
654+
public String getLastName() {
655+
return LastName;
656+
}
657+
public void setLastName(String lastName) {
658+
this.LastName = lastName;
659+
}
660+
public String getFirstName() {
661+
return FirstName;
662+
}
663+
public void setFirstName(String firstName) {
664+
this.FirstName = firstName;
665+
}
666+
public String getCompany() {
667+
return Company;
668+
}
669+
public void setCompany(String company) {
670+
this.Company = company;
671+
}
672+
public String getTeam() {
673+
return Team;
674+
}
675+
public void setTeam(String team) {
676+
this.Team = team;
677+
}
678+
}
679+
```
680+
681+
- Navigate back to your HttpTriggerJava file.
682+
- Open the local.settings.json file, and in the brackets for "Values," verify there is a 'SqlConnectionString.' If not, add it.
683+
- Hit 'F5' to run your code. This will start up the Functions Host with a local HTTP Trigger and SQL Input Binding.
684+
- Click the link that appears in your terminal.
685+
- You should see your database output in the browser window.
686+
- Congratulations! You have successfully created your first SQL input binding! Checkout [Input Binding](#Input-Binding) for more information on how to use it and explore on your own!
687+
688+
#### Output Binding Tutorial
689+
690+
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](#Create-a-SQL-Server), and that you have the 'Employee.java' class from the [Input Binding Tutorial](#Input-Binding-Tutorial).
691+
692+
- Open your app in VSCode
693+
- Press 'F1' and search for 'Azure Functions: Create Function'
694+
- Choose HttpTrigger -> (Provide a package name) -> (Provide a function name) -> anonymous
695+
- In the file that opens, replace the `public HttpResponseMessage run` block with the below code.
696+
697+
```java
698+
public HttpResponseMessage run(
699+
@HttpTrigger(
700+
name = "req",
701+
methods = {HttpMethod.GET},
702+
authLevel = AuthorizationLevel.ANONYMOUS,
703+
route = "addemployees-array")
704+
HttpRequestMessage<Optional<String>> request,
705+
@SQLOutput(
706+
commandText = "dbo.Employees",
707+
connectionStringSetting = "SqlConnectionString")
708+
OutputBinding<Employee[]> output) {
709+
output = new Employee[]
710+
{
711+
new Employee(1, "Hello", "World", "Microsoft", "Functions"),
712+
new Employee(2, "Hi", "SQLupdate", "Microsoft", "Functions")
713+
};
714+
return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(output).build();
715+
}
716+
```
717+
718+
*In the above, "dbo.Employees" is the name of the table our output binding is upserting into. The line below is similar to the input binding and specifies where our SqlConnectionString is. For more information on this, see the [Output Binding](#Output-Binding) section*
719+
720+
- Hit 'F5' to run your code. Click the link to upsert the output array values in your SQL table. Your upserted values should launch in the browser.
721+
- Congratulations! You have successfully created your first SQL output binding! Checkout [Output Binding](#Output-Binding) for more information on how to use it and explore on your own!
722+
568723
## Configuration
569724
570725
This section goes over some of the configuration values you can use to customize the SQL bindings. See [How to Use Azure Function App Settings](https://learn.microsoft.com/azure/azure-functions/functions-how-to-use-azure-function-app-settings) to learn more.

WebJobs.Extensions.Sql.sln

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30204.135
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32929.385
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlExtensionSamples", "samples\samples-csharp\Microsoft.Azure.WebJobs.Extensions.Sql.Samples.csproj", "{B2E0EFB9-BEDB-48F7-BD5A-0E1010333475}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.Sql.Samples", "samples\samples-csharp\Microsoft.Azure.WebJobs.Extensions.Sql.Samples.csproj", "{B2E0EFB9-BEDB-48F7-BD5A-0E1010333475}"
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.Sql", "src\Microsoft.Azure.WebJobs.Extensions.Sql.csproj", "{4453B407-2CA3-4011-BDE5-247FCE5C1974}"
99
EndProject
@@ -28,6 +28,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Worker.Extension.Sql", "Wor
2828
EndProject
2929
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.Functions.Worker.Extension.Sql", "Worker.Extension.Sql\src\Microsoft.Azure.Functions.Worker.Extension.Sql.csproj", "{84D97605-F1BF-4083-9C93-2B68A9FBB00F}"
3030
EndProject
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc", "samples\samples-outofproc\Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.csproj", "{BD0CE086-1778-4B08-905F-6766399C1D44}"
32+
EndProject
3133
Global
3234
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3335
Debug|Any CPU = Debug|Any CPU
@@ -54,6 +56,10 @@ Global
5456
{84D97605-F1BF-4083-9C93-2B68A9FBB00F}.Debug|Any CPU.Build.0 = Debug|Any CPU
5557
{84D97605-F1BF-4083-9C93-2B68A9FBB00F}.Release|Any CPU.ActiveCfg = Release|Any CPU
5658
{84D97605-F1BF-4083-9C93-2B68A9FBB00F}.Release|Any CPU.Build.0 = Release|Any CPU
59+
{BD0CE086-1778-4B08-905F-6766399C1D44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
60+
{BD0CE086-1778-4B08-905F-6766399C1D44}.Debug|Any CPU.Build.0 = Debug|Any CPU
61+
{BD0CE086-1778-4B08-905F-6766399C1D44}.Release|Any CPU.ActiveCfg = Release|Any CPU
62+
{BD0CE086-1778-4B08-905F-6766399C1D44}.Release|Any CPU.Build.0 = Release|Any CPU
5763
EndGlobalSection
5864
GlobalSection(SolutionProperties) = preSolution
5965
HideSolutionNode = FALSE
@@ -64,6 +70,7 @@ Global
6470
{A5B55530-71C8-4A9A-92AD-1D33A5E80FC1} = {F7E99EB5-47D3-4B50-A6AA-D8D5508A121A}
6571
{1A5148B7-F877-4813-852C-F94D6EF795E8} = {F0F3562F-9176-4461-98E4-13D38D3DD056}
6672
{84D97605-F1BF-4083-9C93-2B68A9FBB00F} = {605E19C0-3A77-477F-928E-85B8972B734D}
73+
{BD0CE086-1778-4B08-905F-6766399C1D44} = {3691FB44-971D-43FD-9B2F-916B8CE689DB}
6774
EndGlobalSection
6875
GlobalSection(ExtensibilityGlobals) = postSolution
6976
SolutionGuid = {49902AA5-150F-4567-B562-4AA8549B2CF4}

Worker.Extension.Sql/src/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
55

6-
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.Sql", "0.*-preview")]
6+
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.Sql", "0.*-*")]

builds/TSAConfig.gdntsa

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"BinSkim",
1616
"RoslynAnalyzers",
1717
"CredScan",
18-
"Policheck"
18+
"Policheck",
19+
"CodeQL"
1920
]
2021
}

builds/azure-pipelines/build-release-java.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@ steps:
55
mavenPomFile: java-library/pom.xml
66
options: --batch-mode --define=gpg.skip --define=org.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --update-snapshots
77

8+
- task: Semmle@1
9+
env:
10+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
11+
inputs:
12+
toolVersion: 'Latest'
13+
sourceCodeDirectory: '$(Build.SourcesDirectory)/java-library'
14+
language: 'java'
15+
buildCommandsString: 'mvn clean package'
16+
querySuite: 'Recommended'
17+
timeout: '1800'
18+
ram: '16384'
19+
addProjectDirToScanningExclusionList: true
20+
821
- powershell: |
9-
$prefix = 'azure-functions-java-library-sql-*'
1022
$source = 'java-library'
1123
$destination = '$(Build.ArtifactStagingDirectory)/java-library'
24+
$jar = Get-ChildItem $source/target/*.jar | Select-Object -First 1 | Select Name
25+
$jar -match '\d+\.\d+\.\d+'
26+
$version = $matches[0]
27+
$prefix = 'azure-functions-java-library-sql-'+$version
1228
New-Item $destination -ItemType Directory
13-
Copy-Item "$source/pom.xml" "$destination/"
29+
Copy-Item "$source/pom.xml" "$destination/$prefix.pom"
1430
Copy-Item "$source/target/$prefix.jar" "$destination/"
1531
Copy-Item "$source/target/$prefix-javadoc.jar" "$destination/"
1632
Copy-Item "$source/target/$prefix-sources.jar" "$destination/"

builds/azure-pipelines/build-release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ variables:
1919
versionPatch: $[counter(variables['versionMajorMinor'], 0)] # This will reset when we bump minor version
2020
binariesVersion: '$(versionMajor).$(versionMinor).$(versionPatch)'
2121
nugetVersion: '$(binariesVersion)-preview'
22+
LGTM.UploadSnapshot: true
23+
Semmle.SkipAnalysis: true
2224

2325
stages:
2426
- stage: BuildPublish
@@ -88,7 +90,7 @@ stages:
8890
displayName: Build Java Library
8991

9092
pool:
91-
vmImage: 'ubuntu-latest'
93+
vmImage: 'windows-latest'
9294

9395
steps:
9496
- template: build-release-java.yml

builds/azure-pipelines/template-steps-build-test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ steps:
1212
inputs:
1313
useGlobalJson: true
1414

15+
# Install .Net Core 3.1.0 as PowerShell tests are unable to find 3.1.0 framework to run tests
16+
- task: UseDotNet@2
17+
displayName: 'Install .NET Core 3.1 sdk'
18+
inputs:
19+
packageType: sdk
20+
version: '3.1.x'
21+
1522
# Run Policheck early to avoid scanning dependency folders
1623
- task: securedevelopmentteam.vss-secure-development-tools.build-task-policheck.PoliCheck@2
1724
displayName: 'Run PoliCheck'

java-library/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.microsoft.azure.functions</groupId>
66
<artifactId>azure-functions-java-library-sql</artifactId>
7-
<version>0.1.0</version>
7+
<version>0.1.0</version> <!-- Update the dependency version in samples-java/pom.xml too if this version is updated. -->
88
<packaging>jar</packaging>
99

1010
<parent>

0 commit comments

Comments
 (0)