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

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


        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


  @SuppressWarnings("unchecked")
  @Override
  public void translateToColumn(InfoForIndex<OWNER> info) {
    OWNER entity = info.getEntity();
    RowToPersist row = info.getRow();
   
    Collection<T> values = (Collection<T>) ReflectionUtil.fetchFieldValue(entity, field);
    Collection<T> toBeAdded = values; //all values in the list get added if not an OurAbstractCollection
    Collection<T> toBeRemoved = new ArrayList<T>();
    if(values instanceof SimpleAbstractCollection) {
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

   
    addIndexRemoves(info, value, byteVal, storageType);
  }
 
  private void addIndexRemoves(InfoForIndex<OWNER> info, Object value, byte[] byteVal, StorageTypeEnum storageType) {
    RowToPersist row = info.getRow();
    Map<Field, Object> fieldToValue = info.getFieldToValue();
    //if we are here, we are indexed, BUT if fieldToValue is null, then it is a brand new entity and not a proxy
    Object originalValue = fieldToValue.get(field);
    if(originalValue == null)
      return;
    else if(originalValue.equals(value))
      return; //previous value is the same, yeah, nothing to do here!!!
     
    byte[] pk = row.getKey();
    byte[] oldIndexedVal = translateValue(originalValue);
   
    List<IndexData> indexList = row.getIndexToRemove();
   
    addToList(info, oldIndexedVal, storageType, pk, indexList);
  }
View Full Code Here

    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

  }

  @SuppressWarnings("unchecked")
  public void translateToColumn(InfoForIndex<OWNER> info) {
    OWNER entity = info.getEntity();
    RowToPersist row = info.getRow();
    Column col = new Column();
    row.getColumns().add(col);

    PROXY value = (PROXY) ReflectionUtil.fetchFieldValue(entity, field);
   
    if(value instanceof ToOneProvider) {
      value = (PROXY) ((ToOneProvider)value).get();
View Full Code Here

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

    }
    elementsToRemove.clear();
  }

  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

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.