Removing root version

This is a discussion on Removing root version within the Apache forums in Application Servers & Tools category; I would like to implement rollback function for the versioned node. If node has only one version, the node itself is removed. If there is more then one version of the node, the root (top, head) node is removed. I tried v.remove() or history.removeVersion(v.getName()), but both fail with exception: javax.jcr.nodetype.ConstraintViolationException: /jcr:system/jcr:versionStorage/23/4c/e0/234ce0e4-4a6a-435c-a4b4-7a8e3fe4f2cf/jcr:rootVersion: cannot remove a protected node Here is the code: VersionHistory history = document.getVersionHistory(); VersionIterator ito = history.getAllVersions(); if (ito.hasNext()) { Version v = ito.nextVersion(); // Top version if (ito.hasNext()) v.remove(); else document.remove(); session.save(); } My question is, is it possible or do I have to use workaround like create ...

Go Back   Application Development Forum > Application Servers & Tools > Apache

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 04-03-2007, 06:45 PM
Lubos and Alena Pochman
Guest
 
Default Removing root version

I would like to implement rollback function for the versioned node. If node
has only one version, the node itself is removed. If there is more then one
version
of the node, the root (top, head) node is removed. I tried v.remove() or
history.removeVersion(v.getName()), but both fail with exception:

javax.jcr.nodetype.ConstraintViolationException:
/jcr:system/jcr:versionStorage/23/4c/e0/234ce0e4-4a6a-435c-a4b4-7a8e3fe4f2cf/jcr:rootVersion:
cannot remove a protected node

Here is the code:

VersionHistory history = document.getVersionHistory();
VersionIterator ito = history.getAllVersions();
if (ito.hasNext()) {
Version v = ito.nextVersion(); // Top version
if (ito.hasNext())
v.remove();
else
document.remove();
session.save();
}


My question is, is it possible or do I have to use workaround like create
new version from version head-1 (create new version) and then remove the
original root version and the original head-1 version?

Thanks, Lubos

Reply With Quote
  #2  
Old 04-03-2007, 07:25 PM
Brian Thompson
Guest
 
Default Re: Removing root version

Are you checking out the document node before you check on its version
history? If not, that might cause the problem.

Also, if you're removing the document node, you probably have to check out
its parent.

-Brian



On 4/3/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
>
> I would like to implement rollback function for the versioned node. If
> node
> has only one version, the node itself is removed. If there is more then
> one
> version
> of the node, the root (top, head) node is removed. I tried v.remove() or
> history.removeVersion(v.getName()), but both fail with exception:
>
> javax.jcr.nodetype.ConstraintViolationException:
>
> /jcr:system/jcr:versionStorage/23/4c/e0/234ce0e4-4a6a-435c-a4b4-7a8e3fe4f2cf/jcr:rootVersion:
> cannot remove a protected node
>
> Here is the code:
>
> VersionHistory history = document.getVersionHistory();
> VersionIterator ito = history.getAllVersions();
> if (ito.hasNext()) {
> Version v = ito.nextVersion(); // Top version
> if (ito.hasNext())
> v.remove();
> else
> document.remove();
> session.save();
> }
>
>
> My question is, is it possible or do I have to use workaround like create
> new version from version head-1 (create new version) and then remove the
> original root version and the original head-1 version?
>
> Thanks, Lubos
>


Reply With Quote
  #3  
Old 04-04-2007, 12:27 PM
Lubos and Alena Pochman
Guest
 
Default Re: Removing root version

Thanks Brian,

yes I am checking out the document node before I get the version history.
It looks like you cannot remove the head (base/top) version from the version
list.
Anybody from developers to confirm that?

Lubos

On 4/3/07, Brian Thompson <elephantium@gmail.com> wrote:
>
> Are you checking out the document node before you check on its version
> history? If not, that might cause the problem.
>
> Also, if you're removing the document node, you probably have to check out
> its parent.
>
> -Brian
>
>
>
> On 4/3/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
> >
> > I would like to implement rollback function for the versioned node. If
> > node
> > has only one version, the node itself is removed. If there is more then
> > one
> > version
> > of the node, the root (top, head) node is removed. I tried v.remove() or
> > history.removeVersion(v.getName()), but both fail with exception:
> >
> > javax.jcr.nodetype.ConstraintViolationException:
> >
> >

> /jcr:system/jcr:versionStorage/23/4c/e0/234ce0e4-4a6a-435c-a4b4-7a8e3fe4f2cf/jcr:rootVersion:
> > cannot remove a protected node
> >
> > Here is the code:
> >
> > VersionHistory history = document.getVersionHistory();
> > VersionIterator ito = history.getAllVersions();
> > if (ito.hasNext()) {
> > Version v = ito.nextVersion(); // Top version
> > if (ito.hasNext())
> > v.remove();
> > else
> > document.remove();
> > session.save();
> > }
> >
> >
> > My question is, is it possible or do I have to use workaround like

> create
> > new version from version head-1 (create new version) and then remove the
> > original root version and the original head-1 version?
> >
> > Thanks, Lubos
> >

>


Reply With Quote
  #4  
Old 04-04-2007, 03:12 PM
Tobias Bocanegra
Guest
 
Default Re: Removing root version

hi,
you cannot remove a version with the normal Node.remove() method. use
VersionHistory.removeVersion() instead. further, you cannot remove the
root version, since it's part of the initial version history.

regards, toby

On 4/4/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
> Thanks Brian,
>
> yes I am checking out the document node before I get the version history.
> It looks like you cannot remove the head (base/top) version from the version
> list.
> Anybody from developers to confirm that?
>
> Lubos
>
> On 4/3/07, Brian Thompson <elephantium@gmail.com> wrote:
> >
> > Are you checking out the document node before you check on its version
> > history? If not, that might cause the problem.
> >
> > Also, if you're removing the document node, you probably have to check out
> > its parent.
> >
> > -Brian
> >
> >
> >
> > On 4/3/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
> > >
> > > I would like to implement rollback function for the versioned node. If
> > > node
> > > has only one version, the node itself is removed. If there is more then
> > > one
> > > version
> > > of the node, the root (top, head) node is removed. I tried v.remove() or
> > > history.removeVersion(v.getName()), but both fail with exception:
> > >
> > > javax.jcr.nodetype.ConstraintViolationException:
> > >
> > >

> > /jcr:system/jcr:versionStorage/23/4c/e0/234ce0e4-4a6a-435c-a4b4-7a8e3fe4f2cf/jcr:rootVersion:
> > > cannot remove a protected node
> > >
> > > Here is the code:
> > >
> > > VersionHistory history = document.getVersionHistory();
> > > VersionIterator ito = history.getAllVersions();
> > > if (ito.hasNext()) {
> > > Version v = ito.nextVersion(); // Top version
> > > if (ito.hasNext())
> > > v.remove();
> > > else
> > > document.remove();
> > > session.save();
> > > }
> > >
> > >
> > > My question is, is it possible or do I have to use workaround like

> > create
> > > new version from version head-1 (create new version) and then remove the
> > > original root version and the original head-1 version?
> > >
> > > Thanks, Lubos
> > >

> >

>



--
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Reply With Quote
  #5  
Old 04-05-2007, 03:08 PM
Lubos and Alena Pochman
Guest
 
Default Re: Removing root version

I finally made it work. Here is what I do to emulate head (base) version
rollback behavior (delete head version):

1. Get base version of the node
2. From base version get predecessor
3. Create new version of the node (checkout, checkin) from the predecessor
4. The head (base) version now contains the rolled back version, its
predecessor is original head and its predecessor is the original rollback.
5. Remove the original head and rollback using VersionHistory.removeVersion
()

Versions and predecessors needs to be checked for jcr:rootVersion!

This is somewhat similar to what you would do by rolling back head version
in source control system.

On 4/4/07, Tobias Bocanegra <tobias.bocanegra@day.com> wrote:
>
> hi,
> you cannot remove a version with the normal Node.remove() method. use
> VersionHistory.removeVersion() instead. further, you cannot remove the
> root version, since it's part of the initial version history.
>
> regards, toby
>
> On 4/4/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
> > Thanks Brian,
> >
> > yes I am checking out the document node before I get the version

> history.
> > It looks like you cannot remove the head (base/top) version from the

> version
> > list.
> > Anybody from developers to confirm that?
> >
> > Lubos
> >
> > On 4/3/07, Brian Thompson <elephantium@gmail.com> wrote:
> > >
> > > Are you checking out the document node before you check on its version
> > > history? If not, that might cause the problem.
> > >
> > > Also, if you're removing the document node, you probably have to check

> out
> > > its parent.
> > >
> > > -Brian
> > >
> > >
> > >
> > > On 4/3/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
> > > >
> > > > I would like to implement rollback function for the versioned node.

> If
> > > > node
> > > > has only one version, the node itself is removed. If there is more

> then
> > > > one
> > > > version
> > > > of the node, the root (top, head) node is removed. I tried v.remove()

> or
> > > > history.removeVersion(v.getName()), but both fail with exception:
> > > >
> > > > javax.jcr.nodetype.ConstraintViolationException:
> > > >
> > > >
> > >

> /jcr:system/jcr:versionStorage/23/4c/e0/234ce0e4-4a6a-435c-a4b4-7a8e3fe4f2cf/jcr:rootVersion:
> > > > cannot remove a protected node
> > > >
> > > > Here is the code:
> > > >
> > > > VersionHistory history = document.getVersionHistory();
> > > > VersionIterator ito = history.getAllVersions();
> > > > if (ito.hasNext()) {
> > > > Version v = ito.nextVersion(); // Top version
> > > > if (ito.hasNext())
> > > > v.remove();
> > > > else
> > > > document.remove();
> > > > session.save();
> > > > }
> > > >
> > > >
> > > > My question is, is it possible or do I have to use workaround like
> > > create
> > > > new version from version head-1 (create new version) and then remove

> the
> > > > original root version and the original head-1 version?
> > > >
> > > > Thanks, Lubos
> > > >
> > >

> >

>
>
> --
> -----------------------------------------< tobias.bocanegra@day.com >---
> Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
> T +41 61 226 98 98, F +41 61 226 98 97
> -----------------------------------------------< http://www.day.com >---
>


Reply With Quote
  #6  
Old 04-06-2007, 11:30 AM
Brian Thompson
Guest
 
Default Re: Removing root version

As it happens, I ran into a similar issue today. There are cases where I
need to delete a versionable node entirely - including the entire version
history for that node. My current code only deletes the head version,
leaving the version history intact.

Does anyone have any hints on how to completely eradicate a version history?

-Brian


On 4/5/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
>
> I finally made it work. Here is what I do to emulate head (base) version
> rollback behavior (delete head version):
>
> 1. Get base version of the node
> 2. From base version get predecessor
> 3. Create new version of the node (checkout, checkin) from the predecessor
> 4. The head (base) version now contains the rolled back version, its
> predecessor is original head and its predecessor is the original rollback.
> 5. Remove the original head and rollback using
> VersionHistory.removeVersion
> ()
>
> Versions and predecessors needs to be checked for jcr:rootVersion!
>
> This is somewhat similar to what you would do by rolling back head version
> in source control system.
>
> On 4/4/07, Tobias Bocanegra <tobias.bocanegra@day.com> wrote:
> >
> > hi,
> > you cannot remove a version with the normal Node.remove() method. use
> > VersionHistory.removeVersion() instead. further, you cannot remove the
> > root version, since it's part of the initial version history.
> >
> > regards, toby
> >
> > On 4/4/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
> > > Thanks Brian,
> > >
> > > yes I am checking out the document node before I get the version

> > history.
> > > It looks like you cannot remove the head (base/top) version from the

> > version
> > > list.
> > > Anybody from developers to confirm that?
> > >
> > > Lubos
> > >
> > > On 4/3/07, Brian Thompson <elephantium@gmail.com> wrote:
> > > >
> > > > Are you checking out the document node before you check on its

> version
> > > > history? If not, that might cause the problem.
> > > >
> > > > Also, if you're removing the document node, you probably have to

> check
> > out
> > > > its parent.
> > > >
> > > > -Brian
> > > >
> > > >
> > > >
> > > > On 4/3/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
> > > > >
> > > > > I would like to implement rollback function for the versioned

> node.
> > If
> > > > > node
> > > > > has only one version, the node itself is removed. If there is more

> > then
> > > > > one
> > > > > version
> > > > > of the node, the root (top, head) node is removed. I tried

> v.remove()
> > or
> > > > > history.removeVersion(v.getName()), but both fail with exception:
> > > > >
> > > > > javax.jcr.nodetype.ConstraintViolationException:
> > > > >
> > > > >
> > > >

> >

> /jcr:system/jcr:versionStorage/23/4c/e0/234ce0e4-4a6a-435c-a4b4-7a8e3fe4f2cf/jcr:rootVersion:
> > > > > cannot remove a protected node
> > > > >
> > > > > Here is the code:
> > > > >
> > > > > VersionHistory history = document.getVersionHistory();
> > > > > VersionIterator ito = history.getAllVersions();
> > > > > if (ito.hasNext()) {
> > > > > Version v = ito.nextVersion(); // Top version
> > > > > if (ito.hasNext())
> > > > > v.remove();
> > > > > else
> > > > > document.remove();
> > > > > session.save();
> > > > > }
> > > > >
> > > > >
> > > > > My question is, is it possible or do I have to use workaround like
> > > > create
> > > > > new version from version head-1 (create new version) and then

> remove
> > the
> > > > > original root version and the original head-1 version?
> > > > >
> > > > > Thanks, Lubos
> > > > >
> > > >
> > >

> >
> >
> > --
> > -----------------------------------------< tobias.bocanegra@day.com >---
> > Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
> > T +41 61 226 98 98, F +41 61 226 98 97
> > -----------------------------------------------< http://www.day.com >---
> >

>


Reply With Quote
  #7  
Old 04-06-2007, 01:27 PM
Tobias Bocanegra
Guest
 
Default Re: Removing root version

this is still an open issue:

http://issues.apache.org/jira/browse/JCR-134

regards, toby

On 4/6/07, Brian Thompson <elephantium@gmail.com> wrote:
> As it happens, I ran into a similar issue today. There are cases where I
> need to delete a versionable node entirely - including the entire version
> history for that node. My current code only deletes the head version,
> leaving the version history intact.
>
> Does anyone have any hints on how to completely eradicate a version history?
>
> -Brian
>
>
> On 4/5/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
> >
> > I finally made it work. Here is what I do to emulate head (base) version
> > rollback behavior (delete head version):
> >
> > 1. Get base version of the node
> > 2. From base version get predecessor
> > 3. Create new version of the node (checkout, checkin) from the predecessor
> > 4. The head (base) version now contains the rolled back version, its
> > predecessor is original head and its predecessor is the original rollback.
> > 5. Remove the original head and rollback using
> > VersionHistory.removeVersion
> > ()
> >
> > Versions and predecessors needs to be checked for jcr:rootVersion!
> >
> > This is somewhat similar to what you would do by rolling back head version
> > in source control system.
> >
> > On 4/4/07, Tobias Bocanegra <tobias.bocanegra@day.com> wrote:
> > >
> > > hi,
> > > you cannot remove a version with the normal Node.remove() method. use
> > > VersionHistory.removeVersion() instead. further, you cannot remove the
> > > root version, since it's part of the initial version history.
> > >
> > > regards, toby
> > >
> > > On 4/4/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
> > > > Thanks Brian,
> > > >
> > > > yes I am checking out the document node before I get the version
> > > history.
> > > > It looks like you cannot remove the head (base/top) version from the
> > > version
> > > > list.
> > > > Anybody from developers to confirm that?
> > > >
> > > > Lubos
> > > >
> > > > On 4/3/07, Brian Thompson <elephantium@gmail.com> wrote:
> > > > >
> > > > > Are you checking out the document node before you check on its

> > version
> > > > > history? If not, that might cause the problem.
> > > > >
> > > > > Also, if you're removing the document node, you probably have to

> > check
> > > out
> > > > > its parent.
> > > > >
> > > > > -Brian
> > > > >
> > > > >
> > > > >
> > > > > On 4/3/07, Lubos and Alena Pochman <pochmans@gmail.com> wrote:
> > > > > >
> > > > > > I would like to implement rollback function for the versioned

> > node.
> > > If
> > > > > > node
> > > > > > has only one version, the node itself is removed. If there is more
> > > then
> > > > > > one
> > > > > > version
> > > > > > of the node, the root (top, head) node is removed. I tried

> > v.remove()
> > > or
> > > > > > history.removeVersion(v.getName()), but both fail with exception:
> > > > > >
> > > > > > javax.jcr.nodetype.ConstraintViolationException:
> > > > > >
> > > > > >
> > > > >
> > >

> > /jcr:system/jcr:versionStorage/23/4c/e0/234ce0e4-4a6a-435c-a4b4-7a8e3fe4f2cf/jcr:rootVersion:
> > > > > > cannot remove a protected node
> > > > > >
> > > > > > Here is the code:
> > > > > >
> > > > > > VersionHistory history = document.getVersionHistory();
> > > > > > VersionIterator ito = history.getAllVersions();
> > > > > > if (ito.hasNext()) {
> > > > > > Version v = ito.nextVersion(); // Top version
> > > > > > if (ito.hasNext())
> > > > > > v.remove();
> > > > > > else
> > > > > > document.remove();
> > > > > > session.save();
> > > > > > }
> > > > > >
> > > > > >
> > > > > > My question is, is it possible or do I have to use workaround like
> > > > > create
> > > > > > new version from version head-1 (create new version) and then

> > remove
> > > the
> > > > > > original root version and the original head-1 version?
> > > > > >
> > > > > > Thanks, Lubos
> > > > > >
> > > > >
> > > >
> > >
> > >
> > > --
> > > -----------------------------------------< tobias.bocanegra@day.com >---
> > > Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
> > > T +41 61 226 98 98, F +41 61 226 98 97
> > > -----------------------------------------------< http://www.day.com >---
> > >

> >

>



--
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 09:11 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.