-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pageable queries with dynamic entity name (#3245)
* Fix schema generator when mapped entity contains property placeholder * Fix tests * Fix tests and move to jdbc-example-java * Try to improve test coverage * Fix pageable query for entity with dynamic name * Add test with find IN * Revert unwanted change * Test with IN and property expression value * Added test with count as well * More examples with count * Trigger build
- Loading branch information
1 parent
06c93d2
commit 13e8122
Showing
4 changed files
with
106 additions
and
1 deletion.
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
22 changes: 22 additions & 0 deletions
22
doc-examples/jdbc-example-java/src/main/java/example/CustomEntityRepository.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 |
---|---|---|
@@ -1,9 +1,31 @@ | ||
package example; | ||
|
||
import io.micronaut.data.annotation.Query; | ||
import io.micronaut.data.jdbc.annotation.JdbcRepository; | ||
import io.micronaut.data.model.Page; | ||
import io.micronaut.data.model.Pageable; | ||
import io.micronaut.data.model.Slice; | ||
import io.micronaut.data.model.query.builder.sql.Dialect; | ||
import io.micronaut.data.repository.CrudRepository; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@JdbcRepository(dialect = Dialect.H2) | ||
public interface CustomEntityRepository extends CrudRepository<CustomEntity, Long> { | ||
Page<CustomEntity> findAll(Pageable pageable); | ||
|
||
Page<CustomEntity> findByNameIn(List<String> names, Pageable pageable); | ||
|
||
@Query(value = "SELECT * FROM ${entity.prefix}entity WHERE name IN ('${entity.name}')", nativeQuery = true) | ||
List<CustomEntity> findDataByEnvPropertyValue(); | ||
|
||
@Query(value = "SELECT id, '${entity.name}' AS name FROM ${entity.prefix}entity WHERE id IN (:id)", nativeQuery = true | ||
) | ||
List<CustomEntity> findDataById(List<Long> id); | ||
|
||
@Query(value = "SELECT COUNT(*) FROM ${entity.prefix}entity WHERE name IN ('${entity.name}')", nativeQuery = true) | ||
long countDataByEnvPropertyValue(); | ||
|
||
long countByIdIn(List<Long> ids); | ||
} |
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ datasources: | |
dialect: H2 | ||
entity: | ||
prefix: demo_ | ||
name: Entity1 |
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