When you remove an item, you generally also need to remove references to the item. The atg.repository.RepositoryUtils class includes two methods that are useful in this context.

The removeReferencesToItem method removes any references to a given item from other items in its repository. This method can only remove references in queryable properties. You can invoke the removeReferencesToItem method by setting remove-references-to="true" in a <remove-item> tag.

The changes to the data caused by the removeReferencesToItem method depend on the reference type. For example, you might delete an item of type X, where type Y references X. Item descriptor Y might reference item descriptor X in three ways:

If Y references X in this way…

Delete the reference to X as follows…

Y has a non-required property whose item-type is X

Set the reference property to null and update item of type Y, essentially nullifying the foreign key.

Y has a required property whose item-type is X

Delete the item of type Y, because the foreign key cannot be set to null.

Y has a multi-valued property whose component-item-type is X

Remove the element in the multi-valued property in Y that refers to the item of type X. This deletes the one-to-many or many-to-many row that represents the Y to X reference. The item of type Y is not deleted.

Data in an auxiliary table is always deleted by a <remove-item> tag regardless of the remove-references-to attribute because it is not considered a reference.

The anyReferencesToItem method queries whether any cross-references to a repository item exist within the repository that contains that item. It uses the same logic as the removeReferencesToItem method to determine whether references exist. The anyReferencesToItem method can only detect references through queryable properties.

Calling these methods generates multiple repository queries per call, one for each property descriptor that might refer to the item. For example, if the item’s type is contact-info, one query is performed for each property descriptor whose type is contact-info, or any multi-valued type that might contain a list of items of type contact-info. The queries each fetch at most one item from the repository, so the effect on the repository’s cache should be minimal.


Copyright © 1997, 2013 Oracle and/or its affiliates. All rights reserved. Legal Notices