You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Tobias Bocanegra <to...@day.com> on 2006/04/26 07:54:15 UTC

Re: jcr:sucessors property not persisted immediatly within a transaction

hi nicolas,
thank you for looking into this. having a corresponding jira bug would
be great :-). the way of how the version storage (the stuff below
/jcr:system/jcr:versionStorage) exposed to the workspace is done by
'virtual itemstates'. the version storage needs to be 'mounted' to all
workspaces. so it could be, that the version manager does not
invalidate the above caches properly.

regards, toby

On 4/25/06, Nicolas Belisle <Ni...@bibl.ulaval.ca> wrote:
> Hi again,
>
> A get another strange behavior running a similar chunk of code (see below).
>  From repeated execution the output changes! Sometimes the first and second
> versionHistory print displays 2 versions, sometimes only the rootVersion...
> Commenting the transaction context seem to solve the problem.
>
> Maybe it's my coffee ... @_@
>
>
> Regards,
> Nicolas
>
>
> package net.sf.archimede;
>
> import javax.jcr.Node;
> import javax.jcr.NodeIterator;
> import javax.jcr.Property;
> import javax.jcr.PropertyIterator;
> import javax.jcr.Repository;
> import javax.jcr.RepositoryException;
> import javax.jcr.Session;
> import javax.jcr.SimpleCredentials;
> import javax.jcr.Value;
> import javax.jcr.version.Version;
> import javax.jcr.version.VersionIterator;
> import javax.transaction.UserTransaction;
>
> import net.sf.archimede.model.UserTransactionImpl;
>
> import org.apache.jackrabbit.core.TransientRepository;
>
> public class VersioningTest {
>
>      public static void main(String[] args) throws Exception {
>          //RepositoryConfig config = RepositoryConfig.create(new
> FileInputStream(new File("C:/tmp/repository.xml")), "C:/tmp/repository");
>          Repository repository = new
> TransientRepository();//RepositoryImpl.create(config);
>          Session session = repository.login( new
> SimpleCredentials("username", "password".toCharArray()) );
>          try {
>
>              String nodeName = "" + System.currentTimeMillis();
>
>              Node rootNode = session.getRootNode();
>              Node test = rootNode.addNode(nodeName);
>              test.addMixin("mix:versionable");
>              session.save();
>
>              UserTransaction tx = new UserTransactionImpl(session);
>              tx.begin();
>
>              //Create a version
>              test.checkin();
>              test.checkout();
>
>              //Create another
>              test.checkin();
>              test.checkout();
>
>              for (VersionIterator vi =
> test.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
>                  Version version = vi.nextVersion();
>                  System.out.println();
>                  print(version);
>              }
>
>              for (VersionIterator vi =
> test.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
>                  Version version = vi.nextVersion();
>                  System.out.println();
>                  print(version);
>              }
>
> //          Commit transaction
>              tx.commit();
>
>              for (VersionIterator vi =
> test.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
>                  Version version = vi.nextVersion();
>                  System.out.println();
>                  print(version);
>              }
>
>
>          } finally {
>              session.logout();
>          }
>      }
>
>      public static void print(Node node) throws RepositoryException {
>          System.out.println("Printing content of node: " + node.getName());
>          System.out.println(" Properties:");
>          for (PropertyIterator pi = node.getProperties(); pi.hasNext();) {
>              Property p = pi.nextProperty();
>              if (p.getDefinition().isMultiple()) {
>                  Value[] values = p.getValues();
>                  for (int i = 0; i < values.length; i++) {
>                      System.out.println("  - " + p.getName() + ": " +
> values[i].getString());
>                  }
>              } else {
>                  System.out.println("  - " + p.getName() + ": " +
> p.getValue().getString());
>              }
>          }
>          System.out.println(" Child nodes:");
>          for (NodeIterator ni = node.getNodes(); ni.hasNext();) {
>              Node n = ni.nextNode();
>              System.out.println("  - " + n.getName());
>          }
>      }
>
> }
>
>
>
>
> Le 14:16 2006-04-25, vous avez écrit:
> >Hi,
> >
> >*Is this a desired behavior ? If not, I will file an issue.
> >
> >During a transaction, if you create a new version (checkin + checkout)
> >then read the version history the "jcr:sucessors" property is not updated.
> >Note that "jcr:predecessors" is updated properly.
> >
> > From what I understand, since the changes are commited immedialy for
> > checkin (8.2.5), the read should reflect the current status.
> >
> >Here's an example to show the situation:
> >
> >
> >package net.sf.archimede;
> >
> >import javax.jcr.Node;
> >import javax.jcr.NodeIterator;
> >import javax.jcr.Property;
> >import javax.jcr.PropertyIterator;
> >import javax.jcr.Repository;
> >import javax.jcr.RepositoryException;
> >import javax.jcr.Session;
> >import javax.jcr.SimpleCredentials;
> >import javax.jcr.Value;
> >import javax.jcr.version.Version;
> >import javax.jcr.version.VersionIterator;
> >import javax.transaction.UserTransaction;
> >
> >//Found in /src/test/
> >import org.apache.jackrabbit.core.UserTransactionImpl;
> >
> >import org.apache.jackrabbit.core.TransientRepository;
> >
> >public class VersioningTest {
> >
> >     public static void main(String[] args) throws Exception {
> >         //RepositoryConfig config = RepositoryConfig.create(new
> > FileInputStream(new File("C:/tmp/repository.xml")), "C:/tmp/repository");
> >         Repository repository = new
> > TransientRepository();//RepositoryImpl.create(config);
> >         Session session = repository.login(
> >                 new SimpleCredentials("username", "password".toCharArray()));
> >         try {
> >
> >             UserTransaction tx = new UserTransactionImpl(session);
> >             tx.begin();
> >             Node rootNode = session.getRootNode();
> >             Node test = rootNode.addNode("test");
> >             test.addMixin("mix:versionable");
> >             session.save();
> >
> >             //Create a version
> >             test.checkin();
> >             test.checkout();
> >
> >             test.checkin();
> >             test.checkout();
> >
> >             //Create another
> >             test.checkin();
> >             test.checkout();
> >
> >             //Read versions
> >             for (VersionIterator vi =
> > test.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
> >                 Version version = vi.nextVersion();
> >                 System.out.println();
> >                 print(version);
> >             }
> >
> >             //Read versions from another session
> >             Session session2 = repository.login();
> >             Node test2 = session2.getRootNode().getNode("test");
> >             for (VersionIterator vi =
> > test2.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
> >                 Version version = vi.nextVersion();
> >                 System.out.println();
> >                 print(version);
> >             }
> >
> >             //Commit transaction
> >             tx.commit();
> >
> >             //Read versions after transaction
> >             for (VersionIterator vi =
> > test.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
> >                 Version version = vi.nextVersion();
> >                 System.out.println();
> >                 print(version);
> >             }
> >
> >         } finally {
> >             session.logout();
> >         }
> >     }
> >
> >     public static void print(Node node) throws RepositoryException {
> >         System.out.println("Printing content of node: " + node.getName());
> >         System.out.println(" Properties:");
> >         for (PropertyIterator pi = node.getProperties(); pi.hasNext();) {
> >             Property p = pi.nextProperty();
> >             if (p.getDefinition().isMultiple()) {
> >                 Value[] values = p.getValues();
> >                 for (int i = 0; i < values.length; i++) {
> >                     System.out.println("  - " + p.getName() + ": " +
> > values[i].getString());
> >                 }
> >             } else {
> >                 System.out.println("  - " + p.getName() + ": " +
> > p.getValue().getString());
> >             }
> >         }
> >         System.out.println(" Child nodes:");
> >         for (NodeIterator ni = node.getNodes(); ni.hasNext();) {
> >             Node n = ni.nextNode();
> >             System.out.println("  - " + n.getName());
> >         }
> >     }
> >
> >}
> >
> >Regards,
> >
> >Nicolas
>
>


--
-----------------------------------------< 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 >---

Re: jcr:sucessors property not persisted immediatly within a transaction

Posted by Nicolas Belisle <Ni...@bibl.ulaval.ca>.
Hi Tobias,

Done : http://issues.apache.org/jira/browse/JCR-414

The issue mentions the two problems : jcr:succesors not updated and 
inconsistent read of version history.

Thanks for your comments,

Nick


Le 01:54 2006-04-26, vous avez écrit:
>hi nicolas,
>thank you for looking into this. having a corresponding jira bug would
>be great :-). the way of how the version storage (the stuff below
>/jcr:system/jcr:versionStorage) exposed to the workspace is done by
>'virtual itemstates'. the version storage needs to be 'mounted' to all
>workspaces. so it could be, that the version manager does not
>invalidate the above caches properly.
>
>regards, toby
>
>On 4/25/06, Nicolas Belisle <Ni...@bibl.ulaval.ca> wrote:
> > Hi again,
> >
> > A get another strange behavior running a similar chunk of code (see below).
> >  From repeated execution the output changes! Sometimes the first and second
> > versionHistory print displays 2 versions, sometimes only the rootVersion...
> > Commenting the transaction context seem to solve the problem.
> >
> > Maybe it's my coffee ... @_@
> >
> >
> > Regards,
> > Nicolas
> >
> >
> > package net.sf.archimede;
> >
> > import javax.jcr.Node;
> > import javax.jcr.NodeIterator;
> > import javax.jcr.Property;
> > import javax.jcr.PropertyIterator;
> > import javax.jcr.Repository;
> > import javax.jcr.RepositoryException;
> > import javax.jcr.Session;
> > import javax.jcr.SimpleCredentials;
> > import javax.jcr.Value;
> > import javax.jcr.version.Version;
> > import javax.jcr.version.VersionIterator;
> > import javax.transaction.UserTransaction;
> >
> > import net.sf.archimede.model.UserTransactionImpl;
> >
> > import org.apache.jackrabbit.core.TransientRepository;
> >
> > public class VersioningTest {
> >
> >      public static void main(String[] args) throws Exception {
> >          //RepositoryConfig config = RepositoryConfig.create(new
> > FileInputStream(new File("C:/tmp/repository.xml")), "C:/tmp/repository");
> >          Repository repository = new
> > TransientRepository();//RepositoryImpl.create(config);
> >          Session session = repository.login( new
> > SimpleCredentials("username", "password".toCharArray()) );
> >          try {
> >
> >              String nodeName = "" + System.currentTimeMillis();
> >
> >              Node rootNode = session.getRootNode();
> >              Node test = rootNode.addNode(nodeName);
> >              test.addMixin("mix:versionable");
> >              session.save();
> >
> >              UserTransaction tx = new UserTransactionImpl(session);
> >              tx.begin();
> >
> >              //Create a version
> >              test.checkin();
> >              test.checkout();
> >
> >              //Create another
> >              test.checkin();
> >              test.checkout();
> >
> >              for (VersionIterator vi =
> > test.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
> >                  Version version = vi.nextVersion();
> >                  System.out.println();
> >                  print(version);
> >              }
> >
> >              for (VersionIterator vi =
> > test.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
> >                  Version version = vi.nextVersion();
> >                  System.out.println();
> >                  print(version);
> >              }
> >
> > //          Commit transaction
> >              tx.commit();
> >
> >              for (VersionIterator vi =
> > test.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
> >                  Version version = vi.nextVersion();
> >                  System.out.println();
> >                  print(version);
> >              }
> >
> >
> >          } finally {
> >              session.logout();
> >          }
> >      }
> >
> >      public static void print(Node node) throws RepositoryException {
> >          System.out.println("Printing content of node: " + node.getName());
> >          System.out.println(" Properties:");
> >          for (PropertyIterator pi = node.getProperties(); pi.hasNext();) {
> >              Property p = pi.nextProperty();
> >              if (p.getDefinition().isMultiple()) {
> >                  Value[] values = p.getValues();
> >                  for (int i = 0; i < values.length; i++) {
> >                      System.out.println("  - " + p.getName() + ": " +
> > values[i].getString());
> >                  }
> >              } else {
> >                  System.out.println("  - " + p.getName() + ": " +
> > p.getValue().getString());
> >              }
> >          }
> >          System.out.println(" Child nodes:");
> >          for (NodeIterator ni = node.getNodes(); ni.hasNext();) {
> >              Node n = ni.nextNode();
> >              System.out.println("  - " + n.getName());
> >          }
> >      }
> >
> > }
> >
> >
> >
> >
> > Le 14:16 2006-04-25, vous avez écrit:
> > >Hi,
> > >
> > >*Is this a desired behavior ? If not, I will file an issue.
> > >
> > >During a transaction, if you create a new version (checkin + checkout)
> > >then read the version history the "jcr:sucessors" property is not updated.
> > >Note that "jcr:predecessors" is updated properly.
> > >
> > > From what I understand, since the changes are commited immedialy for
> > > checkin (8.2.5), the read should reflect the current status.
> > >
> > >Here's an example to show the situation:
> > >
> > >
> > >package net.sf.archimede;
> > >
> > >import javax.jcr.Node;
> > >import javax.jcr.NodeIterator;
> > >import javax.jcr.Property;
> > >import javax.jcr.PropertyIterator;
> > >import javax.jcr.Repository;
> > >import javax.jcr.RepositoryException;
> > >import javax.jcr.Session;
> > >import javax.jcr.SimpleCredentials;
> > >import javax.jcr.Value;
> > >import javax.jcr.version.Version;
> > >import javax.jcr.version.VersionIterator;
> > >import javax.transaction.UserTransaction;
> > >
> > >//Found in /src/test/
> > >import org.apache.jackrabbit.core.UserTransactionImpl;
> > >
> > >import org.apache.jackrabbit.core.TransientRepository;
> > >
> > >public class VersioningTest {
> > >
> > >     public static void main(String[] args) throws Exception {
> > >         //RepositoryConfig config = RepositoryConfig.create(new
> > > FileInputStream(new File("C:/tmp/repository.xml")), "C:/tmp/repository");
> > >         Repository repository = new
> > > TransientRepository();//RepositoryImpl.create(config);
> > >         Session session = repository.login(
> > >                 new SimpleCredentials("username", 
> "password".toCharArray()));
> > >         try {
> > >
> > >             UserTransaction tx = new UserTransactionImpl(session);
> > >             tx.begin();
> > >             Node rootNode = session.getRootNode();
> > >             Node test = rootNode.addNode("test");
> > >             test.addMixin("mix:versionable");
> > >             session.save();
> > >
> > >             //Create a version
> > >             test.checkin();
> > >             test.checkout();
> > >
> > >             test.checkin();
> > >             test.checkout();
> > >
> > >             //Create another
> > >             test.checkin();
> > >             test.checkout();
> > >
> > >             //Read versions
> > >             for (VersionIterator vi =
> > > test.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
> > >                 Version version = vi.nextVersion();
> > >                 System.out.println();
> > >                 print(version);
> > >             }
> > >
> > >             //Read versions from another session
> > >             Session session2 = repository.login();
> > >             Node test2 = session2.getRootNode().getNode("test");
> > >             for (VersionIterator vi =
> > > test2.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
> > >                 Version version = vi.nextVersion();
> > >                 System.out.println();
> > >                 print(version);
> > >             }
> > >
> > >             //Commit transaction
> > >             tx.commit();
> > >
> > >             //Read versions after transaction
> > >             for (VersionIterator vi =
> > > test.getVersionHistory().getAllVersions(); vi.hasNext(); ) {
> > >                 Version version = vi.nextVersion();
> > >                 System.out.println();
> > >                 print(version);
> > >             }
> > >
> > >         } finally {
> > >             session.logout();
> > >         }
> > >     }
> > >
> > >     public static void print(Node node) throws RepositoryException {
> > >         System.out.println("Printing content of node: " + 
> node.getName());
> > >         System.out.println(" Properties:");
> > >         for (PropertyIterator pi = node.getProperties(); pi.hasNext();) {
> > >             Property p = pi.nextProperty();
> > >             if (p.getDefinition().isMultiple()) {
> > >                 Value[] values = p.getValues();
> > >                 for (int i = 0; i < values.length; i++) {
> > >                     System.out.println("  - " + p.getName() + ": " +
> > > values[i].getString());
> > >                 }
> > >             } else {
> > >                 System.out.println("  - " + p.getName() + ": " +
> > > p.getValue().getString());
> > >             }
> > >         }
> > >         System.out.println(" Child nodes:");
> > >         for (NodeIterator ni = node.getNodes(); ni.hasNext();) {
> > >             Node n = ni.nextNode();
> > >             System.out.println("  - " + n.getName());
> > >         }
> > >     }
> > >
> > >}
> > >
> > >Regards,
> > >
> > >Nicolas
> >
> >
>
>
>--
>-----------------------------------------< 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 >---