Package io.ebeaninternal.server.core
Class PersistRequestBean<T>
- java.lang.Object
-
- io.ebeaninternal.server.core.BeanRequest
-
- io.ebeaninternal.server.core.PersistRequest
-
- io.ebeaninternal.server.core.PersistRequestBean<T>
-
- All Implemented Interfaces:
PreGetterCallback
,BeanPersistRequest<T>
,SpiProfileTransactionEvent
,TxnProfileEventCodes
,BatchPostExecute
,DocStoreUpdate
public final class PersistRequestBean<T> extends PersistRequest implements BeanPersistRequest<T>, DocStoreUpdate, PreGetterCallback, SpiProfileTransactionEvent
PersistRequest for insert update or delete of a bean.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.ebeaninternal.server.core.PersistRequest
PersistRequest.Type
-
-
Field Summary
-
Fields inherited from interface io.ebeaninternal.api.TxnProfileEventCodes
EVT_CALLABLESQL, EVT_COMMIT, EVT_DELETE, EVT_DELETE_PERMANENT, EVT_DELETE_SOFT, EVT_INSERT, EVT_ORMUPDATE, EVT_ROLLBACK, EVT_UPDATE, EVT_UPDATESQL, FIND_ATTRIBUTE, FIND_COUNT, FIND_DELETE, FIND_ID_LIST, FIND_ITERATE, FIND_MANY, FIND_MANY_LAZY, FIND_ONE, FIND_ONE_LAZY, FIND_SUBQUERY, FIND_UPDATE
-
-
Constructor Summary
Constructors Constructor Description PersistRequestBean(SpiEbeanServer server, T bean, Object parentBean, BeanManager<T> mgr, SpiTransaction t, PersistExecute persistExecute, PersistRequest.Type type, int flags)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBeanUpdate(CacheChangeSet changeSet)
Build the bean update for the L2 cache.void
addCollectionChange(String name, Object value)
Add an element collection change to L2 bean cache update.void
addDocStoreUpdates(DocStoreUpdates docStoreUpdates)
For requests that update document store add this event to either the list of queue events or list of update events.void
addSaveMany(SaveMany saveManyRequest)
The intersection table updates or element collection to the batch executed later on postExecute.void
addTimingBatch(long startNanos, int batch)
Add timing metrics for batch persist.void
addTimingNoBatch(long startNanos)
void
addToPersistMap(BeanPersistIdMap beanPersistMap)
void
addToQueue(DocStoreUpdates docStoreUpdates)
Add this event to the queue entries in IndexUpdates.void
addUpdatedManyProperty(BeanPropertyAssocMany<?> updatedAssocMany)
This many property has been cascade saved.void
checkBatchEscalationOnCascade()
Check for batch escalation on cascade.void
checkDraft()
Checks for @Draftable entity beans with @Draft property that the bean is a 'draft'.void
checkRowCount(int rowCount)
Check for optimistic concurrency exception.void
complete()
Completed insert or delete request.void
completeUpdate()
Completed update request handling cases for element collection and where ONLY many properties were updated.T
createReference()
Create and return a new reference bean matching this beans Id value.void
deferredRelationship(EntityBean assocBean, ImportedId importedId, EntityBean bean)
Register the derived relationships to get executed later (on JDBC batch flush or commit).DeleteMode
deleteMode()
Return the delete mode - Soft or Hard.void
docStorePersist()
Persist to the document store now (via buffer, not post commit).void
docStoreUpdate(DocStoreUpdateContext txn)
Process the persist request updating the document store.int
executeNow()
Execute the request right now.int
executeOrQueue()
Execute a the request or queue/batch it for later execution.void
flagInsert()
Set the request flags indicating this is an insert.void
flagUpdate()
Unset the request insert flag indicating this is an update.void
flushBatchOnCascade()
If using batch on cascade flush if required.T
getBean()
Return the bean associated with this request.BeanDescriptor<T>
getBeanDescriptor()
Return the BeanDescriptor for the associated bean.Object
getBeanId()
Return the Id value for the bean.ConcurrencyMode
getConcurrencyMode()
Return the concurrency mode used for this persist.boolean[]
getDirtyProperties()
Return the dirty properties on this request.EntityBean
getEntityBean()
EntityBeanIntercept
getEntityBeanIntercept()
Return the intercept if there is one.int
getFlags()
Return the flags set on this persist request.String
getFullName()
Returns a description of the request.EntityBean
getImportedOrphanForRemoval()
Set<String>
getLoadedProperties()
For an update or delete of a partially populated bean this is the set of loaded properties and otherwise returns null.Object
getOrigValue(BeanProperty prop)
Return the original / old value for the given property.Object
getParentBean()
Return the parent bean for cascading save with unidirectional relationship.String
getSelectLastInsertedId()
Return the SQL used to fetch the last inserted id value.List<BeanPropertyAssocMany<?>>
getUpdatedManyCollections()
Return the list of cascade updated many properties (can be null).Set<String>
getUpdatedProperties()
For an update this is the set of properties that where updated.Map<String,ValuePair>
getUpdatedValues()
Returns a map of the properties that have changed and their new and old values.String
getUpdatePlanHash()
Return the key for an update persist request.String
getUpdateTable()
Return the table to update depending if the request is a 'publish' one or normal.long
getVersion()
Return the version in long form (if set).boolean
hasDirtyProperty(int[] propertyPositions)
Return true if any of the given properties are dirty.boolean
hasDirtyProperty(Set<String> propertyNames)
Return true if any of the given property names are dirty.void
initForSoftDelete()
Init generated properties for soft delete (as it's an update).void
initTransIfRequiredWithBatchCascade()
Init the transaction and also check for batch on cascade escalation.boolean
isAddToUpdate(BeanProperty prop)
Return true if the property should be included in the update.boolean
isBatched()
Return true is this request was added to the JDBC batch.boolean
isBatchThisRequest()
Return true if this persist request should use JDBC batch.boolean
isDirty()
Used to skip updates if we know the bean is not dirty.boolean
isDirtyProperty(BeanProperty prop)
Return true if the property is dirty.boolean
isDraftable()
Return true if the bean type is a Draftable.boolean
isForcedUpdate()
boolean
isHardDeleteCascade()
Return true if this was a hard/permanent delete request (and should cascade as such).boolean
isHardDeleteDraft()
Return true if this request is a hard delete of a draftable bean.boolean
isInsert()
Return true if this is an insert request.boolean
isInsertedParent()
Return true if this request is an insert.boolean
isLoadedProperty(BeanProperty prop)
Return true if this property is loaded (full bean or included in partial bean).boolean
isNotifyCache()
boolean
isParent(Object o)
boolean
isPublish()
Return true if this request is a 'publish' action.boolean
isQueueSaveMany()
Return true if the intersection table updates or element collection updates should be queued.boolean
isReference()
boolean
isRegisteredBean()
Return true if this bean has been already been persisted (inserted or updated) in this transaction.boolean
isRegisteredForDeleteBean()
boolean
isStatelessUpdate()
Return true if this is a stateless update request (in which case it doesn't really have 'old values').void
notifyLocalPersistListener()
long
now()
Use a common 'now' value across both when created and when updated etc.void
postExecute()
Post processing.void
preElementCollectionUpdate()
Ensure the preUpdate event fires (for case where only element collection has changed).void
preGetterTrigger(int propertyIndex)
Trigger the callback based on a getter on a property.void
profile()
Add to profile as single bean insert, update or delete (not batched).void
profile(long offset, int flushCount)
Add to profile as batched bean insert, update or delete.void
registerDeleteBean()
void
rollbackTransIfRequired()
Rollback the transaction if it was created for this request.void
setBatched()
Set when request is added to the JDBC batch.void
setBoundId(Object idValue)
Set the Id value that was bound.void
setGeneratedKey(Object idValue)
Set the generated key back to the bean.void
setImportedOrphanForRemoval(BeanPropertyAssocOne<?> prop)
Set an orphan bean that needs to be deleted AFTER the request has persisted.void
setSaveRecurse()
Set when this request is from cascading persist.void
setSkipBatchForTopLevel()
void
setTrans(SpiTransaction transaction)
Set the transaction from prior persist request.void
unRegisterBean()
-
Methods inherited from class io.ebeaninternal.server.core.PersistRequest
getType, initTransIfRequired, isFlushQueue, isLogSql, isLogSummary, isPersistCascade, startBind, translateSqlException
-
Methods inherited from class io.ebeaninternal.server.core.BeanRequest
clearTransIfRequired, commitTransIfRequired, createImplicitTransIfRequired, getDataTimeZone, getEbeanServer, getServer, getTransaction, setTransaction
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.ebean.event.BeanPersistRequest
getEbeanServer, getTransaction
-
-
-
-
Constructor Detail
-
PersistRequestBean
public PersistRequestBean(SpiEbeanServer server, T bean, Object parentBean, BeanManager<T> mgr, SpiTransaction t, PersistExecute persistExecute, PersistRequest.Type type, int flags)
-
-
Method Detail
-
initForSoftDelete
public void initForSoftDelete()
Init generated properties for soft delete (as it's an update).
-
addTimingBatch
public void addTimingBatch(long startNanos, int batch)
Description copied from interface:BatchPostExecute
Add timing metrics for batch persist.- Specified by:
addTimingBatch
in interfaceBatchPostExecute
- Overrides:
addTimingBatch
in classPersistRequest
-
addTimingNoBatch
public void addTimingNoBatch(long startNanos)
- Overrides:
addTimingNoBatch
in classPersistRequest
-
profile
public void profile(long offset, int flushCount)
Add to profile as batched bean insert, update or delete.- Specified by:
profile
in interfaceBatchPostExecute
-
setTrans
public void setTrans(SpiTransaction transaction)
Set the transaction from prior persist request. Only used when hard deleting draft & associated live beans.
-
initTransIfRequiredWithBatchCascade
public void initTransIfRequiredWithBatchCascade()
Init the transaction and also check for batch on cascade escalation.
-
checkBatchEscalationOnCascade
public void checkBatchEscalationOnCascade()
Check for batch escalation on cascade.
-
flushBatchOnCascade
public void flushBatchOnCascade()
If using batch on cascade flush if required.
-
rollbackTransIfRequired
public void rollbackTransIfRequired()
Description copied from class:BeanRequest
Rollback the transaction if it was created for this request.- Overrides:
rollbackTransIfRequired
in classBeanRequest
-
isBatched
public boolean isBatched()
Return true is this request was added to the JDBC batch.
-
setBatched
public void setBatched()
Set when request is added to the JDBC batch.
-
preGetterTrigger
public void preGetterTrigger(int propertyIndex)
Description copied from interface:PreGetterCallback
Trigger the callback based on a getter on a property.- Specified by:
preGetterTrigger
in interfacePreGetterCallback
- Parameters:
propertyIndex
- The index of the property
-
setSkipBatchForTopLevel
public void setSkipBatchForTopLevel()
-
isBatchThisRequest
public boolean isBatchThisRequest()
Description copied from class:PersistRequest
Return true if this persist request should use JDBC batch.- Overrides:
isBatchThisRequest
in classPersistRequest
-
isInsert
public boolean isInsert()
Return true if this is an insert request.
-
getLoadedProperties
public Set<String> getLoadedProperties()
Description copied from interface:BeanPersistRequest
For an update or delete of a partially populated bean this is the set of loaded properties and otherwise returns null.- Specified by:
getLoadedProperties
in interfaceBeanPersistRequest<T>
-
getUpdatedProperties
public Set<String> getUpdatedProperties()
Description copied from interface:BeanPersistRequest
For an update this is the set of properties that where updated.Note that hasDirtyProperty() is a more efficient check than this method and should be preferred if it satisfies the requirement.
- Specified by:
getUpdatedProperties
in interfaceBeanPersistRequest<T>
-
getDirtyProperties
public boolean[] getDirtyProperties()
Return the dirty properties on this request.- Specified by:
getDirtyProperties
in interfaceBeanPersistRequest<T>
-
hasDirtyProperty
public boolean hasDirtyProperty(Set<String> propertyNames)
Return true if any of the given property names are dirty.- Specified by:
hasDirtyProperty
in interfaceBeanPersistRequest<T>
- Parameters:
propertyNames
- a set of property names which we are checking to see if at least one of them is dirty.
-
hasDirtyProperty
public boolean hasDirtyProperty(int[] propertyPositions)
Return true if any of the given properties are dirty.
-
getUpdatedValues
public Map<String,ValuePair> getUpdatedValues()
Description copied from interface:BeanPersistRequest
Returns a map of the properties that have changed and their new and old values.- Specified by:
getUpdatedValues
in interfaceBeanPersistRequest<T>
-
docStoreUpdate
public void docStoreUpdate(DocStoreUpdateContext txn) throws IOException
Process the persist request updating the document store.- Specified by:
docStoreUpdate
in interfaceDocStoreUpdate
- Throws:
IOException
-
addToQueue
public void addToQueue(DocStoreUpdates docStoreUpdates)
Add this event to the queue entries in IndexUpdates.- Specified by:
addToQueue
in interfaceDocStoreUpdate
-
addToPersistMap
public void addToPersistMap(BeanPersistIdMap beanPersistMap)
-
notifyLocalPersistListener
public void notifyLocalPersistListener()
-
isRegisteredBean
public boolean isRegisteredBean()
Return true if this bean has been already been persisted (inserted or updated) in this transaction.
-
unRegisterBean
public void unRegisterBean()
-
registerDeleteBean
public void registerDeleteBean()
-
isRegisteredForDeleteBean
public boolean isRegisteredForDeleteBean()
-
getBeanDescriptor
public BeanDescriptor<T> getBeanDescriptor()
Return the BeanDescriptor for the associated bean.
-
isDirty
public boolean isDirty()
Used to skip updates if we know the bean is not dirty. This is the case for EntityBeans that have not been modified.
-
getConcurrencyMode
public ConcurrencyMode getConcurrencyMode()
Return the concurrency mode used for this persist.
-
getFullName
public String getFullName()
Returns a description of the request. This is typically the bean class name or the base table for MapBeans.Used to determine common persist requests for queueing and statement batching.
-
getBean
public T getBean()
Return the bean associated with this request.- Specified by:
getBean
in interfaceBeanPersistRequest<T>
-
getEntityBean
public EntityBean getEntityBean()
-
createReference
public T createReference()
Create and return a new reference bean matching this beans Id value.
-
isDraftable
public boolean isDraftable()
Return true if the bean type is a Draftable.
-
isHardDeleteDraft
public boolean isHardDeleteDraft()
Return true if this request is a hard delete of a draftable bean. If this is true Ebean is expected to auto-publish and delete the associated live bean.
-
isHardDeleteCascade
public boolean isHardDeleteCascade()
Return true if this was a hard/permanent delete request (and should cascade as such).
-
checkDraft
public void checkDraft()
Checks for @Draftable entity beans with @Draft property that the bean is a 'draft'. Save or Update is not allowed to execute using 'live' beans - must use publish().
-
getParentBean
public Object getParentBean()
Return the parent bean for cascading save with unidirectional relationship.
-
getEntityBeanIntercept
public EntityBeanIntercept getEntityBeanIntercept()
Return the intercept if there is one.
-
isLoadedProperty
public boolean isLoadedProperty(BeanProperty prop)
Return true if this property is loaded (full bean or included in partial bean).
-
isDirtyProperty
public boolean isDirtyProperty(BeanProperty prop)
Return true if the property is dirty.
-
getOrigValue
public Object getOrigValue(BeanProperty prop)
Return the original / old value for the given property.
-
executeNow
public int executeNow()
Description copied from class:PersistRequest
Execute the request right now.- Specified by:
executeNow
in classPersistRequest
-
executeOrQueue
public int executeOrQueue()
Description copied from class:PersistRequest
Execute a the request or queue/batch it for later execution.- Specified by:
executeOrQueue
in classPersistRequest
-
setGeneratedKey
public void setGeneratedKey(Object idValue)
Set the generated key back to the bean. Only used for inserts with getGeneratedKeys.- Specified by:
setGeneratedKey
in interfaceBatchPostExecute
-
setBoundId
public void setBoundId(Object idValue)
Set the Id value that was bound. Used for the purposes of logging summary information on this request.
-
checkRowCount
public final void checkRowCount(int rowCount)
Check for optimistic concurrency exception.- Specified by:
checkRowCount
in interfaceBatchPostExecute
-
postExecute
public void postExecute()
Post processing.- Specified by:
postExecute
in interfaceBatchPostExecute
-
preElementCollectionUpdate
public void preElementCollectionUpdate()
Ensure the preUpdate event fires (for case where only element collection has changed).
-
isNotifyCache
public boolean isNotifyCache()
-
isAddToUpdate
public boolean isAddToUpdate(BeanProperty prop)
Return true if the property should be included in the update.
-
deferredRelationship
public void deferredRelationship(EntityBean assocBean, ImportedId importedId, EntityBean bean)
Register the derived relationships to get executed later (on JDBC batch flush or commit).
-
isReference
public boolean isReference()
-
addUpdatedManyProperty
public void addUpdatedManyProperty(BeanPropertyAssocMany<?> updatedAssocMany)
This many property has been cascade saved. Keep note of this and update the 'many property' cache on post commit.
-
getUpdatedManyCollections
public List<BeanPropertyAssocMany<?>> getUpdatedManyCollections()
Return the list of cascade updated many properties (can be null).
-
complete
public void complete()
Completed insert or delete request. Do cache notify in non-batched case.
-
completeUpdate
public void completeUpdate()
Completed update request handling cases for element collection and where ONLY many properties were updated.
-
addDocStoreUpdates
public void addDocStoreUpdates(DocStoreUpdates docStoreUpdates)
For requests that update document store add this event to either the list of queue events or list of update events.
-
getFlags
public int getFlags()
Return the flags set on this persist request.
-
isPublish
public boolean isPublish()
Return true if this request is a 'publish' action.
-
getUpdatePlanHash
public String getUpdatePlanHash()
Return the key for an update persist request.
-
getUpdateTable
public String getUpdateTable()
Return the table to update depending if the request is a 'publish' one or normal.
-
deleteMode
public DeleteMode deleteMode()
Return the delete mode - Soft or Hard.
-
getVersion
public long getVersion()
Return the version in long form (if set).
-
docStorePersist
public void docStorePersist()
Persist to the document store now (via buffer, not post commit).
-
now
public long now()
Use a common 'now' value across both when created and when updated etc.
-
isStatelessUpdate
public boolean isStatelessUpdate()
Return true if this is a stateless update request (in which case it doesn't really have 'old values').
-
profile
public void profile()
Add to profile as single bean insert, update or delete (not batched).- Specified by:
profile
in interfaceSpiProfileTransactionEvent
-
flagInsert
public void flagInsert()
Set the request flags indicating this is an insert.
-
flagUpdate
public void flagUpdate()
Unset the request insert flag indicating this is an update.
-
isInsertedParent
public boolean isInsertedParent()
Return true if this request is an insert.
-
addCollectionChange
public void addCollectionChange(String name, Object value)
Add an element collection change to L2 bean cache update.
-
addBeanUpdate
public void addBeanUpdate(CacheChangeSet changeSet)
Build the bean update for the L2 cache.
-
setImportedOrphanForRemoval
public void setImportedOrphanForRemoval(BeanPropertyAssocOne<?> prop)
Set an orphan bean that needs to be deleted AFTER the request has persisted.
-
getImportedOrphanForRemoval
public EntityBean getImportedOrphanForRemoval()
-
getSelectLastInsertedId
public String getSelectLastInsertedId()
Return the SQL used to fetch the last inserted id value.
-
isQueueSaveMany
public boolean isQueueSaveMany()
Return true if the intersection table updates or element collection updates should be queued.
-
addSaveMany
public void addSaveMany(SaveMany saveManyRequest)
The intersection table updates or element collection to the batch executed later on postExecute.
-
isForcedUpdate
public boolean isForcedUpdate()
-
setSaveRecurse
public void setSaveRecurse()
Set when this request is from cascading persist.
-
-