-
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
7 changed files
with
131 additions
and
38 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
89 changes: 89 additions & 0 deletions
89
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,89 @@ | ||
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 io.micronaut.transaction.SynchronousTransactionManager | ||
import io.micronaut.transaction.TransactionCallback | ||
import io.micronaut.transaction.TransactionStatus | ||
import spock.lang.AutoCleanup | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
import javax.inject.Inject | ||
|
||
class PostgresNoIdEntitySpec extends Specification implements PostgresTestPropertyProvider { | ||
@AutoCleanup | ||
@Shared | ||
ApplicationContext applicationContext = ApplicationContext.run(getProperties()) | ||
|
||
@Shared | ||
@Inject | ||
NoIdEntityRepository noIdEntityRepository = applicationContext.getBean(NoIdEntityRepository) | ||
|
||
@Shared | ||
@Inject | ||
SynchronousTransactionManager transactionManager = applicationContext.getBean(SynchronousTransactionManager) | ||
|
||
void setup() { | ||
transactionManager.executeWrite(new TransactionCallback() { | ||
@Override | ||
Object call(TransactionStatus status) throws Exception { | ||
status.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() } | ||
return null | ||
} | ||
|
||
}) | ||
} | ||
|
||
void 'test no-id entity operations'() { | ||
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
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