-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed JDBC ResultSet column names metadata processing. Signed-off-by: Tomas Kraus <Tomas.Kraus@oracle.com> * Added pokemon sample. - JDBC module is finished - MongoDB needs DB model update Signed-off-by: Tomas Kraus <Tomas.Kraus@oracle.com> * Added mongoDB support to pokemons demo example. Signed-off-by: Tomas Kraus <Tomas.Kraus@oracle.com> * Checkstyle fixes. Signed-off-by: Tomas Kraus <Tomas.Kraus@oracle.com> * Exception handling should be tha same. Signed-off-by: Tomas Kraus <Tomas.Kraus@oracle.com> * Final code cleanup. Signed-off-by: Tomas Kraus <Tomas.Kraus@oracle.com> * README update Signed-off-by: Tomas Kraus <Tomas.Kraus@oracle.com> * Readme fix. Signed-off-by: Tomas Kraus <Tomas.Kraus@oracle.com> * Review notes applied. Signed-off-by: Tomas Kraus <Tomas.Kraus@oracle.com> * Fixed checkstyle issues. Signed-off-by: Tomas Kraus <Tomas.Kraus@oracle.com>
- Loading branch information
1 parent
5d039a7
commit 015daea
Showing
19 changed files
with
1,287 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Helidon DB Client Pokemon Example with JDBC | ||
|
||
This example shows how to run Helidon DB Client over JDBC. | ||
|
||
Application provides REST service endpoint with CRUD operations on Pokemnons | ||
database. | ||
|
||
## Database | ||
|
||
Database model contains two tables: | ||
|
||
**Types** | ||
|
||
| Column | Type | Integrity | | ||
|--------|---------|-------------| | ||
| id | integer | Primary key | | ||
| name | varchar | | | ||
|
||
**Pokemons** | ||
|
||
| Column | Type | Integrity | | ||
|---------|---------|-------------| | ||
| id | integer | Primary key | | ||
| name | varchar | | | ||
| id_type | integer | Type(id) | | ||
|
||
with 1:N relationship between *Types* and *Pokemons* | ||
|
||
## Build | ||
|
||
``` | ||
cd <project_root>/examples/dbclient/pokemons | ||
mvn package | ||
``` | ||
|
||
## Run | ||
|
||
This example requires a MySQL database, start it using docker: | ||
``` | ||
docker run --rm --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root \ | ||
-e MYSQL_DATABASE=pokemon -e MYSQL_USER=user -e MYSQL_PASSWORD=password mysql:5.7 | ||
``` | ||
|
||
Then run the `io.helidon.examples.dbclient.pokemons.PokemonMain` class: | ||
``` | ||
cd <project_root>/examples/dbclient/pokemons | ||
java -jar target/helidon-examples-dbclient-pokemons.jar | ||
``` | ||
|
||
### Run with MongoDB | ||
|
||
It's possible to run example with MongoDB database. Start it using docker: | ||
``` | ||
docker run --rm --name mongo -p 27017:27017 mongo | ||
``` | ||
|
||
Then run the `io.helidon.examples.dbclient.pokemons.PokemonMain` class with `mongo` argument: | ||
``` | ||
cd <project_root>/examples/dbclient/pokemons | ||
java -jar target/helidon-examples-dbclient-pokemons.jar mongo | ||
``` | ||
|
||
## Test Example | ||
|
||
The application has the following endpoints: | ||
|
||
- http://localhost:8079/db - the main business endpoint (see `curl` commands below) | ||
- http://localhost:8079/metrics - the metrics endpoint (query adds application metrics) | ||
- http://localhost:8079/health - has a custom database health check | ||
|
||
Application also connects to zipkin on default address. | ||
The query operation adds database trace. | ||
|
||
`curl` commands: | ||
|
||
- `curl http://localhost:8079/db/type | json_pp` - list all pokemon types in the database | ||
- `curl http://localhost:8079/db/pokemon | json_pp` - list all pokemons in the database | ||
- `curl http://localhost:8079/db/pokemon/2 | json_pp` - get a single pokemon by id | ||
- `curl http://localhost:8079/db/pokemon/name/Squirtle | json_pp` - get a single pokemon by name | ||
- `curl -i -X POST -d '{"id":7,"name":"Rattata","idType":1}' http://localhost:8079/db/pokemon` - add a new pokemon Rattata | ||
- `curl -i -X PUT -d '{"id":7,"name":"Raticate","idType":2}' http://localhost:8079/db/pokemon` - rename pokemon with id 7 to Raticate | ||
- `curl -i -X DELETE http://localhost:8079/db/pokemon/7` - delete pokemon with id 7 | ||
|
||
### Proxy | ||
|
||
Make sure that `localhost` is not being accessed trough proxy when proxy is configured on your system: | ||
``` | ||
export NO_PROXY='localhost' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.helidon.applications</groupId> | ||
<artifactId>helidon-se</artifactId> | ||
<version>2.0-SNAPSHOT</version> | ||
<relativePath>../../../applications/se/pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>helidon-examples-dbclient-pokemons</artifactId> | ||
<name>Helidon Examples DB Client: Pokemons Database</name> | ||
|
||
<properties> | ||
<mainClass>io.helidon.examples.dbclient.pokemons.PokemonMain</mainClass> | ||
<arg>jdbc</arg> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.helidon.health</groupId> | ||
<artifactId>helidon-health</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.metrics</groupId> | ||
<artifactId>helidon-metrics</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.tracing</groupId> | ||
<artifactId>helidon-tracing</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.tracing</groupId> | ||
<artifactId>helidon-tracing-zipkin</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.dbclient</groupId> | ||
<artifactId>helidon-dbclient-jdbc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.dbclient</groupId> | ||
<artifactId>helidon-dbclient-mongodb</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.dbclient</groupId> | ||
<artifactId>helidon-dbclient-tracing</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.dbclient</groupId> | ||
<artifactId>helidon-dbclient-metrics</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.dbclient</groupId> | ||
<artifactId>helidon-dbclient-metrics-jdbc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.dbclient</groupId> | ||
<artifactId>helidon-dbclient-health</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.dbclient</groupId> | ||
<artifactId>helidon-dbclient-jsonp</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.dbclient</groupId> | ||
<artifactId>helidon-dbclient-webserver-jsonp</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.zaxxer</groupId> | ||
<artifactId>HikariCP</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-jdk14</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.webserver</groupId> | ||
<artifactId>helidon-webserver</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.media.jsonp</groupId> | ||
<artifactId>helidon-media-jsonp-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.media.jsonb</groupId> | ||
<artifactId>helidon-media-jsonb-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.config</groupId> | ||
<artifactId>helidon-config-yaml</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>copy-libs</id> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Oops, something went wrong.