|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.BasicItem<AnyToAnyData> net.sf.basedb.core.AnyToAny
public class AnyToAny
An any-to-any link is a named, directed link from one item to another item. The items can be of any type. Permission-wise the links belong to the start item. Ie. to be able create, update and delete links a user must have WRITE permission on the start item. The user must also have USE permission on the item we are linking to.
All any-to-any links from an item has a name which must be unique for that item.
Field Summary | |
---|---|
private BasicItem |
from
|
private BasicItem |
to
|
static Item |
TYPE
The type of item represented by this class. |
Fields inherited from interface net.sf.basedb.core.Nameable |
---|
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH |
Constructor Summary | |
---|---|
AnyToAny(AnyToAnyData data)
Creates a new link item from the given data. |
|
AnyToAny(AnyToAnyData data,
BasicItem from)
Special constructor when the from item is known. |
Method Summary | |
---|---|
static void |
deleteStrayLinks()
Deprecated. Use deleteStrayLinks(ProgressReporter) instead. |
static int |
deleteStrayLinks(ProgressReporter progress)
Delete all links that are linking to non-existing items. |
static boolean |
exists(DbControl dc,
BasicItem from,
String name)
Check if an item has a link with a given name. |
static AnyToAny |
getById(DbControl dc,
int id)
Get an AnyToAny link when you know the id. |
static AnyToAny |
getByName(DbControl dc,
BasicItem from,
String name)
Get an AnyToAny link when you know the item
it is linking from and the name of the link. |
(package private) static AnyToAnyData |
getDataByName(org.hibernate.Session session,
int fromId,
Item fromType,
String name)
Get an any-to-any link. |
String |
getDescription()
Get the description for the item. |
BasicItem |
getFrom()
Get the item this link is linking from. |
int |
getFromId()
Get the ID of the item this link is linking from. |
Item |
getFromType()
Get the type of the item this link is linking from. |
static ItemQuery<AnyToAny> |
getLinksFrom(BasicItem from)
Get a query that returns all links linking from the specified item. |
static ItemQuery<AnyToAny> |
getLinksTo(BasicItem to)
Get a query that returns all links linking to the specified item. |
String |
getName()
Get the name of the item. |
static AnyToAny |
getNew(DbControl dc,
BasicItem from,
BasicItem to,
String name,
boolean usingTo)
Create a new AnyToAny link |
static AnyToAny |
getNewOrExisting(DbControl dc,
BasicItem from,
String name,
BasicItem to,
boolean usingTo)
Get a new or existing AnyToAny link. |
(package private) PluginPermission |
getPluginPermissions()
|
BasicItem |
getTo()
Get the item this link is linking to. |
int |
getToId()
Get the ID of the item this link is linking to. |
Item |
getToType()
Get the type of the item this link is linking to. |
Item |
getType()
Get the type of item represented by the object. |
(package private) void |
initPermissions(int granted,
int denied)
Permissions are granted based on the permission on the from item. |
boolean |
isUsed()
Always FALSE. |
boolean |
isUsingTo()
If this link counts as using the destination item. |
(package private) void |
onBeforeCommit(Transactional.Action action)
We may have to set the getFromId() and/or getToId()
values if those items are also created in the same transaction. |
void |
setDescription(String description)
Set the description for the item. |
private void |
setFrom(BasicItem from)
|
void |
setName(String name)
Set the name of the item. |
void |
setTo(BasicItem to)
Set the destination item of the link. |
void |
setUsingTo(boolean usesTo)
If this link counts as using the destination item. |
static int |
unlinkAllFrom(DbControl dc,
BasicItem from)
Delete all links linking from the specified item. |
static void |
unlinkFrom(DbControl dc,
BasicItem from,
String name)
|
Methods inherited from class net.sf.basedb.core.BasicItem |
---|
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface net.sf.basedb.core.Identifiable |
---|
getId, getVersion |
Methods inherited from interface net.sf.basedb.core.AccessControlled |
---|
checkPermission, getPermissions, hasPermission |
Field Detail |
---|
public static final Item TYPE
Item.ANYTOANY
,
getType()
private BasicItem from
private BasicItem to
Constructor Detail |
---|
AnyToAny(AnyToAnyData data)
AnyToAny(AnyToAnyData data, BasicItem from)
Method Detail |
---|
public static AnyToAny getNew(DbControl dc, BasicItem from, BasicItem to, String name, boolean usingTo) throws InvalidDataException
AnyToAny
link
dc
- The DbControl
which will be used for
permission checking and database accessfrom
- The item to create the link fromto
- The item to link toname
- The name of the link, must be unique among all links for the from
itemusingTo
- TRUE if the link counts as using the to
item,
FALSE otherwise (see BasicItem.isUsed()
)
AnyToAny
link
InvalidDataException
- If any of the items are null, or if the
items are equal or if any of the items is an AnyToAny item
BaseException
- If there is an errorpublic static AnyToAny getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
AnyToAny
link when you know the id.
dc
- The DbControl
which will be used for
permission checking and database accessid
- The id of the item to load
AnyToAnyLink
item
ItemNotFoundException
- If an item with the specified
id is not found
PermissionDeniedException
- If the logged in user doesn't
have read permission to the item
BaseException
- If there is another errorpublic static AnyToAny getByName(DbControl dc, BasicItem from, String name) throws InvalidDataException, ItemNotFoundException, BaseException
AnyToAny
link when you know the item
it is linking from and the name of the link.
dc
- The DbControl
which will be used for
permission checking and database access.from
- The item the link is linking fromname
- The name of the link
AnyToAnyLink
item
InvalidDataException
- If the from or name parameter is null
ItemNotFoundException
- If a link with the specified
name is not found
BaseException
- If there is another errorstatic AnyToAnyData getDataByName(org.hibernate.Session session, int fromId, Item fromType, String name)
session
- An open Hibernate sessionfromId
- The id of the source itemfromType
- The type of the source itemname
- The name of the link
public static AnyToAny getNewOrExisting(DbControl dc, BasicItem from, String name, BasicItem to, boolean usingTo)
AnyToAny
link. If a link
already exists it's destination item will be updated to link
to the to
parameter. If a new link was created
you must call DbControl.saveItem(BasicItem)
to save
the link in the database. Otherwise, you don't have to do anything.
dc
- The DbControl
which will be used for
permission checking and database accessfrom
- The item to create/get the link fromto
- The item to link toname
- The name of the link, must be unique among all links for the from
itemusingTo
- TRUE if the link counts as using the to
item,
FALSE otherwise (see BasicItem.isUsed()
)
AnyToAny
link
InvalidDataException
- If any of the items are null, or if the
items are equal or if any of the items is an AnyToAny item
BaseException
- If there is an errorpublic static ItemQuery<AnyToAny> getLinksFrom(BasicItem from) throws InvalidDataException
from
- The source of the links
ItemQuery
object
InvalidDataException
- If the from parameter is nullpublic static ItemQuery<AnyToAny> getLinksTo(BasicItem to)
to
- The destination of the links
ItemQuery
object
InvalidDataException
- If the to parameter is nullpublic static void unlinkFrom(DbControl dc, BasicItem from, String name) throws PermissionDeniedException, InvalidDataException, BaseException
dc
- DbControl to use when accessing the databasefrom
- BasicItem to unlink from.name
- Name of the link.
PermissionDeniedException
- If the logged in user doesn't have
WRITE permission for the item
InvalidDataException
- If the from or name parameter is null
BaseException
- If there is another errorpublic static int unlinkAllFrom(DbControl dc, BasicItem from) throws PermissionDeniedException, InvalidDataException, BaseException
dc
- The DbControl
which will be used for
permission checking and database accessfrom
- The source of the links
PermissionDeniedException
- If the logged in user doesn't have
WRITE permission for the item
InvalidDataException
- If the from parameter is null
BaseException
- If there is another errorpublic static boolean exists(DbControl dc, BasicItem from, String name) throws InvalidDataException, BaseException
dc
- The DbControl
which will be used for
permission checking and database access.from
- The item the link is linking fromname
- The name of the link
InvalidDataException
- If the from or name parameter is null
BaseException
- If there is another errorpublic static void deleteStrayLinks()
deleteStrayLinks(ProgressReporter)
instead.
public static int deleteStrayLinks(ProgressReporter progress)
BasicItem.onBeforeCommit(Transactional.Action)
method
tries to delete as many links as it can, it will not not delete links
leading to items that have been deleted by Hibernate cascade.
progress
- An optional progress reporterpublic Item getType()
Identifiable
Item
enumeration.
getType
in interface Identifiable
public boolean isUsed() throws BaseException
isUsed
in class BasicItem<AnyToAnyData>
BaseException
- If not able to tell if item is used or not.BasicItem.getUsingItems()
void onBeforeCommit(Transactional.Action action) throws BaseException
getFromId()
and/or getToId()
values if those items are also created in the same transaction.
onBeforeCommit
in class BasicItem<AnyToAnyData>
BaseException
- If there is an errorTransactional
,
Core API overview - Transaction handling,
Coding rules and guidelines for item classesvoid initPermissions(int granted, int denied) throws BaseException
initPermissions
in class BasicItem<AnyToAnyData>
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclass
BaseException
- If the permissions couldn't be initialisedPluginPermission getPluginPermissions()
getPluginPermissions
in class BasicItem<AnyToAnyData>
public String getName()
Nameable
getName
in interface Nameable
String
with the name of the itempublic void setName(String name) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_NAME_LENGTH
constant.
setName
in interface Nameable
name
- The new name for the item
PermissionDeniedException
- If the logged in user doesn't
have write permission
InvalidDataException
- If the name is null or longer
than specified by the Nameable.MAX_NAME_LENGTH
constantpublic String getDescription()
Nameable
getDescription
in interface Nameable
String
with a description of the itempublic void setDescription(String description) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_DESCRIPTION_LENGTH
constant.
setDescription
in interface Nameable
description
- The new description for the item
PermissionDeniedException
- If the logged in user doesn't
have write permission
InvalidDataException
- If the description longer
than specified by the Nameable.MAX_DESCRIPTION_LENGTH
constantprivate void setFrom(BasicItem from) throws InvalidDataException, PermissionDeniedException
InvalidDataException
PermissionDeniedException
public int getFromId()
public Item getFromType()
public BasicItem getFrom() throws PermissionDeniedException, BaseException
BasicItem
item
PermissionDeniedException
- If the logged in user doesn't have
read permission to the item
BaseException
- If there is another errorpublic int getToId()
public Item getToType()
public BasicItem getTo() throws PermissionDeniedException, BaseException
BasicItem
item
PermissionDeniedException
- If the logged in user doesn't have
read permission to the item
BaseException
- If there is another errorpublic void setTo(BasicItem to) throws InvalidDataException, PermissionDeniedException
to
- The destination item
InvalidDataException
- If the item is null or is an AnyToAny
link
PermissionDeniedException
- If the logged in user doesn't have write permission
for the link and use permission for the itempublic boolean isUsingTo()
public void setUsingTo(boolean usesTo) throws PermissionDeniedException
usesTo
- TRUE if this counts as using the item, FALSE otherwise.
PermissionDeniedException
- If the logged in user doesn't
have write permission
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |