mirror of
https://github.com/google/nomulus.git
synced 2025-05-22 04:09:46 +02:00
Implement remaining methods in JpaTransactionManager (#633)
This commit is contained in:
parent
31841ccc55
commit
2f600e3e69
2 changed files with 37 additions and 10 deletions
|
@ -122,32 +122,35 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T transactNew(Supplier<T> work) {
|
public <T> T transactNew(Supplier<T> work) {
|
||||||
// TODO(shicong): Implements the functionality to start a new transaction.
|
return transact(work);
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transactNew(Runnable work) {
|
public void transactNew(Runnable work) {
|
||||||
// TODO(shicong): Implements the functionality to start a new transaction.
|
transact(work);
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T transactNewReadOnly(Supplier<T> work) {
|
public <T> T transactNewReadOnly(Supplier<T> work) {
|
||||||
// TODO(shicong): Implements read only transaction.
|
return transact(
|
||||||
throw new UnsupportedOperationException();
|
() -> {
|
||||||
|
getEntityManager().createNativeQuery("SET TRANSACTION READ ONLY").executeUpdate();
|
||||||
|
return work.get();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transactNewReadOnly(Runnable work) {
|
public void transactNewReadOnly(Runnable work) {
|
||||||
// TODO(shicong): Implements read only transaction.
|
transactNewReadOnly(
|
||||||
throw new UnsupportedOperationException();
|
() -> {
|
||||||
|
work.run();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T doTransactionless(Supplier<T> work) {
|
public <T> T doTransactionless(Supplier<T> work) {
|
||||||
// TODO(shicong): Implements doTransactionless.
|
return transact(work);
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -116,6 +116,30 @@ public class TransactionManagerTest {
|
||||||
assertEntityExists(theEntity);
|
assertEntityExists(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestTemplate
|
||||||
|
void transactNew_succeeds() {
|
||||||
|
assertEntityNotExist(theEntity);
|
||||||
|
tm().transactNew(() -> tm().saveNew(theEntity));
|
||||||
|
assertEntityExists(theEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestTemplate
|
||||||
|
void transactNewReadOnly_succeeds() {
|
||||||
|
assertEntityNotExist(theEntity);
|
||||||
|
tm().transact(() -> tm().saveNew(theEntity));
|
||||||
|
assertEntityExists(theEntity);
|
||||||
|
TestEntity persisted = tm().transactNewReadOnly(() -> tm().load(theEntity.key()));
|
||||||
|
assertThat(persisted).isEqualTo(theEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestTemplate
|
||||||
|
void transactNewReadOnly_throwsWhenWritingEntity() {
|
||||||
|
assertEntityNotExist(theEntity);
|
||||||
|
assertThrows(
|
||||||
|
RuntimeException.class, () -> tm().transactNewReadOnly(() -> tm().saveNew(theEntity)));
|
||||||
|
assertEntityNotExist(theEntity);
|
||||||
|
}
|
||||||
|
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void saveNew_succeeds() {
|
void saveNew_succeeds() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue