|
19 | 19 | */ |
20 | 20 | package org.neo4j.gds.compat; |
21 | 21 |
|
22 | | -import org.apache.commons.lang3.mutable.MutableInt; |
23 | 22 | import org.neo4j.exceptions.KernelException; |
24 | 23 | import org.neo4j.gds.core.cypher.CypherGraphStore; |
25 | 24 | import org.neo4j.gds.storageengine.InMemoryTransactionStateVisitor; |
26 | | -import org.neo4j.kernel.lifecycle.LifecycleAdapter; |
| 25 | +import org.neo4j.storageengine.api.CommandCreationContext; |
27 | 26 | import org.neo4j.token.TokenHolders; |
28 | 27 | import org.neo4j.token.api.NamedToken; |
29 | 28 |
|
30 | 29 | import java.util.HashSet; |
31 | 30 |
|
32 | | -class TokenManager extends LifecycleAdapter implements CypherGraphStore.StateVisitor { |
| 31 | +class TokenManager implements CypherGraphStore.StateVisitor { |
33 | 32 |
|
34 | 33 | private final TokenHolders tokenHolders; |
35 | 34 | private final InMemoryTransactionStateVisitor transactionStateVisitor; |
36 | 35 | private final CypherGraphStore graphStore; |
| 36 | + private final CommandCreationContext commandCreationContext; |
37 | 37 |
|
38 | 38 | TokenManager( |
39 | 39 | TokenHolders tokenHolders, |
40 | 40 | InMemoryTransactionStateVisitor transactionStateVisitor, |
41 | | - CypherGraphStore graphStore |
| 41 | + CypherGraphStore graphStore, |
| 42 | + CommandCreationContext commandCreationContext |
42 | 43 | ) { |
43 | 44 | this.tokenHolders = tokenHolders; |
44 | 45 | this.transactionStateVisitor = transactionStateVisitor; |
45 | 46 | this.graphStore = graphStore; |
| 47 | + this.commandCreationContext = commandCreationContext; |
46 | 48 |
|
47 | 49 | init(); |
48 | 50 | } |
49 | 51 |
|
50 | | - @Override |
51 | 52 | public void init() { |
52 | 53 | initializeTokensFromGraphStore(); |
53 | 54 | graphStore.initialize(tokenHolders); |
@@ -106,29 +107,26 @@ private void initializeTokensFromGraphStore() { |
106 | 107 | // When this method is called there is no kernel available |
107 | 108 | // which is needed to use the `getOrCreate` method on |
108 | 109 | // the `TokenHolders` |
109 | | - var labelCounter = new MutableInt(0); |
110 | | - var typeCounter = new MutableInt(0); |
111 | | - var propertyCounter = new MutableInt(0); |
112 | 110 |
|
113 | 111 | var propertyKeys = new HashSet<>(graphStore.nodePropertyKeys()); |
114 | 112 | propertyKeys.addAll(graphStore.relationshipPropertyKeys()); |
115 | 113 | propertyKeys.forEach(propertyKey -> |
116 | 114 | tokenHolders |
117 | 115 | .propertyKeyTokens() |
118 | | - .addToken(new NamedToken(propertyKey, propertyCounter.getAndIncrement())) |
| 116 | + .addToken(new NamedToken(propertyKey, commandCreationContext.reservePropertyKeyTokenId())) |
119 | 117 | ); |
120 | 118 |
|
121 | 119 | graphStore |
122 | 120 | .nodeLabels() |
123 | 121 | .forEach(nodeLabel -> tokenHolders |
124 | 122 | .labelTokens() |
125 | | - .addToken(new NamedToken(nodeLabel.name(), labelCounter.getAndIncrement()))); |
| 123 | + .addToken(new NamedToken(nodeLabel.name(), commandCreationContext.reserveLabelTokenId()))); |
126 | 124 |
|
127 | 125 | graphStore |
128 | 126 | .relationshipTypes() |
129 | 127 | .forEach(relType -> tokenHolders |
130 | 128 | .relationshipTypeTokens() |
131 | | - .addToken(new NamedToken(relType.name(), typeCounter.getAndIncrement()))); |
| 129 | + .addToken(new NamedToken(relType.name(), commandCreationContext.reserveRelationshipTypeTokenId()))); |
132 | 130 | } |
133 | 131 |
|
134 | 132 |
|
|
0 commit comments