Пример #1
0
  protected boolean examineHasLocalAlter(String id, E entity) {
    JsonElement lastRaw = this.lastRaw.get(id);
    JsonElement currentRaw = null;

    try {
      currentRaw = this.getGson().toJsonTree(entity, this.getEntityClass());
    } catch (Exception e) {
      MCore.get()
          .log(
              Txt.parse(
                  "<b>Database examineHasLocalAlter failed convert current entity to JSON tree."));
      MCore.get().log(Txt.parse("<k>Error: <v>%s", e.getMessage()));
      MCore.get().log(Txt.parse("<k>Entity: <v>%s", id));
      MCore.get().log(Txt.parse("<k>Collection: <v>%s", this.getName()));
      throw e;
    }

    return !MStore.equal(lastRaw, currentRaw);
  }
Пример #2
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;
  }