Skip to content

Commit

Permalink
refactor: general fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasnogueira committed Oct 1, 2023
1 parent b4059c0 commit f5579eb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions docs/jakarta-ee/cdi-lab-1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Jakarta CDI - Lab 1 - Basic part 1

In this lab, we will explore creating the first injection where Vehicle interface into a single implementation Car.
In this lab, we will explore creating the first injection where the Vehicle interface into a single implementation Car.

## 1. Defining the interface

Expand Down Expand Up @@ -57,11 +57,11 @@ In this lab, we will explore creating the first injection where Vehicle interfac
!!! Tip
You can use the `UUID.randomUUID().toString()` method to generate a random String

7. Override the method `move()` logging the `name` of the veicle using the logger
7. Override the method `move()` by logging the `name` of the vehicle using the logger

### :material-checkbox-multiple-outline: Expected results

* Class `Car` implenmenting `Vehicle` created containing a method `move()`
* Class `Car` implementing `Vehicle` created containing a method `move()`

### :material-check-outline: Solution

Expand Down
4 changes: 2 additions & 2 deletions docs/jakarta-ee/cdi.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ You might wonder, "Why is CDI so crucial when working with NoSQL databases in mo
| **Request** | Scoped to an HTTP request in a web application. The bean instance is created for the duration of an HTTP request and destroyed when the request is completed. |
| **Session** | Scoped to an HTTP session in a web application. The bean instance is created when the session is initiated and destroyed when the session ends. |
| **Application** | Scoped to the entire lifecycle of the application. The bean instance is created when the application starts and destroyed when the application is shut down. |
| **Conversation** | Scoped to a long-running conversation in a web application. It spans multiple HTTP requests and allows maintaining conversational state. The bean instance is created at the beginning of a conversation and destroyed when the conversation ends. |
| **Singleton** | Scoped to a single, shared instance across the entire application. The same bean instance is reused for all clients, promoting global state and sharing among components. |
| **Conversation** | Scoped to a long-running conversation in a web application. It spans multiple HTTP requests and allows maintaining a conversational state. The bean instance is created at the beginning of a conversation and destroyed when the conversation ends. |
| **Singleton** | Scoped to a single, shared instance across the entire application. The same bean instance is reused for all clients, promoting a global state and sharing among components. |


These CDI scopes provide a powerful mechanism for managing the lifecycle and visibility of beans in your application, allowing you to control how and when dependencies are created and maintained. The choice of scope depends on the specific requirements of your application and how you want to manage bean instances and their interactions.
Expand Down
30 changes: 14 additions & 16 deletions docs/key-value/java-lab-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

This lab will introduce an entity integration with Redis database with Java.


## 1. Create an entity

### :material-play-box-multiple-outline: Steps

1. Create a class called `User` in the `expert.os.labs.persistence` package
2. Annotate this class with `@Entity` , indicating that it's a persistent entity
2. Annotate this class with `@Entity`, indicating that it's a persistent entity
3. Add the following `private` fields with its types

| type | field |
Expand All @@ -18,7 +17,7 @@ This lab will introduce an entity integration with Redis database with Java.
| `Map<String, String>` | `settings` |
| `Set<String>` | `languages` |

4. Annotate the `userName` with `@Id`
4. Annotate the `userName` with `@Id` from the `jakarta.nosql` package
5. Create a constructor using all fields
6. Create get methods for each field
7. Add the `toString()` method
Expand All @@ -27,7 +26,6 @@ This lab will introduce an entity integration with Redis database with Java.

* Entity `User` created


### :material-check-outline: Solution

??? example "Click to see..."
Expand Down Expand Up @@ -198,7 +196,7 @@ This lab will introduce an entity integration with Redis database with Java.
2. Add a main method

```java
public static void main(String[] args) {
public static void main(String[] args) throws InterruptedException {
}
```

Expand All @@ -215,7 +213,7 @@ This lab will introduce an entity integration with Redis database with Java.
KeyValueTemplate template = container.select(KeyValueTemplate.class).get();
```

5. Create two user instances using the `UserBuilder` class with different data insde the `try` statement
5. Create two user instances using the builder from the `User` class with different data inside the `try` statement

```java
User user1 = User.builder().username("user1").name("Otavio Santana")
Expand All @@ -228,14 +226,14 @@ This lab will introduce an entity integration with Redis database with Java.
.settings(Map.of("location", "Portugal", "currency", "EUR")).build();
```

6. Add the two user instances into the key-value store using the `KeuValueTemplate`, where the second one will have a delat of 1 second
6. Add the two user instances into the key-value store using the `KeuValueTemplate`, where the second one will have a delay of 1 second

```java
template.put(user1);
template.put(user2, Duration.ofSeconds(1));
```

7. Retrieve the `user2` data based on its `userName` and print out the result
7. Retrieve the `user2` data based on its `userName` and printout the result
- use the method `get()` from the `template` field
- the first parameter is the value of the `userName` field and the second parameter is the class

Expand All @@ -244,15 +242,15 @@ This lab will introduce an entity integration with Redis database with Java.
System.out.println("User2 data: " + user2Data);
```

8. Add a wait time, then retrieve and print out the same user again
8. Add a wait time, then retrieve and printout the same user again

```java
TimeUnit.SECONDS.sleep(2L);
Optional<User> user2DataSecondRetrieve = template.get("user2", User.class);
System.out.println("User2 second retrieve data: " + user2DataSecondRetrieve);
```

9. Retrieve the `user1` data based on its `userName` and print out the result
9. Retrieve the `user1` data based on its `userName` and printout the result

```java
Optional<User> user1Data = template.get("user1", User.class);
Expand All @@ -278,7 +276,7 @@ This lab will introduce an entity integration with Redis database with Java.
User1 data: Optional[User{userName='user1', name='Otavio Santana', settings={location=Portugal, currency=EUR}, languages=[English, Italian, French, Portuguese, Spanish]}]
```

* The second print out, related to the `user2` does not show any data because it expired
* The second printout, related to the `user2` does not show any data because it expired

### :material-check-outline: Solution

Expand Down Expand Up @@ -394,17 +392,17 @@ This lab will introduce an entity integration with Redis database with Java.
repository.save(ada);
```

7. Retrieve the `User` object saved by its id, which is `username`, using the `findById` method fom the repository and print out the result
7. Retrieve the `User` object saved by its id, which is `username`, using the `findById` method from the repository and printout the result

```java
Optional<User> userFound = repository.findById("ada");
System.out.println(userFound);
```

8. Check if an user already exists using the `existsById` method from the repository, and print out the result
8. Check if a user already exists using the `existsById` method from the repository, and printout the result

```java
boolean userExist = repository.existsById("ada");
boolea userExist = repository.existsById("ada");
System.out.println("userExist? = " + userExist);
```

Expand All @@ -414,7 +412,7 @@ This lab will introduce an entity integration with Redis database with Java.
repository.deleteById("ada");
```

10. Check if an user still exists using the `existsById` method from the repository, and print out the result
10. Check if a user still exists using the `existsById` method from the repository, and printout the result

```java
userExist = repository.existsById("ada");
Expand Down Expand Up @@ -466,7 +464,7 @@ This lab will introduce an entity integration with Redis database with Java.
Optional<User> userFound = repository.findById("ada");
System.out.println(userFound);

boolean userExist = repository.existsById("ada");
boolea userExist = repository.existsById("ada");
System.out.println("userExist? = " + userExist);

repository.deleteById("ada");
Expand Down
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ nav:
- "4.3 Cassandra Commands": "column/commands.md"
- "4.4 Lab 🧪":
- "4.4.1 Cassandra Basic": "column/database-lab.md"
- "4.4.2 Cassandra Java": "column/java-lab.md"
- "4.4.2 Cassandra Java 1": "column/java-lab.md"
- "4.4.3 Cassandra Java 2": "column/java-lab-2.md"
- "4.4.4 Cassandra Java 3": "column/java-lab-3.md"
- "📕 5. Document database":
- "5.1 Introduction": "document/introduction.md"
- "5.2 MongoDB": "document/mongodb.md"
Expand Down

0 comments on commit f5579eb

Please sign in to comment.