Exemplo n.º 1
0
 private void deleteNode2(
     long node, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3)
     throws IOException {
   ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
   xaCon.getTransaction().nodeLoadProperties(node, false, newPropertyReceiver(props));
   int count = 0;
   for (int keyId : props.keySet()) {
     long id = props.get(keyId).other();
     PropertyRecord record = pStore.getRecord(id);
     PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
     DefinedProperty data = block.newPropertyData(pStore);
     if (data.propertyKeyId() == prop1.propertyKeyId()) {
       assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
       assertEquals("-string2", data.value());
     } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
       assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
       assertEquals(-2, data.value());
     } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
       assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
       assertEquals(true, data.value());
       xaCon.getTransaction().nodeRemoveProperty(node, prop3.propertyKeyId());
     } else {
       throw new IOException();
     }
     count++;
   }
   assertEquals(3, count);
   CountingPropertyReceiver propertyCounter = new CountingPropertyReceiver();
   xaCon.getTransaction().nodeLoadProperties(node, false, propertyCounter);
   assertEquals(3, propertyCounter.count);
   MutableRelationshipLoadingPosition pos = getPosition(xaCon, node);
   Iterator<RelationshipRecord> rels = getMore(xaCon, node, pos).iterator();
   assertTrue(rels.hasNext());
   xaCon.getTransaction().nodeDelete(node);
 }
Exemplo n.º 2
0
 @Test
 public void testRels1() throws Exception {
   initializeStores();
   startTx();
   int relType1 = (int) ds.nextId(RelationshipType.class);
   String typeName = "relationshiptype1";
   xaCon.getTransaction().createRelationshipTypeToken(relType1, typeName);
   long nodeIds[] = new long[3];
   for (int i = 0; i < 3; i++) {
     nodeIds[i] = ds.nextId(Node.class);
     xaCon.getTransaction().nodeCreate(nodeIds[i]);
     xaCon.getTransaction().nodeAddProperty(nodeIds[i], index("nisse"), new Integer(10 - i));
   }
   for (int i = 0; i < 2; i++) {
     xaCon
         .getTransaction()
         .relationshipCreate(ds.nextId(Relationship.class), relType1, nodeIds[i], nodeIds[i + 1]);
   }
   commitTx();
   startTx();
   for (int i = 0; i < 3; i += 2) {
     MutableRelationshipLoadingPosition pos = getPosition(xaCon, nodeIds[i]);
     for (RelationshipRecord rel : getMore(xaCon, nodeIds[i], pos)) {
       xaCon.getTransaction().relDelete(rel.getId());
     }
     xaCon.getTransaction().nodeDelete(nodeIds[i]);
   }
   commitTx();
   ds.stop();
 }
Exemplo n.º 3
0
 private void deleteRel1(
     long rel,
     DefinedProperty prop1,
     DefinedProperty prop2,
     DefinedProperty prop3,
     long firstNode,
     long secondNode,
     int relType)
     throws IOException {
   ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
   xaCon.getTransaction().relLoadProperties(rel, false, newPropertyReceiver(props));
   int count = 0;
   for (int keyId : props.keySet()) {
     long id = props.get(keyId).other();
     PropertyRecord record = pStore.getRecord(id);
     PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
     DefinedProperty data = block.newPropertyData(pStore);
     if (data.propertyKeyId() == prop1.propertyKeyId()) {
       assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
       assertEquals("-string1", data.value());
     } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
       assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
       assertEquals(-1, data.value());
     } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
       assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
       assertEquals(false, data.value());
       xaCon.getTransaction().relRemoveProperty(rel, prop3.propertyKeyId());
     } else {
       throw new IOException();
     }
     count++;
   }
   assertEquals(3, count);
   CountingPropertyReceiver propertyCounter = new CountingPropertyReceiver();
   xaCon.getTransaction().relLoadProperties(rel, false, propertyCounter);
   assertEquals(3, propertyCounter.count);
   RelationshipRecord relData = xaCon.getTransaction().relLoadLight(rel);
   assertEquals(firstNode, relData.getFirstNode());
   assertEquals(secondNode, relData.getSecondNode());
   assertEquals(relType, relData.getType());
   xaCon.getTransaction().relDelete(rel);
   MutableRelationshipLoadingPosition firstPos = getPosition(xaCon, firstNode);
   Iterator<RelationshipRecord> first = getMore(xaCon, firstNode, firstPos).iterator();
   first.next();
   MutableRelationshipLoadingPosition secondPos = getPosition(xaCon, secondNode);
   Iterator<RelationshipRecord> second = getMore(xaCon, secondNode, secondPos).iterator();
   second.next();
   assertTrue(first.hasNext());
   assertTrue(second.hasNext());
 }
Exemplo n.º 4
0
 private int index(String key) {
   Iterator<Token> itr = MyPropertyKeyToken.index(key).iterator();
   if (!itr.hasNext()) {
     int id = (int) ds.nextId(PropertyKeyTokenRecord.class);
     createDummyIndex(id, key);
     xaCon.getTransaction().createPropertyKeyToken(key, id);
     return id;
   }
   return itr.next().id();
 }
Exemplo n.º 5
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();
 }
Exemplo n.º 6
0
 private void validateRel2(
     long rel,
     DefinedProperty prop1,
     DefinedProperty prop2,
     DefinedProperty prop3,
     long firstNode,
     long secondNode,
     int relType)
     throws IOException {
   ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
   xaCon.getTransaction().relLoadProperties(rel, false, newPropertyReceiver(props));
   int count = 0;
   for (int keyId : props.keySet()) {
     long id = props.get(keyId).other();
     PropertyRecord record = pStore.getRecord(id);
     PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
     DefinedProperty data = block.newPropertyData(pStore);
     if (data.propertyKeyId() == prop1.propertyKeyId()) {
       assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
       assertEquals("string2", data.value());
       xaCon.getTransaction().relChangeProperty(rel, prop1.propertyKeyId(), "-string2");
     } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
       assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
       assertEquals(2, data.value());
       xaCon.getTransaction().relChangeProperty(rel, prop2.propertyKeyId(), new Integer(-2));
     } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
       assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
       assertEquals(false, data.value());
       xaCon.getTransaction().relChangeProperty(rel, prop3.propertyKeyId(), true);
     } else {
       throw new IOException();
     }
     count++;
   }
   assertEquals(3, count);
   RelationshipRecord relData = xaCon.getTransaction().relLoadLight(rel);
   assertEquals(firstNode, relData.getFirstNode());
   assertEquals(secondNode, relData.getSecondNode());
   assertEquals(relType, relData.getType());
 }
Exemplo n.º 7
0
 private Iterable<RelationshipRecord> getMore(
     NeoStoreXaConnection xaCon, long node, MutableRelationshipLoadingPosition position) {
   Pair<Map<DirectionWrapper, Iterable<RelationshipRecord>>, RelationshipLoadingPosition> rels =
       xaCon
           .getTransaction()
           .getMoreRelationships(node, position, DirectionWrapper.BOTH, new int[0]);
   List<Iterable<RelationshipRecord>> list = new ArrayList<>();
   for (Map.Entry<DirectionWrapper, Iterable<RelationshipRecord>> entry :
       rels.first().entrySet()) {
     list.add(entry.getValue());
   }
   position.setActual(rels.other());
   return new CombiningIterable<>(list);
 }
Exemplo n.º 8
0
 @Test
 public void testRels3() throws Exception {
   // test linked list stuff during relationship delete
   initializeStores();
   startTx();
   int relType1 = (int) ds.nextId(RelationshipType.class);
   xaCon.getTransaction().createRelationshipTypeToken(relType1, "relationshiptype1");
   long nodeIds[] = new long[8];
   for (int i = 0; i < nodeIds.length; i++) {
     nodeIds[i] = ds.nextId(Node.class);
     xaCon.getTransaction().nodeCreate(nodeIds[i]);
   }
   for (int i = 0; i < nodeIds.length / 2; i++) {
     xaCon
         .getTransaction()
         .relationshipCreate(ds.nextId(Relationship.class), relType1, nodeIds[i], nodeIds[i * 2]);
   }
   long rel5 = ds.nextId(Relationship.class);
   xaCon.getTransaction().relationshipCreate(rel5, relType1, nodeIds[0], nodeIds[5]);
   long rel2 = ds.nextId(Relationship.class);
   xaCon.getTransaction().relationshipCreate(rel2, relType1, nodeIds[1], nodeIds[2]);
   long rel3 = ds.nextId(Relationship.class);
   xaCon.getTransaction().relationshipCreate(rel3, relType1, nodeIds[1], nodeIds[3]);
   long rel6 = ds.nextId(Relationship.class);
   xaCon.getTransaction().relationshipCreate(rel6, relType1, nodeIds[1], nodeIds[6]);
   long rel1 = ds.nextId(Relationship.class);
   xaCon.getTransaction().relationshipCreate(rel1, relType1, nodeIds[0], nodeIds[1]);
   long rel4 = ds.nextId(Relationship.class);
   xaCon.getTransaction().relationshipCreate(rel4, relType1, nodeIds[0], nodeIds[4]);
   long rel7 = ds.nextId(Relationship.class);
   xaCon.getTransaction().relationshipCreate(rel7, relType1, nodeIds[0], nodeIds[7]);
   commitTx();
   startTx();
   xaCon.getTransaction().relDelete(rel7);
   xaCon.getTransaction().relDelete(rel4);
   xaCon.getTransaction().relDelete(rel1);
   xaCon.getTransaction().relDelete(rel6);
   xaCon.getTransaction().relDelete(rel3);
   xaCon.getTransaction().relDelete(rel2);
   xaCon.getTransaction().relDelete(rel5);
   commitTx();
   ds.stop();
 }
Exemplo n.º 9
0
 private void testGetRels(long relIds[]) {
   for (long relId : relIds) {
     assertEquals(null, xaCon.getTransaction().relLoadLight(relId));
   }
 }
Exemplo n.º 10
0
  private void validateNodeRel2(
      long node,
      DefinedProperty prop1,
      DefinedProperty prop2,
      DefinedProperty prop3,
      long rel1,
      long rel2,
      int relType1,
      int relType2)
      throws IOException {
    NodeRecord nodeRecord = xaCon.getTransaction().nodeLoadLight(node);
    assertTrue(nodeRecord != null);
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    xaCon.getTransaction().nodeLoadProperties(node, false, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
      long id = props.get(keyId).other();
      PropertyRecord record = pStore.getRecord(id);
      PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
      DefinedProperty data = block.newPropertyData(pStore);
      if (data.propertyKeyId() == prop1.propertyKeyId()) {
        assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
        assertEquals("string2", data.value());
        xaCon.getTransaction().nodeChangeProperty(node, prop1.propertyKeyId(), "-string2");
      } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
        assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
        assertEquals(2, data.value());
        xaCon.getTransaction().nodeChangeProperty(node, prop2.propertyKeyId(), new Integer(-2));
      } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
        assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
        assertEquals(false, data.value());
        xaCon.getTransaction().nodeChangeProperty(node, prop3.propertyKeyId(), true);
      } else {
        throw new IOException();
      }
      count++;
    }
    assertEquals(3, count);
    count = 0;

    MutableRelationshipLoadingPosition pos = getPosition(xaCon, node);
    while (true) {
      Iterable<RelationshipRecord> relData = getMore(xaCon, node, pos);
      if (!relData.iterator().hasNext()) {
        break;
      }
      for (RelationshipRecord rel : relData) {
        if (rel.getId() == rel1) {
          assertEquals(node, rel.getSecondNode());
          assertEquals(relType1, rel.getType());
        } else if (rel.getId() == rel2) {
          assertEquals(node, rel.getFirstNode());
          assertEquals(relType2, rel.getType());
        } else {
          throw new IOException();
        }
        count++;
      }
    }
    assertEquals(2, count);
  }
Exemplo n.º 11
0
 private MutableRelationshipLoadingPosition getPosition(NeoStoreXaConnection xaCon, long node) {
   return new MutableRelationshipLoadingPosition(
       xaCon.getTransaction().getRelationshipChainPosition(node));
 }
Exemplo n.º 12
0
  @Test
  public void testCreateNeoStore() throws Exception {
    initializeStores();
    startTx();
    // setup test population
    long node1 = ds.nextId(Node.class);
    xaCon.getTransaction().nodeCreate(node1);
    long node2 = ds.nextId(Node.class);
    xaCon.getTransaction().nodeCreate(node2);
    DefinedProperty n1prop1 =
        xaCon.getTransaction().nodeAddProperty(node1, index("prop1"), "string1");
    DefinedProperty n1prop2 = xaCon.getTransaction().nodeAddProperty(node1, index("prop2"), 1);
    DefinedProperty n1prop3 = xaCon.getTransaction().nodeAddProperty(node1, index("prop3"), true);

    DefinedProperty n2prop1 =
        xaCon.getTransaction().nodeAddProperty(node2, index("prop1"), "string2");
    DefinedProperty n2prop2 = xaCon.getTransaction().nodeAddProperty(node2, index("prop2"), 2);
    DefinedProperty n2prop3 = xaCon.getTransaction().nodeAddProperty(node2, index("prop3"), false);

    int relType1 = (int) ds.nextId(RelationshipType.class);
    String typeName1 = "relationshiptype1";
    xaCon.getTransaction().createRelationshipTypeToken(relType1, typeName1);
    int relType2 = (int) ds.nextId(RelationshipType.class);
    String typeName2 = "relationshiptype2";
    xaCon.getTransaction().createRelationshipTypeToken(relType2, typeName2);
    long rel1 = ds.nextId(Relationship.class);
    xaCon.getTransaction().relationshipCreate(rel1, relType1, node1, node2);
    long rel2 = ds.nextId(Relationship.class);
    xaCon.getTransaction().relationshipCreate(rel2, relType2, node2, node1);

    DefinedProperty r1prop1 =
        xaCon.getTransaction().relAddProperty(rel1, index("prop1"), "string1");
    DefinedProperty r1prop2 = xaCon.getTransaction().relAddProperty(rel1, index("prop2"), 1);
    DefinedProperty r1prop3 = xaCon.getTransaction().relAddProperty(rel1, index("prop3"), true);

    DefinedProperty r2prop1 =
        xaCon.getTransaction().relAddProperty(rel2, index("prop1"), "string2");
    DefinedProperty r2prop2 = xaCon.getTransaction().relAddProperty(rel2, index("prop2"), 2);
    DefinedProperty r2prop3 = xaCon.getTransaction().relAddProperty(rel2, index("prop3"), false);
    commitTx();
    ds.stop();

    initializeStores();
    startTx();
    // validate node
    validateNodeRel1(node1, n1prop1, n1prop2, n1prop3, rel1, rel2, relType1, relType2);
    validateNodeRel2(node2, n2prop1, n2prop2, n2prop3, rel1, rel2, relType1, relType2);
    // validate rels
    validateRel1(rel1, r1prop1, r1prop2, r1prop3, node1, node2, relType1);
    validateRel2(rel2, r2prop1, r2prop2, r2prop3, node2, node1, relType2);
    validateRelTypes(relType1, relType2);
    // validate reltypes
    validateRelTypes(relType1, relType2);
    commitTx();
    ds.stop();

    initializeStores();
    startTx();
    // validate and delete rels
    deleteRel1(rel1, r1prop1, r1prop2, r1prop3, node1, node2, relType1);
    deleteRel2(rel2, r2prop1, r2prop2, r2prop3, node2, node1, relType2);
    // validate and delete nodes
    deleteNode1(node1, n1prop1, n1prop2, n1prop3);
    deleteNode2(node2, n2prop1, n2prop2, n2prop3);
    commitTx();
    ds.stop();

    initializeStores();
    startTx();
    assertNull(xaCon.getTransaction().nodeLoadLight(node1));
    assertNull(xaCon.getTransaction().nodeLoadLight(node2));
    testGetRels(new long[] {rel1, rel2});
    // testGetProps( neoStore, new int[] {
    // n1prop1, n1prop2, n1prop3, n2prop1, n2prop2, n2prop3,
    // r1prop1, r1prop2, r1prop3, r2prop1, r2prop2, r2prop3
    // } );
    long nodeIds[] = new long[10];
    for (int i = 0; i < 3; i++) {
      nodeIds[i] = ds.nextId(Node.class);
      xaCon.getTransaction().nodeCreate(nodeIds[i]);
      xaCon.getTransaction().nodeAddProperty(nodeIds[i], index("nisse"), new Integer(10 - i));
    }
    for (int i = 0; i < 2; i++) {
      long id = ds.nextId(Relationship.class);
      xaCon.getTransaction().relationshipCreate(id, relType1, nodeIds[i], nodeIds[i + 1]);
      xaCon.getTransaction().relDelete(id);
    }
    for (int i = 0; i < 3; i++) {
      MutableRelationshipLoadingPosition pos = getPosition(xaCon, nodeIds[i]);
      for (RelationshipRecord rel : getMore(xaCon, nodeIds[i], pos)) {
        xaCon.getTransaction().relDelete(rel.getId());
      }
      xaCon.getTransaction().nodeDelete(nodeIds[i]);
    }
    commitTx();
    ds.stop();
  }