This repository has been archived by the owner on Jun 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
/
RelationshipWriteHandler.java
96 lines (73 loc) · 3.23 KB
/
RelationshipWriteHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package org.neo4j.batchimport.handlers;
import com.lmax.disruptor.EventHandler;
import org.neo4j.batchimport.structs.NodeStruct;
import org.neo4j.batchimport.structs.Relationship;
import org.neo4j.kernel.impl.nioneo.store.Record;
import java.io.*;
/**
* @author mh
* @since 27.10.12
*/
public class RelationshipWriteHandler implements EventHandler<NodeStruct> {
private long counter;
private final RelationshipWriter relationshipWriter;
// ForwardRelationshipUpdateManager futureNodeRelInfo;
// private final RelationshipUpdateCache cache;
public RelationshipWriteHandler(RelationshipWriter relationshipWriter, final long totalNrOfRels) {
this.relationshipWriter = relationshipWriter;
// cache = new RelationshipUpdateCache(relationshipWriter, totalNrOfRels);
// futureNodeRelInfo = new ForwardRelationshipUpdateManager(cache);
}
@Override
public void onEvent(NodeStruct event, long nodeId, boolean endOfBatch) throws Exception {
// event.firstRel = firstRelationshipId(event,futureNodeRelInfo.getFirstRelId(nodeId));
if (Record.NO_NEXT_RELATIONSHIP.is(event.firstRel)) return;
long maxRelationshipId = maxRelationshipId(event);
relationshipWriter.start(maxRelationshipId);
int count = event.relationshipCount;
long followingNextRelationshipId = Record.NO_NEXT_RELATIONSHIP.intValue();
// long prevId = futureNodeRelInfo.done(nodeId, getFirstOwnRelationshipId(event));
long prevId = event.prevId;
for (int i = 0; i < count; i++) {
long nextId = i+1 < count ? event.getRelationship(i+1).id : followingNextRelationshipId;
Relationship relationship = event.getRelationship(i);
relationshipWriter.create(nodeId,event, relationship, prevId, nextId);
prevId = relationship.id;
// storeFutureRelId(nodeId, relationship,prevId);
counter++;
}
// if (endOfBatch) relationshipWriter.flush();
}
@Override
public String toString() {
return "rel-record-writer " + counter + " \n"+relationshipWriter; // +" "+cache;
}
public void close() {
try {
// cache.close();
relationshipWriter.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/*
private void storeFutureRelId(long nodeId, Relationship relationship, long relId) throws IOException {
long other = relationship.other();
if (other < nodeId) return;
final boolean otherDirection = !relationship.outgoing();
futureNodeRelInfo.add(other,relId,otherDirection);
}
private long firstRelationshipId(NodeStruct event, Long firstFutureId) {
if (firstFutureId!=null) return firstFutureId;
return getFirstOwnRelationshipId(event);
}
private long getFirstOwnRelationshipId(NodeStruct event) {
if (event.relationshipCount == 0) return Record.NO_PREV_RELATIONSHIP.intValue();
return event.getRelationship(0).id;
}
*/
private long maxRelationshipId(NodeStruct event) {
if (event.relationshipCount == 0) return Record.NO_NEXT_RELATIONSHIP.intValue();
return event.getRelationship(event.relationshipCount-1).id;
}
}