Package javax.persistence

Examples of javax.persistence.PersistenceContext


                (WebServiceRef) field.getAnnotation(WebServiceRef.class);
            lookupFieldResource(context, instance, field, annotation.name());
        }*/
        if (field.isAnnotationPresent(PersistenceContext.class))
        {
            PersistenceContext annotation = field.getAnnotation(PersistenceContext.class);
            lookupFieldResource(context, instance, field, annotation.name());
        }
        if (field.isAnnotationPresent(PersistenceUnit.class))
        {
            PersistenceUnit annotation = field.getAnnotation(PersistenceUnit.class);
            lookupFieldResource(context, instance, field, annotation.name());
        }
    }
View Full Code Here


    private PersistenceContextMetaEntry findPersistenceContextEntry(Class target)
    {
        //TODO support other injection types
        Class currentParamClass = target;
        PersistenceContext persistenceContext;
        while (currentParamClass != null && !Object.class.getName().equals(currentParamClass.getName()))
        {
            for(Field currentField : currentParamClass.getDeclaredFields())
            {
                persistenceContext = currentField.getAnnotation(PersistenceContext.class);
                if(persistenceContext != null)
                {
                    return new PersistenceContextMetaEntry(
                                   currentParamClass,
                                   currentField.getName(),
                                   persistenceContext.unitName(),
                                   PersistenceContextType.EXTENDED.equals(persistenceContext.type()));
                }
            }
            currentParamClass = currentParamClass.getSuperclass();
        }
View Full Code Here

    private Properties properties;

    public PersistenceElement(Member member, PropertyDescriptor pd) {
      super(member, pd);
      AnnotatedElement ae = (AnnotatedElement) member;
      PersistenceContext pc = ae.getAnnotation(PersistenceContext.class);
      PersistenceUnit pu = ae.getAnnotation(PersistenceUnit.class);
      Class<?> resourceType = EntityManager.class;
      if (pc != null) {
        if (pu != null) {
          throw new IllegalStateException("Member may only be annotated with either " +
              "@PersistenceContext or @PersistenceUnit, not both: " + member);
        }
        Properties properties = null;
        PersistenceProperty[] pps = pc.properties();
        if (!ObjectUtils.isEmpty(pps)) {
          properties = new Properties();
          for (PersistenceProperty pp : pps) {
            properties.setProperty(pp.name(), pp.value());
          }
        }
        this.unitName = pc.unitName();
        this.type = pc.type();
        this.properties = properties;
      }
      else {
        resourceType = EntityManagerFactory.class;
        this.unitName = pu.unitName();
View Full Code Here

        metadata = this.injectionMetadataCache.get(clazz);
        if (metadata == null) {
          final InjectionMetadata newMetadata = new InjectionMetadata();
          ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() {
            public void doWith(Field field) {
              PersistenceContext pc = field.getAnnotation(PersistenceContext.class);
              PersistenceUnit pu = field.getAnnotation(PersistenceUnit.class);
              if (pc != null || pu != null) {
                if (Modifier.isStatic(field.getModifiers())) {
                  throw new IllegalStateException("Persistence annotations are not supported on static fields");
                }
                newMetadata.addInjectedField(new PersistenceElement(field, null));
              }
            }
          });
          ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
            public void doWith(Method method) {
              PersistenceContext pc = method.getAnnotation(PersistenceContext.class);
              PersistenceUnit pu = method.getAnnotation(PersistenceUnit.class);
              if (pc != null || pu != null) {
                if (Modifier.isStatic(method.getModifiers())) {
                  throw new IllegalStateException("Persistence annotations are not supported on static methods");
                }
View Full Code Here

    private Properties properties;

    public PersistenceElement(Member member, PropertyDescriptor pd) {
      super(member, pd);
      AnnotatedElement ae = (AnnotatedElement) member;
      PersistenceContext pc = ae.getAnnotation(PersistenceContext.class);
      PersistenceUnit pu = ae.getAnnotation(PersistenceUnit.class);
      Class resourceType = EntityManager.class;
      if (pc != null) {
        if (pu != null) {
          throw new IllegalStateException("Member may only be annotated with either " +
              "@PersistenceContext or @PersistenceUnit, not both: " + member);
        }
        Properties properties = null;
        PersistenceProperty[] pps = pc.properties();
        if (!ObjectUtils.isEmpty(pps)) {
          properties = new Properties();
          for (int i = 0; i < pps.length; i++) {
            PersistenceProperty pp = pps[i];
            properties.setProperty(pp.name(), pp.value());
          }
        }
        this.unitName = pc.unitName();
        this.type = pc.type();
        this.properties = properties;
      }
      else {
        resourceType = EntityManagerFactory.class;
        this.unitName = pu.unitName();
View Full Code Here

    }
  }

  private void addIfPresent(List<AnnotatedMember> metadata, Member member) {
    AnnotatedElement ae = (AnnotatedElement) member;
    PersistenceContext pc = ae.getAnnotation(PersistenceContext.class);
    PersistenceUnit pu = ae.getAnnotation(PersistenceUnit.class);
    if (pc != null) {
      if (pu != null) {
        throw new IllegalStateException(
            "Method may only be annotated with either @PersistenceContext or @PersistenceUnit, not both");
      }
      if (member instanceof Method && ((Method) member).getParameterTypes().length != 1) {
        throw new IllegalStateException("PersistenceContext annotation requires a single-arg method: " + member);
      }
      Properties properties = null;
      PersistenceProperty[] pps = pc.properties();
      if (!ObjectUtils.isEmpty(pps)) {
        properties = new Properties();
        for (int i = 0; i < pps.length; i++) {
          PersistenceProperty pp = pps[i];
          properties.setProperty(pp.name(), pp.value());
        }
      }
      metadata.add(new AnnotatedMember(member, pc.unitName(), pc.type(), properties));
    }
    else if (pu != null) {
      if (member instanceof Method && ((Method) member).getParameterTypes().length != 1) {
        throw new IllegalStateException("PersistenceUnit annotation requires a single-arg method: " + member);
      }
View Full Code Here

        List<Method> methodswithPersistenceContext = classFinder.findAnnotatedMethods(PersistenceContext.class);
        List<Field> fieldswithPersistenceContext = classFinder.findAnnotatedFields(PersistenceContext.class);

        // Class-level annotation
        for (Class cls : classeswithPersistenceContext) {
            PersistenceContext persistenceContext = (PersistenceContext) cls.getAnnotation(PersistenceContext.class);
            if (persistenceContext != null) {
                addPersistenceContext(annotatedApp, persistenceContext, cls, null, null);
            }
        }

        // Method-level annotation
        for (Method method : methodswithPersistenceContext) {
            PersistenceContext persistenceContext = method.getAnnotation(PersistenceContext.class);
            if (persistenceContext != null) {
                addPersistenceContext(annotatedApp, persistenceContext, null, method, null);
            }
        }

        // Field-level annotation
        for (Field field : fieldswithPersistenceContext) {
            PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
            if (persistenceContext != null) {
                addPersistenceContext(annotatedApp, persistenceContext, null, null, field);
            }
        }
View Full Code Here

    private PersistenceContextMetaEntry findPersistenceContextEntry(Class target)
    {
        //TODO support other injection types
        Class currentParamClass = target;
        PersistenceContext persistenceContext;
        while (currentParamClass != null && !Object.class.getName().equals(currentParamClass.getName()))
        {
            for(Field currentField : currentParamClass.getDeclaredFields())
            {
                persistenceContext = currentField.getAnnotation(PersistenceContext.class);
                if(persistenceContext != null)
                {
                    return new PersistenceContextMetaEntry(
                                   currentParamClass,
                                   currentField.getName(),
                                   persistenceContext.unitName(),
                                   PersistenceContextType.EXTENDED.equals(persistenceContext.type()));
                }
            }
            currentParamClass = currentParamClass.getSuperclass();
        }
View Full Code Here

    private PersistenceContextMetaEntry findPersistenceContextEntry(Class target)
    {
        //TODO support other injection types
        Class currentParamClass = target;
        PersistenceContext persistenceContext;
        while (currentParamClass != null && !Object.class.getName().equals(currentParamClass.getName()))
        {
            for(Field currentField : currentParamClass.getDeclaredFields())
            {
                persistenceContext = currentField.getAnnotation(PersistenceContext.class);
                if(persistenceContext != null)
                {
                    return new PersistenceContextMetaEntry(
                                   currentParamClass,
                                   currentField.getName(),
                                   persistenceContext.unitName(),
                                   PersistenceContextType.EXTENDED.equals(persistenceContext.type()));
                }
            }
            currentParamClass = currentParamClass.getSuperclass();
        }
View Full Code Here

    {

        for (final TransformField field : transformation
                .matchFieldsWithAnnotation(PersistenceContext.class))
        {
            final PersistenceContext annotation = field.getAnnotation(PersistenceContext.class);

            field.claim(annotation);

            field.replaceAccess(new FieldValueConduit()
            {
View Full Code Here

TOP

Related Classes of javax.persistence.PersistenceContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.