use of javax.persistence.spi.PersistenceUnitTransactionType in project aries by apache.
the class JPAEntityManagerProviderFactoryImpl method validateEMF.
private void validateEMF(EntityManagerFactory emf) {
Object o = emf.getProperties().get("javax.persistence.transactionType");
PersistenceUnitTransactionType tranType;
if (o instanceof PersistenceUnitTransactionType) {
tranType = (PersistenceUnitTransactionType) o;
} else if (o instanceof String) {
tranType = PersistenceUnitTransactionType.valueOf(o.toString());
} else {
//TODO log this?
tranType = RESOURCE_LOCAL;
}
if (RESOURCE_LOCAL != tranType) {
throw new IllegalArgumentException("The supplied EntityManagerFactory is not declared RESOURCE_LOCAL");
}
}
use of javax.persistence.spi.PersistenceUnitTransactionType in project hibernate-orm by hibernate.
the class PersistenceXmlParser method bindPersistenceUnit.
private void bindPersistenceUnit(ParsedPersistenceXmlDescriptor persistenceUnit, Element persistenceUnitElement) {
final String name = persistenceUnitElement.getAttribute("name");
if (StringHelper.isNotEmpty(name)) {
LOG.tracef("Persistence unit name from persistence.xml : %s", name);
persistenceUnit.setName(name);
}
final PersistenceUnitTransactionType transactionType = parseTransactionType(persistenceUnitElement.getAttribute("transaction-type"));
if (transactionType != null) {
persistenceUnit.setTransactionType(transactionType);
}
NodeList children = persistenceUnitElement.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) children.item(i);
String tag = element.getTagName();
if (tag.equals("non-jta-data-source")) {
persistenceUnit.setNonJtaDataSource(extractContent(element));
} else if (tag.equals("jta-data-source")) {
persistenceUnit.setJtaDataSource(extractContent(element));
} else if (tag.equals("provider")) {
persistenceUnit.setProviderClassName(extractContent(element));
} else if (tag.equals("class")) {
persistenceUnit.addClasses(extractContent(element));
} else if (tag.equals("mapping-file")) {
persistenceUnit.addMappingFiles(extractContent(element));
} else if (tag.equals("jar-file")) {
persistenceUnit.addJarFileUrl(ArchiveHelper.getURLFromPath(extractContent(element)));
} else if (tag.equals("exclude-unlisted-classes")) {
persistenceUnit.setExcludeUnlistedClasses(extractBooleanContent(element, true));
} else if (tag.equals("delimited-identifiers")) {
persistenceUnit.setUseQuotedIdentifiers(true);
} else if (tag.equals("validation-mode")) {
persistenceUnit.setValidationMode(extractContent(element));
} else if (tag.equals("shared-cache-mode")) {
persistenceUnit.setSharedCacheMode(extractContent(element));
} else if (tag.equals("properties")) {
NodeList props = element.getChildNodes();
for (int j = 0; j < props.getLength(); j++) {
if (props.item(j).getNodeType() == Node.ELEMENT_NODE) {
Element propElement = (Element) props.item(j);
if (!"property".equals(propElement.getTagName())) {
continue;
}
String propName = propElement.getAttribute("name").trim();
String propValue = propElement.getAttribute("value").trim();
if (StringHelper.isEmpty(propValue)) {
// fall back to the natural (Hibernate) way of description
propValue = extractContent(propElement, "");
}
persistenceUnit.getProperties().put(propName, propValue);
}
}
}
}
}
}
use of javax.persistence.spi.PersistenceUnitTransactionType in project hibernate-orm by hibernate.
the class EntityManagerFactoryBuilderImpl method applyTransactionProperties.
private void applyTransactionProperties(StandardServiceRegistryBuilder ssrBuilder) {
PersistenceUnitTransactionType txnType = PersistenceUnitTransactionTypeHelper.interpretTransactionType(configurationValues.get(JPA_TRANSACTION_TYPE));
if (txnType == null) {
txnType = persistenceUnit.getTransactionType();
}
if (txnType == null) {
// is it more appropriate to have this be based on bootstrap entry point (EE vs SE)?
txnType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
}
boolean hasTxStrategy = configurationValues.containsKey(TRANSACTION_COORDINATOR_STRATEGY);
if (hasTxStrategy) {
LOG.overridingTransactionStrategyDangerous(TRANSACTION_COORDINATOR_STRATEGY);
} else {
if (txnType == PersistenceUnitTransactionType.JTA) {
ssrBuilder.applySetting(TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class);
} else if (txnType == PersistenceUnitTransactionType.RESOURCE_LOCAL) {
ssrBuilder.applySetting(TRANSACTION_COORDINATOR_STRATEGY, JdbcResourceLocalTransactionCoordinatorBuilderImpl.class);
}
}
}
use of javax.persistence.spi.PersistenceUnitTransactionType in project aries by apache.
the class JPAEntityManagerProviderFactoryImpl method validateEMF.
private void validateEMF(EntityManagerFactory emf) {
Object o = emf.getProperties().get("javax.persistence.transactionType");
PersistenceUnitTransactionType tranType;
if (o instanceof PersistenceUnitTransactionType) {
tranType = (PersistenceUnitTransactionType) o;
} else if (o instanceof String) {
tranType = PersistenceUnitTransactionType.valueOf(o.toString());
} else {
//TODO log this?
tranType = JTA;
}
if (JTA != tranType) {
throw new IllegalArgumentException("The supplied EntityManagerFactory is not declared RESOURCE_LOCAL");
}
}
use of javax.persistence.spi.PersistenceUnitTransactionType in project tomee by apache.
the class PersistenceBuilder method createEntityManagerFactory.
public ReloadableEntityManagerFactory createEntityManagerFactory(final PersistenceUnitInfo info, final ClassLoader classLoader, final Map<ComparableValidationConfig, ValidatorFactory> validators, final boolean hasCdi) throws Exception {
final PersistenceUnitInfoImpl unitInfo = new PersistenceUnitInfoImpl(persistenceClassLoaderHandler);
// Persistence Unit Id
unitInfo.setId(info.id);
// Persistence Unit Name
unitInfo.setPersistenceUnitName(info.name);
// Persistence Provider Class Name
unitInfo.setPersistenceProviderClassName(info.provider);
// ClassLoader
unitInfo.setClassLoader(classLoader);
// Exclude Unlisted Classes
unitInfo.setExcludeUnlistedClasses(info.excludeUnlistedClasses);
unitInfo.setLazilyInitialized(info.webappName != null || "true".equalsIgnoreCase(info.properties.getProperty("tomee.jpa.factory.lazy", SystemInstance.get().getProperty("tomee.jpa.factory.lazy", "false"))));
final Context context = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext();
// JTA Datasource
String jtaDataSourceId = info.jtaDataSource;
unitInfo.setJtaDataSourceName(jtaDataSourceId);
if (jtaDataSourceId != null) {
if (!SystemInstance.get().hasProperty("openejb.geronimo")) {
final String initialJndiName = jtaDataSourceId;
try {
if (!jtaDataSourceId.startsWith("java:openejb/Resource/") && !jtaDataSourceId.startsWith("openejb/Resource/")) {
jtaDataSourceId = "openejb/Resource/" + jtaDataSourceId;
}
final CommonDataSource jtaDataSource = (CommonDataSource) context.lookup(jtaDataSourceId);
unitInfo.setJtaDataSource(jtaDataSource);
} catch (final NamingException e) {
try {
unitInfo.setJtaDataSource((DataSource) new InitialContext().lookup(initialJndiName));
} catch (final NamingException ne) {
throw new OpenEJBException("Could not lookup <jta-data-source> '" + jtaDataSourceId + "' for unit '" + unitInfo.getPersistenceUnitName() + "'", e);
}
}
}
}
// Managed Class Names
unitInfo.setManagedClassNames(info.classes);
// Mapping File Names
unitInfo.setMappingFileNames(info.mappingFiles);
// Handle Properties
unitInfo.setProperties(info.properties);
// Schema version of the persistence.xml file
unitInfo.setPersistenceXMLSchemaVersion(info.persistenceXMLSchemaVersion);
// Second-level cache mode for the persistence unit
final SharedCacheMode sharedCacheMode = Enum.valueOf(SharedCacheMode.class, info.sharedCacheMode);
unitInfo.setSharedCacheMode(sharedCacheMode);
// The validation mode to be used for the persistence unit
final ValidationMode validationMode = Enum.valueOf(ValidationMode.class, info.validationMode);
unitInfo.setValidationMode(validationMode);
// Persistence Unit Transaction Type
final PersistenceUnitTransactionType type = Enum.valueOf(PersistenceUnitTransactionType.class, info.transactionType);
unitInfo.setTransactionType(type);
// Non JTA Datasource
String nonJtaDataSourceId = info.nonJtaDataSource;
unitInfo.setNonJtaDataSourceName(nonJtaDataSourceId);
if (nonJtaDataSourceId != null) {
if (!SystemInstance.get().hasProperty("openejb.geronimo")) {
final String initialJndiName = nonJtaDataSourceId;
try {
if (!nonJtaDataSourceId.startsWith("java:openejb/Resource/")) {
nonJtaDataSourceId = "java:openejb/Resource/" + nonJtaDataSourceId;
}
final CommonDataSource nonJtaDataSource = (CommonDataSource) context.lookup(nonJtaDataSourceId);
unitInfo.setNonJtaDataSource(nonJtaDataSource);
} catch (final NamingException e) {
try {
unitInfo.setNonJtaDataSource((DataSource) new InitialContext().lookup(initialJndiName));
} catch (final NamingException ne) {
throw new OpenEJBException("Could not lookup <non-jta-data-source> '" + nonJtaDataSourceId + "' for unit '" + unitInfo.getPersistenceUnitName() + "'", e);
}
}
}
}
// Persistence Unit Root Url
unitInfo.setRootUrlAndJarUrls(info.persistenceUnitRootUrl, info.jarFiles);
// create the persistence provider
final String persistenceProviderClassName = unitInfo.getPersistenceProviderClassName();
unitInfo.setPersistenceProviderClassName(persistenceProviderClassName);
final EntityManagerFactoryCallable callable = new EntityManagerFactoryCallable(persistenceProviderClassName, unitInfo, classLoader, validators, hasCdi);
return new ReloadableEntityManagerFactory(classLoader, callable, unitInfo);
}
Aggregations