Package com.alvazan.orm.api.z8spi.meta

Examples of com.alvazan.orm.api.z8spi.meta.RowToPersist


    addToList(info, oldIndexedVal, storageType, pk, indexRemoves);
  }
 
  protected void addIndexInfo(InfoForIndex<OWNER> info, Object value, byte[] byteVal, StorageTypeEnum storageType) {
    OWNER entity = info.getEntity();
    RowToPersist row = info.getRow();
    Map<Field, Object> fieldToValue = info.getFieldToValue();
   
    if(!this.getMetaDbo().isIndexed())
      return;
    else if(storageType == StorageTypeEnum.BYTES)
      throw new IllegalArgumentException("Cannot do indexing for types that are stored as bytes at this time");
   
    if(!isNeedPersist(entity, value, fieldToValue))
      return;
   
    //original value and current value differ so we need to persist new value
    byte[] pk = row.getKey();
    List<IndexData> indexList = row.getIndexToAdd();
    addToList(info, byteVal, storageType, pk, indexList);
  }
View Full Code Here


      field.translateFromColumn(row, inst, session);
    }
  }
 
  public RowToPersist translateToRow(T entity) {
    RowToPersist row = new RowToPersist();
    Map<Field, Object> fieldToValue = null;
    if(entity instanceof NoSqlProxy) {
      fieldToValue = ((NoSqlProxy) entity).__getOriginalValues();
    }
   
View Full Code Here

    for(PROXY p : elementsToAdd) {
      translateToColumn(info, p);
    }
   
    for(PROXY p : elementsToRemove) {
      RowToPersist row = info.getRow();
      IndexData data = fetchIndexData(info, p);
      row.addIndexToRemove(data);
    }
  }
View Full Code Here

      row.addIndexToRemove(data);
    }
  }

  private void translateToColumn(InfoForIndex<OWNER> info, PROXY value) {
    RowToPersist row = info.getRow();
    IndexData data = fetchIndexData(info, value);
    row.addIndexToPersist(data);
  }
View Full Code Here

    IndexData data = fetchIndexData(info, value);
    row.addIndexToPersist(data);
  }

  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);
View Full Code Here

        entity = temp;
        BeanProps.copyProps(originalEntity, entity);
      }
    }
   
    RowToPersist row = metaClass.translateToRow(entity);
   
    DboTableMeta metaDbo = metaClass.getMetaDbo();
    //This is if we need to be removing columns from the row that represents the entity in a oneToMany or ManyToMany
    //as the entity.accounts may have removed one of the accounts!!!
    if(row.hasRemoves())
      session.remove(metaDbo, row.getKey(), row.getColumnNamesToRemove());

    //NOW for index removals if any indexed values change of the entity, we remove from the index
    for(IndexData ind : row.getIndexToRemove()) {
      session.removeFromIndex(metaDbo, ind.getColumnFamilyName(), ind.getRowKeyBytes(), ind.getIndexColumn());
    }
   
    //NOW for index adds, if it is a new entity or if values change, we persist those values
    for(IndexData ind : row.getIndexToAdd()) {
      session.persistIndex(metaDbo, ind.getColumnFamilyName(), ind.getRowKeyBytes(), ind.getIndexColumn());
    }

    byte[] virtKey = row.getVirtualKey();
    List<Column> cols = row.getColumns();
    session.put(metaDbo, virtKey, cols);
  }
View Full Code Here

  public void put(String colFamily, TypedRow typedRow) {
    DboTableMeta metaClass = cachedMeta.getMeta(colFamily);
    if(metaClass == null)
      throw new IllegalArgumentException("DboTableMeta for colFamily="+colFamily+" was not found");

    RowToPersist row = metaClass.translateToRow(typedRow);
   
    //This is if we need to be removing columns from the row that represents the entity in a oneToMany or ManyToMany
    //as the entity.accounts may have removed one of the accounts!!!
    if(row.hasRemoves())
      session.remove(metaClass, row.getKey(), row.getColumnNamesToRemove());
   
    //NOW for index removals if any indexed values change of the entity, we remove from the index
    for(IndexData ind : row.getIndexToRemove()) {
      session.removeFromIndex(metaClass, ind.getColumnFamilyName(), ind.getRowKeyBytes(), ind.getIndexColumn());
    }
   
    //NOW for index adds, if it is a new entity or if values change, we persist those values
    for(IndexData ind : row.getIndexToAdd()) {
      session.persistIndex(metaClass, ind.getColumnFamilyName(), ind.getRowKeyBytes(), ind.getIndexColumn());
    }
   
    byte[] virtualKey = row.getVirtualKey();
    List<Column> cols = row.getColumns();
    session.put(metaClass, virtualKey, cols);
  }
View Full Code Here

  }
 
  @Override
  public void translateToColumn(InfoForIndex<OWNER> info) {
    OWNER entity = info.getEntity();
    RowToPersist row = info.getRow();
   
    Object id = fillInAndFetchId(entity);
    byte[] byteVal = converter.convertToNoSql(id);
    byte[] virtualKey = metaDbo.formVirtRowKey(byteVal);
    row.setKeys(byteVal, virtualKey);
   
    StorageTypeEnum storageType = metaDbo.getStorageType();
    addIndexInfo(info, id, byteVal, storageType);
    //NOTICE: there is no call to remove because if an id is changed, it is a new entity and we only need to add index not remove since
    //the old entity was not deleted during this save....we remove from index on remove of old entity only
View Full Code Here

 
  @Override
  public void translateToColumn(InfoForIndex<OWNER> info) {
    OWNER entity = info.getEntity();
   
    RowToPersist row = info.getRow();
    if(field.getType().equals(Map.class))
      translateToColumnMap(entity, row);
    else
      translateToColumnList(entity, row);
  }
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  private void translateToColumnMap(InfoForIndex<OWNER> info) {
        OWNER entity = info.getEntity();
        RowToPersist row = info.getRow();
    Map values = (Map) ReflectionUtil.fetchFieldValue(entity, field);
    if (values == null)
      values = new HashMap();
    Map toBeAdded = values; //all values in the list get added if not an OurAbstractCollection
    Collection<T> toBeRemoved = new ArrayList<T>();
View Full Code Here

TOP

Related Classes of com.alvazan.orm.api.z8spi.meta.RowToPersist

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.