Refine search
@PersistenceUnit private EntityManagerFactory emf; @PersistenceUnit( unitName = "CRM" @PersistenceContext private EntityManager em; @PersistenceContext( unitName = "CRM", properties = {
@Override public Object resolve(Injectee injectee) { 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))); }
private String getNameFromAnnotation(Annotation annotation) { String name = null; if (annotation instanceof Resource) { name = ((Resource) annotation).name(); } else if (annotation instanceof EJB) { name = ((EJB) annotation).name(); } else if (annotation instanceof PersistenceUnit) { name = ((PersistenceUnit) annotation).name(); } else if (annotation instanceof PersistenceContext) { name = ((PersistenceContext) annotation).name(); } return name; } }
@PersistenceUnit @SuppressWarnings("rawtypes") public void setSomething(Comparable c) { } }
private String getLookupName( Class annotatedClass, AnnotatedField annotatedField, List<InjectionCapable> injectionResources ) { String lookupName = null; if ( annotatedField.isAnnotationPresent( Resource.class ) ) { Resource resource = annotatedField.getAnnotation( Resource.class ); lookupName = getJndiName( resource.lookup(), resource.mappedName(), resource.name() ); } else if ( annotatedField.isAnnotationPresent( EJB.class ) ) { EJB ejb = annotatedField.getAnnotation( EJB.class ); lookupName = getJndiName(ejb.lookup(), ejb.mappedName(), ejb.name()); } else if ( annotatedField.isAnnotationPresent( WebServiceRef.class ) ) { WebServiceRef webServiceRef = annotatedField.getAnnotation( WebServiceRef.class ); lookupName = getJndiName(webServiceRef.lookup(), webServiceRef.mappedName(), webServiceRef.name()); } else if ( annotatedField.isAnnotationPresent( PersistenceUnit.class ) ) { PersistenceUnit persistenceUnit = annotatedField.getAnnotation( PersistenceUnit.class ); lookupName = getJndiName( persistenceUnit.unitName(), null, persistenceUnit.name() ); } else if ( annotatedField.isAnnotationPresent( PersistenceContext.class ) ) { PersistenceContext persistenceContext = annotatedField.getAnnotation( PersistenceContext.class ); lookupName = getJndiName( persistenceContext.unitName(), null, persistenceContext.name() ); } if ( lookupName == null || lookupName.trim().length() == 0 ) { lookupName = getComponentEnvName( annotatedClass, annotatedField.getJavaMember().getName(), injectionResources ); } return lookupName; }
public PersistenceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); 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.synchronizedWithTransaction = SynchronizationType.SYNCHRONIZED.equals(pc.synchronization()); this.properties = properties; } else { resourceType = EntityManagerFactory.class; this.unitName = pu.unitName(); } checkResourceType(resourceType); }
@Nullable InjectionPoint getInjectionPointIfAvailable(@Nonnull Annotation jpaAnnotation) { Class<? extends Annotation> annotationType = jpaAnnotation.annotationType(); Class<?> jpaClass; String unitName; if (annotationType == PersistenceUnit.class) { jpaClass = EntityManagerFactory.class; unitName = ((PersistenceUnit) jpaAnnotation).unitName(); } else if (annotationType == PersistenceContext.class) { jpaClass = EntityManager.class; unitName = ((PersistenceContext) jpaAnnotation).unitName(); } else { return null; } if (unitName.isEmpty()) { unitName = discoverNameOfDefaultPersistenceUnit(); } return new InjectionPoint(jpaClass, unitName, true); }
public static String getDBName(Class<?> clazz) { String name = JPA.DEFAULT; if (clazz != null) { PersistenceUnit pu = clazz.getAnnotation(PersistenceUnit.class); if (pu != null) { name = pu.name(); } } return name; }
public PersistenceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); 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.synchronizedWithTransaction = SynchronizationType.SYNCHRONIZED.equals(pc.synchronization()); this.properties = properties; } else { resourceType = EntityManagerFactory.class; this.unitName = pu.unitName(); } checkResourceType(resourceType); }
@Override protected void checkFieldAnnotation(Field field, Object instance) throws NamingException, IllegalAccessException { super.checkFieldAnnotation(field, instance); if (field.isAnnotationPresent(EJB.class)) { EJB annotation = field.getAnnotation(EJB.class); lookupFieldResource(context, instance, field, annotation.name()); } /*if (field.isAnnotationPresent(WebServiceRef.class)) { WebServiceRef annotation = (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()); } } }
@PersistenceUnit public void setSomething() { } }
public PersistenceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); 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.synchronizedWithTransaction = SynchronizationType.SYNCHRONIZED.equals(pc.synchronization()); this.properties = properties; } else { resourceType = EntityManagerFactory.class; this.unitName = pu.unitName(); } checkResourceType(resourceType); }
Class<?> iface = AnnotationScanner.getType(member); LOGGER.debug("Injecting {} into prop {} of bean {} with class {}", iface.getSimpleName(), propName, compName, compClass); MutableRefMetadata ref = getServiceRef(cdr, pcAnn.unitName(), iface); compDef.addProperty(propName, ref); MutableRefMetadata emRef = getServiceRef(cdr, pcAnn.unitName(), EntityManager.class); Interceptor interceptor = new JpaInterceptor(container, JPA_COORDINATOR, emRef.getComponentId()); cdr.registerInterceptorWithComponent(compDef, interceptor); Class<?> iface = AnnotationScanner.getType(member); LOGGER.debug("Injecting {} into prop {} of bean {} with class {}", iface.getSimpleName(), propName, compName, compClass); MutableRefMetadata ref = getServiceRef(cdr, puAnn.unitName(), iface); compDef.addProperty(propName, ref);
private void applyToMethod(FacesContext facesContext, Method method, PersistenceUnit unit, Object instance) { if (method.getName().startsWith("set")) { Object value = null; if (unit.name() != null && !"".equals(unit.name().trim())) { value = lookup(facesContext, JAVA_COMP_ENV + unit.name()); } invokeMethod(facesContext, method, instance, value); } }
public class Persistor { @PersistenceContext protected EntityManager superPersistenceContextField; protected EntityManager superPersistenceContext; @PersistenceUnit protected EntityManagerFactory superPersistenceUnitField; protected EntityManagerFactory superPersistenceUnit; @PersistenceContext private void setSuperPersistenceContext(EntityManager superPersistenceContext) { this.superPersistenceContext = superPersistenceContext; } @PersistenceUnit private void setSuperPersistenceUnit(EntityManagerFactory superPersistenceUnit) { this.superPersistenceUnit = superPersistenceUnit; } }
@Override protected void checkFieldAnnotation(Field field, Object instance) throws NamingException, IllegalAccessException { super.checkFieldAnnotation(field, instance); if (field.isAnnotationPresent(EJB.class)) { EJB annotation = field.getAnnotation(EJB.class); lookupFieldResource(context, instance, field, annotation.name()); } /*if (field.isAnnotationPresent(WebServiceRef.class)) { WebServiceRef annotation = (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()); } } }
public static class DefaultPrivatePersistenceUnitField { @PersistenceUnit private EntityManagerFactory emf; }