Methods Summary |
---|
public static void | addPUDependency(java.lang.String unitName, InjectionContainer container)
PersistenceUnitDeployment deployment = null;
// look in EAR first
deployment = container.getPersistenceUnitDeployment(unitName);
if (deployment != null)
{
container.getDependencyPolicy().addDependency(deployment.getKernelName());
log.debug("***** adding PU dependency from located persistence unit: " + deployment.getKernelName());
return;
}
// probably not deployed yet.
// todo not sure if we should do this in JBoss 5
log.debug("******* could not find PU dependency so adding a default: " + PersistenceUnitDeployment.getDefaultKernelName(unitName));
container.getDependencyPolicy().addDependency(PersistenceUnitDeployment.getDefaultKernelName(unitName));
|
public static javax.persistence.EntityManagerFactory | getEntityManagerFactory(javax.persistence.PersistenceUnit ref, InjectionContainer container)
return getEntityManagerFactory(ref.unitName(), container);
|
public static javax.persistence.EntityManagerFactory | getEntityManagerFactory(java.lang.String unitName, InjectionContainer container)
ManagedEntityManagerFactory managedFactory;
PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(unitName);
if (deployment != null)
{
managedFactory = deployment.getManagedFactory();
}
else
{
return null;
}
return new InjectedEntityManagerFactory(managedFactory);
|
public static java.lang.Object | getFactory(java.lang.Class type, java.lang.String unitName, InjectionContainer container)
if (type != null && type.getName().equals(SessionFactory.class.getName()))
return getSessionFactory(unitName, container);
return getEntityManagerFactory(unitName, container);
|
public static org.jboss.ejb3.entity.ManagedEntityManagerFactory | getManagedEntityManagerFactory(InjectionContainer container, java.lang.String unitName)
ManagedEntityManagerFactory factory;
PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(unitName);
if (deployment != null)
{
factory = deployment.getManagedFactory();
}
else
{
throw new NameNotFoundException("Unable to find persistence unit: " + unitName + " for deployment: " + container.getIdentifier());
}
return factory;
|
private static org.hibernate.SessionFactory | getSessionFactory(java.lang.String ref, InjectionContainer container)
ManagedEntityManagerFactory managedFactory;
PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(ref);
if (deployment != null)
{
managedFactory = deployment.getManagedFactory();
}
else
{
return null;
}
return new InjectedSessionFactory(managedFactory);
|
private static void | handleClassAnnotation(javax.persistence.PersistenceUnit ref, InjectionContainer container, java.lang.Class clazz)
String encName = ref.name();
if (encName == null || encName.equals(""))
{
throw new RuntimeException("JBoss requires name() for class level @PersistenceUnit");
}
encName = "env/" + encName;
if (container.getEncInjectors().containsKey(encName)) return;
container.getEncInjectors().put(encName, new PuEncInjector(encName, null, ref.unitName(), "@PersistenceUnit"));
try
{
addPUDependency(ref.unitName(), container);
}
catch (NameNotFoundException e)
{
throw new RuntimeException("Illegal @PersistenceUnit on " + clazz.getName() + " of unitname " + ref.unitName() + " :" + e.getMessage());
}
|
public void | handleClassAnnotations(java.lang.Class clazz, InjectionContainer container)
PersistenceUnits resources = container.getAnnotation(
PersistenceUnits.class, clazz);
if (resources != null)
{
for (PersistenceUnit ref : resources.value())
{
handleClassAnnotation(ref, container, clazz);
}
}
PersistenceUnit pu = container.getAnnotation(PersistenceUnit.class, clazz);
if (pu != null)
{
handleClassAnnotation(pu, container, clazz);
}
|
public void | handleFieldAnnotations(java.lang.reflect.Field field, InjectionContainer container, java.util.Map injectors)
PersistenceUnit ref = field.getAnnotation(PersistenceUnit.class);
if (ref == null) return;
String encName = ref.name();
if (encName == null || encName.equals(""))
{
encName = InjectionUtil.getEncName(field);
}
else
{
encName = "env/" + encName;
}
if (!container.getEncInjectors().containsKey(encName))
{
container.getEncInjectors().put(encName, new PuEncInjector(encName, field.getType(), ref.unitName(), "@PersistenceUnit"));
try
{
if (!field.isAnnotationPresent(IgnoreDependency.class)) addPUDependency(ref.unitName(), container);
}
catch (NameNotFoundException e)
{
throw new RuntimeException("Illegal @PersistenceUnit on " + field + " :" + e.getMessage());
}
}
injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
|
public void | handleMethodAnnotations(java.lang.reflect.Method method, InjectionContainer container, java.util.Map injectors)
PersistenceUnit ref = method.getAnnotation(PersistenceUnit.class);
if (ref == null) return;
if (!method.getName().startsWith("set"))
throw new RuntimeException("@PersistenceUnit can only be used with a set method: " + method);
String encName = ref.name();
if (encName == null || encName.equals(""))
{
encName = InjectionUtil.getEncName(method);
}
else
{
encName = "env/" + encName;
}
if (!container.getEncInjectors().containsKey(encName))
{
container.getEncInjectors().put(encName, new PuEncInjector(encName, method.getParameterTypes()[0], ref.unitName(), "@PersistenceUnit"));
try
{
if (!method.isAnnotationPresent(IgnoreDependency.class)) addPUDependency(ref.unitName(), container);
}
catch (NameNotFoundException e)
{
throw new RuntimeException("Illegal @PersistenceUnit on " + method + " :" + e.getMessage());
}
}
injectors.put(method, new JndiMethodInjector(method, encName, container.getEnc()));
|
public void | loadXml(org.jboss.metamodel.descriptor.EnvironmentRefGroup xml, InjectionContainer container)
if (xml == null) return;
if (xml.getPersistenceUnitRefs() == null) return;
for (PersistenceUnitRef ref : xml.getPersistenceUnitRefs())
{
String encName = "env/" + ref.getRefName();
// we add injection target no matter what. enc injection might be overridden but
// XML injection cannot be overriden
Class injectionType = InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections());
if (container.getEncInjectors().containsKey(encName))
return;
container.getEncInjectors().put(encName, new PuEncInjector(encName, injectionType, ref.getUnitName(), "<persistence-unit-ref>"));
try
{
addPUDependency(ref.getUnitName(), container);
}
catch (NameNotFoundException e)
{
throw new RuntimeException("Illegal <persistence-unit-ref> of " + ref.getRefName() + " :" + e.getMessage());
}
}
|