Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The configuration itself is provided by implementing the CODI DataSourceConfig class. The DataSourceConfig determines whether a JNDI path, a JDBC connection or another DataSource should get used, by just returning the proper values. You can use all the flexible CDI and CODI mechanisms like @ProjectStageActivated, @ExpressionActivated, @Alternative, @Specializes, etc and even if/then/else,... to find the perfect settings for your current runtime environment!

TransactionHelper

This helper allows to execute CDI-unmanaged code blocks in a @Transactional manner. E.g. with the test modules provided by MyFaces CODI you can inject CDI beans and therefore transactional services into a JUnit test. So it's possible to use existing implementations e.g. to create sample data for unit tests or to remove such entries again. If a service doesn't (or shouldn't) provide the needed functionality e.g. for deleting entities, it's possible to use TransactionHelper for such additional logic which should be executed within a transaction.

Note
titleAttention

Please be aware that this helper only works for @Transactional with the default qualifier! If you need the functionality for another EntityManager, then you need to copy this code and adopt it.

Code Block
XML
XML
titleOptional usage of TransactionHelper

MyReslt result = TransactionHelper.getInstance().executeTransactional(new Callable<MyReslt>() {
    public MyReslt call() throws Exception
    {
        EntityManager entityManager = BeanManagerProvider.getInstance().getContextualReference(EntityManager.class);
        entityManager.remove(...);
        return entityManager.find(...);
    }
});