/**
* Checks class descriptors for {@link @RemoveMapping} and {@link RemoveMappings} annotations at the class level
* and removes any specified mappings from the ClassDescriptor.
*
* @param session the current session.
*/
protected void handleRemoveMapping(Session session) {
Map<Class, ClassDescriptor> descriptors = session.getDescriptors();
if (descriptors == null || descriptors.isEmpty()) {
return;
}
for (ClassDescriptor classDescriptor : descriptors.values()) {
List<DatabaseMapping> mappingsToRemove = new ArrayList<DatabaseMapping>();
List<RemoveMapping> removeMappings = scanForRemoveMappings(classDescriptor);
for (RemoveMapping removeMapping : removeMappings) {
if (StringUtils.isBlank(removeMapping.name())) {
throw DescriptorException.attributeNameNotSpecified();
}
DatabaseMapping databaseMapping = classDescriptor.getMappingForAttributeName(removeMapping.name());
if (databaseMapping == null) {
throw DescriptorException.mappingForAttributeIsMissing(removeMapping.name(), classDescriptor);
}
mappingsToRemove.add(databaseMapping);
}
for (DatabaseMapping mappingToRemove : mappingsToRemove) {
classDescriptor.removeMappingForAttributeName(mappingToRemove.getAttributeName());
}
}
}
@Override
public void executeEvent(DescriptorEvent event) throws DescriptorException {
delegate.executeEvent(event);
}