Ejemplo n.º 1
0
  @Override
  public ConfigProgram introspectField(AnnotatedField<?> field) {
    PersistenceContext pContext = field.getAnnotation(PersistenceContext.class);

    PersistenceContextType type = pContext.type();

    Field javaField = field.getJavaMember();
    String location = getLocation(javaField);

    if (!javaField.getType().isAssignableFrom(EntityManager.class)) {
      throw new ConfigException(
          L.l(
              "{0}: @PersistenceContext field must be assignable from EntityManager.",
              getLocation(javaField)));
    }

    ValueGenerator gen;

    if (PersistenceContextType.EXTENDED.equals(type))
      gen = generateExtendedContext(location, pContext);
    else gen = generateTransactionContext(location, pContext);

    return new FieldGeneratorProgram(javaField, gen);
  }
 private boolean isExtendedPersistenceContext(final AnnotationInstance annotation) {
   AnnotationValue value = annotation.value("type");
   return annotation.name().local().equals("PersistenceContext")
       && (value != null && PersistenceContextType.EXTENDED.name().equals(value.asString()));
 }