private void writePersistenceUnit(Field field) throws XMLStreamException {
   PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
   if (persistenceUnit != null) {
     writer.writeCharacters("    ");
     writer.writeEmptyElement("jpa", "context", NS_JPA);
     writer.writeAttribute("unitname", persistenceUnit.unitName());
     writer.writeAttribute("property", field.getName());
     writer.writeCharacters("\n");
   }
 }
Ejemplo n.º 2
0
    @Override
    public Object resolve(final Injectee injectee, final ServiceHandle<?> root) {
      if (!injectee.getRequiredType().equals(EntityManagerFactory.class)) {
        return null;
      }

      final PersistenceUnit annotation = injectee.getParent().getAnnotation(PersistenceUnit.class);
      final String unitName = annotation.unitName();

      if (!persistenceUnits.containsKey(unitName)) {
        throw new ContainerException(
            LocalizationMessages.PERSISTENCE_UNIT_NOT_CONFIGURED(unitName));
      }

      return Proxy.newProxyInstance(
          this.getClass().getClassLoader(),
          new Class[] {EntityManagerFactory.class},
          new ThreadLocalNamedInvoker<EntityManagerFactory>(persistenceUnits.get(unitName)));
    }