You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by mitziuro <mi...@gmail.com> on 2009/09/03 10:40:04 UTC
Delete problem
In my application i need to delete all the version data of a node when the
node is deleted.
I'm getting the version history, I delete the node, then I'm trying to
delete all the versions exept the rootVersion node.
When I commit the transaction I get a ReferencialIntegrityException because
the rootVersion node is referring a deleted node.
What is the solution in this case ?
Re: Delete problem
Posted by mitziuro <mi...@gmail.com>.
So, I have the following code for deleting a node:
VersionHistory vh = null;
boolean versionable = false;
String uuid = node.getUUID();
try {
// check if node is versionable
if (((NodeImpl) node).isNodeType(NameConstants.MIX_VERSIONABLE))
{
node.checkout();
logger.debug("node is versionable...get version history");
vh = node.getVersionHistory();
versionable = true;
}
} catch (Exception e) {
// just log the exception...don't throw it
logger.debug("Error at getting the version history for node: "
.concat(uuid), e);
}
Node child = null;
// before removing the node, first remove all its children and their
versions
NodeIterator nit = node.getNodes();
while(nit.hasNext()){
child = nit.nextNode();
// check if the child is rep:policy
if (child.getPrimaryNodeType().isNodeType(NODE_TYPE_ACL)) {
//no op. rep:policy children are deleted automatically
} else{
// delete the child and its subtree and their versions
delete(session, child);
}
}
node.remove();
session.save();
try {
// check if node is versionable
if (versionable) {
logger.debug("node is versionable...delete all versions");
// delete version history
VersionIterator vit = vh.getAllVersions();
// skip the root version(it cannot be deleted)
vit.skip(1);
Version v = null;
while (vit.hasNext()) {
v = vit.nextVersion();
vh.removeVersion(v.getName());
}
}
} catch (Exception e) {
// just log the exception...don't throw it
logger.error("Error at deleting versions for node:
".concat(uuid),
e);
and after that i'm commiting the transaction started before:
DMETransaction.getInstance().commit((Session) args[0]) with the code
public void commit(Session s) {
logger.debug("-----< comit transaction >-------");
Xid xid = null;
try {
XASession session = (XASession) s;
// get XAResource
XAResource xares = session.getXAResource();
xid = xids.get(s.toString());
//commit transaction
xares.end(xid, XAResource.TMSUCCESS);
xares.prepare(xid);
xares.commit(xid, false);
//remove xid that unique identifies this transaction
xids.remove(s.toString());
} catch(Exception e) {
logger.error("", e);
}
}
and i've got this:
javax.jcr.ReferentialIntegrityException:
feea1825-175a-4579-a894-efb217b1a779: the node cannot be removed because it
is still being referenced.
Is there a way to include the version delete process in the same transaction
with the node ?
Re: Delete problem
Posted by mitziuro <mi...@gmail.com>.
So, I have the following code for deleting a node:
VersionHistory vh = null;
boolean versionable = false;
String uuid = node.getUUID();
try {
// check if node is versionable
if (((NodeImpl) node).isNodeType(NameConstants.MIX_VERSIONABLE))
{
node.checkout();
logger.debug("node is versionable...get version history");
vh = node.getVersionHistory();
versionable = true;
}
} catch (Exception e) {
// just log the exception...don't throw it
logger.debug("Error at getting the version history for node: "
.concat(uuid), e);
}
Node child = null;
// before removing the node, first remove all its children and their
versions
NodeIterator nit = node.getNodes();
while(nit.hasNext()){
child = nit.nextNode();
// check if the child is rep:policy
if (child.getPrimaryNodeType().isNodeType(NODE_TYPE_ACL)) {
//no op. rep:policy children are deleted automatically
} else{
// delete the child and its subtree and their versions
delete(session, child);
}
}
node.remove();
session.save();
//DMETransaction.getInstance().commit(session);
try {
// check if node is versionable
if (versionable) {
logger.debug("node is versionable...delete all versions");
// delete version history
VersionIterator vit = vh.getAllVersions();
// skip the root version(it cannot be deleted)
vit.skip(1);
Version v = null;
while (vit.hasNext()) {
v = vit.nextVersion();
vh.removeVersion(v.getName());
}
}
} catch (Exception e) {
// just log the exception...don't throw it
logger.error("Error at deleting versions for node:
".concat(uuid),
e);
}
On Thu, Sep 3, 2009 at 11:52 AM, Alexander Klimetschek <ak...@day.com>wrote:
> On Thu, Sep 3, 2009 at 10:51 AM, Alexander Klimetschek<ak...@day.com>
> wrote:
> > AFAIK, deleting the root node is not possible.
>
> Deleting the root *version* that is ;-)
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
>
Re: Delete problem
Posted by Alexander Klimetschek <ak...@day.com>.
On Thu, Sep 3, 2009 at 10:51 AM, Alexander Klimetschek<ak...@day.com> wrote:
> AFAIK, deleting the root node is not possible.
Deleting the root *version* that is ;-)
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Delete problem
Posted by Alexander Klimetschek <ak...@day.com>.
On Thu, Sep 3, 2009 at 10:40 AM, mitziuro<mi...@gmail.com> wrote:
> In my application i need to delete all the version data of a node when the
> node is deleted.
> I'm getting the version history, I delete the node, then I'm trying to
> delete all the versions exept the rootVersion node.
> When I commit the transaction I get a ReferencialIntegrityException because
> the rootVersion node is referring a deleted node.
>
> What is the solution in this case ?
AFAIK, deleting the root node is not possible. But with
https://issues.apache.org/jira/browse/JCR-134 included in 1.6.0, an
empty, orphanded version history will be deleted automatically. See
the test for some sample code on that behaviour:
http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RemoveOrphanVersionHistoryTest.java?revision=789701
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com