/**
  * Prepare a transaction on the given EntityManager, if possible.
  *
  * @param transactionData arbitrary object that holds transaction data, if any (as returned by
  *     prepareTransaction)
  * @param emf the EntityManagerFactory that the EntityManager has been created with
  * @see JpaDialect#cleanupTransaction
  */
 private static void cleanupTransaction(Object transactionData, EntityManagerFactory emf) {
   if (emf instanceof EntityManagerFactoryInfo) {
     EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf;
     JpaDialect jpaDialect = emfInfo.getJpaDialect();
     if (jpaDialect != null) {
       jpaDialect.cleanupTransaction(transactionData);
     }
   }
 }
 /**
  * Prepare a transaction on the given EntityManager, if possible.
  *
  * @param em the EntityManager to prepare
  * @param emf the EntityManagerFactory that the EntityManager has been created with
  * @return an arbitrary object that holds transaction data, if any (to be passed into
  *     cleanupTransaction)
  * @see JpaDialect#prepareTransaction
  */
 private static Object prepareTransaction(EntityManager em, EntityManagerFactory emf) {
   if (emf instanceof EntityManagerFactoryInfo) {
     EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf;
     JpaDialect jpaDialect = emfInfo.getJpaDialect();
     if (jpaDialect != null) {
       return jpaDialect.prepareTransaction(
           em,
           TransactionSynchronizationManager.isCurrentTransactionReadOnly(),
           TransactionSynchronizationManager.getCurrentTransactionName());
     }
   }
   return null;
 }