Skip to content

Commit

Permalink
Remove custom LongFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Dec 10, 2015
1 parent 26242c7 commit b6c12ef
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 123 deletions.

This file was deleted.

Expand Up @@ -23,11 +23,11 @@
import java.net.URL; import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.function.LongFunction;
import java.util.function.Supplier; import java.util.function.Supplier;


import org.neo4j.collection.primitive.PrimitiveLongCollections; import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.function.LongFunction;
import org.neo4j.graphdb.ConstraintViolationException; import org.neo4j.graphdb.ConstraintViolationException;
import org.neo4j.graphdb.DependencyResolver; import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Label;
Expand Down Expand Up @@ -354,43 +354,33 @@ private void checkAvailability()
public ResourceIterable<Node> getAllNodes() public ResourceIterable<Node> getAllNodes()
{ {
threadToTransactionBridge.assertInUnterminatedTransaction(); threadToTransactionBridge.assertInUnterminatedTransaction();
return new ResourceIterable<Node>() return () -> {
{ Statement statement = threadToTransactionBridge.get();
@Override return map2nodes( statement.readOperations().nodesGetAll(), statement );
public ResourceIterator<Node> iterator()
{
Statement statement = threadToTransactionBridge.get();
return map2nodes( statement.readOperations().nodesGetAll(), statement );
}
}; };
} }


@Override @Override
public ResourceIterable<Relationship> getAllRelationships() public ResourceIterable<Relationship> getAllRelationships()
{ {
threadToTransactionBridge.assertInUnterminatedTransaction(); threadToTransactionBridge.assertInUnterminatedTransaction();
return new ResourceIterable<Relationship>() return () -> {
{ final Statement statement = threadToTransactionBridge.get();
@Override final PrimitiveLongIterator ids = statement.readOperations().relationshipsGetAll();
public ResourceIterator<Relationship> iterator() return new PrefetchingResourceIterator<Relationship>()
{ {
final Statement statement = threadToTransactionBridge.get(); @Override
final PrimitiveLongIterator ids = statement.readOperations().relationshipsGetAll(); public void close()
return new PrefetchingResourceIterator<Relationship>()
{ {
@Override statement.close();
public void close() }
{
statement.close();
}


@Override @Override
protected Relationship fetchNextOrNull() protected Relationship fetchNextOrNull()
{ {
return ids.hasNext() ? nodeManager.newRelationshipProxy( ids.next() ) : null; return ids.hasNext() ? nodeManager.newRelationshipProxy( ids.next() ) : null;
} }
}; };
}
}; };
} }


Expand Down Expand Up @@ -480,14 +470,7 @@ public ResourceIterator<Node> findNodes( final Label myLabel )
public ResourceIterable<Node> findNodesByLabelAndProperty( final Label myLabel, final String key, public ResourceIterable<Node> findNodesByLabelAndProperty( final Label myLabel, final String key,
final Object value ) final Object value )
{ {
return new ResourceIterable<Node>() return () -> nodesByLabelAndProperty( myLabel, key, value );
{
@Override
public ResourceIterator<Node> iterator()
{
return nodesByLabelAndProperty( myLabel, key, value );
}
};
} }


private ResourceIterator<Node> nodesByLabelAndProperty( Label myLabel, String key, Object value ) private ResourceIterator<Node> nodesByLabelAndProperty( Label myLabel, String key, Object value )
Expand Down Expand Up @@ -562,26 +545,14 @@ private ResourceIterator<Node> allNodesWithLabel( final Label myLabel )
} }


final PrimitiveLongIterator nodeIds = statement.readOperations().nodesGetForLabel( labelId ); final PrimitiveLongIterator nodeIds = statement.readOperations().nodesGetForLabel( labelId );
return ResourceClosingIterator.newResourceIterator( statement, map( new LongFunction<Node>() return ResourceClosingIterator.newResourceIterator( statement, map(
{ (LongFunction<Node>) nodeId -> nodeManager.newNodeProxyById( nodeId ), nodeIds ) );
@Override
public Node apply( long nodeId )
{
return nodeManager.newNodeProxyById( nodeId );
}
}, nodeIds ) );
} }


private ResourceIterator<Node> map2nodes( PrimitiveLongIterator input, Statement statement ) private ResourceIterator<Node> map2nodes( PrimitiveLongIterator input, Statement statement )
{ {
return ResourceClosingIterator.newResourceIterator( statement, map( new LongFunction<Node>() return ResourceClosingIterator.newResourceIterator( statement, map(
{ (LongFunction<Node>) id -> nodeManager.newNodeProxyById( id ), input ) );
@Override
public Node apply( long id )
{
return nodeManager.newNodeProxyById( id );
}
}, input ) );
} }


@Override @Override
Expand Down
Expand Up @@ -31,9 +31,9 @@
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.function.LongFunction;


import org.neo4j.collection.primitive.PrimitiveLongCollections; import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.function.LongFunction;
import org.neo4j.graphdb.ConstraintViolationException; import org.neo4j.graphdb.ConstraintViolationException;
import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.NotFoundException; import org.neo4j.graphdb.NotFoundException;
Expand Down Expand Up @@ -150,7 +150,6 @@
import org.neo4j.logging.NullLog; import org.neo4j.logging.NullLog;


import static java.lang.Boolean.parseBoolean; import static java.lang.Boolean.parseBoolean;

import static org.neo4j.collection.primitive.PrimitiveLongCollections.map; import static org.neo4j.collection.primitive.PrimitiveLongCollections.map;
import static org.neo4j.graphdb.Label.label; import static org.neo4j.graphdb.Label.label;
import static org.neo4j.helpers.collection.IteratorUtil.first; import static org.neo4j.helpers.collection.IteratorUtil.first;
Expand Down Expand Up @@ -300,14 +299,7 @@ public Label apply( long from )
schemaCache = new SchemaCache( new StandardConstraintSemantics(), schemaStore ); schemaCache = new SchemaCache( new StandardConstraintSemantics(), schemaStore );


Dependencies deps = new Dependencies(); Dependencies deps = new Dependencies();
deps.satisfyDependencies( fileSystem, config, logService, new NeoStoresSupplier() deps.satisfyDependencies( fileSystem, config, logService, (NeoStoresSupplier) () -> neoStores );
{
@Override
public NeoStores get()
{
return neoStores;
}
} );


KernelContext kernelContext = new KernelContext() KernelContext kernelContext = new KernelContext()
{ {
Expand Down Expand Up @@ -542,36 +534,31 @@ private void repopulateAllIndexes() throws IOException, IndexCapacityExceededExc
populators[i].create(); populators[i].create();
} }


Visitor<NodePropertyUpdate, IOException> propertyUpdateVisitor = new Visitor<NodePropertyUpdate, IOException>() Visitor<NodePropertyUpdate, IOException> propertyUpdateVisitor = update -> {
{ // Do a lookup from which property has changed to a list of indexes worried about that property.
@Override int propertyKeyInQuestion = update.getPropertyKeyId();
public boolean visit( NodePropertyUpdate update ) throws IOException for ( int i = 0; i < propertyKeyIds.length; i++ )
{ {
// Do a lookup from which property has changed to a list of indexes worried about that property. if ( propertyKeyIds[i] == propertyKeyInQuestion )
int propertyKeyInQuestion = update.getPropertyKeyId();
for ( int i = 0; i < propertyKeyIds.length; i++ )
{ {
if ( propertyKeyIds[i] == propertyKeyInQuestion ) if ( update.forLabel( labelIds[i] ) )
{ {
if ( update.forLabel( labelIds[i] ) ) try
{
populators[i].add( update.getNodeId(), update.getValueAfter() );
}
catch ( IndexEntryConflictException conflict )
{
throw conflict.notAllowed( rules[i].getLabel(), rules[i].getPropertyKey() );
}
catch ( IndexCapacityExceededException e )
{ {
try throw new UnderlyingStorageException( e );
{
populators[i].add( update.getNodeId(), update.getValueAfter() );
}
catch ( IndexEntryConflictException conflict )
{
throw conflict.notAllowed( rules[i].getLabel(), rules[i].getPropertyKey() );
}
catch ( IndexCapacityExceededException e )
{
throw new UnderlyingStorageException( e );
}
} }
} }
} }
return true;
} }
return true;
}; };


InitialNodeLabelCreationVisitor labelUpdateVisitor = new InitialNodeLabelCreationVisitor(); InitialNodeLabelCreationVisitor labelUpdateVisitor = new InitialNodeLabelCreationVisitor();
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
import java.util.function.LongFunction;
import java.util.function.LongPredicate; import java.util.function.LongPredicate;


import org.neo4j.collection.primitive.base.Empty; import org.neo4j.collection.primitive.base.Empty;
Expand Down Expand Up @@ -705,8 +706,7 @@ public static PrimitiveLongSet setOf( long... values )
return set; return set;
} }


public static <T> Iterator<T> map( final org.neo4j.function.LongFunction<T> mapFunction, public static <T> Iterator<T> map( final LongFunction<T> mapFunction, final PrimitiveLongIterator source )
final PrimitiveLongIterator source )
{ {
return new Iterator<T>() return new Iterator<T>()
{ {
Expand Down

0 comments on commit b6c12ef

Please sign in to comment.