code: public CommandAuthorization createOrUpdate(String chargingStationId, String userIdentity, Class commandClass) {
          EntityManager em = getEntityManager();
  
          EntityTransaction tx = null;
          try {
              tx = em.getTransaction();
              tx.begin();
  
              CommandAuthorization storedCommandAuthorization = em.merge(new CommandAuthorization(new CommandAuthorizationId(chargingStationId, userIdentity, commandClass)));
  
              tx.commit();
  
              return storedCommandAuthorization;
          } catch (Exception e) {
              if(tx != null && tx.isActive()) {
                  tx.rollback();
              }
              throw e;
          } finally {
              em.close();
          }
      }
docs: Creates or updates a {@code CommandAuthorization} based on charging station id, user identity and command class.
  
  @param chargingStationId    charging station identifier.
  @param userIdentity         user identity (user name).
  @param commandClass         command class.
  @return (updated) command authorization.