Embedded TopLink Essentials (Glassfish)

Compass 2.0 M1 supports an embedded mode when working with TopLink Essentials (which its development is part of the Glassfish project).

Here are the simple steps needed to enable Compass with TopLink Essentials:

First, add the following to your persistence xml file:

1
2
3
4
5
6
7
8
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
  <provider>oracle.toplink.essentials.PersistenceProvider</provider>
  <properties>    
    <!-- ... (other properties) -->
    <property name="toplink.session.customizer" 
         value="org.compass.gps.device.jpa.embedded.toplink.CompassSessionCustomizer" />
  </properties>
</persistence-unit>

This will enable Compass within TopLink Essentials, basically going over all the mapped JPA classes and adding them to Compass automatically if they have the @Searchable annotation.

Now, if we want to completely index the database based on the mappings, we can execute the following code:

1
TopLinkHelper.getCompassGps(emf).index();

Last, if we want to perform a search, we can simply obtain the Compass instance and perform it. Here is the code:

1
Compass compass = TopLinkHelper.getCompass(emf);

That is it. Simple no? Now, Compass comes with support for embedded OpenJPA, Hibernate, and TopLink (as well as EclipseLink, which is very similar to TopLink). More information on the integration can be found in the reference manual.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>