Example #1
0
  private long createPropertyChain(Map<String, Object> properties) {
    if (properties == null || properties.isEmpty()) {
      return Record.NO_NEXT_PROPERTY.intValue();
    }
    PropertyStore propStore = getPropertyStore();
    List<PropertyRecord> propRecords = new ArrayList<PropertyRecord>();
    PropertyRecord currentRecord = new PropertyRecord(propStore.nextId());
    currentRecord.setInUse(true);
    currentRecord.setCreated();
    propRecords.add(currentRecord);
    for (Entry<String, Object> entry : properties.entrySet()) {
      int keyId = indexHolder.getKeyId(entry.getKey());
      if (keyId == -1) {
        keyId = createNewPropertyIndex(entry.getKey());
      }

      PropertyBlock block = new PropertyBlock();
      propStore.encodeValue(block, keyId, entry.getValue());
      if (currentRecord.size() + block.getSize() > PropertyType.getPayloadSize()) {
        // Here it means the current block is done for
        PropertyRecord prevRecord = currentRecord;
        // Create new record
        long propertyId = propStore.nextId();
        currentRecord = new PropertyRecord(propertyId);
        currentRecord.setInUse(true);
        currentRecord.setCreated();
        // Set up links
        prevRecord.setNextProp(propertyId);
        currentRecord.setPrevProp(prevRecord.getId());
        propRecords.add(currentRecord);
        // Now current is ready to start picking up blocks
      }
      currentRecord.addPropertyBlock(block);
    }
    /*
     * Add the property records in reverse order, which means largest
     * id first. That is to make sure we expand the property store file
     * only once.
     */
    for (int i = propRecords.size() - 1; i >= 0; i--) {
      propStore.updateRecord(propRecords.get(i));
    }
    /*
     *  0 will always exist, if the map was empty we wouldn't be here
     *  and even one property will create at least one record.
     */
    return propRecords.get(0).getId();
  }
Example #2
0
 @Test
 public void testProps1() throws Exception {
   initializeStores();
   startTx();
   long nodeId = ds.nextId(Node.class);
   xaCon.getTransaction().nodeCreate(nodeId);
   pStore.nextId();
   DefinedProperty prop =
       xaCon.getTransaction().nodeAddProperty(nodeId, index("nisse"), new Integer(10));
   commitTx();
   ds.stop();
   initializeStores();
   startTx();
   xaCon.getTransaction().nodeChangeProperty(nodeId, prop.propertyKeyId(), new Integer(5));
   xaCon.getTransaction().nodeRemoveProperty(nodeId, prop.propertyKeyId());
   xaCon.getTransaction().nodeDelete(nodeId);
   commitTx();
   ds.stop();
 }