-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
AllStoreHolder.java
299 lines (262 loc) · 9.76 KB
/
AllStoreHolder.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.newapi;
import java.nio.ByteBuffer;
import java.util.function.Supplier;
import org.neo4j.function.Suppliers;
import org.neo4j.function.Suppliers.Lazy;
import org.neo4j.internal.kernel.api.CapableIndexReference;
import org.neo4j.internal.kernel.api.IndexCapability;
import org.neo4j.internal.kernel.api.Token;
import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.api.ExplicitIndex;
import org.neo4j.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException;
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException;
import org.neo4j.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema.index.IndexDescriptor;
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory;
import org.neo4j.kernel.api.txstate.ExplicitIndexTransactionState;
import org.neo4j.kernel.impl.api.store.PropertyUtil;
import org.neo4j.kernel.impl.store.RecordCursor;
import org.neo4j.kernel.impl.store.RecordStore;
import org.neo4j.kernel.impl.store.record.AbstractBaseRecord;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.RecordLoad;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.storageengine.api.StorageEngine;
import org.neo4j.storageengine.api.StorageStatement;
import org.neo4j.storageengine.api.StoreReadLayer;
import org.neo4j.storageengine.api.schema.IndexReader;
import org.neo4j.storageengine.api.schema.LabelScanReader;
import org.neo4j.string.UTF8;
import org.neo4j.values.storable.ArrayValue;
import org.neo4j.values.storable.TextValue;
import org.neo4j.values.storable.Values;
import static org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL;
class AllStoreHolder extends Read implements Token
{
private final StorageStatement.Nodes nodes;
private final StorageStatement.Groups groups;
private final StorageStatement.Properties properties;
private final StorageStatement.Relationships relationships;
private final StorageStatement statement;
private final StoreReadLayer read;
private final Lazy<ExplicitIndexTransactionState> explicitIndexes;
AllStoreHolder( StorageEngine engine,
StorageStatement statement,
Supplier<ExplicitIndexTransactionState> explicitIndexes,
Cursors cursors )
{
super( cursors );
this.read = engine.storeReadLayer();
this.statement = statement; // use provided statement, to assert no leakage
this.explicitIndexes = Suppliers.lazySingleton( explicitIndexes );
this.nodes = statement.nodes();
this.relationships = statement.relationships();
this.groups = statement.groups();
this.properties = statement.properties();
}
@Override
long graphPropertiesReference()
{
throw new UnsupportedOperationException( "not implemented" );
}
@Override
IndexReader indexReader( org.neo4j.internal.kernel.api.IndexReference index )
{
try
{
IndexDescriptor indexDescriptor = index.isUnique() ?
IndexDescriptorFactory.uniqueForLabel( index.label(), index.properties() ) :
IndexDescriptorFactory.forLabel( index.label(), index.properties() );
return statement.getIndexReader( indexDescriptor );
}
catch ( IndexNotFoundKernelException e )
{
throw new IllegalStateException( e );
}
}
@Override
LabelScanReader labelScanReader()
{
return statement.getLabelScanReader();
}
@Override
ExplicitIndex explicitNodeIndex( String indexName ) throws ExplicitIndexNotFoundKernelException
{
return explicitIndexes.get().nodeChanges( indexName );
}
@Override
ExplicitIndex explicitRelationshipIndex( String indexName ) throws ExplicitIndexNotFoundKernelException
{
return explicitIndexes.get().relationshipChanges( indexName );
}
@Override
public CapableIndexReference index( int label, int... properties )
{
IndexDescriptor indexDescriptor = read.indexGetForSchema( new LabelSchemaDescriptor( label, properties ) );
if ( indexDescriptor == null )
{
return CapableIndexReference.NO_INDEX;
}
boolean unique = indexDescriptor.type() == IndexDescriptor.Type.UNIQUE;
try
{
IndexCapability indexCapability = read.indexGetCapability( indexDescriptor );
return new DefaultCapableIndexReference( unique, indexCapability, label, properties );
}
catch ( IndexNotFoundKernelException e )
{
throw new IllegalStateException( "Could not find capability for index " + indexDescriptor, e );
}
}
@Override
public int labelGetOrCreateForName( String labelName ) throws KernelException
{
throw new UnsupportedOperationException( "not implemented" );
}
@Override
public int propertyKeyGetOrCreateForName( String propertyKeyName ) throws KernelException
{
throw new UnsupportedOperationException( "not implemented" );
}
@Override
public int relationshipTypeGetOrCreateForName( String relationshipTypeName ) throws KernelException
{
throw new UnsupportedOperationException( "not implemented" );
}
@Override
public void labelCreateForName( String labelName, int id ) throws KernelException
{
throw new UnsupportedOperationException( "not implemented" );
}
@Override
public void propertyKeyCreateForName( String propertyKeyName, int id ) throws KernelException
{
throw new UnsupportedOperationException( "not implemented" );
}
@Override
public void relationshipTypeCreateForName( String relationshipTypeName, int id ) throws KernelException
{
throw new UnsupportedOperationException( "not implemented" );
}
@Override
public int nodeLabel( String name )
{
return read.labelGetForName( name );
}
@Override
public int relationshipType( String name )
{
return read.relationshipTypeGetForName( name );
}
@Override
public int propertyKey( String name )
{
return read.propertyKeyGetForName( name );
}
@Override
PageCursor nodePage( long reference )
{
return nodes.openPageCursor( reference );
}
@Override
PageCursor relationshipPage( long reference )
{
return relationships.openPageCursor( reference );
}
@Override
PageCursor groupPage( long reference )
{
return groups.openPageCursor( reference );
}
@Override
PageCursor propertyPage( long reference )
{
return properties.openPageCursor( reference );
}
@Override
PageCursor stringPage( long reference )
{
return properties.openStringPageCursor( reference );
}
@Override
PageCursor arrayPage( long reference )
{
return properties.openArrayPageCursor( reference );
}
@Override
RecordCursor<DynamicRecord> labelCursor()
{
return nodes.newLabelCursor();
}
@Override
void node( NodeRecord record, long reference, PageCursor pageCursor )
{
nodes.loadRecordByCursor( reference, record, RecordLoad.CHECK, pageCursor );
}
@Override
void relationship( RelationshipRecord record, long reference, PageCursor pageCursor )
{
relationships.loadRecordByCursor( reference, record, RecordLoad.CHECK, pageCursor );
}
@Override
void property( PropertyRecord record, long reference, PageCursor pageCursor )
{
properties.loadRecordByCursor( reference, record, RecordLoad.NORMAL, pageCursor );
}
@Override
void group( RelationshipGroupRecord record, long reference, PageCursor page )
{
groups.loadRecordByCursor( reference, record, RecordLoad.NORMAL, page );
}
@Override
long nodeHighMark()
{
return nodes.getHighestPossibleIdInUse();
}
@Override
long relationshipHighMark()
{
return relationships.getHighestPossibleIdInUse();
}
@Override
TextValue string( PropertyCursor cursor, long reference, PageCursor page )
{
ByteBuffer buffer = cursor.buffer = properties.loadString( reference, cursor.buffer, page );
buffer.flip();
return Values.stringValue( UTF8.decode( buffer.array(), 0, buffer.limit() ) );
}
@Override
ArrayValue array( PropertyCursor cursor, long reference, PageCursor page )
{
ByteBuffer buffer = cursor.buffer = properties.loadArray( reference, cursor.buffer, page );
buffer.flip();
return PropertyUtil.readArrayFromBuffer( buffer );
}
public boolean nodeExists( long id )
{
return read.nodeExists( id );
}
}