Example #1
0
  private void addRemoveItems(InfoForIndex<OWNER> info, CursorProxy<PROXY> cursor) {
    List<PROXY> elementsToAdd = cursor.getElementsToAdd();
    List<PROXY> elementsToRemove = cursor.getElementsToRemove();

    for (PROXY p : elementsToAdd) {
      translateToColumn(info, p);
    }
    elementsToAdd.clear();

    for (PROXY p : elementsToRemove) {
      RowToPersist row = info.getRow();
      IndexData data = fetchIndexData(info, p);
      row.addIndexToRemove(data);
    }
    elementsToRemove.clear();
  }
Example #2
0
  private IndexData fetchIndexData(InfoForIndex<OWNER> info, PROXY value) {
    RowToPersist row = info.getRow();
    // Value is the Account.java or a Proxy of Account.java field and what we need to save in
    // the database is the ID inside this Account.java object!!!!
    byte[] byteVal = classMeta.convertEntityToId(value);
    if (byteVal == null && value != null) {
      // if value is not null but we get back a byteVal of null, it means the entity has not been
      // initialized with a key yet, BUT this is required to be able to save this object
      String owner = "'" + field.getDeclaringClass().getSimpleName() + "'";
      String child = "'" + field.getType().getSimpleName() + "'";
      String fieldName = "'" + field.getType().getSimpleName() + " " + field.getName() + "'";
      throw new ChildWithNoPkException(
          "The entity you are saving of type="
              + owner
              + " has a field="
              + fieldName
              + " that does not yet have a primary key so you cannot save it.  To correct this\n"
              + "problem, you can either\n"
              + "1. SAVE the "
              + child
              + " BEFORE you save the "
              + owner
              + " OR\n"
              + "2. Call entityManager.fillInWithKey(Object entity), then SAVE your "
              + owner
              + "', then save your "
              + child
              + " NOTE that this"
              + "\nmethod #2 is used for when you have a bi-directional relationship where each is a child of the other");
    }

    byte[] key = info.getRow().getKey();

    IndexData data = new IndexData();
    String colFamily = getMetaDbo().getIndexTableName();
    String rowKey = formRowKey(row.getKey());

    data.setColumnFamilyName(colFamily);
    data.setRowKey(rowKey);
    IndexColumn indCol = data.getIndexColumn();
    indCol.setIndexedValue(byteVal);
    indCol.setPrimaryKey(key);
    return data;
  }
Example #3
0
 private void translateToColumn(InfoForIndex<OWNER> info, PROXY value) {
   RowToPersist row = info.getRow();
   IndexData data = fetchIndexData(info, value);
   row.addIndexToPersist(data);
 }