Usage

Usage

Dependencies

Include this dependency in your project:

<dependency> <groupId>org.ops4j.orient</groupId> <artifactId>orient-ra-api</artifactId> <version>${ops4j.orient.version}</version> </dependency>

The main API class is org.ops4j.orient.adapter.api.OrientDatabaseConnection. This class is an interface with the following methods:

public interface OrientDatabaseConnection { ODatabaseDocumentTx document(); OObjectDatabaseTx object(); OGraphDatabase graph(); }

Use one of these methods to obtain a transactional document, object or graph database handle, depending on the type property of your connection configuration. The lifecycle of the connection and the underlying database object is managed by the application server. Do not call close() in your application code.

Injecting a Connection Resource

To work with the JCA Resource Adapter in your application, inject a resource with the appropriate JNDI name defined in your connection configuration. The underlying databases automatically take part in container-managed transactions.

When registering entity classes with an object database, make sure to use a non-transactional method.

@Stateless public class LibraryService { @Resource(lookup = "orient/library") private OrientDatabaseConnection odc; @TransactionAttribute(TransactionAttributeType.NEVER) public void registerEntityClasses() { OEntityManager em = odc.object().getEntityManager(); em.registerEntityClass(Author.class); em.registerEntityClass(Book.class); } public void createEntities() { Book hobbit = odc.object().newInstance(Book.class); hobbit.setTitle("The Hobbit"); odc.object().save(hobbit); } }