-
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.
Allow limited no-id entity operations
- Loading branch information
Showing
6 changed files
with
117 additions
and
35 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
81 changes: 81 additions & 0 deletions
81
data-jdbc/src/test/groovy/io/micronaut/data/jdbc/postgres/PostgresNoIdEntitySpec.groovy
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,81 @@ | ||
package io.micronaut.data.jdbc.postgres | ||
|
||
import io.micronaut.context.ApplicationContext | ||
import io.micronaut.data.annotation.MappedEntity | ||
import io.micronaut.data.jdbc.annotation.JdbcRepository | ||
import io.micronaut.data.model.Pageable | ||
import io.micronaut.data.model.Sort | ||
import io.micronaut.data.model.query.builder.sql.Dialect | ||
import io.micronaut.data.runtime.config.SchemaGenerate | ||
import spock.lang.AutoCleanup | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
import javax.inject.Inject | ||
import java.sql.Connection | ||
|
||
class PostgresNoIdEntitySpec extends Specification implements PostgresTestPropertyProvider { | ||
@AutoCleanup | ||
@Shared | ||
ApplicationContext applicationContext = ApplicationContext.run(getProperties()) | ||
|
||
@Shared | ||
@Inject | ||
NoIdEntityRepository noIdEntityRepository = applicationContext.getBean(NoIdEntityRepository) | ||
|
||
@Shared | ||
@Inject | ||
Connection connection = applicationContext.getBean(Connection) | ||
|
||
void setup() { | ||
connection.prepareStatement(''' | ||
drop sequence if exists "no_id_names_seq"; | ||
drop table if exists "no_id_names"; | ||
create sequence "no_id_names_seq" increment by 1; | ||
create table "no_id_names" | ||
( | ||
"id" bigint default nextval('no_id_names_seq'::regclass) not null, | ||
"first_name" varchar(255) , | ||
"last_name" varchar(255) | ||
); | ||
''').withCloseable { it.executeUpdate() } | ||
} | ||
|
||
void 'test no-id entity operations'() { | ||
given: | ||
when: | ||
noIdEntityRepository.save(new NoIdEntity(firstName: "Xyz", lastName: "Abc")) | ||
noIdEntityRepository.save(new NoIdEntity(firstName: "Qwe", lastName: "Jkl")) | ||
def all = noIdEntityRepository.listAll() | ||
def allPageable = noIdEntityRepository.listAll(Pageable.from(1, 1).order("firstName", Sort.Order.Direction.DESC)) | ||
then: | ||
all.size() == 2 | ||
all.find { it.firstName == "Xyz" } | ||
all.find { it.firstName == "Qwe" } | ||
allPageable.size() == 1 | ||
allPageable.find { it.firstName == "Qwe" } | ||
} | ||
|
||
@Override | ||
SchemaGenerate schemaGenerate() { | ||
return SchemaGenerate.NONE | ||
} | ||
} | ||
|
||
@JdbcRepository(dialect = Dialect.POSTGRES) | ||
interface NoIdEntityRepository { | ||
|
||
NoIdEntity save(NoIdEntity entity) | ||
|
||
List<NoIdEntity> listAll() | ||
|
||
List<NoIdEntity> listAll(Pageable pageable) | ||
|
||
} | ||
|
||
@MappedEntity("no_id_names") | ||
class NoIdEntity { | ||
|
||
String firstName | ||
String lastName | ||
} |
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