class RepositoryBackedSession {

  public void setAttribute(String key, Object value) {
    assertValid();
    if (value == null) {
      removeAttribute(key);
      return;
    }
    Object oldValue;
    Attribute attr;
    if (sessionData.isNonCacheable(key)) {
      manager.getRepository().setSessionAttribute(sessionData, key, value);
      attr = getAttributeFromCache(key);
    } else {
      attr = retrieveAttribute(key, getAttributeFromCache(key));
    }
    if (attr == null) {
      attr = new Attribute(value);
      attrs.put(key, attr);
      oldValue = null;
    } else {
      oldValue = attr.value;
      attr.value = value;
      attr.deleted = false;
    }
    attr.changed = true;
    dirty = true;
    checkUsedAndLock();
    if (oldValue != value) { // NOSONAR identity check
      // Trigger the replace events
      if (oldValue != null) {
        manager.getNotifier().attributeReplaced(this, key, oldValue);
      }
      // Trigger the add events
      manager.getNotifier().attributeAdded(this, key, value);
    }
  }

  public  RepositoryBackedSession(SessionData sessionData, SessionManager manager, SessionFactory factory);
  protected  RepositoryBackedSession(RepositoryBackedSession linked);

}