docs: @Override
      public void storePortletEntity(HttpServletRequest request, final IPortletEntity portletEntity) {
          Validate.notNull(portletEntity, "portletEntity can not be null");
  
          final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
          final IPerson person = userInstance.getPerson();
          if (person.isGuest()) {
              // Never persist things for the guest user, just rely on in-memory storage
              return;
          }
  
          final IPortletEntityId wrapperPortletEntityId = portletEntity.getPortletEntityId();
          final Lock portletEntityLock = this.getPortletEntityLock(request, wrapperPortletEntityId);
          portletEntityLock.lock();
          try {
              final boolean shouldBePersisted = this.shouldBePersisted(portletEntity);
  
              if (portletEntity instanceof PersistentPortletEntityWrapper) {
                  // Unwrap the persistent entity
                  final IPortletEntity persistentEntity =
                          ((PersistentPortletEntityWrapper) portletEntity).getPersistentEntity();
  
                  // Already persistent entity that still has prefs
                  if (shouldBePersisted) {
                      try {
                          this.portletEntityDao.updatePortletEntity(persistentEntity);
                      } catch (HibernateOptimisticLockingFailureException e) {
                          // Check if this exception is from the entity being deleted from under us.
                          final boolean exists =
                                  this.portletEntityDao.portletEntityExists(
                                          persistentEntity.getPortletEntityId());
                          if (!exists) {
                              this.logger.warn(
                                      "The persistent portlet has already been deleted: "
                                              + persistentEntity
                                              + ". The passed entity should be persistent so a new persistent entity will be created");
                              this.deletePortletEntity(request, portletEntity, true);
                              this.createPersistentEntity(persistentEntity, wrapperPortletEntityId);
                          } else {
                              throw e;
                          }
                      }
                  }
                  // Already persistent entity that should not be, DELETE!
                  else {
                      // Capture identifiers needed to recreate the entity as session persistent
                      final IPortletDefinitionId portletDefinitionId =
                              portletEntity.getPortletDefinitionId();
                      final String layoutNodeId = portletEntity.getLayoutNodeId();
                      final int userId = portletEntity.getUserId();
  
                      // Delete the persistent entity
                      this.deletePortletEntity(request, portletEntity, false);
  
                      // Create a new entity and stick it in the cache
                      this.getOrCreatePortletEntity(
                              request, portletDefinitionId, layoutNodeId, userId);
                  }
              } else if (portletEntity instanceof SessionPortletEntityImpl) {
                  // There are preferences on the interim entity, create an store it
                  if (shouldBePersisted) {
                      // Remove the session scoped entity from the request and session caches
                      this.deletePortletEntity(request, portletEntity, false);
  
                      final IPortletEntity persistentEntity =
                              createPersistentEntity(portletEntity, wrapperPortletEntityId);
  
                      if (this.logger.isTraceEnabled()) {
                          this.logger.trace(
                                  "Session scoped entity "
                                          + wrapperPortletEntityId
                                          + " should now be persistent. Deleted it from session cache and created persistent portlet entity "
                                          + persistentEntity.getPortletEntityId());
                      }
                  }
                  // Session scoped entity that is still session scoped,
                  else {
                      // Look for a persistent entity and delete it
                      final String channelSubscribeId = portletEntity.getLayoutNodeId();
                      final int userId = portletEntity.getUserId();
                      IPortletEntity existingPersistentEntity =
                              this.portletEntityDao.getPortletEntity(channelSubscribeId, userId);
                      if (existingPersistentEntity != null) {
                          final IPortletEntityId consistentPortletEntityId =
                                  this.createConsistentPortletEntityId(existingPersistentEntity);
                          existingPersistentEntity =
                                  new PersistentPortletEntityWrapper(
                                          existingPersistentEntity, consistentPortletEntityId);
  
                          this.logger.warn(
                                  "A persistent portlet entity already exists: "
                                          + existingPersistentEntity
                                          + ". The passed entity has no preferences so the persistent version will be deleted");
                          this.deletePortletEntity(request, existingPersistentEntity, false);
  
                          // Add to request cache
                          final PortletEntityCache<IPortletEntity> portletEntityMap =
                                  this.getPortletEntityMap(request);
                          portletEntityMap.storeIfAbsentEntity(portletEntity);
  
                          // Add to session cache
                          final PortletEntityCache<PortletEntityData> portletEntityDataMap =
                                  this.getPortletEntityDataMap(request);
                          portletEntityDataMap.storeIfAbsentEntity(
                                  ((SessionPortletEntityImpl) portletEntity).getPortletEntityData());
                      }
                  }
              } else {
                  throw new IllegalArgumentException(
                          "Invalid portlet entity implementation passed: "
                                  + portletEntity.getClass());
              }
          } finally {
              portletEntityLock.unlock();
          }
      }