-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changes to open-api-generator server guide to use JDBC (#818)
- Loading branch information
Showing
25 changed files
with
342 additions
and
243 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
openapiGeneratorVersion=5.4.0 |
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
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
|
||
org.gradle.parallel=true |
78 changes: 78 additions & 0 deletions
78
...s/micronaut-openapi-generator-server/java/src/main/java/example/micronaut/BookEntity.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 example.micronaut; | ||
|
||
import example.micronaut.model.BookAvailability; | ||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.core.annotation.Nullable; | ||
import io.micronaut.data.annotation.GeneratedValue; | ||
import io.micronaut.data.annotation.Id; | ||
import io.micronaut.data.annotation.MappedEntity; | ||
import io.micronaut.data.annotation.MappedProperty; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
@MappedEntity("book") // <1> | ||
public class BookEntity { | ||
|
||
@Id // <2> | ||
@GeneratedValue(GeneratedValue.Type.AUTO) | ||
private Long id; | ||
|
||
@NonNull | ||
@NotNull | ||
private String name; | ||
|
||
@NonNull | ||
@NotNull | ||
private BookAvailability availability; | ||
|
||
@Nullable | ||
private String author; | ||
|
||
@Nullable | ||
@MappedProperty("ISBN") | ||
private String isbn; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
@NonNull | ||
public BookAvailability getAvailability() { | ||
return availability; | ||
} | ||
|
||
public void setAvailability(@NonNull BookAvailability availability) { | ||
this.availability = availability; | ||
} | ||
|
||
@Nullable | ||
public String getIsbn() { | ||
return isbn; | ||
} | ||
|
||
public void setIsbn(@Nullable String isbn) { | ||
this.isbn = isbn; | ||
} | ||
|
||
@NonNull | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(@NonNull String name) { | ||
this.name = name; | ||
} | ||
|
||
@Nullable | ||
public String getAuthor() { | ||
return author; | ||
} | ||
|
||
public void setAuthor(@Nullable String author) { | ||
this.author = author; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...cronaut-openapi-generator-server/java/src/main/java/example/micronaut/BookRepository.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,31 @@ | ||
package example.micronaut; | ||
|
||
import example.micronaut.model.BookAvailability; | ||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.data.jdbc.annotation.JdbcRepository; | ||
import io.micronaut.data.model.query.builder.sql.Dialect; | ||
import io.micronaut.data.repository.GenericRepository; | ||
import io.micronaut.data.repository.jpa.JpaSpecificationExecutor; | ||
import io.micronaut.data.repository.jpa.criteria.PredicateSpecification; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
@JdbcRepository(dialect = Dialect.MYSQL) // <1> | ||
public interface BookRepository extends GenericRepository<BookEntity, Long>, // <2> | ||
JpaSpecificationExecutor<BookEntity> { // <3> | ||
|
||
@NonNull | ||
List<BookEntity> findAll(PredicateSpecification<BookEntity> spec); // <4> | ||
|
||
@NonNull | ||
List<BookEntity> findAll(); | ||
|
||
|
||
@NonNull | ||
BookEntity save(@NonNull @NotBlank String name, | ||
@NonNull @NotNull BookAvailability availability, | ||
@NonNull @NotBlank String author, | ||
@NonNull @NotBlank String isbn); | ||
} |
33 changes: 0 additions & 33 deletions
33
.../micronaut-openapi-generator-server/java/src/main/java/example/micronaut/BookService.java
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...aut-openapi-generator-server/java/src/main/java/example/micronaut/BookSpecifications.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 example.micronaut; | ||
|
||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.data.repository.jpa.criteria.PredicateSpecification; | ||
|
||
public class BookSpecifications { | ||
public static PredicateSpecification<BookEntity> nameLike(@NonNull String name) { | ||
return (root, criteriaBuilder) -> criteriaBuilder.like(root.get("name"), "%"+name+"%"); | ||
} | ||
|
||
public static PredicateSpecification<BookEntity> authorLike(@NonNull String author) { | ||
return (root, criteriaBuilder) -> criteriaBuilder.like(root.get("author"), "%"+author+"%"); | ||
} | ||
} |
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
Oops, something went wrong.