Search in sources :

Example 1 with PersistenceUnitInfoImpl

use of org.apache.openejb.persistence.PersistenceUnitInfoImpl in project tomee by apache.

the class ReloadableEntityManagerFactory method setSharedCacheMode.

public synchronized void setSharedCacheMode(final SharedCacheMode mode) {
    final PersistenceUnitInfoImpl info = entityManagerFactoryCallable.getUnitInfo();
    info.setSharedCacheMode(mode);
    final Properties properties = entityManagerFactoryCallable.getUnitInfo().getProperties();
    if (properties.containsKey(JAVAX_PERSISTENCE_SHARED_CACHE_MODE)) {
        properties.setProperty(JAVAX_PERSISTENCE_SHARED_CACHE_MODE, mode.name());
    }
}
Also used : PersistenceUnitInfoImpl(org.apache.openejb.persistence.PersistenceUnitInfoImpl) Properties(java.util.Properties)

Example 2 with PersistenceUnitInfoImpl

use of org.apache.openejb.persistence.PersistenceUnitInfoImpl in project tomee by apache.

the class ReloadableEntityManagerFactory method setTransactionType.

public synchronized void setTransactionType(final PersistenceUnitTransactionType type) {
    final PersistenceUnitInfoImpl info = entityManagerFactoryCallable.getUnitInfo();
    info.setTransactionType(type);
    final Properties properties = entityManagerFactoryCallable.getUnitInfo().getProperties();
    if (properties.containsKey(JAVAX_PERSISTENCE_TRANSACTION_TYPE)) {
        properties.setProperty(JAVAX_PERSISTENCE_TRANSACTION_TYPE, type.name());
    }
}
Also used : PersistenceUnitInfoImpl(org.apache.openejb.persistence.PersistenceUnitInfoImpl) Properties(java.util.Properties)

Example 3 with PersistenceUnitInfoImpl

use of org.apache.openejb.persistence.PersistenceUnitInfoImpl in project tomee by apache.

the class ReloadableEntityManagerFactory method setProperty.

public synchronized void setProperty(final String key, final String value) {
    final PersistenceUnitInfoImpl unitInfo = entityManagerFactoryCallable.getUnitInfo();
    if (unitInfo.getProperties() == null) {
        unitInfo.setProperties(new Properties());
    }
    unitInfo.getProperties().setProperty(key, value);
}
Also used : PersistenceUnitInfoImpl(org.apache.openejb.persistence.PersistenceUnitInfoImpl) Properties(java.util.Properties)

Example 4 with PersistenceUnitInfoImpl

use of org.apache.openejb.persistence.PersistenceUnitInfoImpl 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);
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenEJBException(org.apache.openejb.OpenEJBException) PersistenceUnitInfoImpl(org.apache.openejb.persistence.PersistenceUnitInfoImpl) ValidationMode(javax.persistence.ValidationMode) CommonDataSource(javax.sql.CommonDataSource) InitialContext(javax.naming.InitialContext) CommonDataSource(javax.sql.CommonDataSource) DataSource(javax.sql.DataSource) SharedCacheMode(javax.persistence.SharedCacheMode) NamingException(javax.naming.NamingException) PersistenceUnitTransactionType(javax.persistence.spi.PersistenceUnitTransactionType)

Example 5 with PersistenceUnitInfoImpl

use of org.apache.openejb.persistence.PersistenceUnitInfoImpl in project tomee by apache.

the class ReloadableEntityManagerFactory method setValidationMode.

public synchronized void setValidationMode(final ValidationMode mode) {
    final PersistenceUnitInfoImpl info = entityManagerFactoryCallable.getUnitInfo();
    info.setValidationMode(mode);
    final Properties properties = entityManagerFactoryCallable.getUnitInfo().getProperties();
    if (properties.containsKey(JAVAX_PERSISTENCE_VALIDATION_MODE)) {
        properties.setProperty(JAVAX_PERSISTENCE_VALIDATION_MODE, mode.name());
    }
}
Also used : PersistenceUnitInfoImpl(org.apache.openejb.persistence.PersistenceUnitInfoImpl) Properties(java.util.Properties)

Aggregations

PersistenceUnitInfoImpl (org.apache.openejb.persistence.PersistenceUnitInfoImpl)7 Properties (java.util.Properties)6 ClassFileTransformer (java.lang.instrument.ClassFileTransformer)2 HashMap (java.util.HashMap)2 PersistenceProvider (javax.persistence.spi.PersistenceProvider)2 TempClassLoader (org.apache.openejb.core.TempClassLoader)2 PersistenceClassLoaderHandler (org.apache.openejb.persistence.PersistenceClassLoaderHandler)2 Instrumentation (java.lang.instrument.Instrumentation)1 URLClassLoader (java.net.URLClassLoader)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 SharedCacheMode (javax.persistence.SharedCacheMode)1 ValidationMode (javax.persistence.ValidationMode)1 PersistenceUnitTransactionType (javax.persistence.spi.PersistenceUnitTransactionType)1 CommonDataSource (javax.sql.CommonDataSource)1 DataSource (javax.sql.DataSource)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 ContainerSystem (org.apache.openejb.spi.ContainerSystem)1