Пример #1
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  protected synchronized String attach(E entity, Object oid, boolean noteChange) {
    // Check entity
    if (entity == null) return null;
    String id = this.getId(entity);
    if (id != null) return id;

    // Check/Fix id
    if (oid == null) {
      id = MStore.createId();
    } else {
      id = this.fixId(oid);
      if (id == null) return null;
      if (this.id2entity.containsKey(id)) return null;
    }

    // PRE
    this.preAttach(entity, id);

    // Add entity reference info
    if (entity instanceof Entity) {
      ((Entity) entity).setColl(this);
      ((Entity) entity).setid(id);
    }

    // Attach
    this.ids.add(id);
    this.id2entity.put(id, entity);
    this.entity2id.put(entity, id);

    // Make note of the change
    if (noteChange) {
      this.localAttachIds.add(id);
      this.changedIds.add(id);
    }

    // POST
    this.postAttach(entity, id);

    return id;
  }