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); }
@Override public String synchronization() { return persistenceContext.synchronization().name(); }
@Override public ResourceReference<EntityManager> createResource() { final TransactionScopedEntityManager result = new TransactionScopedEntityManager(scopedPuName, new HashMap<>(), entityManagerFactory, context.synchronization(), transactionSynchronizationRegistry, transactionManager); return new SimpleResourceReference<EntityManager>(result); } }
name = n; final SynchronizationType synchronizationType = persistenceContextAnnotation.synchronization(); assert synchronizationType != null; synchronized (this) {
@Override public ResourceReferenceFactory<EntityManager> registerPersistenceContextInjectionPoint (InjectionPoint injectionPoint) { PersistenceUnitHolder holder = PersistenceUnitHolder.getInstance(); PersistenceContext pc = injectionPoint.getAnnotated().getAnnotation(PersistenceContext .class); String unitName = pc.unitName(); if (unitName.isEmpty()) { unitName = holder.getDefaultUnitName(); if (unitName.isEmpty()) { throw new NoDefaultPersistenceUnit(); } } PersistenceWrapper wrapper = holder.getEntityManagerFactory(unitName); return new PersistenceContextResourceFactory(unitName, wrapper.getEntityManagerFactory(), wrapper.getTransactionType(), pc.synchronization()); }
@Override public ResourceReferenceFactory<EntityManager> registerPersistenceContextInjectionPoint (InjectionPoint injectionPoint) { PersistenceUnitHolder holder = PersistenceUnitHolder.getInstance(); PersistenceContext pc = injectionPoint.getAnnotated().getAnnotation(PersistenceContext .class); String unitName = pc.unitName(); if (unitName.isEmpty()) { unitName = holder.getDefaultUnitName(); if (unitName.isEmpty()) { throw new NoDefaultPersistenceUnit(); } } PersistenceWrapper wrapper = holder.getEntityManagerFactory(unitName); return new PersistenceContextResourceFactory(unitName, wrapper.getEntityManagerFactory(), wrapper.getTransactionType(), pc.synchronization()); }
private void processNewEmRefAnnotation (EntityManagerReferenceDescriptor emRef, String logicalName, PersistenceContext annotation) { emRef.setName(logicalName); if( !(annotation.unitName().equals("")) ) { emRef.setUnitName(annotation.unitName()); } emRef.setPersistenceContextType(annotation.type()); emRef.setSynchronizationType(annotation.synchronization()); // Add each property from annotation to descriptor, unless // it has been overridden within the .xml. Map existingProperties = emRef.getProperties(); for(PersistenceProperty next : annotation.properties()) { if( !existingProperties.containsKey(next.name()) ) { emRef.addProperty(next.name(), next.value()); } } }