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
Copy file name to clipboardExpand all lines: README.adoc
+30-24Lines changed: 30 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,10 +8,10 @@
8
8
//
9
9
:page-layout: guide-multipane
10
10
:projectid: jakarta-data
11
-
:page-duration: 500 minutes
11
+
:page-duration: 15 minutes
12
12
:page-releasedate: 2024-01-01
13
13
:page-majorupdateddate: 2023-01-01
14
-
:page-description: Description - TODO
14
+
Description - TODO
15
15
:page-tags: ['jakarta-ee']
16
16
:page-related-guides: []
17
17
:page-permalink: /guides/{projectid}
@@ -28,7 +28,7 @@ NOTE: This repository contains the guide documentation source. To view the guide
28
28
29
29
You will learn how to use Jakarta Data to store data as well as the simple, yet powerful options it provides for querying data. This will include writing queries that are created from the method name, as well as queries using annotations. Finally, you will learn about the Jakarta Data Query Language (JDQL).
30
30
31
-
The application demonstrates a number of different queries that are possible with Jakarta Data. Once you have completed the guide you can try writing your own queries with provided sample data.
31
+
The application demonstrates a number of different queries that are possible with Jakarta Data. Once you have completed the guide you can try writing your own queries with the provided sample data.
32
32
33
33
=== What is Jakarta Data?
34
34
Jakarta Data is a new data access specification being released with Jakarta EE 11. It provides a new API for simplified data access. Jakarta Data follows the Repository design pattern for data access, and allows for implementations which may support both SQL and NoSQL data stores. It also provides enhanced type safety with a Static Metamodel.
Go to the http://localhost:9080 URL to see all the application data. You will see a column of queries, some of which will accept input. To start find the `findAll` query with no inputs. Selecting this will return all of the packages similar to the following:
42
+
This application allows you to run queries against a set of shipping packages which have a variety of dimensions and destinations. Go to the http://localhost:9080 URL to see all the application data. You will see a column of queries, some of which will accept input. To start find the `findAll` query with no inputs. Selecting this will return all of the query data similar to the following:
43
43
44
44
```
45
45
ID Length Width Height Destination
@@ -53,8 +53,8 @@ ID Length Width Height Destination
53
53
8 2 15 18 Rochester
54
54
```
55
55
56
+
You can then try some of the queries which use input to see how it changes which packages are returned.
56
57
57
-
You can then try some of the queries which use input to see how it changes the returned packages.
Repositories in Jakarta Data provide a simplified means for interacting with persistent data. Jakarta Data provides several built in Repositories with common methods which can be extended with application specific queries. The [hotspot=CrudRepository file=1]`CrudRepository` interface provides methods for Create, Read, Update, and Delete (CRUD) operations.
90
90
91
-
[hotspot=CrudRepository file=1]`CrudRepository` provides two options for persisting entities, `insert` and `save`. The first option `insert` will persist an entity only if the entity does not already exist. The `save` option will persist and entity even if it already exists, allowing it to be used for updating entities as well. [hotspot=CrudRepository file=1]`CrudRepository` provides a `delete` method for removing entities. All three of these methods can be applied to a list of entites using `insertAll`, `saveAll`, and `deleteAll`.
91
+
[hotspot=CrudRepository file=1]`CrudRepository` provides two options for persisting entities, `insert` and `save`. The first option `insert` will persist an entity only if the entity does not already exist. The `save` option will persist an entity even if it already exists, allowing it to be used for updating entities as well. [hotspot=CrudRepository file=1]`CrudRepository` provides a `delete` method for removing entities.
92
92
93
93
```java
94
94
Package p1 = new Package(1, 10f, 20f, 10f, "Rochester");
95
95
packages.insert(p1);
96
+
packages.save(p1);
96
97
packages.delete(p1);
97
98
```
98
99
100
+
All three of these methods can be applied to a list of entities using `insertAll`, `saveAll`, and `deleteAll`.
Query by Method Name allows you to write queries using a descriptive method name following a few intuitive rules on how the method name is structured. This allows methods like `findByLengthGreaterThan(float length)` or `findByHeightAndWidth(float height, float width)` to automatically be turned into queries. Method names must start with an action like `find`, `delete`, or `count` and can contain include operators (such as `And`, `Or`, and `Not`) and conditions (such as `GreaterThan`, `LessThan`, and `Between`).
118
+
Query by Method Name allows you to write queries using a descriptive method name following a few intuitive rules on how the method name is structured. This allows methods like `findByLengthGreaterThan(float length)` or `findByHeightAndWidth(float height, float width)` to automatically be turned into queries. Method names must start with an action like `find`, `delete`, or `count` and can include operators (such as `And`, `Or`, and `Not`) and conditions (such as `GreaterThan`, `LessThan`, and `Between`).
115
119
116
120
For more information on all of the options available with Query by Method name, see the https://jakarta.ee/specifications/data/1.0/jakarta-data-addendum-1.0.pdf[Query by Method Name Extension] of the Jakarta Data specification.
//TODO should this mention --parameters at this point?
142
146
143
147
=== Renaming provided methods
144
-
If a method name provided by a built in Jakarta Data repository class doesn't align with your repository you can use annotations to provide your own method. For example, using the `@Insert` annotation you can create a method named `add` instead of the `insert` method inherited from `CrudRepository` like this.
148
+
If a method name provided by a built in Jakarta Data repository class doesn't align with your repository you can use annotations to provide your own method. For example, using the `@Insert` annotation you can create a method named `add` instead of the `insert` method inherited from `CrudRepository` like this:
145
149
146
150
```java
147
151
@Insert
@@ -152,22 +156,22 @@ This method is functionally equivalent to the `insert` method provided by `CrudR
152
156
153
157
154
158
=== The `@OrderBy` Annotation
155
-
To provide ordering annotatively, you can use the `@OrderBy` annotation. The default ordering direction is ascending. To obtain all of the entities in a repository sorted by the height parameter, you could use the following.
159
+
To provide ordering annotatively, you can use the `@OrderBy` annotation. The default ordering direction is ascending. To obtain all of the packages in the repository sorted by the height parameter, you could use the following:
156
160
157
161
```java
158
162
@Find
159
163
@OrderBy("height")
160
164
List<Package> sortedByHeightAscending();
161
165
```
162
166
163
-
`@OrderBy` can also return in descending order by specifying `descending = true` in the annotation.
167
+
`@OrderBy` can also return in descending order by specifying `descending = true` in the annotation:
164
168
165
169
```java
166
170
@OrderBy(value = "height", descending = true)
167
171
```
168
172
//TODO rename? Runtime Modifications...?
169
173
== Sort, Limit, and Pagination
170
-
Jakarta Data provides the `Sort` class and the `@Limit` annotation to create queries which can be modified at runtime. It also includes a mechanism for pagination to better handle large sets of results.
174
+
Jakarta Data provides the `Sort` and `Limit` classes to create queries which can be modified at runtime. It also includes a mechanism for pagination to better handle large sets of results.
In addition to the `@OrderBy` annotation it is possible to provide sorting at runtime. This is accomplished by adding a `Sort` as a parameter to your query method.
189
+
In addition to the `@OrderBy` annotation it is possible to provide sorting at runtime. This is accomplished by adding a `Sort` parameter to your query method:
186
190
187
191
```java
188
192
@Find
189
193
List<Package> sorted(Sort<?> sortBy);
190
194
```
191
195
192
-
A `Sort` can be created and provided at runtime using the Sort class's static methods:
196
+
A `Sort` can be created and provided at runtime using the `Sort` class's static methods:
193
197
```java
194
198
Sort sort = Sort.desc("height");
195
199
```
196
200
197
201
=== Limit
198
-
Jakarta Data queries can restrict the number of results returned at runtime by providing a `Limit` object to the query.
202
+
Jakarta Data queries can restrict the number of entities returned at runtime by providing a `Limit` object to the query:
199
203
200
204
```java
201
205
List<Package> longestWithLimit(Limit limit);
202
206
```
203
207
204
-
Limits can be created and supplied using the Limit class's static methods:
208
+
Limits can be created and supplied using the `Limit` class's static methods:
205
209
```java
206
210
Limit limitTen = Limit.of(10);
207
211
```
208
212
209
-
Limits can also be used to access a range of results, such as starting at result 10 and ending at result 20:
213
+
Limits can also be used to access a range of entities, such as starting at the 10th entity and ending at the 20th:
210
214
```java
211
215
Limit range = Limit.range(10,20);
212
216
```
213
217
214
218
215
219
=== Paging
216
-
When querying large amounts of data, paging is possible by providing a `PageRequest` in a query.
220
+
When querying large amounts of data, paging is possible by adding a `PageRequest` parameter to your query method:
The `@Query` annotation allows users to write queries using the Jakarta Data Query Language (JDQL). Complex queries can be written concisely using JDQL.
241
+
The `@Query` annotation allows users to write queries using the Jakarta Data Query Language (JDQL). Complex queries can be written concisely using JDQL. JDQL is a strict subset of the Jakarta Persistence Query Language (JPQL).
Achieving the same query with Query by Method Name would result in a very long method name and additional parameters. JDQL is a strict subset of the Jakarta Persistence Query Language (JPQL), supporting named and ordinal parameters, as well as a number of operators.
262
+
Achieving the same query with Query by Method Name would result in a very long method name and additional parameters.
263
+
259
264
265
+
JDQL supports named and ordinal parameters, as well as a number of operators.
See the Jakarta Data specification for a more comprehensive overview of the Jakarta Data Query Language.
271
+
See the https://jakarta.ee/specifications/data/1.0/jakarta-data-1.0#_jakarta_data_query_language[Jakarta Data specification] for a more comprehensive overview of the Jakarta Data Query Language.
266
272
267
273
== Where to next?
268
-
Try out the sample application by creating your own queries. Add your own queries to the `Packages` class like the provided ones and then try them out in the sample application.
274
+
Experiment by creating your own queries. Use the existing ones in the `Packages` class as a starting point and then test them out in the sample application.
0 commit comments