Package javax.persistence

Examples of javax.persistence.PersistenceContext


    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


        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

                    Field[] fields = Introspection.getDeclaredFields(clazz);
                    for (Field field : fields) {
                        Resource resourceAnnotation;
                        EJB ejbAnnotation;
                        WebServiceRef webServiceRefAnnotation;
                        PersistenceContext persistenceContextAnnotation;
                        PersistenceUnit persistenceUnitAnnotation;
                        if (injections != null && injections.containsKey(field.getName())) {
                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null,
                                    injections.get(field.getName()),
                                    AnnotationCacheEntryType.FIELD));
                        } else if ((resourceAnnotation =
                                field.getAnnotation(Resource.class)) != null) {
                            annotations.add(new AnnotationCacheEntry(field.getName(), null,
                                    resourceAnnotation.name(), AnnotationCacheEntryType.FIELD));
                        } else if ((ejbAnnotation =
                                field.getAnnotation(EJB.class)) != null) {
                            annotations.add(new AnnotationCacheEntry(field.getName(), null,
                                    ejbAnnotation.name(), AnnotationCacheEntryType.FIELD));
                        } else if ((webServiceRefAnnotation =
                                field.getAnnotation(WebServiceRef.class)) != null) {
                            annotations.add(new AnnotationCacheEntry(field.getName(), null,
                                    webServiceRefAnnotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        } else if ((persistenceContextAnnotation =
                                field.getAnnotation(PersistenceContext.class)) != null) {
                            annotations.add(new AnnotationCacheEntry(field.getName(), null,
                                    persistenceContextAnnotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        } else if ((persistenceUnitAnnotation =
                                field.getAnnotation(PersistenceUnit.class)) != null) {
                            annotations.add(new AnnotationCacheEntry(field.getName(), null,
                                    persistenceUnitAnnotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        }
                    }
                }

                // Initialize methods annotations
                Method[] methods = Introspection.getDeclaredMethods(clazz);
                Method postConstruct = null;
                String postConstructFromXml = postConstructMethods.get(clazz.getName());
                Method preDestroy = null;
                String preDestroyFromXml = preDestroyMethods.get(clazz.getName());
                for (Method method : methods) {
                    if (context != null) {
                        // Resource injection only if JNDI is enabled
                        if (injections != null &&
                                Introspection.isValidSetter(method)) {
                            String fieldName = Introspection.getPropertyName(method);
                            if (injections.containsKey(fieldName)) {
                                annotations.add(new AnnotationCacheEntry(
                                        method.getName(),
                                        method.getParameterTypes(),
                                        injections.get(fieldName),
                                        AnnotationCacheEntryType.SETTER));
                                continue;
                            }
                        }
                        Resource resourceAnnotation;
                        EJB ejbAnnotation;
                        WebServiceRef webServiceRefAnnotation;
                        PersistenceContext persistenceContextAnnotation;
                        PersistenceUnit persistenceUnitAnnotation;
                        if ((resourceAnnotation =
                                method.getAnnotation(Resource.class)) != null) {
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    resourceAnnotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if ((ejbAnnotation =
                                method.getAnnotation(EJB.class)) != null) {
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    ejbAnnotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if ((webServiceRefAnnotation =
                                method.getAnnotation(WebServiceRef.class)) != null) {
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    webServiceRefAnnotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if ((persistenceContextAnnotation =
                                method.getAnnotation(PersistenceContext.class)) != null) {
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    persistenceContextAnnotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if ((persistenceUnitAnnotation = method.getAnnotation(PersistenceUnit.class)) != null) {
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
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

    {
     
      if (invocation.hasAnnotation(CommitAfter.class))
      {
     
      final PersistenceContext annotation = invocation.getAnnotation(PersistenceContext.class);
          final EntityTransaction transaction = getTransaction(annotation);
 
          if (transaction != null && !transaction.isActive())
          {
              transaction.begin();
View Full Code Here

    public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model)
    {
        for (final PlasticMethod method : plasticClass
                .getMethodsWithAnnotation(CommitAfter.class))
        {
            PersistenceContext annotation = method.getAnnotation(PersistenceContext.class);

            MethodAdvice advice = annotation == null ? shared : new CommitAfterMethodAdvice(manager);

            method.addAdvice(advice);
        }
View Full Code Here

        if (proxy == null)
        {
            final PlasticProxyFactory proxyFactory = objectLocator.getService("PlasticProxyFactory",
                    PlasticProxyFactory.class);

            final PersistenceContext annotation = annotationProvider
                    .getAnnotation(PersistenceContext.class);

            proxy = proxyFactory.createProxy(EntityManager.class, new ObjectCreator()
            {
                @Override
View Full Code Here

    public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model)
    {
        for (final PlasticField field : plasticClass
                .getFieldsWithAnnotation(PersistenceContext.class))
        {
            final PersistenceContext annotation = field.getAnnotation(PersistenceContext.class);

            field.claim(annotation);

            field.setConduit(new ReadOnlyComponentFieldConduit(plasticClass.getClassName(), field.getName())
            {
View Full Code Here

        }
               
        if(resourceReference.supports(PersistenceContext.class))
        {
            PersistenceContext persistenceContext = resourceReference.getAnnotation(PersistenceContext.class);
            return processor.getEntityManager(persistenceContext, resourceReference.getResourceType());
        }
       
        if(resourceReference.supports(PersistenceUnit.class))
        {
View Full Code Here

                PersistenceContexts persistenceContexts = clazz.getAnnotation(PersistenceContexts.class);
                persistenceContextList.addAll(asList(persistenceContexts.value()));
                pcFactory.addAnnotations(clazz);
            }
            for (Class<?> clazz : classFinder.findAnnotatedClasses(PersistenceContext.class)) {
                PersistenceContext persistenceContext = clazz.getAnnotation(PersistenceContext.class);
                persistenceContextList.add(persistenceContext);
                pcFactory.addAnnotations(clazz);
            }
            for (PersistenceContext pCtx : persistenceContextList) {
                buildPersistenceContext(consumer, pcFactory.create(pCtx, null), null);
            }
            for (Field field : classFinder.findAnnotatedFields(PersistenceContext.class)) {
                PersistenceContext pCtx = field.getAnnotation(PersistenceContext.class);
                Member member = new FieldMember(field);
                buildPersistenceContext(consumer, pcFactory.create(pCtx, member), member);
            }
            for (Method method : classFinder.findAnnotatedMethods(PersistenceContext.class)) {
                PersistenceContext pCtx = method.getAnnotation(PersistenceContext.class);
                Member member = new MethodMember(method);
                buildPersistenceContext(consumer, pcFactory.create(pCtx, member), member);
            }

        }
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.