EnkiBestPractices

From LucidDB Wiki
Jump to: navigation, search

Best practices for Enki usage.

Contents

Repository Object References

Testing for Equality

Due to Hibernate's use of proxy objects, do not assume that the reference equality operators (== and !=) can be used in place of Object.equals(Object). The latter should be used at all times, since Hibernate may mix proxied and non-proxied objects in the same session under some circumstances. See the EnkiFindBugsPlugin for a way to help detect this error.

Holding References Across Transaction Boundaries

Do not hold repository object references across transaction boundaries. Simple properties of the object may still be read outside of transactions, but may be stall. In addition, if Hibernate requires access to the underlying RDBMS to traverse an association, an exception will be thrown if your code is executing outside of a repository transaction or is executing in a different transaction than the one in which the object was loaded.

If you need to obtain access to an object in a new transaction, the fastest way to look it up use EnkiMDRepository.getByMofId(String, RefClass).

MDR API

Session Boundaries

  • Sessions do not automatically span thread boundaries. Do not load a repository object in one thread and expect to use it in another thread. If multi-threaded access is required, use detachSession() and reattachSession() in org.eigenbase.enki.mdr.EnkiMDRepository[1] to explicitly transfer the session from one thread to another.
  • Sessions should be as short-lived as possible. Once a session is used to manipulate a repository object, it should be assumed to represent an open connection to the repository database. Note, however, that beginning a session does not cause such a connection to be created or allocated. The Enki repository session maps directly to a Hibernate session.

Lookup by MOF ID and Type

The method getByMofId(String) in org.netbeans.mdr.api.MDRepository causes Enki/Hibernate to first look up the object in a MOF ID-to-type lookup table, and then find the object in its table.

It is preferable to use org.eigenbase.enki.mdr.EnkiMDRepository.getByMofId(String, RefClass)[2], which can determine the table from the RefClass information.

Reflective APIs

Avoid refAllOfType

Executing javax.jmi.reflect.RefClass.refAllOfType() requires a full scan of each table which contains a subclass of the class in question. This may result in performance issues.

Product Documentation