-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add oracle example #489
Merged
Merged
Add oracle example #489
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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.quarkus.qe</groupId> | ||
<artifactId>quarkus-test-parent</artifactId> | ||
<version>1.2.1.Beta1-SNAPSHOT</version> | ||
<relativePath>../../</relativePath> | ||
</parent> | ||
<artifactId>examples-database-oracle</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Quarkus - Test Framework - Examples - Database - Oracle</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-orm-panache</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-validator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-jdbc-oracle</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus.qe</groupId> | ||
<artifactId>quarkus-test-containers</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus.qe</groupId> | ||
<artifactId>quarkus-test-service-database</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus.qe</groupId> | ||
<artifactId>quarkus-test-openshift</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>${quarkus.platform.group-id}</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<version>${quarkus.platform.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<!-- Skipped on Windows as does not support Linux Containers / Testcontainers --> | ||
<profile> | ||
<id>skip-tests-on-windows</id> | ||
<activation> | ||
<os> | ||
<family>windows</family> | ||
</os> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
28 changes: 28 additions & 0 deletions
28
...tabase-oracle/src/main/java/io/quarkus/qe/database/oracle/ApplicationExceptionMapper.java
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,28 @@ | ||
package io.quarkus.qe.database.oracle; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
@Provider | ||
public class ApplicationExceptionMapper implements ExceptionMapper<Exception> { | ||
@Override | ||
public Response toResponse(Exception exception) { | ||
int code = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); | ||
if (exception instanceof WebApplicationException) { | ||
code = ((WebApplicationException) exception).getResponse().getStatus(); | ||
} | ||
|
||
return Response.status(code) | ||
.type(MediaType.APPLICATION_JSON) | ||
.entity(new ObjectMapper().createObjectNode() | ||
.put("code", code) | ||
.put("error", exception.getMessage()) | ||
.toString()) | ||
.build(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/database-oracle/src/main/java/io/quarkus/qe/database/oracle/Book.java
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,17 @@ | ||
package io.quarkus.qe.database.oracle; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Table; | ||
import javax.validation.constraints.NotBlank; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheEntity; | ||
|
||
@Entity | ||
@Table(name = "book") | ||
public class Book extends PanacheEntity { | ||
@NotBlank(message = "book title must be set") | ||
public String title; | ||
|
||
@NotBlank(message = "book author must be set") | ||
public String author; | ||
} |
78 changes: 78 additions & 0 deletions
78
examples/database-oracle/src/main/java/io/quarkus/qe/database/oracle/BookResource.java
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,78 @@ | ||
package io.quarkus.qe.database.oracle; | ||
|
||
import java.util.List; | ||
|
||
import javax.transaction.Transactional; | ||
import javax.validation.Valid; | ||
import javax.ws.rs.ClientErrorException; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.DELETE; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.NotFoundException; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import io.quarkus.panache.common.Sort; | ||
|
||
@Path("/book") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
public class BookResource { | ||
|
||
@GET | ||
public List<Book> getAll() { | ||
return Book.listAll(Sort.by("title")); | ||
} | ||
|
||
@GET | ||
@Path("/{id}") | ||
public Book get(@PathParam("id") Long id) { | ||
Book book = Book.findById(id); | ||
if (book == null) { | ||
throw new NotFoundException("book '" + id + "' not found"); | ||
} | ||
return book; | ||
} | ||
|
||
@POST | ||
@Transactional | ||
public Response create(@Valid Book book) { | ||
if (book.id != null) { | ||
throw new ClientErrorException("unexpected ID in request", ValidationExceptionMapper.UNPROCESSABLE_ENTITY); | ||
} | ||
|
||
book.persist(); | ||
return Response.ok(book).status(Response.Status.CREATED).build(); | ||
} | ||
|
||
@PUT | ||
@Path("/{id}") | ||
@Transactional | ||
public Book update(@PathParam("id") Long id, @Valid Book newBook) { | ||
Book book = Book.findById(id); | ||
if (book == null) { | ||
throw new NotFoundException("book '" + id + "' not found"); | ||
} | ||
|
||
book.title = newBook.title; | ||
book.author = newBook.author; | ||
return book; | ||
} | ||
|
||
@DELETE | ||
@Path("/{id}") | ||
@Transactional | ||
public Response delete(@PathParam("id") Long id) { | ||
Book book = Book.findById(id); | ||
if (book == null) { | ||
throw new NotFoundException("book '" + id + "' not found"); | ||
} | ||
book.delete(); | ||
return Response.noContent().build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
.../database-oracle/src/main/java/io/quarkus/qe/database/oracle/NotFoundExceptionMapper.java
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,14 @@ | ||
package io.quarkus.qe.database.oracle; | ||
|
||
import javax.ws.rs.NotFoundException; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
@Provider | ||
public class NotFoundExceptionMapper implements ExceptionMapper<NotFoundException> { | ||
@Override | ||
public Response toResponse(NotFoundException exception) { | ||
return new ApplicationExceptionMapper().toResponse(exception); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...atabase-oracle/src/main/java/io/quarkus/qe/database/oracle/ValidationExceptionMapper.java
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,36 @@ | ||
package io.quarkus.qe.database.oracle; | ||
|
||
import javax.validation.ConstraintViolation; | ||
import javax.validation.ConstraintViolationException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
|
||
@Provider | ||
public class ValidationExceptionMapper implements ExceptionMapper<ConstraintViolationException> { | ||
|
||
public static final int UNPROCESSABLE_ENTITY = 422; | ||
|
||
@Override | ||
public Response toResponse(ConstraintViolationException exception) { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
ArrayNode errors = mapper.createArrayNode(); | ||
|
||
for (ConstraintViolation<?> constraintViolation : exception.getConstraintViolations()) { | ||
errors.addObject() | ||
.put("path", constraintViolation.getPropertyPath().toString()) | ||
.put("message", constraintViolation.getMessage()); | ||
} | ||
|
||
return Response.status(UNPROCESSABLE_ENTITY) | ||
.type(MediaType.APPLICATION_JSON) | ||
.entity(mapper.createObjectNode() | ||
.put("code", UNPROCESSABLE_ENTITY) | ||
.set("error", errors)) | ||
.build(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/database-oracle/src/main/resources/application.properties
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,3 @@ | ||
quarkus.datasource.db-kind=oracle | ||
quarkus.hibernate-orm.sql-load-script=import.sql | ||
quarkus.hibernate-orm.database.generation=drop-and-create | ||
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,7 @@ | ||
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Foundation', 'Isaac Asimov'); | ||
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, '2001: A Space Odyssey', 'Arthur C. Clarke'); | ||
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Stranger in a Strange Land', 'Robert A. Heinlein'); | ||
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Ender''s Game', 'Orson Scott Card'); | ||
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Hyperion', 'Dan Simmons'); | ||
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Anathem', 'Neal Stephenson'); | ||
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Perdido Street Station', 'China Miéville'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log contains a lot of error messages because of
drop-and-create
strategy, tests are passing, application boots etc.It's just noise and distraction, so I was wondering if that could be suppressed. I would keep
drop-and-create
in place, just if the verbosity could be a bit reduced.12:49:16,923 INFO [app] Caused by: Error : 942, Position : 11, Sql = drop table book cascade constraints, OriginalSql = drop table book cascade constraints, Error Msg = ORA-00942: table or view does not exist
12:49:16,928 INFO [app] Caused by: Error : 2289, Position : 14, Sql = drop sequence hibernate_sequence, OriginalSql = drop sequence hibernate_sequence, Error Msg = ORA-02289: sequence does not exist