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

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


  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


        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

      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

      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

    if(entity instanceof Proxy) {
      clazz = entity.getClass().getSuperclass();
    }
    String type = classToType.get(clazz);
    MetaClassSingle<T> metaClassSingle = dbTypeToMeta.get(type);
    RowToPersist translateToRow = metaClassSingle.translateToRow(entity);
   
    byte[] value = StandardConverters.convertToBytes(type);
    Column typeCol = new Column();
    typeCol.setName(discColAsBytes);
    typeCol.setValue(value);
    translateToRow.getColumns().add(typeCol);
    return translateToRow;
  }
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

    ReflectionUtil.putFieldValue(entity, field, value);
  }
  @Override
  public void translateToColumn(InfoForIndex<OWNER> info) {
    OWNER entity = info.getEntity();
    RowToPersist row = info.getRow();
   
    Column col = new Column();
    row.getColumns().add(col);

    Object value = ReflectionUtil.fetchFieldValue(entity, field);
    byte[] byteVal = translateValue(value);
    byte[] colBytes = StandardConverters.convertToBytes(columnName);
    col.setName(colBytes);
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 if (field.getType().equals(List.class))
      translateToColumnList(entity, row);
    else translateToColumn(entity, row);
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.