Skip to content

Commit

Permalink
Extract Progression interface
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed May 8, 2017
1 parent 6b82386 commit 627753b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
Expand Up @@ -22,7 +22,7 @@
import org.neo4j.kernel.api.StatementConstants; import org.neo4j.kernel.api.StatementConstants;
import org.neo4j.kernel.impl.store.NodeStore; import org.neo4j.kernel.impl.store.NodeStore;


public class AllNodeProgression implements NodeCursor.Progression public class AllNodeProgression implements Progression
{ {
private final AllIdIterator allIdIterator; private final AllIdIterator allIdIterator;


Expand Down
Expand Up @@ -37,28 +37,15 @@
import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.storageengine.api.txstate.ReadableTransactionState;


import static org.neo4j.collection.primitive.PrimitiveIntCollections.asSet; import static org.neo4j.collection.primitive.PrimitiveIntCollections.asSet;
import static org.neo4j.kernel.impl.api.store.NodeCursor.Progression.Mode.APPEND; import static org.neo4j.kernel.impl.api.store.Progression.Mode.APPEND;
import static org.neo4j.kernel.impl.api.store.NodeCursor.Progression.Mode.FETCH; import static org.neo4j.kernel.impl.api.store.Progression.Mode.FETCH;
import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK; import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK;
import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK_SERVICE; import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK_SERVICE;
import static org.neo4j.kernel.impl.store.record.RecordLoad.CHECK; import static org.neo4j.kernel.impl.store.record.RecordLoad.CHECK;
import static org.neo4j.kernel.impl.util.IoPrimitiveUtils.safeCastLongToInt; import static org.neo4j.kernel.impl.util.IoPrimitiveUtils.safeCastLongToInt;


public class NodeCursor implements NodeItem, Cursor<NodeItem> public class NodeCursor implements NodeItem, Cursor<NodeItem>
{ {
public interface Progression
{
enum Mode
{
APPEND,
FETCH
}

long nextId();

Mode mode();
}

private final NodeRecord nodeRecord; private final NodeRecord nodeRecord;
private final Consumer<NodeCursor> instanceCache; private final Consumer<NodeCursor> instanceCache;
private final RecordCursors recordCursors; private final RecordCursors recordCursors;
Expand Down
@@ -0,0 +1,33 @@
/*
* 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.api.store;

public interface Progression
{
enum Mode
{
APPEND,
FETCH
}

long nextId();

Mode mode();
}
Expand Up @@ -21,7 +21,7 @@


import org.neo4j.kernel.api.StatementConstants; import org.neo4j.kernel.api.StatementConstants;


public class SingleNodeProgression implements NodeCursor.Progression public class SingleNodeProgression implements Progression
{ {
private long nodeId; private long nodeId;


Expand Down
Expand Up @@ -36,7 +36,7 @@
import org.neo4j.cursor.Cursor; import org.neo4j.cursor.Cursor;
import org.neo4j.kernel.api.StatementConstants; import org.neo4j.kernel.api.StatementConstants;
import org.neo4j.kernel.impl.api.state.TxState; import org.neo4j.kernel.impl.api.state.TxState;
import org.neo4j.kernel.impl.api.store.NodeCursor.Progression.Mode; import org.neo4j.kernel.impl.api.store.Progression.Mode;
import org.neo4j.kernel.impl.locking.Lock; import org.neo4j.kernel.impl.locking.Lock;
import org.neo4j.kernel.impl.store.RecordCursor; import org.neo4j.kernel.impl.store.RecordCursor;
import org.neo4j.kernel.impl.store.RecordCursors; import org.neo4j.kernel.impl.store.RecordCursors;
Expand All @@ -54,8 +54,8 @@
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.neo4j.collection.primitive.PrimitiveIntCollections.asArray; import static org.neo4j.collection.primitive.PrimitiveIntCollections.asArray;
import static org.neo4j.collection.primitive.PrimitiveIntCollections.asSet; import static org.neo4j.collection.primitive.PrimitiveIntCollections.asSet;
import static org.neo4j.kernel.impl.api.store.NodeCursor.Progression.Mode.APPEND; import static org.neo4j.kernel.impl.api.store.Progression.Mode.APPEND;
import static org.neo4j.kernel.impl.api.store.NodeCursor.Progression.Mode.FETCH; import static org.neo4j.kernel.impl.api.store.Progression.Mode.FETCH;
import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK_SERVICE; import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK_SERVICE;
import static org.neo4j.kernel.impl.store.record.RecordLoad.CHECK; import static org.neo4j.kernel.impl.store.record.RecordLoad.CHECK;
import static org.neo4j.kernel.impl.transaction.state.NodeLabelsFieldTest.inlinedLabelsLongRepresentation; import static org.neo4j.kernel.impl.transaction.state.NodeLabelsFieldTest.inlinedLabelsLongRepresentation;
Expand Down Expand Up @@ -224,7 +224,7 @@ public void shouldCallTheConsumerOnClose()
MutableBoolean called = new MutableBoolean(); MutableBoolean called = new MutableBoolean();
NodeCursor cursor = NodeCursor cursor =
new NodeCursor( nodeRecord, c -> called.setTrue(), recordCursors, NO_LOCK_SERVICE ); new NodeCursor( nodeRecord, c -> called.setTrue(), recordCursors, NO_LOCK_SERVICE );
cursor.init( mock( NodeCursor.Progression.class ), mock( ReadableTransactionState.class ) ); cursor.init( mock( Progression.class ), mock( ReadableTransactionState.class ) );
assertFalse( called.booleanValue() ); assertFalse( called.booleanValue() );


cursor.close(); cursor.close();
Expand Down Expand Up @@ -523,9 +523,9 @@ Cursor<NodeItem> initialize( NodeCursor cursor, RecordCursor<NodeRecord> recordC
return cursor.init( createProgression( ops, mode ), state ); return cursor.init( createProgression( ops, mode ), state );
} }


private NodeCursor.Progression createProgression( Operation[] ops, Mode mode ) private Progression createProgression( Operation[] ops, Mode mode )
{ {
return new NodeCursor.Progression() return new Progression()
{ {
private int i = 0; private int i = 0;


Expand Down

0 comments on commit 627753b

Please sign in to comment.