Beispiel #1
0
 /**
  * Creates a relationship with the given id, from the nodes identified by id and of type typeId
  *
  * @param id The id of the relationship to create.
  * @param type The id of the relationship type this relationship will have.
  * @param firstNodeId The id of the start node.
  * @param secondNodeId The id of the end node.
  */
 public void relationshipCreate(
     long id, int type, long firstNodeId, long secondNodeId, RecordAccessSet recordChangeSet) {
   // TODO could be unnecessary to mark as changed here already, dense nodes may not need to change
   NodeRecord firstNode =
       recordChangeSet.getNodeRecords().getOrLoad(firstNodeId, null).forChangingLinkage();
   if (!firstNode.inUse()) {
     throw new IllegalStateException(
         "First node[" + firstNodeId + "] is deleted and cannot be used to create a relationship");
   }
   NodeRecord secondNode =
       recordChangeSet.getNodeRecords().getOrLoad(secondNodeId, null).forChangingLinkage();
   if (!secondNode.inUse()) {
     throw new IllegalStateException(
         "Second node["
             + secondNodeId
             + "] is deleted and cannot be used to create a relationship");
   }
   convertNodeToDenseIfNecessary(
       firstNode, recordChangeSet.getRelRecords(), recordChangeSet.getRelGroupRecords());
   convertNodeToDenseIfNecessary(
       secondNode, recordChangeSet.getRelRecords(), recordChangeSet.getRelGroupRecords());
   RelationshipRecord record =
       recordChangeSet.getRelRecords().create(id, null).forChangingLinkage();
   record.setLinks(firstNodeId, secondNodeId, type);
   record.setInUse(true);
   record.setCreated();
   connectRelationship(
       firstNode,
       secondNode,
       record,
       recordChangeSet.getRelRecords(),
       recordChangeSet.getRelGroupRecords());
 }
Beispiel #2
0
 @Override
 public long createRelationship(
     long node1, long node2, RelationshipType type, Map<String, Object> properties) {
   NodeRecord firstNode = getNodeRecord(node1);
   NodeRecord secondNode = getNodeRecord(node2);
   int typeId = typeHolder.getTypeId(type.name());
   if (typeId == -1) {
     typeId = createNewRelationshipType(type.name());
   }
   long id = getRelationshipStore().nextId();
   RelationshipRecord record = new RelationshipRecord(id, node1, node2, typeId);
   record.setInUse(true);
   record.setCreated();
   connectRelationship(firstNode, secondNode, record);
   getNodeStore().updateRecord(firstNode);
   getNodeStore().updateRecord(secondNode);
   record.setNextProp(createPropertyChain(properties));
   getRelationshipStore().updateRecord(record);
   return id;
 }