Skip to content

Commit

Permalink
Update reactive tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
danieloh30 committed Oct 23, 2024
1 parent fe79c1b commit bf98bee
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ package org.acme.person.model;
import java.time.LocalDate;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;

import io.quarkus.hibernate.reactive.panache.PanacheEntity;
import io.smallrye.mutiny.Multi;
Expand Down Expand Up @@ -212,10 +212,6 @@ public class Person extends PanacheEntity {
|----|
|In the source code file, `src/main/java/org/acme/person/model/Person.java` you will see a `// TODO` comment at `Line XX`. **Do Not Delete It!** You will need this comment later on.|

`Step 5d:` Click on the `Disk` icon or press `CTRL+S` to save the contents of the Java file as shown in the figure below.

![Save Person](../assets/save-person-java.png)

# Defining the eye color enum

You previously defined the `Person` entity to have the fields `name`, `birth`, and `eyes`. The `eyes` field is an enumeration type that is defined as follows using the Java Persistence API's `@Enumerated` annotation, like so:
Expand Down Expand Up @@ -276,13 +272,13 @@ import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import javax.enterprise.event.Observes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import jakarta.enterprise.event.Observes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;

import org.acme.person.model.DataTable;
import org.acme.person.model.EyeColor;
Expand Down Expand Up @@ -324,7 +320,7 @@ public class PersonResource {
* `@Path("/person")` - Indicates the path to the `Person` resource that is appended to the base URL of the RESTful API
* `@GET` - Indicates the the API call will use the [HTTP GET method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET).
* `getAll` - Is the Java function that will be executed with the request to the `/person` endpoint is received by the server
* [`@Produces(MediaType.APPLICATION_JSON)`](https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/MediaType.html) - Indicates that the response will be returned as JSON.
* [`@Produces(MediaType.APPLICATION_JSON)`](https://docs.oracle.com/javaee/7/api/jakarta/ws/rs/core/MediaType.html) - Indicates that the response will be returned as JSON.
* `Uni<T>` - A data type defined in the [Mutiny library]((https://javadoc.io/doc/io.smallrye.reactive/mutiny/latest/io/smallrye/mutiny/package-summary.html)) that represents a lazy asynchronous action.

# Adding the sample data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.sql-load-script=import.sql
```

`Step 9c:` Click on the `Disk` icon or press `CTRL+S` to save the contents of `EyeColor.java`.

**KEY CONCEPTS TO UNDERSTAND**

The statement `quarkus.package.type=mutable-jar` shown above in the file `application.properties` indicates that Quarkus will package the application as a `mutable` application. A mutable application is one that's capable of being changed and updated in-place, on demand and on a regular basis.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ You are now going to add some reactive queries to the `Person` entity. The reaso
}
```

`Step 2c:` Click on the `Disk` icon or press `CTRL+S` to save the contents of `Person.java`.

**UNDERSTANDING REACTIVE QUERIES**

The query `findByColor(EyeColor color)` retrieves a list of people based on eye color from the demonstration application's database. The query `getBeforeYear(int year)` gets a list of people that have birthdays on or before a particular birth year.
Expand Down Expand Up @@ -108,8 +106,6 @@ Now that the custom entity queries have been implemented in the `Person` entity
}
```

`Step 3c:` Click on the `Disk` icon or press `CTRL+S` to save the contents of `PersonResource.java`.

**IMPORTANT CONCEPTS TO UNDERSTAND**

The code shown above in `Step 4b` uses `Uni<T>` and `Multi<T>` types. These types are defined in the [Mutiny library](https://javadoc.io/doc/io.smallrye.reactive/mutiny/latest/index.html). They are intended to support data streams in an asynchronous, reactive manner. Once declared, `Uni<T>` and `Multi<T>` do the work of establishing and managing the internal asynchronous pipelines. All the developer needs to be concerned with is the data that's emitted from the pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ You are going to work with the following parameters to enable search and paging
}
```

`Step 1d:` Click on the `Disk` icon or press `CTRL+S` to save the contents of `PersonResource.java`.


The code in the method `Uni<DataTable> datatable((...)` shown above in `Step 1c` uses [JAX-RS `@QueryParam`](https://docs.oracle.com/javaee/7/api/javax/ws/rs/QueryParam.html) values to specify the incoming parameters to be applied to queries executed within the function. These parameters are passed to the server from the front-end call to the endpoint, `GET /person/datatable`.
The code in the method `Uni<DataTable> datatable((...)` shown above in `Step 1c` uses [JAX-RS `@QueryParam`](https://docs.oracle.com/javaee/7/api/jakarta/ws/rs/QueryParam.html) values to specify the incoming parameters to be applied to queries executed within the function. These parameters are passed to the server from the front-end call to the endpoint, `GET /person/datatable`.

The method `Uni<DataTable> datatable((...)` code you just added has a number of `TODO` statements that need to be implemented. You'll fill in the `TODO`s in a moment. But, first you need to review the predefined class `DataTable.java`.

Expand Down Expand Up @@ -122,7 +119,6 @@ This work is done by adding a query to the `PersonResource.java` class.
.orElseGet(() -> Person.findAll())
.page(pageNumber, length);
```
`Step 3d:` Click on the `Disk` icon or press `CTRL+S` to save the contents of `PersonResource.java`.

----

Expand All @@ -147,8 +143,6 @@ This work is done by adding a query to the `PersonResource.java` class.
}));
```

`Step 4b:` Click on the `Disk` icon or press `CTRL+S` to save the contents of `PersonResource.java`.

The logic in the code you inserted into the file `PersonResource.java` at `Step 3b` above assigns the results of the search of the database to the object variable `filteredPeople`.

Then, the fields in the object variable `filteredPeople` are applied to a `DataTable` object named `result`. `result` does the work of taking the field values and data in `filteredPeople` and converting it to JSON, which is then passed back from the RESTful endpoint `/person/database`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ Managed beans (like the `PersonResource`) can listen for lifecycle events by usi
}
```

`Step 1d:` Click on the `Disk` icon or press `CTRL+S` to save the contents of `PersonResource.java`.

|NOTE|
|----|
|Adding 10k entries will make the demonstration application's startup time artificially high, around 5-10 seconds.|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,19 @@ tags:
- openshift
owner: openshift
developers:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
sandbox_preset: openshift-411
lab_config:
overlay: false
width: 25
position: right
width: 0
position: ""
feedback_recap_enabled: true
loadingMessages: true
hideStopButton: false
checksum: "8414663982899266740"
default_layout: AssignmentRight
default_layout_sidebar_size: 25
checksum: "10431202518735233778"
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,6 @@ quarkus.datasource.password=password
|----|
|You can change the remote live-reload username/password pair defined by `quarkus.datasource.username` and `quarkus.datasource.password` in the `application.properties` file to whatever you want. Those credentials are used to secure communication between the remote side and the local side.

`Step 8e:` Click on the `Disk` icon or press `CTRL+S` to save the file as shown in the figure below:

![Save properties](../assets/save-properties-01.png)


**KEY POINTS TO UNDERSTAND**

* The `quarkus.package.type=mutable-jar` setting in the `application.properties` file instructs Quarkus to package the application as a `mutable application`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ First you'll add code that will automatically create a table in the PostgresSQL
.indefinitely();
```

`Step 1d:` Click on the `Disk` icon or press `CTRL+S` to save the file.

Next, you'll add the RESTful API methods. You'll add a `GET` method that sill return all coffee types. Also, you'll add `GET` method that returns a specific coffee type according to `id`.

The `getSingle` method that returns a single coffee type uses the `PathParam` to indicate the the `id` passed from the query string value defined by the `@Path` annotation.
Expand All @@ -72,8 +70,6 @@ The `getSingle` method that returns a single coffee type uses the `PathParam` to

```

`Step 2b:` Click on the `Disk` icon or press `CTRL+S` to save the file.

Now add the `POST` and `PUT` request methods.

----
Expand All @@ -98,8 +94,6 @@ Now add the `POST` and `PUT` request methods.
}
```

`Step 3b:` Click on the `Disk` icon or press `CTRL+S` to save the file.

Finally add the DELETE method, so that there's an endpoint for deleting a coffee type from the Quarkus demonstration application.

----
Expand All @@ -116,8 +110,6 @@ Finally add the DELETE method, so that there's an endpoint for deleting a coffee
}
```

`Step 4b:` Click on the `Disk` icon or press `CTRL+S` to save the file.

# Congratulations!

You've added the `coffee` type data to the PostgresSQL database. Also, you created `GET`, `POST`, `PUT` and `DELETE` endpoints to the demonstration application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ The outstanding work is to add intelligence to the `Coffee` class that will enab
.onItem().transform(iterator -> iterator.hasNext() ? from(iterator.next()) : null);
}
```
`Step 3c:` Click on the `Disk` icon or press `CTRL+S` to save the file.

Notice that an `PgPool` object is passed to the `findById()` method as the type of the `client` parameter.

Expand Down
14 changes: 8 additions & 6 deletions instruqt-tracks/developing-with-quarkus-reactive-sql/track.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ tags:
- openshift
owner: openshift
developers:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
sandbox_preset: openshift-411
lab_config:
overlay: false
width: 25
position: right
width: 0
position: ""
feedback_recap_enabled: true
loadingMessages: true
hideStopButton: false
checksum: "7878072425048305736"
default_layout: AssignmentRight
default_layout_sidebar_size: 25
checksum: "15109199724749224002"

0 comments on commit bf98bee

Please sign in to comment.