[ 
https://issues.apache.org/jira/browse/OCM-42?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12849789#action_12849789
 ] 

Dhrubojyoti Kayal commented on OCM-42:
--------------------------------------

I have done tests creating a class which is just like yours and I do not see 
any problem with versioning and OCM. I am using the patch that has been just 
submitted for Jackrabbit 2 OCM. But that should not be a big issue. Here are 
the source code below:

Listing 1 - Page.java
---------------------------


import org.apache.jackrabbit.JcrConstants;

import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;

/**
 * 
 */

/**
 * @author dhrubo
 *
 */
@Node(jcrMixinTypes =JcrConstants.MIX_VERSIONABLE)
public class Page {
        @Field(path=true)
        private String path;
        @Field
        private String docContent;
        
        
        public String getPath() {
                return path;
        }
        public void setPath(String path) {
                this.path = path;
        }
        public String getDocContent() {
                return docContent;
        }
        public void setDocContent(String docContent) {
                this.docContent = docContent;
        }
        
        
}

Listing 2 - VersionTester.java
---------------------------------------
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.jcr.LoginException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.version.VersionException;

import org.apache.jackrabbit.core.TransientRepository;
import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl;
import org.apache.jackrabbit.ocm.mapper.Mapper;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.AnnotationMapperImpl;
import org.apache.jackrabbit.ocm.version.Version;
import org.apache.jackrabbit.ocm.version.VersionIterator;

/**
 * 
 */

/**
 * @author dhrubo
 *
 */
public class VersionTester {
        private Session session;
        /**
         * @param args
         */
        public static void main(String[] args) throws Exception{
                VersionTester vt = new VersionTester();
                
                ObjectContentManager ocm = vt.getOCM();
                // Create a new page - first version
                Page page = new Page();
                page.setPath("/page");
                ocm.insert(page);
                ocm.save();

                // Update the page object with first content and create a new 
version
                page.setDocContent("dc1");
                ocm.checkout("/page");
                ocm.update(page);
                ocm.save();
                ocm.checkin("/page");

                // Update the page object with content 2 and create a new 
version
                page.setDocContent("dc2");
                ocm.checkout("/page");
                ocm.update(page);
                ocm.save();
                ocm.checkin("/page");
                
                // Update the page object with content 3 and create a new 
version
                page.setDocContent("dc2");
                ocm.checkout("/page");
                ocm.update(page);
                ocm.save();
                ocm.checkin("/page");
                
                vt.showAllVersions(ocm);
                vt.cleanUp();
        }
        
        private void showAllVersions(ObjectContentManager ocm) throws 
VersionException {
                VersionIterator versionIterator = ocm.getAllVersions("/page");
                while (versionIterator.hasNext())
                {
                    Version version = (Version) versionIterator.next();
                    System.out.println("version found : "+ version.getName() + 
" - " +
                                          version.getPath() + " - " +  
version.getCreated().getTime());
                }

        }
        
        private ObjectContentManager getOCM() throws LoginException, 
RepositoryException{
                File xml = new 
File("C:/ExperimentalWS/jackrabbit-poc/src/repository.xml");
        File dir = new File("C:/digivault");
        
        Repository repository = new TransientRepository(xml,dir);
        SimpleCredentials adminCred = new SimpleCredentials("admin", 
"admin".toCharArray()); 
        this.session = repository.login(adminCred);
        
        List<Class> classes = new ArrayList<Class>();   
        classes.add(Page.class); 
                        
        Mapper mapper = new AnnotationMapperImpl(classes);
        ObjectContentManager ocm =  new ObjectContentManagerImpl(session, 
mapper);      
        
        return ocm;
        }
        
        private void cleanUp() {
                session.logout();
        }
}

Results
-----------
log4j:WARN No appenders could be found for logger 
(org.apache.jackrabbit.core.TransientRepository).
log4j:WARN Please initialize the log4j system properly.
version found : jcr:rootVersion - 
/jcr:system/jcr:versionStorage/35/c7/76/35c776d6-b8f1-46fe-940f-90ec77d389c8/jcr:rootVersion
 - Thu Mar 25 22:46:50 IST 2010
version found : 1.0 - 
/jcr:system/jcr:versionStorage/35/c7/76/35c776d6-b8f1-46fe-940f-90ec77d389c8/1.0
 - Thu Mar 25 22:46:51 IST 2010
version found : 1.1 - 
/jcr:system/jcr:versionStorage/35/c7/76/35c776d6-b8f1-46fe-940f-90ec77d389c8/1.1
 - Thu Mar 25 22:46:51 IST 2010
version found : 1.2 - 
/jcr:system/jcr:versionStorage/35/c7/76/35c776d6-b8f1-46fe-940f-90ec77d389c8/1.2
 - Thu Mar 25 22:46:51 IST 2010


Note - Jackrabbit does not update the major version number. So this is working 
just as you would expect.
Let me know what is different in your test case.

> OCM Versioning is not working as expected
> -----------------------------------------
>
>                 Key: OCM-42
>                 URL: https://issues.apache.org/jira/browse/OCM-42
>             Project: Jackrabbit OCM
>          Issue Type: Bug
>            Reporter: Sreekanth S Nair
>
> I have an OCM class as given belwo
> @Node(jcrMixinTypes =JcrConstants.MIX_VERSIONABLE)
> public class XYZ  {
> @Field(path=true)
> private String path;
> @Field
> private String docContent;
> // and their closure methods
> }
> Then  i have created a root node as /domainName/moduleName 
> and set XYZ's  path value as /domainName/moduleName/documents.
> I can able to insert and update the XYZ  Objects successfully (i'm doing ocm  
> checkout and checkin at object update time)
> but when try to get the version i'm always getting  root version (means the 
> XYZ object value on update  time). 
> I'm unable to get the base version (means the XYZ object value on insert 
> time).
> If its not a bug...Please direct me how to extract version history. 
> fyi : i used
> ocm.getObject("/domainName/moduleName/documents","1.0") to get the value.
> i've worked based on apache jackrabbit OCM version mgmt site example but 
> didn't work for me.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to