Skip to content

Commit

Permalink
Removed org.neo4j.test.AlgebraicFunction
Browse files Browse the repository at this point in the history
All usages changed to java.util.function.Function.
  • Loading branch information
lutovich committed Dec 17, 2015
1 parent e645ef8 commit c0e1e39
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 166 deletions.

This file was deleted.

Expand Up @@ -20,95 +20,61 @@
package org.neo4j.test; package org.neo4j.test;


import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function;


import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;


public class DatabaseFunctions public final class DatabaseFunctions
{ {
public static AlgebraicFunction<GraphDatabaseService, Node> createNode() private DatabaseFunctions()
{ {
return new AlgebraicFunction<GraphDatabaseService, Node>() throw new AssertionError( "Not for instantiation!" );
{
@Override
public Node apply( GraphDatabaseService graphDb )
{
return graphDb.createNode();
}
};
} }


public static AlgebraicFunction<Node, Node> addLabel( final Label label ) public static Function<GraphDatabaseService,Node> createNode()
{ {
return new AlgebraicFunction<Node, Node>() return GraphDatabaseService::createNode;
{
@Override
public Node apply( Node node )
{
node.addLabel( label );
return node;
}
};
} }


public static AlgebraicFunction<Node, Node> setProperty( final String propertyKey, final Object value ) public static Function<Node,Node> addLabel( Label label )
{ {
return new AlgebraicFunction<Node, Node>() return node -> {
{ node.addLabel( label );
@Override return node;
public Node apply( Node node )
{
node.setProperty( propertyKey, value );
return node;
}
}; };
} }


public static AlgebraicFunction<GraphDatabaseService, Void> index( public static Function<Node,Node> setProperty( String propertyKey, Object value )
final Label label, final String propertyKey )
{ {
return new AlgebraicFunction<GraphDatabaseService, Void>() return node -> {
{ node.setProperty( propertyKey, value );
@Override return node;
public Void apply( GraphDatabaseService graphDb )
{
graphDb.schema().indexFor( label ).on( propertyKey ).create();
return null;
}
}; };
} }


public static AlgebraicFunction<GraphDatabaseService, Void> uniquenessConstraint( public static Function<GraphDatabaseService,Void> index( Label label, String propertyKey )
final Label label, final String propertyKey )
{ {
return new AlgebraicFunction<GraphDatabaseService, Void>() return graphDb -> {
{ graphDb.schema().indexFor( label ).on( propertyKey ).create();
@Override return null;
public Void apply( GraphDatabaseService graphDb )
{
graphDb.schema().constraintFor( label ).assertPropertyIsUnique( propertyKey ).create();
return null;
}
}; };
} }


public static AlgebraicFunction<GraphDatabaseService, Void> awaitIndexesOnline( public static Function<GraphDatabaseService,Void> uniquenessConstraint( Label label, String propertyKey )
final long timeout, final TimeUnit unit )
{ {
return new AlgebraicFunction<GraphDatabaseService, Void>() return graphDb -> {
{ graphDb.schema().constraintFor( label ).assertPropertyIsUnique( propertyKey ).create();
@Override return null;
public Void apply( GraphDatabaseService graphDb )
{
graphDb.schema().awaitIndexesOnline( timeout, unit );
return null;
}
}; };
} }


private DatabaseFunctions() public static Function<GraphDatabaseService,Void> awaitIndexesOnline( long timeout, TimeUnit unit )
{ {
// no instances return graphDb -> {
graphDb.schema().awaitIndexesOnline( timeout, unit );
return null;
};
} }
} }
21 changes: 4 additions & 17 deletions community/kernel/src/test/java/org/neo4j/test/DatabaseRule.java
Expand Up @@ -95,24 +95,11 @@ public <T> T executeAndRollback( Function<? super GraphDatabaseService, T> funct
return transaction( function, false ); return transaction( function, false );
} }


public <FROM, TO> AlgebraicFunction<FROM, TO> tx( final Function<FROM, TO> function ) public <FROM, TO> Function<FROM,TO> tx( Function<FROM,TO> function )
{ {
return new AlgebraicFunction<FROM, TO>() return from -> executeAndCommit( graphDb -> {
{ return function.apply( from );
@Override } );
public TO apply( final FROM from )
{
return executeAndCommit( graphDb -> {
return function.apply( from );
} );
}

@Override
public String toString()
{
return "tx( " + function + " )";
}
};
} }


private <T> T transaction( Function<? super GraphDatabaseService, T> function, boolean commit ) private <T> T transaction( Function<? super GraphDatabaseService, T> function, boolean commit )
Expand Down
Expand Up @@ -86,7 +86,7 @@ public void given() throws Exception
public void tx_createNode_addLabel_setProperty() throws Exception public void tx_createNode_addLabel_setProperty() throws Exception
{ {
db.when( db.tx( db.when( db.tx(
createNode().then( addLabel( label( "Label1" ) ).then( setProperty( "key1", "value1" ) ) ) createNode().andThen( addLabel( label( "Label1" ) ).andThen( setProperty( "key1", "value1" ) ) )
) ); ) );
} }


Expand All @@ -95,17 +95,17 @@ public void tx_createNode_tx_addLabel_setProperty() throws Exception
{ {
db.when( db.tx( db.when( db.tx(
createNode() createNode()
).then( db.tx( ).andThen( db.tx(
addLabel( label( "Label1" ) ).then( setProperty( "key1", "value1" ) ) addLabel( label( "Label1" ) ).andThen( setProperty( "key1", "value1" ) )
) ) ); ) ) );
} }


@Test @Test
public void tx_createNode_addLabel_tx_setProperty() throws Exception public void tx_createNode_addLabel_tx_setProperty() throws Exception
{ {
db.when( db.tx( db.when( db.tx(
createNode().then( addLabel( label( "Label1" ) ) ) createNode().andThen( addLabel( label( "Label1" ) ) )
).then( db.tx( ).andThen( db.tx(
setProperty( "key1", "value1" ) setProperty( "key1", "value1" )
) ) ); ) ) );
} }
Expand All @@ -114,8 +114,8 @@ public void tx_createNode_addLabel_tx_setProperty() throws Exception
public void tx_createNode_setProperty_tx_addLabel() throws Exception public void tx_createNode_setProperty_tx_addLabel() throws Exception
{ {
db.when( db.tx( db.when( db.tx(
createNode().then( setProperty( "key1", "value1" ) ) createNode().andThen( setProperty( "key1", "value1" ) )
).then( db.tx( ).andThen( db.tx(
addLabel( label( "Label1" ) ) addLabel( label( "Label1" ) )
) ) ); ) ) );
} }
Expand All @@ -125,9 +125,9 @@ public void tx_createNode_tx_addLabel_tx_setProperty() throws Exception
{ {
db.when( db.tx( db.when( db.tx(
createNode() createNode()
).then( db.tx( ).andThen( db.tx(
addLabel( label( "Label1" ) ) addLabel( label( "Label1" ) )
).then( db.tx( ).andThen( db.tx(
setProperty( "key1", "value1" ) ) setProperty( "key1", "value1" ) )
) ) ); ) ) );
} }
Expand All @@ -137,9 +137,9 @@ public void tx_createNode_tx_setProperty_tx_addLabel() throws Exception
{ {
db.when( db.tx( db.when( db.tx(
createNode() createNode()
).then( db.tx( ).andThen( db.tx(
setProperty( "key1", "value1" ) setProperty( "key1", "value1" )
).then( db.tx( ).andThen( db.tx(
addLabel( label( "Label1" ) ) addLabel( label( "Label1" ) )
) ) ) ); ) ) ) );
} }
Expand Down

0 comments on commit c0e1e39

Please sign in to comment.