How can I get the property of an older version of a node in jackrabbit?
Asked Answered
H

2

8

I have created the node and created 3 versions.

String path = "/my111";
MyClass m1  = new  MyClass();
m1.setPath(path);
m1.setName("Myname");
m1.setLanguage("English");      
ocm.create(m1);
ocm.save();     

for (int i = 0; i < 4; i++) {
 ocm.checkout(path);
 m1.setName("mz676666" + i);
 ocm.update(m1);
 ocm.save();
 ocm.checkin(path);         
  } 

 VersionIterator iterator = ocm.getAllVersions(path);
 while (iterator.hasNext()) {
      Version version = (Version)iterator.next();
       System.out.println("version::"+version.getName());           
}


Output :

version::jcr:rootVersion
version::1.0
version::1.1
version::1.2
version::1.3

Now i want to get the name of a version 1.2 ..

I tried it through

org.apache.jackrabbit.ocm.version.VersionIterator iterator = ocm.getAllVersions(path);
    while (iterator.hasNext()) {
        Version version = (Version)iterator.next();
        System.out.println("version::"+version.getName());

    MyClass m1 = (MyClass) ocm.getObject(path, version.getName());
    System.out.println(m1.getName());  // But it always print `null`. Why??
}

Can it is possible to fire query and fetch the data?

How i can achieve this?

Please answer this.

Thanks in advance.

Hellbox answered 20/12, 2012 at 8:30 Comment(0)
B
4

It is a long time since I do not work with Jackrabbit, so I might be wrong.

But as far as I remember, the content of a previous version node is stored as a frozen node under the version node.

So, I think you could try to retrieve it with:

VersionIterator iterator = ocm.getAllVersions(path);

while (iterator.hasNext()) {
    Version version = (Version)iterator.next();

    //Here you go:
    MarketingZone m1 = (MarketingZone) version.getFrozenNode();

    System.out.println(m1.getName());

}

Hope this helps.

Boettcher answered 25/12, 2012 at 11:52 Comment(2)
See my edit. Does it work? If not, what error do you receive?Boettcher
I can not try your code because in the snippet you use your own custom class which I don't have. Just tell me the error, so that I can help you further.Boettcher
C
1

Luca was right. Each Version has a frozen node which represents your node at the time it was checked in. You can call methods on it as you would the base node.

Version version = ...
Node node = version.getFrozenNode();
String name = node.getName();

// get a property, eg. someStringProperty
String someStringProperty = node.getProperty("someStringProperty").getString();
Consecrate answered 19/3, 2013 at 15:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.