com.avaje.ebean.bean
Class EntityBeanIntercept

java.lang.Object
  extended by com.avaje.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

Field Summary
static int DEFAULT
          The default state (CacheStrategy readOnly can be applied).
static int READONLY
          Bean is READ ONLY (not editable).
static int SHARED
          Read Only immutable state and can't be made editable (when in cache and sharable).
static int UPDATE
          Editable (used when the default results in a Read Only bean).
 
Constructor Summary
EntityBeanIntercept(Object owner)
          Create a intercept with a given entity.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add a property change listener for this entity bean.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Add a property change listener for this entity bean for a specific property.
 void copyStateTo(EntityBeanIntercept dest)
          Copy the internal state of the intercept to another intercept.
 int getBeanLoaderIndex()
          Return the index position for batch loading via BeanLoader.
 Set<String> getChangedProps()
          Return the set of property names for changed properties.
 String getLazyLoadProperty()
          Return the property read or write that triggered the lazy load.
 Set<String> getLoadedProps()
          Return the set of property names for a partially loaded bean.
 Object getOldValues()
          Return the old values used for ConcurrencyMode.ALL.
 EntityBean getOwner()
          Return the 'owning' entity bean.
 Object getParentBean()
          Return the parent bean (by relationship).
 PersistenceContext getPersistenceContext()
          Return the persistenceContext.
 int getState()
          Return the state of the bean (DEFAULT,UPDATE,READONLY,SHARED).
 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).
 boolean isDisableLazyLoad()
          Return true if lazy loading is disabled.
 boolean isEmbeddedNewOrDirty(Object embeddedBean)
          Return true if the embedded bean is new or dirty and hence needs saving.
 boolean isIntercepting()
          Return true if the bean currently has interception on.
 boolean isLoaded()
          Return true if the entity has been loaded.
 boolean isNew()
          Return true if this entity bean is new and not yet saved.
 boolean isNewOrDirty()
          Return true if the entity bean is new or dirty (and should be saved).
 boolean isReadOnly()
          Return true if the bean should be treated as readOnly.
 boolean isReference()
          Return true if the entity is a reference.
 boolean isSharedInstance()
          Return true if this is a shared instance.
 boolean isUseCache()
          Return true if this bean should use the cache when lazy loading.
 void postSetter(PropertyChangeEvent event)
          Called for "enhancement" postSetter processing.
 void postSetter(PropertyChangeEvent event, Object newValue)
          Called for "subclassed" postSetter processing.
 void preGetter(String propertyName)
          Method that is called prior to a getter method on the actual entity.
 PropertyChangeEvent preSetter(boolean intercept, String propertyName, boolean oldValue, boolean newValue)
          Check for primitive boolean.
 PropertyChangeEvent preSetter(boolean intercept, String propertyName, byte[] oldValue, byte[] newValue)
          byte[].
 PropertyChangeEvent preSetter(boolean intercept, String propertyName, byte oldValue, byte newValue)
          char.
 PropertyChangeEvent preSetter(boolean intercept, String propertyName, char[] oldValue, char[] newValue)
          char[].
 PropertyChangeEvent preSetter(boolean intercept, String propertyName, char oldValue, char newValue)
          char.
 PropertyChangeEvent preSetter(boolean intercept, String propertyName, double oldValue, double newValue)
          double.
 PropertyChangeEvent preSetter(boolean intercept, String propertyName, float oldValue, float newValue)
          float.
 PropertyChangeEvent preSetter(boolean intercept, String propertyName, int oldValue, int newValue)
          Check for primitive int.
 PropertyChangeEvent preSetter(boolean intercept, String propertyName, long oldValue, long newValue)
          long.
 PropertyChangeEvent preSetter(boolean intercept, String propertyName, Object oldValue, Object newValue)
          Check to see if the values are not equal.
 PropertyChangeEvent preSetter(boolean intercept, String propertyName, short oldValue, short newValue)
          short.
 PropertyChangeEvent preSetterMany(boolean interceptField, String propertyName, Object oldValue, Object newValue)
          OneToMany and ManyToMany don't have any interception so just check for PropertyChangeSupport.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a property change listener for this entity bean.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Remove a property change listener for this entity bean for a specific property.
 void setBeanLoader(int index, BeanLoader ctx)
           
 void setDisableLazyLoad(boolean disableLazyLoad)
          Set true to turn off lazy loading.
 void setEmbeddedLoaded(Object embeddedBean)
          Set the loaded status for the embedded bean.
 void setIntercepting(boolean intercepting)
          Turn interception off or on.
 void setLoaded()
          Set the loaded state to true.
 void setLoadedLazy()
          When finished loading for lazy or refresh on an already partially populated bean.
 void setLoadedProps(Set<String> loadedPropertyNames)
          Set the property names for a partially loaded bean.
 void setNodeUsageCollector(NodeUsageCollector usageCollector)
          Turn on profile collection.
 void setParentBean(Object parentBean)
          Special case for a OneToOne, Set the parent bean (by relationship).
 void setPersistenceContext(PersistenceContext persistenceContext)
          Set the persistenceContext.
 void setReadOnly(boolean readOnly)
          Set the readOnly status.
 void setReference()
          Set this as a reference object.
 void setSharedInstance()
          Set this called when it is known this is a shared instance.
 void setState(int parentState)
          Set the state of the bean (DEFAULT,UPDATE,READONLY,SHARED).
 void setUseCache(boolean loadFromCache)
          Set to true if this bean should use the cache when lazy loading.
 String toString()
           
 Object writeReplaceIntercept()
          This is ONLY used for subclass entity beans.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT

public static final int DEFAULT
The default state (CacheStrategy readOnly can be applied).

See Also:
Constant Field Values

UPDATE

public static final int UPDATE
Editable (used when the default results in a Read Only bean).

See Also:
Constant Field Values

READONLY

public static final int READONLY
Bean is READ ONLY (not editable).

See Also:
Constant Field Values

SHARED

public static final int SHARED
Read Only immutable state and can't be made editable (when in cache and sharable).

See Also:
Constant Field Values
Constructor Detail

EntityBeanIntercept

public EntityBeanIntercept(Object owner)
Create a intercept with a given entity.

Refer to agent ProxyConstructor.

Method Detail

setState

public void setState(int parentState)
Set the state of the bean (DEFAULT,UPDATE,READONLY,SHARED).

Note that UPDATE is really only to force readOnly = false when the default cache setting has readOnly = true.


getState

public int getState()
Return the state of the bean (DEFAULT,UPDATE,READONLY,SHARED).


copyStateTo

public void copyStateTo(EntityBeanIntercept dest)
Copy the internal state of the intercept to another intercept.


getOwner

public EntityBean getOwner()
Return the 'owning' entity bean.


toString

public String toString()
Overrides:
toString in class Object

getPersistenceContext

public PersistenceContext getPersistenceContext()
Return the persistenceContext.


setPersistenceContext

public void setPersistenceContext(PersistenceContext persistenceContext)
Set the persistenceContext.


addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Add a property change listener for this entity bean.


addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Add a property change listener for this entity bean for a specific property.


removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener for this entity bean.


removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Remove a property change listener for this entity bean for a specific property.


setNodeUsageCollector

public void setNodeUsageCollector(NodeUsageCollector usageCollector)
Turn on profile collection.


getParentBean

public Object getParentBean()
Return the parent bean (by relationship).


setParentBean

public void setParentBean(Object parentBean)
Special case for a OneToOne, Set the parent bean (by relationship). This is the owner of a 1-1.


getBeanLoaderIndex

public int getBeanLoaderIndex()
Return the index position for batch loading via BeanLoader.


setBeanLoader

public void setBeanLoader(int index,
                          BeanLoader ctx)

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).


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).


isReference

public boolean isReference()
Return true if the entity is a reference.


setReference

public void setReference()
Set this as a reference object.


getOldValues

public Object getOldValues()
Return the old values used for ConcurrencyMode.ALL.


isUseCache

public boolean isUseCache()
Return true if this bean should use the cache when lazy loading.


setUseCache

public void setUseCache(boolean loadFromCache)
Set to true if this bean should use the cache when lazy loading.


isSharedInstance

public boolean isSharedInstance()
Return true if this is a shared instance. Typically this means this instance exists in the server cache and other users/threads could also be using the same instance concurrently.

A shared instance must always be treated as read only.


setSharedInstance

public void setSharedInstance()
Set this called when it is known this is a shared instance. This is when this instance is put into the server 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.


isIntercepting

public boolean isIntercepting()
Return true if the bean currently has interception on.

With interception on the bean will invoke lazy loading and dirty checking.


setIntercepting

public void setIntercepting(boolean intercepting)
Turn interception off or on.

This is to support custom serialisation mechanisms that just read all the properties on the bean.


isLoaded

public boolean isLoaded()
Return true if the entity has been loaded.


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 to support ConcurrencyMode.ALL

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.


isDisableLazyLoad

public boolean isDisableLazyLoad()
Return true if lazy loading is disabled.


setDisableLazyLoad

public void setDisableLazyLoad(boolean disableLazyLoad)
Set true to turn off lazy loading.

Typically used to disable lazy loading on SQL based report beans.


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.


setLoadedProps

public void setLoadedProps(Set<String> loadedPropertyNames)
Set the property names for a partially loaded bean.

Parameters:
loadedPropertyNames - the names of the loaded properties

getLoadedProps

public Set<String> getLoadedProps()
Return the set of property names for a partially loaded bean.


getChangedProps

public Set<String> getChangedProps()
Return the set of property names for changed properties.


getLazyLoadProperty

public String getLazyLoadProperty()
Return the property read or write that triggered the lazy load.


writeReplaceIntercept

public Object writeReplaceIntercept()
                             throws ObjectStreamException
This is ONLY used for subclass entity beans.

This is not used when entity bean classes are enhanced via javaagent or ant etc - only when a subclass is generated.

Returns a Serializable instance that is either the 'byte code generated' object or a 'Vanilla' copy of this bean depending on SerializeControl.isVanillaBeans().

Throws:
ObjectStreamException

preGetter

public void preGetter(String propertyName)
Method that is called prior to a getter method on the actual entity.

This checks if the bean is a reference and should be loaded.


postSetter

public void postSetter(PropertyChangeEvent event)
Called for "enhancement" postSetter processing. This is around a PUTFIELD so no need to check the newValue afterwards.


postSetter

public void postSetter(PropertyChangeEvent event,
                       Object newValue)
Called for "subclassed" postSetter processing. Here the newValue has to be re-fetched (and passed into this method) in case there is code inside the setter that further mutates the value.


preSetterMany

public PropertyChangeEvent preSetterMany(boolean interceptField,
                                         String propertyName,
                                         Object oldValue,
                                         Object newValue)
OneToMany and ManyToMany don't have any interception so just check for PropertyChangeSupport.


preSetter

public PropertyChangeEvent preSetter(boolean intercept,
                                     String propertyName,
                                     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 PropertyChangeEvent preSetter(boolean intercept,
                                     String propertyName,
                                     boolean oldValue,
                                     boolean newValue)
Check for primitive boolean.


preSetter

public PropertyChangeEvent preSetter(boolean intercept,
                                     String propertyName,
                                     int oldValue,
                                     int newValue)
Check for primitive int.


preSetter

public PropertyChangeEvent preSetter(boolean intercept,
                                     String propertyName,
                                     long oldValue,
                                     long newValue)
long.


preSetter

public PropertyChangeEvent preSetter(boolean intercept,
                                     String propertyName,
                                     double oldValue,
                                     double newValue)
double.


preSetter

public PropertyChangeEvent preSetter(boolean intercept,
                                     String propertyName,
                                     float oldValue,
                                     float newValue)
float.


preSetter

public PropertyChangeEvent preSetter(boolean intercept,
                                     String propertyName,
                                     short oldValue,
                                     short newValue)
short.


preSetter

public PropertyChangeEvent preSetter(boolean intercept,
                                     String propertyName,
                                     char oldValue,
                                     char newValue)
char.


preSetter

public PropertyChangeEvent preSetter(boolean intercept,
                                     String propertyName,
                                     byte oldValue,
                                     byte newValue)
char.


preSetter

public PropertyChangeEvent preSetter(boolean intercept,
                                     String propertyName,
                                     char[] oldValue,
                                     char[] newValue)
char[].


preSetter

public PropertyChangeEvent preSetter(boolean intercept,
                                     String propertyName,
                                     byte[] oldValue,
                                     byte[] newValue)
byte[].



Copyright © 2010. All Rights Reserved.