Dev/jta

= Firebase JTA Support =

Note: This page is relevant for Firebase 1.9 or greater.

Firebase supports JTA for ordinary JDBC data sources and JPA archives. This page will briefly detail the configuration and considerations needed to enable this in games and services.

Requirements
You need an intermediate understanding of Firebase and transactional services to understand this page.

Data Sources
You can either use a full XA data source or let Firebase emulate XA functionality for you. Full XA support may be expensive, and is not supported by all drivers. In either case you deploy such data sources normally.

XA Data Source Example
This is an example of an XA data source deployment file. Properties passed to the data source are prefixed 'ds.'.

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> LOCAL-TX oracle.jdbc.xa.client.OracleXADataSource jdbc:oracle:thin:@localhost:1521:XE password1 user1

Emulated XA Data Source Example
This is an example of an emulated XA data source deployment file. The 'tx-type' property is set, which indicates that this is a normal driver which should be emulated.

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> LOCAL-TX com.mysql.jdbc.Driver jdbc:mysql://localhost/test1 password1 user1

Firebase Configuration
You need to enable JTA for the event execution per type, and you do this in the cluster properties.

service.space.tablespace.jta-enabled=true
 * 1) enable JTA for games (tables)

service.space.mttspace.jta-enabled=true
 * 1) enable JTA for tournaments (mtt)

service..jta-enabled
 * 1) enable JTA for routable services

JTA can be enabled per routable service, but if you want JTA for all executing events, you can enable it globally.

service.jta-enabled=true
 * 1) enable JTA for all events

JPA
To enable JTA for JPA you need to configure the persistence archive to use a JTA data source. You do this by pointing out the deployed data source via JNDI. Firebase mounts the data sources under 'comp/env/jdbc', so if your data source is named 'game-db' it will be accessible under this JNDI path:

java:comp/env/jdbc/game-db

You also explicitly need to configure the persistence archive to use JTA transactions.

Hibernate JTA Platform
In order for Hibernate to interact with the Firebase JTA system, you should implement a 'jta platform'. This is easy to do by extending the existing abstract base classes in Hibernate. For example:

package test;

import javax.transaction.TransactionManager; import javax.transaction.UserTransaction;

import org.hibernate.service.jta.platform.internal.AbstractJtaPlatform;

public class FirebaseJtaPlatform extends AbstractJtaPlatform {

private static final long serialVersionUID = 1135227572057735590L; public static final String TM_NAME = "java:comp/env/TransactionManager"; public static final String UT_NAME = "java:comp/env/UserTransaction";

@Override protected TransactionManager locateTransactionManager { return (TransactionManager) jndiService.locate( TM_NAME ); }

@Override protected UserTransaction locateUserTransaction { return (UserTransaction) jndiService.locate( UT_NAME ); } }

The above class is then configured in the persistence archive like so:



Example Hibernate Persistence XML
Below is an example persistence archive configuration for Hibernate, with JTA enabled using a 'game-db' data source (which must be an XA or an emulated data source) for MySQL, and the above Firebase JTA platform.

  org.hibernate.ejb.HibernatePersistence java:comp/env/jdbc/game-db    