// Get cascade attributes from entity
List<Field> cascadeAttributes = ModelUtilities.getCascadeAttributes(entity.getClass());
// Get default DAO
IDefaultDAO dao = DAOFactory.getDefaultDAO(connection);
T result = entity;
if (PERSIST_MODE_SAVE == mode) {
result = dao.insert(entity);
persistAssociatedAttributes(cascadeAttributes, connection, entity, mode); // AFTER
} else if (PERSIST_MODE_UPDATE == mode) {
result = dao.update(entity);
persistAssociatedAttributes(cascadeAttributes, connection, entity, mode); // AFTER
} else if (PERSIST_MODE_DELETE == mode) {
try {
persistAssociatedAttributes(cascadeAttributes, connection, entity, mode); // BEFORE
dao.remove(entity.getClass(), ModelUtilities.getEntityIdentifier(entity));
} catch (ReflectionException ex) {
throw new InternalErrorException("PersisAction::execute::removeEntity", ex);
}
} else {
throw new InternalErrorException("PersistAction::execute -> Unknown mode operation: " + mode);