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 String unitName() { return persistenceContext.unitName(); }
private void injectEntityManager(Object serviceInstance, Field field, PersistenceContext resource) { if (entityManagers == null) { throw new IllegalAccessError("Entity manager not registered"); } Object value = entityManagers.get(resource.unitName()); if (value == null && entityManagers.size() == 1 && "".equals(resource.unitName())) { value = entityManagers.values().iterator().next(); } injectResourceValue(serviceInstance, field, value); }
public <X> X getEntityManager(PersistenceContext persistenceContext, Class<X> clazz) { EntityManager obj = getPersistenceContext(persistenceContext.unitName()); if (obj == null) { logger.log(Level.WARNING, WebBeansLoggerFacade.constructMessage(OWBLogConst.WARN_0014, "@PersistenceContext", persistenceContext.unitName())); } return clazz.cast(obj); }
public static EntityManager getEntityManager(EntityManagerManager entityManagerManager, PersistenceContext annotation) { String unitName = annotation == null ? null : annotation.unitName(); if (InternalUtils.isNonBlank(unitName)) return entityManagerManager.getEntityManager(unitName); Map<String, EntityManager> entityManagers = entityManagerManager.getEntityManagers(); if (entityManagers.size() == 1) return entityManagers.values().iterator().next(); throw new RuntimeException("Unable to locate a single EntityManager. " + "You must provide the persistence unit name as defined in the persistence.xml using the @PersistenceContext annotation."); } }
private static String getPersistenceUnitNameFromPersistenceContext(InjectionPoint injectionPoint) { PersistenceContext context = injectionPoint.getAnnotated().getAnnotation(PersistenceContext.class); String persistenceUnitName = context != null ? context.unitName() : null; if (StringUtils.isEmpty(persistenceUnitName)) persistenceUnitName = null; return persistenceUnitName; }
public static EntityManager getEntityManager(EntityManagerManager entityManagerManager, PersistenceContext annotation) { String unitName = annotation == null ? null : annotation.unitName(); if (InternalUtils.isNonBlank(unitName)) return entityManagerManager.getEntityManager(unitName); Map<String, EntityManager> entityManagers = entityManagerManager.getEntityManagers(); if (entityManagers.size() == 1) return entityManagers.values().iterator().next(); throw new RuntimeException("Unable to locate a single EntityManager. " + "You must provide the persistence unit name as defined in the persistence.xml using the @PersistenceContext annotation."); } }
private static String getPersistenceUnitNameFromPersistenceContext(InjectionPoint injectionPoint) { PersistenceContext context = injectionPoint.getAnnotated().getAnnotation(PersistenceContext.class); String persistenceUnitName = context != null ? context.unitName() : null; if (StringUtils.isEmpty(persistenceUnitName)) persistenceUnitName = null; return persistenceUnitName; }
@Override public void addTransactionCommitAdvice(MethodAdviceReceiver receiver) { for (final Method m : receiver.getInterface().getMethods()) { if (m.getAnnotation(CommitAfter.class) != null) { PersistenceContext annotation = receiver.getMethodAnnotation(m, PersistenceContext.class); receiver.adviseMethod(m, methodAdvices.get(annotation == null ? null : annotation.unitName())); } } }
private HibernateSessionResourceReference createSessionReference(String name, PersistenceContext annotation, InjectingComponentType componentType) { String unitName = annotation.unitName(); boolean multiThreaded = Scope.COMPOSITE == componentType.getScope(); return new HibernateSessionResourceReference(name, unitName, factoryServiceContract, multiThreaded); }
@Override public ResourceReferenceFactory<EntityManager> registerPersistenceContextInjectionPoint(InjectionPoint ip) { PersistenceContext pc = ip.getAnnotated().getAnnotation(PersistenceContext.class); if (pc == null) { throw new IllegalArgumentException("No @PersistenceContext annotation found on EntityManager"); } String name = pc.unitName(); LOG.info("Creating EntityManagerReferenceFactory for unit " + name); return new EntityManagerReferenceFactory(name); }
@Override public ResourceReferenceFactory<EntityManager> registerPersistenceContextInjectionPoint(InjectionPoint ip) { PersistenceContext pc = ip.getAnnotated().getAnnotation(PersistenceContext.class); if (pc == null) { throw new IllegalArgumentException("No @PersistenceContext annotation found on EntityManager"); } String name = pc.unitName(); LOG.info("Creating EntityManagerReferenceFactory for unit " + name); return new EntityManagerReferenceFactory(name); }
private HibernateSessionResourceReference createSessionReference(String name, PersistenceContext annotation, InjectingComponentType componentType) { String unitName = annotation.unitName(); boolean multiThreaded = Scope.COMPOSITE == componentType.getScope(); return new HibernateSessionResourceReference(name, unitName, factoryServiceContract, multiThreaded); }
@Override public ResourceReferenceFactory<EntityManager> registerPersistenceContextInjectionPoint(InjectionPoint ip) { PersistenceContext pc = ip.getAnnotated().getAnnotation(PersistenceContext.class); if (pc == null) { throw new IllegalArgumentException("No @PersistenceContext annotation found on EntityManager"); } String name = pc.unitName(); LOG.info("Creating EntityManagerReferenceFactory for unit " + name); return new EntityManagerReferenceFactory(name); }
private void processPersistenceContextAnnotation(final PersistenceContext persistenceContext) { setStrategy(Strategy.PERSISTENCE); setName(persistenceContext.unitName()); }
@Override public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (final PlasticMethod method : plasticClass.getMethodsWithAnnotation(CommitAfter.class)) { PersistenceContext annotation = method.getAnnotation(PersistenceContext.class); method.addAdvice(methodAdvices.get(annotation == null ? null : annotation.unitName())); } } }
private HibernateSessionResourceReference createSessionDefinition(String name, PersistenceContext annotation, InjectingComponentType componentType) { String unitName = annotation.unitName(); boolean multiThreaded = Scope.COMPOSITE.getScope().equals(componentType.getScope()); return new HibernateSessionResourceReference(name, unitName, factoryServiceContract, multiThreaded); }
PersistenceContextGenerator(String location, PersistenceContext pc) { _location = location; _jndiName = pc.name(); _unitName = pc.unitName(); _type = pc.type(); _properties = new HashMap(); PersistenceProperty[] propertyList = pc.properties(); for (int i = 0; propertyList != null && i < propertyList.length; i++) { PersistenceProperty prop = propertyList[i]; _properties.put(prop.name(), prop.value()); } }
private PersistenceContextResource createDefinition(PersistenceContext annotation, InjectingComponentType componentType) { String name = annotation.name(); String unitName = annotation.unitName(); PersistenceContextType type = annotation.type(); boolean multiThreaded = Scope.COMPOSITE.getScope().equals(componentType.getScope()); return new PersistenceContextResource(name, unitName, type, factoryServiceContract, multiThreaded); } }