Skip to content

Commit 698edf8

Browse files
committed
Fixing code format
1 parent 6396f30 commit 698edf8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

articles/cosmos-db/sql-api-java-application.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,57 +125,57 @@ Now let's add the models, the views, and the controllers to your web application
125125

126126
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:
127127

128-
[!INCLUDE[TodoItem class](~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/model/TodoItem.java)]
128+
:::code language="java" source="~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/model/TodoItem.java":::
129129

130130
### Add the Data Access Object(DAO) classes
131131

132132
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.
133133

134134
1. To invoke the Azure Cosmos DB service, you must instantiate a new `cosmosClient` object. In general, it is best to reuse the `cosmosClient` object rather than constructing a new client for each subsequent request. You can reuse the client by defining it within the `cosmosClientFactory` class. Update the HOST and MASTER_KEY values that you saved in [step 1](#CreateDB). Replace the HOST variable with with your URI and replace the MASTER_KEY with your PRIMARY KEY. Use the following code to create the `CosmosClientFactory` class within the *CosmosClientFactory.java* file:
135135

136-
[!INCLUDE[CosmosClientFactory class](~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/dao/CosmosClientFactory.java)]
136+
:::code language="java" source="~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/dao/CosmosClientFactory.java":::
137137

138138
1. Create a new *TodoDao.java* file and add the `TodoDao` class to create, update, read, and delete the todo items:
139139

140-
[!INCLUDE[TodoDao class](~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/dao/TodoDao.java)]
140+
:::code language="java" source="~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/dao/TodoDao.java":::
141141

142142
1. Create a new *MockDao.java* file and add the `MockDao` class, this class implements the `TodoDao` class to perform CRUD operations on the items:
143143

144-
[!INCLUDE[MockDao class](~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/dao/MockDao.java)]
144+
:::code language="java" source="~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/dao/MockDao.java":::
145145

146146
1. Create a new *DocDbDao.java* file and add the `DocDbDao` class. This class defines code to persist the TodoItems into the container, retrieves your database and collection, if it exists, or create a new one if it doesn't exist. This example uses [Gson](https://code.google.com/p/google-gson/) to serialize and de-serialize the TodoItem Plain Old Java Objects (POJOs) to JSON documents. 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). This class also defines helper function to retrieve the documents by another attribute (e.g. "ID") rather than self-link. You can use the helper method to retrieve a TodoItem JSON document by ID and then deserialize it to a POJO.
147147

148148
You can also use the cosmosClient client object to get a collection or list of TodoItems using a SQL query. Finally, you define the delete method to delete a TodoItem from your list. The following code shows the contents of the `DocDbDao` class:
149149

150-
[!INCLUDE[DocDbDao class](~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/dao/DocDbDao.java)]
150+
:::code language="java" source="~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/dao/DocDbDao.java":::
151151

152152
1. Next, create a new *TodoDaoFactory.java* file and add the `TodoDaoFactory` class that creates a new DocDbDao object:
153153

154-
[!INCLUDE[TodoDaoFactory class](~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/dao/TodoDaoFactory.java)]
154+
:::code language="java" source="~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/dao/TodoDaoFactory.java":::
155155

156156
### Add a controller
157157

158158
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.:
159159

160-
[!INCLUDE[TodoItemController class](~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/controller/TodoItemController.java)]
160+
:::code language="java" source="~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/controller/TodoItemController.java":::
161161

162162
### Create a servlet
163163

164164
Next, create a servlet to route HTTP requests to the controller. Create the *ApiServlet.java* file and define the following code under it:
165165

166-
[!INCLUDE[ApiServlet class](~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/ApiServlet.java)]
166+
:::code language="java" source="~/samples-cosmosdb-java-v4-web-app/src/com/microsoft/azure/documentdb/sample/ApiServlet.java":::
167167

168168
## <a id="Wire"></a>Wire the rest of the of Java app together
169169

170170
Now that we've finished the fun bits, all that's left is to build a quick user interface and wire it up to your DAO.
171171

172172
1. You need a web user interface to display to the user. Let's re-write the index.jsp we created earlier with the following code:
173173

174-
[!INCLUDE[user interface code](~/samples-cosmosdb-java-v4-web-app/WebContent/index.jsp)]
174+
:::code language="java" source="~/samples-cosmosdb-java-v4-web-app/WebContent/index.jsp":::
175175

176176
1. Finally, write some client-side JavaScript to tie the web user interface and the servlet together:
177177

178-
[!INCLUDE[client-side JavaScript code](~/samples-cosmosdb-java-v4-web-app/WebContent/assets/todo.js)]
178+
:::code language="java" source="~/samples-cosmosdb-java-v4-web-app/WebContent/assets/todo.js":::
179179

180180
1. Now all that's left is to test the application. Run the application locally, and add some Todo items by filling in the item name and category and clicking **Add Task**. After the item appears, you can update whether it's complete by toggling the checkbox and clicking **Update Tasks**.
181181

0 commit comments

Comments
 (0)