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