org.mycore.datamodel.classifications2.impl
Class MCRCategoryDAOImpl

java.lang.Object
  extended by org.mycore.datamodel.classifications2.impl.MCRCategoryDAOImpl
All Implemented Interfaces:
MCRCategoryDAO

public class MCRCategoryDAOImpl
extends Object
implements MCRCategoryDAO

Since:
2.0
Version:
$Revision: 15225 $ $Date: 2008-02-06 17:27:24 +0000 (Mi, 06 Feb 2008) $
Author:
Thomas Scheffler (yagee)

Constructor Summary
MCRCategoryDAOImpl()
           
 
Method Summary
 void addCategory(MCRCategoryID parentID, MCRCategory category)
          Adds a category as child of another category.
 void deleteCategory(MCRCategoryID id)
          Deletes a category with all child categories.
 boolean exist(MCRCategoryID id)
          Tells if a given category exists.
(package private) static MCRCategoryImpl getByNaturalID(org.hibernate.Session session, MCRCategoryID id)
           
 List<MCRCategory> getCategoriesByLabel(MCRCategoryID baseID, String lang, String text)
          Retrieve all Categories tagged by a specific label in a specific lang.
 MCRCategory getCategory(MCRCategoryID id, int childLevel)
          Returns MCRCategory with this id and childLevel levels of subcategories.
 List<MCRCategory> getChildren(MCRCategoryID cid)
          Returns the list of child categories for the specified category.
 long getLastModified()
          allows to determine when the last change was made to the categories.
 List<MCRCategory> getParents(MCRCategoryID id)
          Returns the parent of the given category and its parent and so on.
 List<MCRCategory> getRootCategories()
          Returns all categories that do not have a parent category.
 MCRCategory getRootCategory(MCRCategoryID baseID, int childLevel)
          Returns the root Category with ancestor axis of the specified category and childLevel levels of subcategories.
 List<MCRCategoryID> getRootCategoryIDs()
          Returns all category IDs that do not have a parent category.
 boolean hasChildren(MCRCategoryID cid)
          Tells if a given category contains subcategories.
(package private) static boolean isCategoryMovedRight(MCRCategoryImpl oldParent, MCRCategoryImpl newParent, int newIndex, int oldIndex)
          return true if a node moved in Category tree is moved to the right.
 void moveCategory(MCRCategoryID id, MCRCategoryID newParentID)
          Moves a Category from one subtree in a classification to a new parent.
 void moveCategory(MCRCategoryID id, MCRCategoryID newParentID, int index)
          Moves a Category from one subtree in a classification to a new parent as the indexth child.
 void removeLabel(MCRCategoryID id, String lang)
          Removes a label from a Category.
 void replaceCategory(MCRCategory newCategory)
          Replaces a MCRCategory by a new version of the same category.
 void setLabel(MCRCategoryID id, MCRLabel label)
          Sets or updates a label from a Category.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MCRCategoryDAOImpl

public MCRCategoryDAOImpl()
Method Detail

addCategory

public void addCategory(MCRCategoryID parentID,
                        MCRCategory category)
Description copied from interface: MCRCategoryDAO
Adds a category as child of another category.

Specified by:
addCategory in interface MCRCategoryDAO
Parameters:
parentID - ID of the parent category
category - Category (with children) to be added

deleteCategory

public void deleteCategory(MCRCategoryID id)
Description copied from interface: MCRCategoryDAO
Deletes a category with all child categories.

Specified by:
deleteCategory in interface MCRCategoryDAO
Parameters:
id - ID of Category to be removed

exist

public boolean exist(MCRCategoryID id)
Description copied from interface: MCRCategoryDAO
Tells if a given category exists.

Specified by:
exist in interface MCRCategoryDAO
Parameters:
id - ID of Category
Returns:
true if category is present

getCategoriesByLabel

public List<MCRCategory> getCategoriesByLabel(MCRCategoryID baseID,
                                              String lang,
                                              String text)
Description copied from interface: MCRCategoryDAO
Retrieve all Categories tagged by a specific label in a specific lang.

Specified by:
getCategoriesByLabel in interface MCRCategoryDAO
Parameters:
baseID - base Category which subtree is searched for the label.
lang - language attribute of the label
text - text of the label
Returns:
a collection of MCRCategories with matching labels

getCategory

public MCRCategory getCategory(MCRCategoryID id,
                               int childLevel)
Description copied from interface: MCRCategoryDAO
Returns MCRCategory with this id and childLevel levels of subcategories.

Specified by:
getCategory in interface MCRCategoryDAO
Parameters:
id - ID of category
childLevel - how many levels of subcategories should be retrieved (-1 for invinitive)
Returns:
MCRCategory with id

getChildren

public List<MCRCategory> getChildren(MCRCategoryID cid)
Description copied from interface: MCRCategoryDAO
Returns the list of child categories for the specified category.

Specified by:
getChildren in interface MCRCategoryDAO
Parameters:
cid - ID of category
Returns:
list of child category

getParents

public List<MCRCategory> getParents(MCRCategoryID id)
Description copied from interface: MCRCategoryDAO
Returns the parent of the given category and its parent and so on. The last element in the list is the root category (the classification)

Specified by:
getParents in interface MCRCategoryDAO
Parameters:
id - ID of Category
Returns:
list of parents

getRootCategoryIDs

public List<MCRCategoryID> getRootCategoryIDs()
Description copied from interface: MCRCategoryDAO
Returns all category IDs that do not have a parent category.

Specified by:
getRootCategoryIDs in interface MCRCategoryDAO
Returns:
list of category IDs

getRootCategories

public List<MCRCategory> getRootCategories()
Description copied from interface: MCRCategoryDAO
Returns all categories that do not have a parent category.

Specified by:
getRootCategories in interface MCRCategoryDAO
Returns:
list of category IDs

getRootCategory

public MCRCategory getRootCategory(MCRCategoryID baseID,
                                   int childLevel)
Description copied from interface: MCRCategoryDAO
Returns the root Category with ancestor axis of the specified category and childLevel levels of subcategories. You can say it is the combination of getParents(MCRCategoryID) and getCategory(MCRCategoryID, int).

Specified by:
getRootCategory in interface MCRCategoryDAO
Parameters:
baseID - Category with relative level set to "0".
childLevel - amount of subcategory levels rooted at baseID category
Returns:
the root Category (Classification)
See Also:
MCRCategoryDAO.getParents(MCRCategoryID), MCRCategoryDAO.getCategory(MCRCategoryID, int)

hasChildren

public boolean hasChildren(MCRCategoryID cid)
Description copied from interface: MCRCategoryDAO
Tells if a given category contains subcategories.

Specified by:
hasChildren in interface MCRCategoryDAO
Parameters:
cid - ID of Category
Returns:
true if subcategories are present

moveCategory

public void moveCategory(MCRCategoryID id,
                         MCRCategoryID newParentID)
Description copied from interface: MCRCategoryDAO
Moves a Category from one subtree in a classification to a new parent. All subcategories remain children of the moved category.

Specified by:
moveCategory in interface MCRCategoryDAO
Parameters:
id - ID of the Category which should be moved
newParentID - ID of the new parent

moveCategory

public void moveCategory(MCRCategoryID id,
                         MCRCategoryID newParentID,
                         int index)
Description copied from interface: MCRCategoryDAO
Moves a Category from one subtree in a classification to a new parent as the indexth child.

Specified by:
moveCategory in interface MCRCategoryDAO
Parameters:
id - ID of the Category which should be moved
newParentID - ID of the new parent
index - insert category at index in the list of children

removeLabel

public void removeLabel(MCRCategoryID id,
                        String lang)
Description copied from interface: MCRCategoryDAO
Removes a label from a Category.

Specified by:
removeLabel in interface MCRCategoryDAO
Parameters:
id - ID of the category
lang - which language should be removed?

replaceCategory

public void replaceCategory(MCRCategory newCategory)
                     throws IllegalArgumentException
Description copied from interface: MCRCategoryDAO
Replaces a MCRCategory by a new version of the same category. This replacment includes all subcategories and labels. So former subcategories and labels not present in newCategory will be removed while new ones will be inserted. If you can use the other methods defined by this interface as they ought to be more optimized.

Specified by:
replaceCategory in interface MCRCategoryDAO
Parameters:
newCategory - new version of MCRCategory
Throws:
IllegalArgumentException - if old version of MCRCategory does not exist

setLabel

public void setLabel(MCRCategoryID id,
                     MCRLabel label)
Description copied from interface: MCRCategoryDAO
Sets or updates a label from a Category.

Specified by:
setLabel in interface MCRCategoryDAO
Parameters:
id - ID of the category
label - to be set or updated

getLastModified

public long getLastModified()
Description copied from interface: MCRCategoryDAO
allows to determine when the last change was made to the categories.

Specified by:
getLastModified in interface MCRCategoryDAO
Returns:
either the last change time or the init time of the DAO class

isCategoryMovedRight

static boolean isCategoryMovedRight(MCRCategoryImpl oldParent,
                                    MCRCategoryImpl newParent,
                                    int newIndex,
                                    int oldIndex)
return true if a node moved in Category tree is moved to the right. If the newParent is not an ancestor node of oldParent, a simple comparison of their left values is done to determine if a node is moved to the right. If the newParent is an ancestor node of oldParent, the ancestor axis is walked up to the direct child of newParent. The position of the direct child in the childrenList of newParent is compared to newIndex to determine if a node is moved to the right. If oldParent is an ancestor newParent the solution is analog.

Parameters:
oldParent -
newParent -
newIndex -
oldIndex -
Returns:

getByNaturalID

static MCRCategoryImpl getByNaturalID(org.hibernate.Session session,
                                      MCRCategoryID id)