Java Code Examples for javax.persistence.spi.PersistenceUnitTransactionType#JTA

The following examples show how to use javax.persistence.spi.PersistenceUnitTransactionType#JTA . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JpaTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
public void testJta() throws Exception {
    transactionType = PersistenceUnitTransactionType.JTA;
    entityManagerFactory = createEntityManagerFactory();

    final Object jpaTestObject = getClass().getClassLoader().loadClass("org.apache.openejb.core.cmp.jpa.JpaTestObject").newInstance();
    set(jpaTestObject, "EntityManagerFactory", EntityManagerFactory.class, entityManagerFactory);
    set(jpaTestObject, "TransactionManager", TransactionManager.class, transactionManager);
    set(jpaTestObject, "NonJtaDs", DataSource.class, nonJtaDs);

    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    invoke(jpaTestObject, "setUp");
    try {
        invoke(jpaTestObject, "jpaLifecycle");
    } finally {
        invoke(jpaTestObject, "tearDown");
    }
}
 
Example 2
Source File: JpaUtils.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public static EntityManagerFactory createEntityManagerFactory(KeycloakSession session, String unitName, Map<String, Object> properties, boolean jta) {
    PersistenceUnitTransactionType txType = jta ? PersistenceUnitTransactionType.JTA : PersistenceUnitTransactionType.RESOURCE_LOCAL;
    List<ParsedPersistenceXmlDescriptor> persistenceUnits = PersistenceXmlParser.locatePersistenceUnits(properties);
    for (ParsedPersistenceXmlDescriptor persistenceUnit : persistenceUnits) {
        if (persistenceUnit.getName().equals(unitName)) {
            List<Class<?>> providedEntities = getProvidedEntities(session);
            for (Class<?> entityClass : providedEntities) {
                // Add all extra entity classes to the persistence unit.
                persistenceUnit.addClasses(entityClass.getName());
            }
            // Now build the entity manager factory, supplying a proxy classloader, so Hibernate will be able
            // to find and load the extra provided entities.
            persistenceUnit.setTransactionType(txType);
            return Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, properties,
                    new ProxyClassLoader(providedEntities)).build();
        }
    }
    throw new RuntimeException("Persistence unit '" + unitName + "' not found");
}
 
Example 3
Source File: FastBootMetadataBuilder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void applyTransactionProperties(PersistenceUnitDescriptor persistenceUnit,
        Map<String, Object> configurationValues) {
    PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionTypeHelper
            .interpretTransactionType(configurationValues.get(JPA_TRANSACTION_TYPE));
    if (transactionType == null) {
        transactionType = persistenceUnit.getTransactionType();
    }
    if (transactionType == null) {
        // is it more appropriate to have this be based on bootstrap entry point (EE vs SE)?
        transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
    }
    boolean hasTransactionStrategy = configurationValues.containsKey(TRANSACTION_COORDINATOR_STRATEGY);
    if (hasTransactionStrategy) {
        LOG.overridingTransactionStrategyDangerous(TRANSACTION_COORDINATOR_STRATEGY);
    } else {
        if (transactionType == PersistenceUnitTransactionType.JTA) {
            configurationValues.put(TRANSACTION_COORDINATOR_STRATEGY,
                    JtaTransactionCoordinatorBuilderImpl.class);
        } else if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL) {
            configurationValues.put(TRANSACTION_COORDINATOR_STRATEGY,
                    JdbcResourceLocalTransactionCoordinatorBuilderImpl.class);
        }
    }
}
 
Example 4
Source File: PersistenceUnitTransactionTypeHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static PersistenceUnitTransactionType interpretTransactionType(Object value) {
	if ( value == null ) {
		return null;
	}

	if ( PersistenceUnitTransactionType.class.isInstance( value ) ) {
		return (PersistenceUnitTransactionType) value;
	}

	final String stringValue = value.toString();
	if ( StringHelper.isEmpty( stringValue ) ) {
		return null;
	}
	else if ( stringValue.equalsIgnoreCase( "JTA" ) ) {
		return PersistenceUnitTransactionType.JTA;
	}
	else if ( stringValue.equalsIgnoreCase( "RESOURCE_LOCAL" ) ) {
		return PersistenceUnitTransactionType.RESOURCE_LOCAL;
	}
	else {
		throw new PersistenceException( "Unknown TransactionType: " + stringValue );
	}
}
 
Example 5
Source File: PersistenceXmlParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static PersistenceUnitTransactionType parseTransactionType(String value) {
	if ( StringHelper.isEmpty( value ) ) {
		return null;
	}
	else if ( value.equalsIgnoreCase( "JTA" ) ) {
		return PersistenceUnitTransactionType.JTA;
	}
	else if ( value.equalsIgnoreCase( "RESOURCE_LOCAL" ) ) {
		return PersistenceUnitTransactionType.RESOURCE_LOCAL;
	}
	else {
		throw new PersistenceException( "Unknown persistence unit transaction type : " + value );
	}
}
 
Example 6
Source File: PersistenceUnitInfoImpl.java    From hibernate-master-class with Apache License 2.0 5 votes vote down vote up
public static PersistenceUnitInfoImpl newJTAPersistenceUnitInfo(
        String persistenceUnitName, List<String> mappingFileNames, Properties properties, DataSource jtaDataSource) {
    PersistenceUnitInfoImpl persistenceUnitInfo = new PersistenceUnitInfoImpl(
        persistenceUnitName, mappingFileNames, properties
    );
    persistenceUnitInfo.jtaDataSource = jtaDataSource;
    persistenceUnitInfo.nonJtaDataSource = null;
    persistenceUnitInfo.transactionType = PersistenceUnitTransactionType.JTA;
    return persistenceUnitInfo;
}
 
Example 7
Source File: MutablePersistenceUnitInfo.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public PersistenceUnitTransactionType getTransactionType() {
	if (this.transactionType != null) {
		return this.transactionType;
	}
	else {
		return (this.jtaDataSource != null ?
				PersistenceUnitTransactionType.JTA : PersistenceUnitTransactionType.RESOURCE_LOCAL);
	}
}
 
Example 8
Source File: MutablePersistenceUnitInfo.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PersistenceUnitTransactionType getTransactionType() {
	if (this.transactionType != null) {
		return this.transactionType;
	}
	else {
		return (this.jtaDataSource != null ?
				PersistenceUnitTransactionType.JTA : PersistenceUnitTransactionType.RESOURCE_LOCAL);
	}
}
 
Example 9
Source File: MutablePersistenceUnitInfo.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public PersistenceUnitTransactionType getTransactionType() {
	if (this.transactionType != null) {
		return this.transactionType;
	}
	else {
		return (this.jtaDataSource != null ?
				PersistenceUnitTransactionType.JTA : PersistenceUnitTransactionType.RESOURCE_LOCAL);
	}
}
 
Example 10
Source File: PersistenceUnitInfoImpl.java    From tutorials with MIT License 4 votes vote down vote up
public PersistenceUnitInfoImpl setJtaDataSource(DataSource jtaDataSource) {
    this.jtaDataSource = jtaDataSource;
    this.nonJtaDataSource = null;
    transactionType = PersistenceUnitTransactionType.JTA;
    return this;
}
 
Example 11
Source File: PersistenceUnitInfoImpl.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public PersistenceUnitInfoImpl setJtaDataSource(DataSource jtaDataSource) {
    this.jtaDataSource = jtaDataSource;
    this.nonJtaDataSource = null;
    transactionType = PersistenceUnitTransactionType.JTA;
    return this;
}
 
Example 12
Source File: PersistenceUnitInfoImpl.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public PersistenceUnitInfoImpl setJtaDataSource(DataSource jtaDataSource) {
    this.jtaDataSource = jtaDataSource;
    this.nonJtaDataSource = null;
    transactionType = PersistenceUnitTransactionType.JTA;
    return this;
}
 
Example 13
Source File: PersistenceUnitInfoImpl.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public PersistenceUnitInfoImpl setJtaDataSource(DataSource jtaDataSource) {
    this.jtaDataSource = jtaDataSource;
    this.nonJtaDataSource = null;
    transactionType = PersistenceUnitTransactionType.JTA;
    return this;
}
 
Example 14
Source File: HibernatePersistenceUnitInfo.java    From tutorials with MIT License 4 votes vote down vote up
public HibernatePersistenceUnitInfo  setJtaDataSource(DataSource jtaDataSource) {
    this.jtaDataSource = jtaDataSource;
    this.nonjtaDataSource = null;
    transactionType = PersistenceUnitTransactionType.JTA;
    return this;
}
 
Example 15
Source File: PersistenceUnitInfoImpl.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
public PersistenceUnitInfoImpl setJtaDataSource(DataSource jtaDataSource) {
    this.jtaDataSource = jtaDataSource;
    this.nonJtaDataSource = null;
    transactionType = PersistenceUnitTransactionType.JTA;
    return this;
}
 
Example 16
Source File: PersistenceUnitInfoImpl.java    From hypersistence-optimizer with Apache License 2.0 4 votes vote down vote up
public PersistenceUnitInfoImpl setJtaDataSource(DataSource jtaDataSource) {
    this.jtaDataSource = jtaDataSource;
    this.nonJtaDataSource = null;
    transactionType = PersistenceUnitTransactionType.JTA;
    return this;
}
 
Example 17
Source File: ExtendedEntityManagerCreator.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 18
Source File: ExtendedEntityManagerCreator.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * 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);
}
 
Example 19
Source File: ExtendedEntityManagerCreator.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: ExtendedEntityManagerCreator.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * 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);
}