Package io.ebean.bean
Class EntityBeanIntercept
- java.lang.Object
-
- io.ebean.bean.EntityBeanIntercept
-
- All Implemented Interfaces:
Serializable
public final class EntityBeanIntercept extends Object implements Serializable
This is the object added to every entity bean using byte code enhancement.This provides the mechanisms to support deferred fetching of reference beans and oldValues generation for concurrency checking.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description EntityBeanIntercept()EXPERIMENTAL - Constructor only for use by serialization frameworks.EntityBeanIntercept(Object ownerBean)Create a intercept with a given entity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDirtyPropertyNames(Set<String> props, String prefix)Recursively add dirty properties.voidaddDirtyPropertyValues(BeanDiffVisitor visitor)Recursively add dirty properties.voidaddDirtyPropertyValues(Map<String,ValuePair> dirtyValues, String prefix)Recursively add dirty properties.voidclearGetterCallback()Clear the getter callback.intfindProperty(String propertyName)Finds the index position of a given property.boolean[]getDirtyProperties()Return the array of flags indicating the dirty properties.StringBuildergetDirtyPropertyKey()Return a dirty property hash taking into account embedded beans.Set<String>getDirtyPropertyNames()Return the set of dirty properties.Map<String,ValuePair>getDirtyValues()Return a map of dirty properties with their new and old values.ObjectgetEmbeddedOwner()Return the owning bean for an embedded bean.intgetEmbeddedOwnerIndex()Return the property index (for the parent) of this embedded bean.StringgetLazyLoadProperty()Return the property that triggered the lazy load.intgetLazyLoadPropertyIndex()Return the index of the property that triggered the lazy load.boolean[]getLoaded()StringBuildergetLoadedPropertyKey()Return a loaded property hash.Set<String>getLoadedPropertyNames()Return the set of property names for a partially loaded bean.Map<String,Exception>getLoadErrors()Returns the loadErrors.ObjectgetOrigValue(int propertyIndex)Return the original value that was changed via an update.EntityBeangetOwner()Return the 'owning' entity bean.ObjectgetOwnerId()Return the ownerId (IdClass).PersistenceContextgetPersistenceContext()Return the persistenceContext.StringgetProperty(int propertyIndex)Return the property name for the given property.intgetPropertyLength()Return the number of properties.intgetSortOrder()Return the sort order value for an order column.booleanhasDirtyProperty(Set<String> propertyNames)Return true if any of the given property names are dirty.booleanhasIdOnly(int idIndex)Return true if only the Id property has been loaded.voidinitialisedMany(int propertyIndex)Called when a BeanCollection is initialised automatically.booleanisChangedProperty(int propertyIndex)Return true if the property is considered changed.booleanisDirty()Return true if this bean has been directly modified (it has oldValues) or if any embedded beans are either new or dirty (and hence need saving).booleanisDirtyProperty(int propertyIndex)Return true if the property was changed or if it is embedded and one of its embedded properties is dirty.booleanisDisableLazyLoad()Return true if lazy loading is disabled.booleanisEmbeddedNewOrDirty(Object embeddedBean)Return true if the embedded bean is new or dirty and hence needs saving.booleanisFullyLoadedBean()booleanisLazyLoadFailure()Return true if the bean is marked as having failed lazy loading.booleanisLoaded()Return true if the entity has been loaded.booleanisLoadedFromCache()Return true if this bean was loaded from L2 bean cache.booleanisLoadedProperty(int propertyIndex)Return true if the property is loaded.booleanisNew()Return true if this entity bean is new and not yet saved.booleanisNewOrDirty()Return true if the entity bean is new or dirty (and should be saved).booleanisOrphanDelete()booleanisPartial()Check each property to see if the bean is partially loaded.booleanisReadOnly()Return true if the bean should be treated as readOnly.booleanisReference()Return true if the entity is a reference.booleanisUpdate()Return true if the entity should be updated.voidmarkPropertyAsChanged(int propertyIndex)Explicitly mark a property as having been changed.voidpreGetId()Called prior to Id property getter.voidpreGetter(int propertyIndex)Method that is called prior to a getter method on the actual entity.voidpreSetter(boolean intercept, int propertyIndex, boolean oldValue, boolean newValue)Check for primitive boolean.voidpreSetter(boolean intercept, int propertyIndex, byte[] oldValue, byte[] newValue)byte[].voidpreSetter(boolean intercept, int propertyIndex, byte oldValue, byte newValue)byte.voidpreSetter(boolean intercept, int propertyIndex, char[] oldValue, char[] newValue)char[].voidpreSetter(boolean intercept, int propertyIndex, char oldValue, char newValue)char.voidpreSetter(boolean intercept, int propertyIndex, double oldValue, double newValue)double.voidpreSetter(boolean intercept, int propertyIndex, float oldValue, float newValue)float.voidpreSetter(boolean intercept, int propertyIndex, int oldValue, int newValue)Check for primitive int.voidpreSetter(boolean intercept, int propertyIndex, long oldValue, long newValue)long.voidpreSetter(boolean intercept, int propertyIndex, short oldValue, short newValue)short.voidpreSetter(boolean intercept, int propertyIndex, Object oldValue, Object newValue)Check to see if the values are not equal.voidpreSetterMany(boolean interceptField, int propertyIndex, Object oldValue, Object newValue)OneToMany and ManyToMany only set loaded state.voidregisterGetterCallback(PreGetterCallback getterCallback)Register the callback to be triggered when getter is called.voidsetBeanLoader(BeanLoader beanLoader)Set the BeanLoader.voidsetBeanLoader(BeanLoader beanLoader, PersistenceContext ctx)Set the BeanLoader with PersistenceContext.voidsetChangedProperty(int propertyIndex)voidsetDeletedFromCollection(boolean deletedFromCollection)Set if the entity was deleted from a BeanCollection.voidsetDirty(boolean dirty)voidsetDisableLazyLoad(boolean disableLazyLoad)Set true to turn off lazy loading.voidsetEmbeddedDirty(int embeddedProperty)Called by an embedded bean onto its owner.voidsetEmbeddedLoaded(Object embeddedBean)Set the loaded status for the embedded bean.voidsetEmbeddedOwner(EntityBean parentBean, int embeddedOwnerIndex)Set the embedded beans owning bean.voidsetForceUpdate(boolean forceUpdate)Set the bean to be updated when persisted (for merge).voidsetFullyLoadedBean(boolean fullyLoadedBean)voidsetLazyLoadFailure(Object ownerId)Set lazy load failure flag.voidsetLoaded()Set the loaded state to true.voidsetLoadedFromCache(boolean loadedFromCache)Set true when the bean has been loaded from L2 bean cache.voidsetLoadedLazy()When finished loading for lazy or refresh on an already partially populated bean.voidsetLoadedProperty(int propertyIndex)Set the property to be loaded.voidsetLoadedPropertyAll()Set all properties to be loaded (post insert).voidsetLoadError(int propertyIndex, Exception t)Set the load error that happened on this property.voidsetNew()Set the bean into NEW state.voidsetNewBeanForUpdate()For forced update on a 'New' bean set all the loaded properties to changed.voidsetNodeUsageCollector(NodeUsageCollector usageCollector)Turn on profile collection.voidsetOldValue(int propertyIndex, Object oldValue)Explicitly set an old value with force (the old value is forced even it is already set).voidsetOwnerId(Object ownerId)Set the ownerId (IdClass).voidsetPersistenceContext(PersistenceContext persistenceContext)Set the persistenceContext.voidsetPropertyLoaded(String propertyName, boolean loaded)Set the loaded state of the property given it's name.voidsetPropertyUnloaded(int propertyIndex)Set the property to be treated as unloaded.voidsetReadOnly(boolean readOnly)Set the readOnly status.voidsetReference(int idPos)Set this as a reference object.voidsetSortOrder(int sortOrder)Set the sort order value for an order column.
-
-
-
Constructor Detail
-
EntityBeanIntercept
public EntityBeanIntercept(Object ownerBean)
Create a intercept with a given entity.
-
EntityBeanIntercept
public EntityBeanIntercept()
EXPERIMENTAL - Constructor only for use by serialization frameworks.
-
-
Method Detail
-
getOwner
public EntityBean getOwner()
Return the 'owning' entity bean.
-
getPersistenceContext
public PersistenceContext getPersistenceContext()
Return the persistenceContext.
-
setPersistenceContext
public void setPersistenceContext(PersistenceContext persistenceContext)
Set the persistenceContext.
-
setNodeUsageCollector
public void setNodeUsageCollector(NodeUsageCollector usageCollector)
Turn on profile collection.
-
getOwnerId
public Object getOwnerId()
Return the ownerId (IdClass).
-
setOwnerId
public void setOwnerId(Object ownerId)
Set the ownerId (IdClass).
-
getEmbeddedOwner
public Object getEmbeddedOwner()
Return the owning bean for an embedded bean.
-
getEmbeddedOwnerIndex
public int getEmbeddedOwnerIndex()
Return the property index (for the parent) of this embedded bean.
-
clearGetterCallback
public void clearGetterCallback()
Clear the getter callback.
-
registerGetterCallback
public void registerGetterCallback(PreGetterCallback getterCallback)
Register the callback to be triggered when getter is called. This is used primarily to automatically flush the JDBC batch.
-
setEmbeddedOwner
public void setEmbeddedOwner(EntityBean parentBean, int embeddedOwnerIndex)
Set the embedded beans owning bean.
-
setBeanLoader
public void setBeanLoader(BeanLoader beanLoader, PersistenceContext ctx)
Set the BeanLoader with PersistenceContext.
-
setBeanLoader
public void setBeanLoader(BeanLoader beanLoader)
Set the BeanLoader.
-
isFullyLoadedBean
public boolean isFullyLoadedBean()
-
setFullyLoadedBean
public void setFullyLoadedBean(boolean fullyLoadedBean)
-
isPartial
public boolean isPartial()
Check each property to see if the bean is partially loaded.
-
isDirty
public boolean isDirty()
Return true if this bean has been directly modified (it has oldValues) or if any embedded beans are either new or dirty (and hence need saving).
-
setEmbeddedDirty
public void setEmbeddedDirty(int embeddedProperty)
Called by an embedded bean onto its owner.
-
setDirty
public void setDirty(boolean dirty)
-
isNew
public boolean isNew()
Return true if this entity bean is new and not yet saved.
-
isNewOrDirty
public boolean isNewOrDirty()
Return true if the entity bean is new or dirty (and should be saved).
-
hasIdOnly
public boolean hasIdOnly(int idIndex)
Return true if only the Id property has been loaded.
-
isReference
public boolean isReference()
Return true if the entity is a reference.
-
setReference
public void setReference(int idPos)
Set this as a reference object.
-
setLoadedFromCache
public void setLoadedFromCache(boolean loadedFromCache)
Set true when the bean has been loaded from L2 bean cache. The effect of this is that we should skip the cache if there is subsequent lazy loading (bean cache partially populated).
-
isLoadedFromCache
public boolean isLoadedFromCache()
Return true if this bean was loaded from L2 bean cache.
-
isReadOnly
public boolean isReadOnly()
Return true if the bean should be treated as readOnly. If a setter method is called when it is readOnly an Exception is thrown.
-
setReadOnly
public void setReadOnly(boolean readOnly)
Set the readOnly status. If readOnly then calls to setter methods through an exception.
-
setForceUpdate
public void setForceUpdate(boolean forceUpdate)
Set the bean to be updated when persisted (for merge).
-
isUpdate
public boolean isUpdate()
Return true if the entity should be updated.
-
isLoaded
public boolean isLoaded()
Return true if the entity has been loaded.
-
setNew
public void setNew()
Set the bean into NEW state.
-
setLoaded
public void setLoaded()
Set the loaded state to true.Calls to setter methods after the bean is loaded can result in 'Old Values' being created.
Worth noting that this is also set after a insert/update. By doing so it 'resets' the bean for making further changes and saving again.
-
setLoadedLazy
public void setLoadedLazy()
When finished loading for lazy or refresh on an already partially populated bean.
-
setLazyLoadFailure
public void setLazyLoadFailure(Object ownerId)
Set lazy load failure flag.
-
isLazyLoadFailure
public boolean isLazyLoadFailure()
Return true if the bean is marked as having failed lazy loading.
-
isDisableLazyLoad
public boolean isDisableLazyLoad()
Return true if lazy loading is disabled.
-
setDisableLazyLoad
public void setDisableLazyLoad(boolean disableLazyLoad)
Set true to turn off lazy loading.
-
setEmbeddedLoaded
public void setEmbeddedLoaded(Object embeddedBean)
Set the loaded status for the embedded bean.
-
isEmbeddedNewOrDirty
public boolean isEmbeddedNewOrDirty(Object embeddedBean)
Return true if the embedded bean is new or dirty and hence needs saving.
-
getOrigValue
public Object getOrigValue(int propertyIndex)
Return the original value that was changed via an update.
-
findProperty
public int findProperty(String propertyName)
Finds the index position of a given property. Returns -1 if the property can not be found.
-
getProperty
public String getProperty(int propertyIndex)
Return the property name for the given property.
-
getPropertyLength
public int getPropertyLength()
Return the number of properties.
-
setPropertyLoaded
public void setPropertyLoaded(String propertyName, boolean loaded)
Set the loaded state of the property given it's name.
-
setPropertyUnloaded
public void setPropertyUnloaded(int propertyIndex)
Set the property to be treated as unloaded. Used for properties initialised in default constructor.
-
setLoadedProperty
public void setLoadedProperty(int propertyIndex)
Set the property to be loaded.
-
setLoadedPropertyAll
public void setLoadedPropertyAll()
Set all properties to be loaded (post insert).
-
isLoadedProperty
public boolean isLoadedProperty(int propertyIndex)
Return true if the property is loaded.
-
isChangedProperty
public boolean isChangedProperty(int propertyIndex)
Return true if the property is considered changed.
-
isDirtyProperty
public boolean isDirtyProperty(int propertyIndex)
Return true if the property was changed or if it is embedded and one of its embedded properties is dirty.
-
markPropertyAsChanged
public void markPropertyAsChanged(int propertyIndex)
Explicitly mark a property as having been changed.
-
setChangedProperty
public void setChangedProperty(int propertyIndex)
-
setNewBeanForUpdate
public void setNewBeanForUpdate()
For forced update on a 'New' bean set all the loaded properties to changed.
-
getLoadedPropertyNames
public Set<String> getLoadedPropertyNames()
Return the set of property names for a partially loaded bean.
-
getDirtyProperties
public boolean[] getDirtyProperties()
Return the array of flags indicating the dirty properties.
-
getDirtyPropertyNames
public Set<String> getDirtyPropertyNames()
Return the set of dirty properties.
-
addDirtyPropertyNames
public void addDirtyPropertyNames(Set<String> props, String prefix)
Recursively add dirty properties.
-
hasDirtyProperty
public boolean hasDirtyProperty(Set<String> propertyNames)
Return true if any of the given property names are dirty.
-
getDirtyValues
public Map<String,ValuePair> getDirtyValues()
Return a map of dirty properties with their new and old values.
-
addDirtyPropertyValues
public void addDirtyPropertyValues(Map<String,ValuePair> dirtyValues, String prefix)
Recursively add dirty properties.
-
addDirtyPropertyValues
public void addDirtyPropertyValues(BeanDiffVisitor visitor)
Recursively add dirty properties.
-
getDirtyPropertyKey
public StringBuilder getDirtyPropertyKey()
Return a dirty property hash taking into account embedded beans.
-
getLoadedPropertyKey
public StringBuilder getLoadedPropertyKey()
Return a loaded property hash.
-
getLoaded
public boolean[] getLoaded()
-
getLazyLoadPropertyIndex
public int getLazyLoadPropertyIndex()
Return the index of the property that triggered the lazy load.
-
getLazyLoadProperty
public String getLazyLoadProperty()
Return the property that triggered the lazy load.
-
initialisedMany
public void initialisedMany(int propertyIndex)
Called when a BeanCollection is initialised automatically.
-
preGetId
public void preGetId()
Called prior to Id property getter.
-
preGetter
public void preGetter(int propertyIndex)
Method that is called prior to a getter method on the actual entity.
-
preSetterMany
public void preSetterMany(boolean interceptField, int propertyIndex, Object oldValue, Object newValue)
OneToMany and ManyToMany only set loaded state.
-
preSetter
public void preSetter(boolean intercept, int propertyIndex, Object oldValue, Object newValue)
Check to see if the values are not equal. If they are not equal then create the old values for use with ConcurrencyMode.ALL.
-
preSetter
public void preSetter(boolean intercept, int propertyIndex, boolean oldValue, boolean newValue)
Check for primitive boolean.
-
preSetter
public void preSetter(boolean intercept, int propertyIndex, int oldValue, int newValue)
Check for primitive int.
-
preSetter
public void preSetter(boolean intercept, int propertyIndex, long oldValue, long newValue)
long.
-
preSetter
public void preSetter(boolean intercept, int propertyIndex, double oldValue, double newValue)
double.
-
preSetter
public void preSetter(boolean intercept, int propertyIndex, float oldValue, float newValue)
float.
-
preSetter
public void preSetter(boolean intercept, int propertyIndex, short oldValue, short newValue)
short.
-
preSetter
public void preSetter(boolean intercept, int propertyIndex, char oldValue, char newValue)
char.
-
preSetter
public void preSetter(boolean intercept, int propertyIndex, byte oldValue, byte newValue)
byte.
-
preSetter
public void preSetter(boolean intercept, int propertyIndex, char[] oldValue, char[] newValue)
char[].
-
preSetter
public void preSetter(boolean intercept, int propertyIndex, byte[] oldValue, byte[] newValue)
byte[].
-
setOldValue
public void setOldValue(int propertyIndex, Object oldValue)
Explicitly set an old value with force (the old value is forced even it is already set).
-
getSortOrder
public int getSortOrder()
Return the sort order value for an order column.
-
setSortOrder
public void setSortOrder(int sortOrder)
Set the sort order value for an order column.
-
setDeletedFromCollection
public void setDeletedFromCollection(boolean deletedFromCollection)
Set if the entity was deleted from a BeanCollection.
-
isOrphanDelete
public boolean isOrphanDelete()
-
setLoadError
public void setLoadError(int propertyIndex, Exception t)
Set the load error that happened on this property.
-
getLoadErrors
public Map<String,Exception> getLoadErrors()
Returns the loadErrors.
-
-