public abstract class BasicItem extends Object implements Identifiable
Modifier and Type | Field and Description |
---|---|
private BasicData |
data
The data class from the net.sf.basedb.core.data layer that holds the
data for this item.
|
private WeakReference<DbControl> |
dc
A reference to the current DbControl object.
|
private boolean |
hasBeenCalledFromAnnotationBatcher |
private boolean |
hasBeenCalledFromGetAnnotationSet |
private int |
permissions
The logged in user's permission to this item.
|
Constructor and Description |
---|
BasicItem(BasicData data)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addAnnotatableParents(DbControl dc,
Set<Annotatable> parents,
AnnotatableData... items)
Try to load the the item-class representation of all the
data-class items ignoring permission problems.
|
protected void |
addUsingItems(Set<ItemProxy> using,
Item itemType,
Query query)
Add items to the set of items using this one.
|
protected void |
addUsingItems(Set<ItemProxy> using,
Query query)
Add items to the set of items using this one.
|
(package private) int |
breakCircularReferences(Set<ItemProxy> items)
Break references to items that may lead to circular references.
|
(package private) void |
checkBatchAnnotatableUsage(boolean annotationSet,
boolean batcher)
Annotatable items that are used with the
AnnotationBatcher
must not call Annotatable.getAnnotationSet() in the same
transaction. |
void |
checkPermission(Permission permission)
Checks if the logged in user has the specified permission on
this item.
|
boolean |
equals(Object o)
Check if this item is equal to another item.
|
(package private) BasicData |
getBasicData() |
(package private) abstract BasicData |
getData()
Get the
BasicData object that holds all data for this item. |
DbControl |
getDbControl()
Get the
DbControl object that currently manages this item. |
int |
getId()
Get the id for the item.
|
Set<Permission> |
getPermissions()
Get the logged in user's permissions on the item.
|
(package private) PluginPermission |
getPluginPermissions() |
SessionControl |
getSessionControl()
Get the
SessionControl object that manages this item. |
Set<ItemProxy> |
getUsingItems()
Get all items that are using this item.
|
int |
getVersion()
Get the version number of the item.
|
int |
hashCode()
The hash code is calculated at object construction and remains
the same during the objects lifetime.
|
boolean |
hasPermission(Permission permission)
Checks if the logged in user has the specified permission on
this item.
|
(package private) void |
initPermissions(int granted,
int denied)
Initialise the logged in user's permissions for this item.
|
boolean |
isDetached()
Check if this item is attached to a
DbControl object or not. |
boolean |
isInDatabase()
Checks if the item has been saved to the database or not.
|
boolean |
isUsed()
Check if this item is used by some other item.
|
(package private) void |
onAfterCommit(Transactional.Action action)
This method is called on each
Transactional object
after a successful commit to the database. |
(package private) void |
onAfterInsert()
This method is called on all items directly after Hibernate has inserted
it into the database.
|
(package private) void |
onBeforeCommit(Transactional.Action action)
This method is called on each
Transactional item and on
all items if the action is Transactional.Action.CREATE
or Transactional.Action.DELETE before a commit is issued to the database. |
(package private) void |
onRollback(Transactional.Action action)
This method is called on each
Transactional object
after an unsuccessful commit to the database. |
(package private) void |
setDbControl(DbControl dbControl)
Set the
DbControl object that should manage this item. |
(package private) void |
setProjectDefaults(Project activeProject)
This method is called before inserting new items into the database
to allow items to propagate default values from the active project.
|
String |
toString() |
(package private) void |
validate()
This method is called on each
Validatable item
before is saved to the database. |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getType
private final BasicData data
private WeakReference<DbControl> dc
private int permissions
initPermissions(int, int)
method.private boolean hasBeenCalledFromGetAnnotationSet
private boolean hasBeenCalledFromAnnotationBatcher
BasicItem(BasicData data)
DbControl.newItem(Class, Object[])
or
DbControl.getItem(Class, BasicData, Object[])
methods instead.public final boolean hasPermission(Permission permission)
Subclasses that needs to check other keys, such as the
SharedItem
should override the initPermissions(int,int)
method instead.
hasPermission
in interface AccessControlled
permission
- A value from the Permission
classTRUE
if the user has the permission,
FALSE
otherwisepublic final void checkPermission(Permission permission) throws PermissionDeniedException
PermissionDeniedException
is thrown.checkPermission
in interface AccessControlled
permission
- A value from the Permission
classPermissionDeniedException
- If the logged in user doesn't
have the requested permissionpublic final Set<Permission> getPermissions()
AccessControlled
getPermissions
in interface AccessControlled
public final int getId()
Identifiable
getId
in interface Identifiable
public final int getVersion()
Identifiable
getVersion
in interface Identifiable
public final boolean equals(Object o)
equals
in class Object
BasicData.equals(Object)
public final int hashCode()
hashCode
in class Object
BasicData.hashCode()
public final boolean isInDatabase()
public final boolean isDetached()
DbControl
object or not.
An item is detached if there is no DbControl
, if it is closed,
or if is not managed by the DbControl
.DbControl.detachItem(BasicItem)
,
DbControl.reattachItem(BasicItem, boolean)
,
DbControl.saveItem(BasicItem)
public boolean isUsed() throws BaseException
super.isUsed()
, unless it has decided
that the item is used by some other means.BaseException
- If not able to tell if item is used or not.getUsingItems()
public Set<ItemProxy> getUsingItems() throws BaseException
isUsed()
method. Ie.
a subclass must override both or none of these methods. The method must
return a set with proxies for all items (even if the logged in user doesn't
have read permission for all of them). With the proxy it is possible to
get the ID and type of the item. To get full access to the item the logged
in user must of course have read permission to it.BaseException
- If there is an error loading the itemsaddUsingItems(Set, Item, org.hibernate.Query)
int breakCircularReferences(Set<ItemProxy> items)
Trashcan
which has already confirmed that the given items are about to
be deleted and may have circular references between them.
NOTE! This method should not check AnyToAny
links. This has
already been done in the trashcan code.void checkBatchAnnotatableUsage(boolean annotationSet, boolean batcher)
AnnotationBatcher
must not call Annotatable.getAnnotationSet()
in the same
transaction. This method is a helper method for keeping track of
which method that has been called.annotationSet
- TRUE when called from the getAnnotationSet methodbatcher
- TRUE when called from the batcherprotected void addUsingItems(Set<ItemProxy> using, Item itemType, Query query)
using
- The set to add toitemType
- The type of items to addquery
- A Hibernate query that returns the ID of items that are using
this oneprotected void addUsingItems(Set<ItemProxy> using, Query query)
using
- The set to add toquery
- A Hibernate query that returns BasicData objectsprotected void addAnnotatableParents(DbControl dc, Set<Annotatable> parents, AnnotatableData... items)
Annotatable.getAnnotatableParents()
implementations to
load all annotatable parent items.final BasicData getBasicData()
public final DbControl getDbControl() throws ConnectionClosedException
DbControl
object that currently manages this item.ConnectionClosedException
- If the item is connected to a closed
DbControl
object, or not connected at allfinal void setDbControl(DbControl dbControl)
DbControl
object that should manage this item.
A null value detaches the itempublic final SessionControl getSessionControl() throws ConnectionClosedException
SessionControl
object that manages this item.ConnectionClosedException
- If the item is not connected to a
DbControl
objectvoid initPermissions(int granted, int denied) throws BaseException
Subclasses that needs to check other keys or properties, such
as the OwnedItem
and SharedItem
should override
this method. The subclass should calculate additional permissions
to be granted or denied, and combine those with whatever was passed
as parameters. Use the binary OR operator ( | ) to combine
the permissions. Finally the subclass must call
super.initPermissions(granted, denied)
.
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclassBaseException
- If the permissions couldn't be initialisedPluginPermission getPluginPermissions()
void validate() throws InvalidDataException, BaseException
Validatable
item
before is saved to the database. If the subclass
overrides this method it should also propagate the call
to the superclass, ie. super.validate()
.BaseException
- If there is an errorInvalidDataException
Validatable
,
Developer documentation: Data validation,
Developer documentation: Coding rules and guidelines for item classesvoid onBeforeCommit(Transactional.Action action) throws BaseException
Transactional
item and on
all items if the action is Transactional.Action.CREATE
or Transactional.Action.DELETE
before a commit is issued to the database.
If the subclass overrides this method it must also propagate the call
to the superclass, ie. super.onBeforeCommit(action)
.BaseException
- If there is an errorTransactional
,
Developer documentation: Transactions,
Developer documentation: Coding rules and guidelines for item classesvoid setProjectDefaults(Project activeProject) throws BaseException
Implementation note! Subclasses should only set default values for properties that hasn't been set explicitly by client code, also accounting for setAbc(null) calls.
activeProject
- The currently active projectBaseException
void onAfterInsert() throws BaseException
onBeforeCommit(Transactional.Action)
in case the id is needed. The id
has not been generated when the onBeforeCommit
is called.BaseException
- If there is an errorTransactional
,
Developer documentation: Transactions,
Developer documentation: Coding rules and guidelines for item classesvoid onAfterCommit(Transactional.Action action)
Transactional
object
after a successful commit to the database. If the subclass
overrides this method it should also propagate the call
to the superclass, ie. super.onAfterCommit(action)
. It is forbidden
to access the DbControl
object from this method and
it must not throw any exceptions. All exceptions should be logged
using the Application.getLogger()
object.void onRollback(Transactional.Action action)
Transactional
object
after an unsuccessful commit to the database. If the subclass
overrides this method it should also propagate the call
to the superclass, ie. super.onRollback(action)
. It is forbidden
to access the DbControl
object from this method and
it must not throw any exceptions. All exceptions should be logged
using the Application.getLogger()
object.