jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicolas Belisle <Nicolas.Beli...@bibl.ulaval.ca>
Subject jcr:sucessors property not persisted immediatly within a transaction
Date Tue, 25 Apr 2006 18:16:25 GMT
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


Mime
View raw message