@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))); }
@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))); }
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); }
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); }
public <X> X getEntityManagerFactory(PersistenceUnit persistenceUnit, Class<X> clazz) { EntityManagerFactory factory = getPersistenceUnit(persistenceUnit.unitName()); if (factory == null) { logger.log(Level.WARNING, WebBeansLoggerFacade.constructMessage(OWBLogConst.WARN_0014, "@PersistenceUnit", persistenceUnit.unitName())); } return clazz.cast(factory); }
public static EntityManagerFactory getEntityManagerFactory(PersistenceUnit ref, InjectionContainer container) throws NameNotFoundException { return getEntityManagerFactory(ref.unitName(), container); }
@Override public ValueMetaData createValueMetaData(PersistenceUnit annotation) { return new PersistenceUnitValueMetaData(mainDeployer, mainDeployerStructure, resolver, annotation.unitName()); }
private static String getPersistenceUnitNameFromPersistenceUnit(InjectionPoint injectionPoint) { PersistenceUnit persistenceUnit = injectionPoint.getAnnotated().getAnnotation(PersistenceUnit.class); String persistenceUnitName = persistenceUnit != null ? persistenceUnit.unitName() : null; if (StringUtils.isEmpty(persistenceUnitName)) persistenceUnitName = null; return persistenceUnitName; }
private static String getPersistenceUnitNameFromPersistenceUnit(InjectionPoint injectionPoint) { PersistenceUnit persistenceUnit = injectionPoint.getAnnotated().getAnnotation(PersistenceUnit.class); String persistenceUnitName = persistenceUnit != null ? persistenceUnit.unitName() : null; if (StringUtils.isEmpty(persistenceUnitName)) persistenceUnitName = null; return persistenceUnitName; }
@Override public ResourceReferenceFactory<EntityManagerFactory> registerPersistenceUnitInjectionPoint(InjectionPoint ip) { PersistenceUnit pc = ip.getAnnotated().getAnnotation(PersistenceUnit.class); if (pc == null) { throw new IllegalArgumentException("No @PersistenceUnit annotation found on EntityManagerFactory"); } String name = pc.unitName(); LOG.info("Creating EntityManagerFactoryReferenceFactory for unit " + name); return new EntityManagerFactoryReferenceFactory(name); }
PersistenceUnitResourceReference createDefinition(PersistenceUnit annotation) { String name = annotation.name(); String unitName = annotation.unitName(); return new PersistenceUnitResourceReference(name, unitName, factoryServiceContract); } }
@Override public ResourceReferenceFactory<EntityManagerFactory> registerPersistenceUnitInjectionPoint(InjectionPoint ip) { PersistenceUnit pc = ip.getAnnotated().getAnnotation(PersistenceUnit.class); if (pc == null) { throw new IllegalArgumentException("No @PersistenceUnit annotation found on EntityManagerFactory"); } String name = pc.unitName(); LOG.info("Creating EntityManagerFactoryReferenceFactory for unit " + name); return new EntityManagerFactoryReferenceFactory(name); }
PersistenceUnitResourceReference createDefinition(PersistenceUnit annotation) { String name = annotation.name(); String unitName = annotation.unitName(); return new PersistenceUnitResourceReference(name, unitName, factoryServiceContract); } }
PersistenceUnitResourceReference createDefinition(PersistenceUnit annotation) { String name = annotation.name(); String unitName = annotation.unitName(); return new PersistenceUnitResourceReference(name, unitName, factoryServiceContract); } }
@Override public ResourceReferenceFactory<EntityManagerFactory> registerPersistenceUnitInjectionPoint(InjectionPoint ip) { PersistenceUnit pc = ip.getAnnotated().getAnnotation(PersistenceUnit.class); if (pc == null) { throw new IllegalArgumentException("No @PersistenceUnit annotation found on EntityManagerFactory"); } String name = pc.unitName(); LOG.info("Creating EntityManagerFactoryReferenceFactory for unit " + name); return new EntityManagerFactoryReferenceFactory(name); }
PersistenceUnitResource createDefinition(PersistenceUnit annotation) { String name = annotation.name(); String unitName = annotation.unitName(); return new PersistenceUnitResource(name, unitName, factoryServiceContract); } }
@Override protected PropertyDef createPropertyDef(final String propertyName, final AccessTypeDef accessTypeDef, final PersistenceUnit persistenceUnit) { final String name = persistenceUnit.name(); if (!StringUtil.isEmpty(name)) { return createPropertyDef(propertyName, accessTypeDef, name); } final String unitName = persistenceUnit.unitName(); if (StringUtil.isEmpty(unitName)) { return createPropertyDef(propertyName, accessTypeDef); } return createPropertyDef(propertyName, accessTypeDef, createPersistenceUnitComponentDef(unitName)); }
@Override public ResourceReferenceFactory<EntityManagerFactory> registerPersistenceUnitInjectionPoint(final InjectionPoint injectionPoint) { //TODO: cache this stuff final PersistenceUnit context = getResourceAnnotated(injectionPoint).getAnnotation(PersistenceUnit.class); if (context == null) { throw WeldLogger.ROOT_LOGGER.annotationNotFound(PersistenceUnit.class, injectionPoint.getMember()); } final String scopedPuName = getScopedPUName(deploymentUnit, context.unitName(), injectionPoint.getMember()); final ServiceName persistenceUnitServiceName = PersistenceUnitServiceImpl.getPUServiceName(scopedPuName); final ServiceController<?> serviceController = deploymentUnit.getServiceRegistry().getRequiredService(persistenceUnitServiceName); //now we have the service controller, as this method is only called at runtime the service should //always be up final PersistenceUnitServiceImpl persistenceUnitService = (PersistenceUnitServiceImpl) serviceController.getValue(); return new ImmediateResourceReferenceFactory<EntityManagerFactory>(persistenceUnitService.getEntityManagerFactory()); }