Skip to content

Commit 13bcb75

Browse files
authored
Update Trigger Binding set up in SetupGuide_Java.md (#846)
* Update SetupGuide_Java.md * fix annotation
1 parent 5f22b20 commit 13bcb75

File tree

1 file changed

+93
-7
lines changed

1 file changed

+93
-7
lines changed

docs/SetupGuide_Java.md

Lines changed: 93 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55
- [Table of Contents](#table-of-contents)
66
- [Setup Function Project](#setup-function-project)
77
- [Input Binding](#input-binding)
8-
- [SQLInput Attribute](#sqlinput-attribute)
8+
- [SQLInput Annotation](#sqlinput-annotation)
99
- [Setup for Input Bindings](#setup-for-input-bindings)
1010
- [Samples for Input Bindings](#samples-for-input-bindings)
1111
- [Query String](#query-string)
1212
- [Empty Parameter Value](#empty-parameter-value)
1313
- [Null Parameter Value](#null-parameter-value)
1414
- [Stored Procedure](#stored-procedure)
1515
- [Output Binding](#output-binding)
16-
- [SQLOutput Attribute](#sqloutput-attribute)
16+
- [SQLOutput Annotation](#sqloutput-annotation)
1717
- [Setup for Output Bindings](#setup-for-output-bindings)
1818
- [Samples for Output Bindings](#samples-for-output-bindings)
1919
- [Array](#array)
2020
- [Single Row](#single-row)
2121
- [Trigger Binding](#trigger-binding)
22+
- [SqlTrigger Annotation](#sqltriggerbinding-annotation)
23+
- [Setup for Trigger Binding](#setup-for-trigger-bindings)
2224
- [Known Issues](#known-issues)
2325

2426
## Setup Function Project
@@ -60,7 +62,7 @@ These instructions will guide you through creating your Function Project and add
6062
6163
See [Input Binding Overview](./BindingsOverview.md#input-binding) for general information about the Azure SQL Input binding.
6264
63-
### SQLInput Attribute
65+
### SQLInput Annotation
6466
6567
In the Java functions runtime library, use the @SQLInput annotation (com.microsoft.azure.functions.sql.annotation.SQLInput) on parameters whose value comes from the query specified by commandText. This annotation supports the following elements:
6668
@@ -101,7 +103,7 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
101103
}
102104
```
103105
104-
*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 [SQLInput Attribute](#sqlinput-attribute) section*
106+
*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 [SQLInput Annotation](#sqlinput-annotation) section*
105107
106108
- Add `import com.microsoft.azure.functions.sql.annotation.SQLInput;`
107109
- Create a new file and call it `Employee.java`
@@ -321,7 +323,7 @@ If the `{name}` specified in the `getproducts-namenull/{name}` URL is "null", th
321323
322324
See [Output Binding Overview](./BindingsOverview.md#output-binding) for general information about the Azure SQL Output binding.
323325
324-
### SQLOutput Attribute
326+
### SQLOutput Annotation
325327
326328
In the Java functions runtime library, use the @SQLOutput annotation (com.microsoft.azure.functions.sql.annotation.SQLOutput) on parameters whose values you want to upsert into the target table. This annotation supports the following elements:
327329
@@ -365,7 +367,7 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
365367
}
366368
```
367369
368-
*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 [SQLOutput Attribute](#sqloutput-attribute) section*
370+
*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 [SQLOutput Annotation](#sqloutput-annotation) section*
369371
370372
- 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.
371373
- Congratulations! You have successfully created your first SQL output binding!
@@ -426,7 +428,91 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
426428
427429
## Trigger Binding
428430
429-
> Trigger binding support is only available for in-proc C# functions at present.
431+
See [Trigger Binding Overview](./BindingsOverview.md#trigger-binding) for general information about the Azure SQL Trigger binding.
432+
433+
### SqlTrigger Annotation
434+
435+
In the Java functions runtime library, use the @SQLTrigger annotation (com.microsoft.azure.functions.sql.annotation.SQLTrigger) on parameters whose values would come from Azure SQL. This annotation supports the following elements:
436+
437+
| Element |Description|
438+
|---------|---------|
439+
| **name** | Required. The name of the parameter that the trigger binds to. |
440+
| **tableName** | Required. The name of the table monitored by the trigger. |
441+
| **connectionStringSetting** | Required. The name of an app setting that contains the connection string for the database containing the table monitored for changes. This isn't the actual connection string and must instead resolve to an environment variable. Optional keywords in the connection string value are [available to refine SQL bindings connectivity](https://aka.ms/sqlbindings#sql-connection-string). |
442+
443+
When you're developing locally, add your application settings in the local.settings.json file in the Values collection.
444+
### Setup for Trigger Bindings
445+
446+
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](./GeneralSetup.md#create-a-sql-server), and that you have the 'Employee.java' file from the [Setup for Input Bindings](#setup-for-input-bindings) section.
447+
448+
- Create a new file `SqlChangeOperation.java` with the following content:
449+
```java
450+
package com.function;
451+
452+
import com.google.gson.annotations.SerializedName;
453+
454+
public enum SqlChangeOperation {
455+
@SerializedName("0")
456+
Insert,
457+
@SerializedName("1")
458+
Update,
459+
@SerializedName("2")
460+
Delete;
461+
}
462+
```
463+
464+
- Create a new file `SqlChangeEmployee.java` with the following content:
465+
```java
466+
package com.function;
467+
468+
public class SqlChangeEmployee {
469+
public Employee employee;
470+
public SqlChangeOperation operation;
471+
472+
public SqlChangeEmployee() {
473+
}
474+
475+
public SqlChangeEmployee(Employee employee, SqlChangeOperation operation) {
476+
this.employee = employee;
477+
this.operation = operation;
478+
}
479+
}
480+
```
481+
482+
- Create a new file `EmployeeTrigger.java` with the following content:
483+
484+
```java
485+
package com.function;
486+
487+
import com.microsoft.azure.functions.ExecutionContext;
488+
import com.microsoft.azure.functions.annotation.FunctionName;
489+
import com.microsoft.azure.functions.sql.annotation.SQLTrigger;
490+
import com.function.SqlChangeEmployee;
491+
import com.google.gson.Gson;
492+
493+
import java.util.logging.Level;
494+
495+
public class EmployeeTrigger {
496+
@FunctionName("EmployeeTrigger")
497+
public void run(
498+
@SQLTrigger(
499+
name = "changes",
500+
tableName = "[dbo].[Employees]",
501+
connectionStringSetting = "SqlConnectionString")
502+
SqlChangeEmployee[] changes,
503+
ExecutionContext context) {
504+
505+
context.getLogger().log(Level.INFO, "SQL Changes: " + new Gson().toJson(changes));
506+
}
507+
}
508+
```
509+
510+
- *Skip these steps if you have not completed the output binding tutorial.*
511+
- Open your output binding file and modify some of the values. For example, change the value of Team column from 'Functions' to 'Azure SQL'.
512+
- Hit 'F5' to run your code. Click the link of the HTTP trigger from the output binding tutorial.
513+
- Update, insert, or delete rows in your SQL table while the function app is running and observe the function logs.
514+
- You should see the new log messages in the Visual Studio Code terminal containing the values of row-columns after the update operation.
515+
- Congratulations! You have successfully created your first SQL trigger binding!
430516
431517
## Known Issues
432518

0 commit comments

Comments
 (0)