public interface RawEntity<T>
The superinterface for all entities, regardless of primary key. Developers
may choose to extend this interface rather than Entity
if they
need to specify a custom primary key field. As this interface is the most
generic superinterface in the entity hierarchy, it defines most of the
common entity methods, such as save()
and
addPropertyChangeListener(PropertyChangeListener)
.
This interface is parameterized for the sake of typechecking in the
EntityManager.find(Class, String, Object...)
method. The generic
type specified when inheriting this interface should be the same as the
return type of the primary key method. Unfortunately, this is unenforcable,
so it is left up to the developers to ensure the spec is followed.
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a property change listener to the entity.
|
EntityManager |
getEntityManager()
Retrieves the
EntityManager instance which manages this
entity. |
<X extends RawEntity<T>> |
getEntityType()
Returns the actual
Class instance which corresponds to the
original entity interface. |
void |
init()
Called when the entity instance is created.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a property change listener from the entity.
|
void |
save()
Saves all changed (dirty) fields within the entity to the database.
|
void init()
void save()
EntityManager getEntityManager()
EntityManager
instance which manages this
entity. This method can be used by defined implementations to
get the relevant EntityManager
instance in order
to run custom queries.<X extends RawEntity<T>> Class<X> getEntityType()
Returns the actual Class
instance which corresponds to the
original entity interface. This is necessary because calling Object.getClass()
on a proxy instance doesn't return the value one would expect. As
such, RawEntity
provides this method to give
developers access to the originating entity interface. Example:
public interface Person extends Entity { // ... } // ... Person p = manager.get(Person.class, 2); p.getEntityType(); // returns Person.class p.getClass(); // indeterminate return value, probably something like $Proxy26.class
Class
which defines the entity in question.void addPropertyChangeListener(PropertyChangeListener listener)
Adds a property change listener to the entity. This method is included
partly to emphasize compliance with the bean spec (sort of), but
more to enable developers to register listeners on the setters. This
method is called when the setter is called, not when save()
is invoked.
Be aware that the PropertyChangeEvent
may or
may not have a valid oldValue
. This is because
retrieving a previous value under many circumstances may result in an
extra database SELECT. If no oldValue
is available in
memory, null
will be passed.
Any trivial custom code which only needs to run on mutator invocation should use property change listeners, rather than a defined implementation.
listener
- The change listener to add.void removePropertyChangeListener(PropertyChangeListener listener)
listener
- The change listener to remove.addPropertyChangeListener(PropertyChangeListener)
Copyright © 2007–2022 Atlassian. All rights reserved.