if (refName == null && member == null) {
fail(consumer.getJndiConsumerName(), "presistenceContextAnnotation.onClassWithNoName", persistenceContext.unitName());
return;
}
PersistenceContextRef persistenceContextRef = consumer.getPersistenceContextRefMap().get(refName);
if (persistenceContextRef == null) {
persistenceContextRef = new PersistenceContextRef();
persistenceContextRef.setPersistenceUnitName(persistenceContext.unitName());
persistenceContextRef.setPersistenceContextRefName(refName);
if ("EXTENDED".equalsIgnoreCase(persistenceContext.type())) {
persistenceContextRef.setPersistenceContextType(PersistenceContextType.EXTENDED);
} else {
persistenceContextRef.setPersistenceContextType(PersistenceContextType.TRANSACTION);
}
consumer.getPersistenceContextRef().add(persistenceContextRef);
} else {
if (persistenceContextRef.getPersistenceUnitName() == null || ("").equals(persistenceContextRef.getPersistenceUnitName())) {
persistenceContextRef.setPersistenceUnitName(persistenceContext.unitName());
}
if (persistenceContextRef.getPersistenceContextType() == null || ("").equals(persistenceContextRef.getPersistenceContextType())) {
if ("EXTENDED".equalsIgnoreCase(persistenceContext.type())) {
persistenceContextRef.setPersistenceContextType(PersistenceContextType.EXTENDED);
} else {
persistenceContextRef.setPersistenceContextType(PersistenceContextType.TRANSACTION);
}
}
}
List<Property> persistenceProperties = persistenceContextRef.getPersistenceProperty();
if (persistenceProperties == null) {
persistenceProperties = new ArrayList<Property>();
persistenceContextRef.setPersistenceProperty(persistenceProperties);
}
for (Map.Entry<String, String> persistenceProperty : persistenceContext.properties().entrySet()) {
boolean flag = true;
for (Property prpty : persistenceProperties) {
if (prpty.getName().equals(persistenceProperty.getKey())) {
flag = false;
break;
}
}
if (flag) {
Property property = new Property();
property.setName(persistenceProperty.getKey());
property.setValue(persistenceProperty.getValue());
persistenceProperties.add(property);
}
}
if (member != null) {
Class type = member.getType();
if (EntityManagerFactory.class.isAssignableFrom(type)) {
/**
* Was @PersistenceContext mistakenly used when @PersistenceUnit should have been used?
*/
fail(consumer.getJndiConsumerName(), "presistenceContextAnnotation.onEntityManagerFactory", persistenceContextRef.getName());
} else if (!EntityManager.class.isAssignableFrom(type)) {
/**
* Was @PersistenceContext mistakenly used for something that isn't an EntityManager?
*/
fail(consumer.getJndiConsumerName(), "presistenceContextAnnotation.onNonEntityManager", persistenceContextRef.getName());
} else {
// Set the member name where this will be injected
InjectionTarget target = new InjectionTarget();
target.setInjectionTargetClass(member.getDeclaringClass().getName());
target.setInjectionTargetName(member.getName());
persistenceContextRef.getInjectionTarget().add(target);
}
}
}