forked from quarkus-qe/quarkus-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test new Spring Data 3 interfaces and methods introduced in bump
(cherry picked from commit 5bd7470)
- Loading branch information
1 parent
f4f84e6
commit 7e793d6
Showing
10 changed files
with
356 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
spring/spring-data/src/main/java/io/quarkus/ts/spring/data/rest/Magazine.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,60 @@ | ||
package io.quarkus.ts.spring.data.rest; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
@Entity | ||
public class Magazine { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@NotBlank(message = "Name may not be blank") | ||
private String name; | ||
|
||
@Column(name = "issued_in") | ||
@Min(1800) | ||
private Long issuedIn; | ||
|
||
public Magazine() { | ||
} | ||
|
||
public Magazine(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Magazine withName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public Long getIssuedIn() { | ||
return issuedIn; | ||
} | ||
|
||
public void setIssuedIn(Long issuedIn) { | ||
this.issuedIn = issuedIn; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
spring/spring-data/src/main/java/io/quarkus/ts/spring/data/rest/MagazineJpaRepository.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,6 @@ | ||
package io.quarkus.ts.spring.data.rest; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MagazineJpaRepository extends JpaRepository<Magazine, Long> { | ||
} |
11 changes: 11 additions & 0 deletions
11
.../spring-data/src/main/java/io/quarkus/ts/spring/data/rest/MagazineListCrudRepository.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,11 @@ | ||
package io.quarkus.ts.spring.data.rest; | ||
|
||
import org.springframework.data.repository.ListCrudRepository; | ||
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | ||
|
||
@RepositoryRestResource(path = "magazine-list-crud-rest-repository") | ||
public interface MagazineListCrudRepository extends ListCrudRepository<Magazine, Long> { | ||
|
||
Magazine findByName(String name); | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
.../src/main/java/io/quarkus/ts/spring/data/rest/MagazineListPagingAndSortingRepository.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,9 @@ | ||
package io.quarkus.ts.spring.data.rest; | ||
|
||
import org.springframework.data.repository.ListPagingAndSortingRepository; | ||
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | ||
|
||
@RepositoryRestResource(path = "magazine-list-paging-sorting-rest-repository") | ||
public interface MagazineListPagingAndSortingRepository extends ListPagingAndSortingRepository<Magazine, Long> { | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
spring/spring-data/src/main/java/io/quarkus/ts/spring/data/rest/MagazineResource.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,56 @@ | ||
package io.quarkus.ts.spring.data.rest; | ||
|
||
import static jakarta.transaction.Transactional.TxType.REQUIRES_NEW; | ||
|
||
import java.util.Objects; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.PUT; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import io.quarkus.security.PermissionsAllowed; | ||
|
||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@PermissionsAllowed("read") | ||
@Path("magazine-resource") | ||
public class MagazineResource { | ||
|
||
@Inject | ||
MagazineListCrudRepository magazineRepository; | ||
|
||
@Inject | ||
MagazineJpaRepository magazineJpaRepository; | ||
|
||
public record MagazineDto(String oldName, String newName) { | ||
} | ||
|
||
@Path("{id}") | ||
@GET | ||
public Magazine getMagazine(@PathParam("id") long id) { | ||
return magazineJpaRepository.getReferenceById(id); | ||
} | ||
|
||
@Transactional(REQUIRES_NEW) // makes sure we activate transaction here | ||
@PUT | ||
public String updateMagazine(MagazineDto magazineDto) { | ||
Objects.requireNonNull(magazineDto); | ||
Objects.requireNonNull(magazineDto.newName()); | ||
Objects.requireNonNull(magazineDto.oldName()); | ||
|
||
var magazine = magazineRepository.findByName(magazineDto.oldName()); | ||
var updatedMagazine = magazine.withName(magazineDto.newName()); | ||
magazineRepository.save(updatedMagazine); | ||
return magazineRepository | ||
.findById(magazine.getId()) | ||
.map(Magazine::getName) | ||
.orElseThrow(IllegalStateException::new); // we know it does exist by now | ||
} | ||
|
||
} |
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
Oops, something went wrong.