For experimental "transparent persistence" - Inserts added to PC

When inserting bean with transparent persistence the beans are registered with the persistence context. This is done to support the cases where the beans are inserted, a flush() occurs, the inserted bean is mutated and now dirty - we want that to be detected and get an update
This commit is contained in:
Robin Bygrave
2021-04-01 16:59:03 +13:00
parent ba397bbb0c
commit 0527f45f5a
9 changed files with 70 additions and 10 deletions
@@ -131,11 +131,6 @@ public class ScopedTransaction extends SpiTransactionProxy {
}
}
@Override
public void setTransparentPersistence(boolean transparentPersistence) {
current.getTransaction().setTransparentPersistence(transparentPersistence);
}
@Override
public void setRollbackOnly() {
current.setRollbackOnly();
@@ -147,6 +147,11 @@ public interface SpiTransaction extends Transaction {
*/
int depth();
/**
* Return true if transparent persistence is turned on.
*/
boolean isTransparentPersistence();
/**
* Return true if this transaction was created explicitly via
* <code>Ebean.beginTransaction()</code>.
@@ -43,6 +43,16 @@ public abstract class SpiTransactionProxy implements SpiTransaction {
return transaction.getLabel();
}
@Override
public void setTransparentPersistence(boolean transparentPersistence) {
transaction.setTransparentPersistence(transparentPersistence);
}
@Override
public boolean isTransparentPersistence() {
return transaction.isTransparentPersistence();
}
@Override
public void commitAndContinue() {
transaction.commitAndContinue();
@@ -1038,6 +1038,10 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
if (!publish) {
beanDescriptor.setDraft(entityBean);
}
if (transaction.isTransparentPersistence() && idValue != null) {
// with getGeneratedKeys off we will not have a idValue
beanDescriptor.contextPut(transaction.getPersistenceContext(), idValue, entityBean);
}
}
public boolean isReference() {
@@ -100,6 +100,11 @@ class ImplicitReadOnlyTransaction implements SpiTransaction, TxnProfileEventCode
// do nothing
}
@Override
public boolean isTransparentPersistence() {
return false;
}
@Override
public void setLabel(String label) {
// do nothing
@@ -302,6 +302,11 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
this.batchMode = true;
}
@Override
public boolean isTransparentPersistence() {
return transparentPersistence;
}
@Override
public boolean isSkipCacheExplicit() {
return (skipCache != null && !skipCache);
@@ -30,6 +30,11 @@ class NoTransaction implements SpiTransaction {
// do nothing
}
@Override
public boolean isTransparentPersistence() {
return false;
}
@Override
public void setLabel(String label) {
// do nothing
@@ -60,11 +60,6 @@ class SavepointTransaction extends SpiTransactionProxy {
this.rollbackOnly = true;
}
@Override
public void setTransparentPersistence(boolean transparentPersistence) {
throw new IllegalStateException("This is not handled yet. Need to review this case.");
}
@Override
public void commit() {
if (rollbackOnly) {