Methods Summary |
---|
public void | addDependencies(org.jboss.ejb3.DependencyPolicy policy)
Properties props = getXml().getProps();
if (!props.containsKey("jboss.no.implicit.datasource.dependency"))
{
if (getXml().getJtaDatasource() != null)
{
String ds = getXml().getJtaDatasource();
policy.addDatasource(ds);
}
if (getXml().getNonJtaDatasource() != null)
{
String ds = getXml().getNonJtaDatasource();
policy.addDatasource(ds);
}
}
for (Object prop : props.keySet())
{
String property = (String)prop;
if (property.startsWith("jboss.depends"))
{
policy.addDependency(props.getProperty(property));
}
}
|
public javax.persistence.EntityManagerFactory | getActualFactory()
return actualFactory;
|
public static java.lang.String | getDefaultKernelName(java.lang.String unitName)
int hashIndex = unitName.indexOf('#");
if (hashIndex != -1)
{
String relativePath = unitName.substring(3, hashIndex);
String name = unitName.substring(hashIndex + 1);
return "persistence.units:jar=" + relativePath + "," + "unitName=" + name;
}
return "persistence.units:unitName=" + unitName;
|
public org.jboss.ejb3.Ejb3Deployment | getDeployment()
return deployment;
|
public java.lang.String | getEntityManagerName()
return xml.getName() == null ? "" : xml.getName();
|
protected java.lang.String | getJaccContextId()
return di.getShortName();
|
public java.lang.String | getKernelName()
return kernelName;
|
public ManagedEntityManagerFactory | getManagedFactory()
if(managedFactory == null)
log.warn("managed factory is null, persistence unit " + kernelName + " has not yet been started");
return managedFactory;
|
public org.hibernate.ejb.packaging.PersistenceMetadata | getXml()
return xml;
|
public boolean | isScoped()
return scoped;
|
public void | start()
log.info("Starting persistence unit " + kernelName);
Properties props = new Properties();
props.putAll(di.getDefaultPersistenceProperties());
props.put(HibernatePersistence.JACC_CONTEXT_ID, getJaccContextId());
PersistenceUnitInfoImpl pi = new PersistenceUnitInfoImpl();
pi.setClassLoader(di.getClassLoader());
ArrayList<URL> jarFiles = new ArrayList<URL>();
pi.setJarFiles(jarFiles);
pi.setPersistenceProviderClassName(HibernatePersistence.class.getName());
log.debug("Found persistence.xml file in EJB3 jar");
props.putAll(xml.getProps());
pi.setManagedClassnames(xml.getClasses());
pi.setPersistenceUnitName(xml.getName());
pi.setMappingFileNames(xml.getMappingFiles());
pi.setExcludeUnlistedClasses(xml.getExcludeUnlistedClasses());
pi.setPersistenceUnitRootUrl(di.getUrl());
// PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionType.JTA;
// if ("RESOURCE_LOCAL".equals(xml.getTransactionType()))
// transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
PersistenceUnitTransactionType transactionType = xml.getTransactionType();
pi.setTransactionType(transactionType);
for (String jar : xml.getJarFiles())
{
jarFiles.add(deployment.getDeploymentUnit().getRelativeURL(jar));
}
if (xml.getProvider() != null) pi.setPersistenceProviderClassName(xml.getProvider());
if (explicitEntityClasses.size() > 0)
{
List<String> classes = pi.getManagedClassNames();
if (classes == null) classes = explicitEntityClasses;
else classes.addAll(explicitEntityClasses);
pi.setManagedClassnames(classes);
}
if (xml.getJtaDatasource() != null)
{
pi.setJtaDataSource((javax.sql.DataSource) initialContext.lookup(xml.getJtaDatasource()));
}
else if (transactionType == PersistenceUnitTransactionType.JTA)
{
throw new RuntimeException("You have not defined a jta-data-source for a JTA enabled persistence context named: " + xml.getName());
}
if (xml.getNonJtaDatasource() != null)
{
pi.setNonJtaDataSource((javax.sql.DataSource) initialContext.lookup(xml.getNonJtaDatasource()));
}
else if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL)
{
throw new RuntimeException("You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: " + xml.getName());
}
pi.setProperties(props);
if (pi.getPersistenceUnitName() == null)
{
throw new RuntimeException("you must specify a name in persistence.xml");
}
Class providerClass = Thread.currentThread().getContextClassLoader().loadClass(pi.getPersistenceProviderClassName());
// EJBTHREE-893
if(!pi.getProperties().containsKey("hibernate.session_factory_name"))
{
pi.getProperties().put("hibernate.session_factory_name", kernelName);
}
PersistenceProvider pp = (PersistenceProvider) providerClass.newInstance();
actualFactory = pp.createContainerEntityManagerFactory(pi, null);
managedFactory = new ManagedEntityManagerFactory(actualFactory, kernelName);
String entityManagerJndiName = (String) props.get("jboss.entity.manager.jndi.name");
if (entityManagerJndiName != null)
{
EntityManager injectedManager = new TransactionScopedEntityManager(managedFactory);
NonSerializableFactory.rebind(initialContext, entityManagerJndiName, injectedManager);
}
String entityManagerFactoryJndiName = (String) props.get("jboss.entity.manager.factory.jndi.name");
if (entityManagerFactoryJndiName != null)
{
EntityManagerFactory injectedFactory = new InjectedEntityManagerFactory(managedFactory);
NonSerializableFactory.rebind(initialContext, entityManagerFactoryJndiName, injectedFactory);
}
|
public void | stop()
log.info("Stopping persistence unit " + kernelName);
String entityManagerJndiName = (String) xml.getProps().get("jboss.entity.manager.jndi.name");
if (entityManagerJndiName != null)
{
NonSerializableFactory.unbind(initialContext, entityManagerJndiName);
}
String entityManagerFactoryJndiName = (String) xml.getProps().get("jboss.entity.manager.factory.jndi.name");
if (entityManagerFactoryJndiName != null)
{
NonSerializableFactory.unbind(initialContext, entityManagerFactoryJndiName);
}
managedFactory.destroy();
|