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); }
private static 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(); } return null; }
private static 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(); } return null; }
private static 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(); } return null; }
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()); } }
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); }
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); } }
private PersistenceContextResourceReference createDefinition(String name, Member member, PersistenceContext annotation, InjectingComponentType componentType, IntrospectionContext context) { String unitName = annotation.unitName(); PersistenceContextType type = annotation.type(); if (PersistenceContextType.EXTENDED == type) { InvalidPersistenceContextType error = new InvalidPersistenceContextType("Extended persistence contexts not supported: " + unitName, member, componentType); context.addError(error); } boolean multiThreaded = Scope.COMPOSITE.getScope().equals(componentType.getScope()); return new PersistenceContextResourceReference(name, unitName, factoryServiceContract, multiThreaded); }
private static void loadPersistenceContextClassAnnotation( PersistenceContext ref, InjectionContainer container, Class<?> clazz) { String encName = ref.name(); if (encName == null || encName.equals("")) { throw new RuntimeException( "JBoss requires name() for class level @PersistenceContext"); } encName = "env/" + ref.name(); if (container.getEncInjectors().containsKey(encName)) return; String error = "Unable to load class-level @PersistenceContext(" + ref.unitName() + ") on " + container.getIdentifier(); container.getEncInjectors().put(encName, new PcEncInjector(encName, ref.unitName(), ref.type(), null, error)); try { PersistenceUnitHandler.addPUDependency(ref.unitName(), container); } catch (NameNotFoundException e) { throw new RuntimeException("Illegal @PersistenceUnit on " + clazz.getName() + " of unitname " + ref.unitName() + " :" + e.getMessage()); } }
+ container.getIdentifier() + " failed to inject on field " + field.toString(); container.getEncInjectors().put(encName, new PcEncInjector(encName, ref.unitName(), ref.type(), field.getType(), error));
private PersistenceContextResourceReference createReference(String name, Member member, PersistenceContext annotation, InjectingComponentType componentType, IntrospectionContext context) { String unitName = annotation.unitName(); PersistenceContextType type = annotation.type(); if (PersistenceContextType.EXTENDED == type) { InvalidPersistenceContextType error = new InvalidPersistenceContextType("Extended persistence contexts not supported: " + unitName, member, componentType); context.addError(error); } boolean multiThreaded = Scope.COMPOSITE == componentType.getScope(); return new PersistenceContextResourceReference(name, unitName, factoryServiceContract, multiThreaded); }
private PersistenceContextResourceReference createReference(String name, Member member, PersistenceContext annotation, InjectingComponentType componentType, IntrospectionContext context) { String unitName = annotation.unitName(); PersistenceContextType type = annotation.type(); if (PersistenceContextType.EXTENDED == type) { InvalidPersistenceContextType error = new InvalidPersistenceContextType("Extended persistence contexts not supported: " + unitName, member, componentType); context.addError(error); } boolean multiThreaded = Scope.COMPOSITE == componentType.getScope(); return new PersistenceContextResourceReference(name, unitName, factoryServiceContract, multiThreaded); }
@Override public ConfigProgram introspectField(AnnotatedField<?> field) { PersistenceContext pContext = field.getAnnotation(PersistenceContext.class); PersistenceContextType type = pContext.type(); Field javaField = field.getJavaMember(); String location = getLocation(javaField); if (! javaField.getType().isAssignableFrom(EntityManager.class)) { throw new ConfigException(L.l("{0}: @PersistenceContext field must be assignable from EntityManager.", getLocation(javaField))); } ValueGenerator gen; if (PersistenceContextType.EXTENDED.equals(type)) gen = generateExtendedContext(location, pContext); else gen = generateTransactionContext(location, pContext); return new FieldGeneratorProgram(javaField, gen); } // InjectIntrospector.introspect(_injectProgramList, field);
private void processNewEmRefAnnotation (EntityManagerReferenceDescriptor emRef, String logicalName, PersistenceContext annotation) { emRef.setName(logicalName); if( !(annotation.unitName().equals("")) ) { emRef.setUnitName(annotation.unitName()); } emRef.setPersistenceContextType(annotation.type()); // 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()); } } }
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()); } } }
protected PersistenceContextReferenceMetaData createPC(E element, PersistenceContext annotation) { PersistenceContextReferenceMetaData ref = new PersistenceContextReferenceMetaData(); String name = annotation.name(); if(name.length() == 0) name = ProcessorUtils.getName(element); ref.setPersistenceContextRefName(name); if(annotation.unitName().length() > 0) ref.setPersistenceUnitName(annotation.unitName()); PersistenceContextType type = annotation.type(); ref.setPersistenceContextType(type); PersistenceProperty[] properties = annotation.properties(); if(properties.length > 0 ) { PropertiesMetaData refProperties = new PropertiesMetaData(); for(PersistenceProperty p : properties) { PropertyMetaData pmd = new PropertyMetaData(); pmd.setName(p.name()); pmd.setValue(p.value()); refProperties.add(pmd); } ref.setProperties(refProperties); } Set<ResourceInjectionTargetMetaData> injectionTargets = ProcessorUtils.getInjectionTargets(name, element); if(injectionTargets != null) ref.setInjectionTargets(injectionTargets); return ref; }