You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -89,48 +89,51 @@ To create the JSP application:
89
89
90
90
## <aid="InstallSDK"></a>Install the SQL Java SDK
91
91
92
-
The easiest way to pull in the SQL Java SDK and its dependencies is through [Apache Maven](https://maven.apache.org/).
93
-
94
-
To do this, you will need to convert your project to a maven project by completing the following steps:
92
+
The easiest way to pull in the SQL Java SDK and its dependencies is through [Apache Maven](https://maven.apache.org/). To do this, you need to convert your project to a maven project by using the following steps:
95
93
96
94
1. Right-click your project in the Project Explorer, click **Configure**, click **Convert to Maven Project**.
97
-
2. In the **Create new POM** window, accept the defaults, and click **Finish**.
98
-
3. In **Project Explorer**, open the pom.xml file.
99
-
4. On the **Dependencies** tab, in the **Dependencies** pane, click **Add**.
100
-
5. In the **Select Dependency** window, do the following:
101
-
102
-
* In the **Group Id** box, enter com.microsoft.azure.
103
-
* In the **Artifact Id** box, enter azure-documentdb.
* Or add the dependency XML for Group ID and Artifact ID directly to the pom.xml via a text editor:
109
-
```xml
110
-
<dependency>
111
-
<groupId>com.microsoft.azure</groupId>
112
-
<artifactId>azure-documentdb</artifactId>
113
-
<version>1.9.1</version>
114
-
</dependency>
115
-
```
116
-
6. Click **OK** and Maven will install the SQL Java SDK.
117
-
7. Save the pom.xml file.
118
-
119
-
## <aid="UseService"></a>Using the Azure Cosmos DB service in a Java application
120
-
121
-
1. First, let's define the TodoItem object in TodoItem.java:
122
-
123
-
@Data
124
-
@Builder
125
-
public class TodoItem {
126
-
private String category;
127
-
private boolean complete;
128
-
private String id;
129
-
private String name;
130
-
}
95
+
96
+
1. In the **Create new POM** window, accept the defaults, and click **Finish**.
97
+
98
+
1. In **Project Explorer**, open the pom.xml file.
99
+
100
+
1. On the **Dependencies** tab, in the **Dependencies** pane, click **Add**.
101
+
102
+
1. In the **Select Dependency** window, do the following:
131
103
132
-
In this project, you are using [Project Lombok](https://projectlombok.org/) to generate the constructor, getters, setters, and a builder. Alternatively, you can write this code manually or have the IDE generate it.
133
-
2. To invoke the Azure Cosmos DB service, you must instantiate a new **DocumentClient**. In general, it is best to reuse the **DocumentClient** - rather than construct a new client for each subsequent request. We can reuse the client by wrapping the client in a **DocumentClientFactory**. In DocumentClientFactory.java, you need to paste the URI and PRIMARY KEY value you saved to your clipboard in [step 1](#CreateDB). Replace [YOUR\_ENDPOINT\_HERE] with your URI and replace [YOUR\_KEY\_HERE] with your PRIMARY KEY.
104
+
* In the **Group Id** box, enter `com.azure`.
105
+
* In the **Artifact Id** box, enter `azure-cosmos`.
106
+
* In the **Version** box, enter `4.0.1-beta.1`.
107
+
108
+
Or you can add the dependency XML for Group ID and Artifact ID directly to the *pom.xml* file:
109
+
110
+
```xml
111
+
<dependency>
112
+
<groupId>com.azure</groupId>
113
+
<artifactId>azure-cosmos</artifactId>
114
+
<version>4.0.1-beta.1</version>
115
+
</dependency>
116
+
```
117
+
118
+
1. Click **OK** and Maven will install the SQL Java SDK or save the pom.xml file.
119
+
120
+
## <aid="UseService"></a>Use the Azure Cosmos DB service in your Java application
121
+
122
+
Now let's add the models, the views, and the controllers to your web application.
123
+
124
+
### Add a model
125
+
126
+
First, let's define a model within a new file *TodoItem.java*. The `TodoItem` class defines the schema of an item along with the getter and setter methods:
Create a Data Access Object (DAO) to abstract persisting the ToDo items to Azure Cosmos DB. In order to save ToDo items to a collection, the client needs to know which database and collection to persist to (as referenced by self-links). In general, it is best to cache the database and collection when possible to avoid additional round-trips to the database.
133
+
134
+
The following code illustrates how to retrieve our database and collection, if it exists, or create a new one if it doesn't exist:
135
+
136
+
To invoke the Azure Cosmos DB service, you must instantiate a new **DocumentClient**. In general, it is best to reuse the **DocumentClient** - rather than construct a new client for each subsequent request. We can reuse the client by wrapping the client in a **DocumentClientFactory**. In DocumentClientFactory.java, you need to paste the URI and PRIMARY KEY value you saved to your clipboard in [step 1](#CreateDB). Replace [YOUR\_ENDPOINT\_HERE] with your URI and replace [YOUR\_KEY\_HERE] with your PRIMARY KEY.
134
137
135
138
private static final String HOST = "[YOUR_ENDPOINT_HERE]";
136
139
private static final String MASTER_KEY = "[YOUR_KEY_HERE]";
@@ -141,11 +144,27 @@ To do this, you will need to convert your project to a maven project by completi
141
144
public static DocumentClient getDocumentClient() {
142
145
return documentClient;
143
146
}
144
-
3. Now let's create a Data Access Object (DAO) to abstract persisting our ToDo items to Azure Cosmos DB.
145
-
146
-
In order to save ToDo items to a collection, the client needs to know which database and collection to persist to (as referenced by self-links). In general, it is best to cache the database and collection when possible to avoid additional round-trips to the database.
147
-
148
-
The following code illustrates how to retrieve our database and collection, if it exists, or create a new one if it doesn't exist:
147
+
148
+
### Add a controller
149
+
150
+
Add the *TodoItemController* controller to your application. In this project, you are using [Project Lombok](https://projectlombok.org/) to generate the constructor, getters, setters, and a builder. Alternatively, you can write this code manually or have the IDE generate it.:
0 commit comments