public TransactionalEntityManagerSynchronization( EntityManagerHolder emHolder, EntityManagerFactory emf, @Nullable Object txData, boolean newEm) { super(emHolder, emf); this.transactionData = txData; this.jpaDialect = (emf instanceof EntityManagerFactoryInfo ? ((EntityManagerFactoryInfo) emf).getJpaDialect() : null); this.newEntityManager = newEm; }
public TransactionalEntityManagerSynchronization( EntityManagerHolder emHolder, EntityManagerFactory emf, @Nullable Object txData, boolean newEm) { super(emHolder, emf); this.transactionData = txData; this.jpaDialect = (emf instanceof EntityManagerFactoryInfo ? ((EntityManagerFactoryInfo) emf).getJpaDialect() : null); this.newEntityManager = newEm; }
/** * 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(@Nullable 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 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(@Nullable 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 */ @Nullable 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; }
/** * Actually create the EntityManager proxy. * @param rawEntityManager raw EntityManager * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @param containerManaged whether to follow container-managed EntityManager * or application-managed EntityManager semantics * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return the EntityManager proxy */ private static EntityManager createProxy(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean containerManaged, boolean synchronizedWithTransaction) { Assert.notNull(emfInfo, "EntityManagerFactoryInfo must not be null"); JpaDialect jpaDialect = emfInfo.getJpaDialect(); PersistenceUnitInfo pui = emfInfo.getPersistenceUnitInfo(); Boolean jta = (pui != null ? pui.getTransactionType() == PersistenceUnitTransactionType.JTA : null); return createProxy(rawEntityManager, emfInfo.getEntityManagerInterface(), emfInfo.getBeanClassLoader(), jpaDialect, jta, containerManaged, synchronizedWithTransaction); }
@Test public void testExceptionTranslationWithDialectFoundOnIntroducedEntityManagerInfo() throws Exception { doTestExceptionTranslationWithDialectFound(((EntityManagerFactoryInfo) entityManagerFactory).getJpaDialect()); }
/** * Eagerly initialize the JPA dialect, creating a default one * for the specified EntityManagerFactory if none set. * Auto-detect the EntityManagerFactory's DataSource, if any. */ @Override public void afterPropertiesSet() { if (getEntityManagerFactory() == null) { throw new IllegalArgumentException("'entityManagerFactory' or 'persistenceUnitName' is required"); } if (getEntityManagerFactory() instanceof EntityManagerFactoryInfo) { EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) getEntityManagerFactory(); DataSource dataSource = emfInfo.getDataSource(); if (dataSource != null) { setDataSource(dataSource); } JpaDialect jpaDialect = emfInfo.getJpaDialect(); if (jpaDialect != null) { setJpaDialect(jpaDialect); } } }
/** * 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 */ @Nullable 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; }
/** * Actually create the EntityManager proxy. * @param rawEntityManager raw EntityManager * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @param containerManaged whether to follow container-managed EntityManager * or application-managed EntityManager semantics * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return the EntityManager proxy */ private static EntityManager createProxy(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean containerManaged, boolean synchronizedWithTransaction) { Assert.notNull(emfInfo, "EntityManagerFactoryInfo must not be null"); JpaDialect jpaDialect = emfInfo.getJpaDialect(); PersistenceUnitInfo pui = emfInfo.getPersistenceUnitInfo(); Boolean jta = (pui != null ? pui.getTransactionType() == PersistenceUnitTransactionType.JTA : null); return createProxy(rawEntityManager, emfInfo.getEntityManagerInterface(), emfInfo.getBeanClassLoader(), jpaDialect, jta, containerManaged, synchronizedWithTransaction); }
/** * Eagerly initialize the JPA dialect, creating a default one * for the specified EntityManagerFactory if none set. * Auto-detect the EntityManagerFactory's DataSource, if any. */ @Override public void afterPropertiesSet() { if (getEntityManagerFactory() == null) { throw new IllegalArgumentException("'entityManagerFactory' or 'persistenceUnitName' is required"); } if (getEntityManagerFactory() instanceof EntityManagerFactoryInfo) { EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) getEntityManagerFactory(); DataSource dataSource = emfInfo.getDataSource(); if (dataSource != null) { setDataSource(dataSource); } JpaDialect jpaDialect = emfInfo.getJpaDialect(); if (jpaDialect != null) { setJpaDialect(jpaDialect); } } }
public TransactionalEntityManagerSynchronization( EntityManagerHolder emHolder, EntityManagerFactory emf, @Nullable Object txData, boolean newEm) { super(emHolder, emf); this.transactionData = txData; this.jpaDialect = (emf instanceof EntityManagerFactoryInfo ? ((EntityManagerFactoryInfo) emf).getJpaDialect() : null); this.newEntityManager = newEm; }
/** * 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(@Nullable Object transactionData, EntityManagerFactory emf) { if (emf instanceof EntityManagerFactoryInfo) { EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf; JpaDialect jpaDialect = emfInfo.getJpaDialect(); if (jpaDialect != null) { jpaDialect.cleanupTransaction(transactionData); } } }
/** * Actually create the EntityManager proxy. * @param rawEntityManager raw EntityManager * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @param containerManaged whether to follow container-managed EntityManager * or application-managed EntityManager semantics * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return the EntityManager proxy */ private static EntityManager createProxy(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean containerManaged, boolean synchronizedWithTransaction) { Assert.notNull(emfInfo, "EntityManagerFactoryInfo must not be null"); JpaDialect jpaDialect = emfInfo.getJpaDialect(); PersistenceUnitInfo pui = emfInfo.getPersistenceUnitInfo(); Boolean jta = (pui != null ? pui.getTransactionType() == PersistenceUnitTransactionType.JTA : null); return createProxy(rawEntityManager, emfInfo.getEntityManagerInterface(), emfInfo.getBeanClassLoader(), jpaDialect, jta, containerManaged, synchronizedWithTransaction); }