3.1.6. Frequently asked questions

Warning

You are looking at documentation for an older release. Not what you want? See the current release documentation.

Q1. How to open and close a session properly to avoid memory leaks?
Q2. What should I use to check if an Item exists before getting the Value?
Q3. Does it make sense to have all the nodes referable to use getNodeByUUID all the time?
Q4. Is it better to use Session.getNodeByUUID or Session.getItem?
Q5. How to use Observation properly?
Q6. What is default query ordering?
Q7. How does eXo JCR indexer use content encoding?
Q8. Can I use Session after logging out?

Q1.

How to open and close a session properly to avoid memory leaks?

Session session = repository.login(credentials);

        try
        {
        // here your code
        }
        finally
        {
        session.logout();
        }
      

Q2.

What should I use to check if an Item exists before getting the Value?

Use Session.itemExists(String absPath), Node.hasNode(String relPath) or Property.hasProperty(String name). It is also possible to check Node.hasNodes() and Node.hasProprties().

Q3.

Does it make sense to have all the nodes referable to use getNodeByUUID all the time?

Until it is applicable for a business logic, it can be. But take into account the paths are human readable and let you think in hierarchy. If it is important, a location based approach is preferable.

Q4.

Is it better to use Session.getNodeByUUID or Session.getItem?

Session.getNodeByUUID() about 2.5 times faster of Session.getItem(String) and only 25% faster of Node.getNode(String). See the daily test results for such comparisons in the following link as the following: http://tests.exoplatform.org/jcr.html

Q5.

How to use Observation properly?

JCR Observation is a way to listen on persistence changes of a Repository. It provides several options to configure the listener for interesting changes only. To use properly, it is important to understand concept of events filtering for a registered EventListener (8.3.3 Observation Manager). An often confusing part, it is the absPath, it is an associated parent of a location you want to observe events on. For example, it is a parent of child node(s) or this parent property(ies); if isDeep is true, then you will get events of all the subtree of child nodes also. The same actual for uuid and nodeTypeName parameters of the ObservationManager.addEventListener() method.

Q6.

What is default query ordering?

By default, (if query does not contain any ordering statements) result nodes are sorted by document order.

Q7.

How does eXo JCR indexer use content encoding?

1. Indexer uses the jcr:encoding property of the nt:resource node (used as the jcr:content child node of nt:file).

2. If no jcr:encoding property is set, the Document Service will use the one configured in the service (defaultEncoding).

3. If nothing is configured a JVM, the default encoding will be used.

Q8.

Can I use Session after logging out?

No. Any instance of Session or Node (acquired through session) should not be used after logging out anymore. At least, it is highly recommended not to use.

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus