-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
RelationshipRecordFormat.java
103 lines (95 loc) · 4.17 KB
/
RelationshipRecordFormat.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
/*
* Copyright (c) 2002-2016 "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 Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.store.format.busted;
import java.io.IOException;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.impl.store.format.busted.Reference.DataAdapter;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
class RelationshipRecordFormat extends BaseBustedRecordFormat<RelationshipRecord>
{
private static final int RECORD_SIZE = 32;
private static final int FIRST_IN_START_BIT = 0b0000_1000;
private static final int FIRST_IN_END_BIT = 0b0001_0000;
private static final int HAS_START_NEXT_BIT = 0b0010_0000;
private static final int HAS_END_NEXT_BIT = 0b0100_0000;
private static final int HAS_PROPERTY_BIT = 0b1000_0000;
public RelationshipRecordFormat()
{
super( fixedRecordSize( RECORD_SIZE ), 0 );
}
@Override
public RelationshipRecord newRecord()
{
return new RelationshipRecord( -1 );
}
@Override
protected void doReadInternal( RelationshipRecord record, PageCursor cursor, int recordSize, long headerByte,
boolean inUse, DataAdapter<PageCursor> adapter )
{
int type = cursor.getShort() & 0xFFFF;
record.initialize( inUse,
decode( cursor, adapter, headerByte, HAS_PROPERTY_BIT, NULL ),
decode( cursor, adapter ),
decode( cursor, adapter ),
type,
decode( cursor, adapter ),
decode( cursor, adapter, headerByte, HAS_START_NEXT_BIT, NULL ),
decode( cursor, adapter ),
decode( cursor, adapter, headerByte, HAS_END_NEXT_BIT, NULL ),
has( headerByte, FIRST_IN_START_BIT ),
has( headerByte, FIRST_IN_END_BIT ) );
}
@Override
protected byte headerBits( RelationshipRecord record )
{
byte header = 0;
header = set( header, FIRST_IN_START_BIT, record.isFirstInFirstChain() );
header = set( header, FIRST_IN_END_BIT, record.isFirstInSecondChain() );
header = set( header, HAS_PROPERTY_BIT, record.getNextProp(), NULL );
header = set( header, HAS_START_NEXT_BIT, record.getFirstNextRel(), NULL );
header = set( header, HAS_END_NEXT_BIT, record.getSecondNextRel(), NULL );
return header;
}
@Override
protected int requiredDataLength( RelationshipRecord record )
{
return 2 + // type
length( record.getNextProp(), NULL ) +
length( record.getFirstNode() ) +
length( record.getSecondNode() ) +
length( record.getFirstPrevRel() ) +
length( record.getFirstNextRel(), NULL ) +
length( record.getSecondPrevRel() ) +
length( record.getSecondNextRel(), NULL );
}
@Override
protected void doWriteInternal( RelationshipRecord record, PageCursor cursor, DataAdapter<PageCursor> adapter )
throws IOException
{
cursor.putShort( (short) record.getType() );
encode( cursor, adapter, record.getNextProp(), NULL );
encode( cursor, adapter, record.getFirstNode() );
encode( cursor, adapter, record.getSecondNode() );
encode( cursor, adapter, record.getFirstPrevRel() );
encode( cursor, adapter, record.getFirstNextRel(), NULL );
encode( cursor, adapter, record.getSecondPrevRel() );
encode( cursor, adapter, record.getSecondNextRel(), NULL );
}
}