diff --git a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/MandatoryTransactionsForNodeIndexFacadeTest.java b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/MandatoryTransactionsForNodeIndexFacadeTest.java index 465432a4a70c8..bf4df1e35baac 100644 --- a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/MandatoryTransactionsForNodeIndexFacadeTest.java +++ b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/MandatoryTransactionsForNodeIndexFacadeTest.java @@ -23,14 +23,12 @@ import org.neo4j.graphdb.index.Index; -import static org.neo4j.graphdb.NodeIndexFacadeMethods.ALL_NODE_INDEX_FACADE_METHODS; - public class MandatoryTransactionsForNodeIndexFacadeTest extends AbstractMandatoryTransactionsTest> { @Test public void shouldRequireTransactionsWhenCallingMethodsOnNodeIndexFacade() { - assertFacadeMethodsThrowNotInTransaction( obtainEntity(), ALL_NODE_INDEX_FACADE_METHODS ); + assertFacadeMethodsThrowNotInTransaction( obtainEntity(), NodeIndexFacadeMethods.values() ); } @Override diff --git a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/MandatoryTransactionsForRelationshipIndexFacadeTest.java b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/MandatoryTransactionsForRelationshipIndexFacadeTest.java index e0a79f2cff80c..13c922f0cdc5b 100644 --- a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/MandatoryTransactionsForRelationshipIndexFacadeTest.java +++ b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/MandatoryTransactionsForRelationshipIndexFacadeTest.java @@ -23,14 +23,12 @@ import org.neo4j.graphdb.index.RelationshipIndex; -import static org.neo4j.graphdb.RelationshipIndexFacadeMethods.ALL_RELATIONSHIP_INDEX_FACADE_METHODS; - public class MandatoryTransactionsForRelationshipIndexFacadeTest extends AbstractMandatoryTransactionsTest { @Test public void shouldRequireTransactionsWhenCallingMethodsOnRelationshipIndexFacade() { - assertFacadeMethodsThrowNotInTransaction( obtainEntity(), ALL_RELATIONSHIP_INDEX_FACADE_METHODS ); + assertFacadeMethodsThrowNotInTransaction( obtainEntity(), RelationshipIndexFacadeMethods.values() ); } @Override diff --git a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/NodeIndexFacadeMethods.java b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/NodeIndexFacadeMethods.java index 3daa158c21a4d..1b224b1f1e03c 100644 --- a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/NodeIndexFacadeMethods.java +++ b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/NodeIndexFacadeMethods.java @@ -19,37 +19,38 @@ */ package org.neo4j.graphdb; -import org.neo4j.graphdb.index.Index; +import java.util.function.Consumer; -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableCollection; +import org.neo4j.graphdb.index.Index; -public class NodeIndexFacadeMethods +public enum NodeIndexFacadeMethods implements Consumer> { - private static final FacadeMethod> GET = new FacadeMethod<>( "IndexHits get( String key, Object value )", self -> self.get( "foo", "bar" ) ); - private static final FacadeMethod> QUERY_BY_KEY = new FacadeMethod<>( "IndexHits query( String key, Object queryOrQueryObject )", self -> self.query( "foo", "bar" ) ); - private static final FacadeMethod> QUERY = new FacadeMethod<>( "IndexHits query( Object queryOrQueryObject )", self -> self.query( "foo" ) ); - private static final FacadeMethod> ADD = new FacadeMethod<>( "void add( T entity, String key, Object value )", self -> self.add( null, "foo", 42 ) ); - private static final FacadeMethod> REMOVE_BY_KEY_AND_VALUE = new FacadeMethod<>( "void remove( T entity, String key, Object value )", self -> self.remove( null, "foo", 42 ) ); - private static final FacadeMethod> REMOVE_BY_KEY = new FacadeMethod<>( "void remove( T entity, String key )", self -> self.remove( null, "foo" ) ); - private static final FacadeMethod> REMOVE = new FacadeMethod<>( "void remove( T entity )", self -> self.remove( null ) ); - private static final FacadeMethod> DELETE = new FacadeMethod<>( "void delete()", Index::delete ); - private static final FacadeMethod> PUT_IF_ABSENT = new FacadeMethod<>( "T putIfAbsent( T entity, String key, Object value )", self -> self.putIfAbsent( null, "foo", 42 ) ); + GET( new FacadeMethod<>( "IndexHits get( String key, Object value )", self -> self.get( "foo", "bar" ) ) ), + QUERY_BY_KEY( new FacadeMethod<>( "IndexHits query( String key, Object queryOrQueryObject )", self -> self.query( "foo", "bar" ) ) ), + QUERY( new FacadeMethod<>( "IndexHits query( Object queryOrQueryObject )", self -> self.query( "foo" ) ) ), + ADD( new FacadeMethod<>( "void add( T entity, String key, Object value )", self -> self.add( null, "foo", 42 ) ) ), + REMOVE_BY_KEY_AND_VALUE( new FacadeMethod<>( "void remove( T entity, String key, Object value )", self -> self.remove( null, "foo", 42 ) ) ), + REMOVE_BY_KEY( new FacadeMethod<>( "void remove( T entity, String key )", self -> self.remove( null, "foo" ) ) ), + REMOVE( new FacadeMethod<>( "void remove( T entity )", self -> self.remove( null ) ) ), + DELETE( new FacadeMethod<>( "void delete()", Index::delete ) ), + PUT_IF_ABSENT( new FacadeMethod<>( "T putIfAbsent( T entity, String key, Object value )", self -> self.putIfAbsent( null, "foo", 42 ) ) ); + + private final FacadeMethod> facadeMethod; + + NodeIndexFacadeMethods( FacadeMethod> facadeMethod ) + { + this.facadeMethod = facadeMethod; + } - static final Iterable>> ALL_NODE_INDEX_FACADE_METHODS = unmodifiableCollection( - asList( - GET, - QUERY_BY_KEY, - QUERY, - ADD, - REMOVE_BY_KEY_AND_VALUE, - REMOVE_BY_KEY, - REMOVE, - DELETE, - PUT_IF_ABSENT - ) ); + @Override + public void accept( Index nodeIndex ) + { + facadeMethod.accept( nodeIndex ); + } - private NodeIndexFacadeMethods() + @Override + public String toString() { + return facadeMethod.toString(); } } diff --git a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/RelationshipIndexFacadeMethods.java b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/RelationshipIndexFacadeMethods.java index 9fe7a6e3b953a..471d328987ed7 100644 --- a/community/community-it/index-it/src/test/java/org/neo4j/graphdb/RelationshipIndexFacadeMethods.java +++ b/community/community-it/index-it/src/test/java/org/neo4j/graphdb/RelationshipIndexFacadeMethods.java @@ -19,44 +19,45 @@ */ package org.neo4j.graphdb; -import org.neo4j.graphdb.index.RelationshipIndex; +import java.util.function.Consumer; -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableCollection; +import org.neo4j.graphdb.index.RelationshipIndex; -public class RelationshipIndexFacadeMethods +public enum RelationshipIndexFacadeMethods implements Consumer { - private static final FacadeMethod GET_WITH_FILTER = new FacadeMethod<>( "IndexHits get( String key, Object valueOrNull, Node startNodeOrNull, Node endNodeOrNull )", ri -> ri.get( "foo", 42, null, null ) ); - private static final FacadeMethod QUERY_BY_KEY_WITH_FILTER = new FacadeMethod<>( "IndexHits query( String key, Object queryOrQueryObjectOrNull, Node startNodeOrNull, Node endNodeOrNull )", ri -> ri.query( "foo", 42, null, null ) ); - private static final FacadeMethod QUERY_WITH_FILTER = new FacadeMethod<>( "IndexHits query( Object queryOrQueryObjectOrNull, Node startNodeOrNull, Node endNodeOrNull )", ri -> ri.query( 42, null, null ) ); - private static final FacadeMethod GET = new FacadeMethod<>( "IndexHits get( String key, Object value )", ri -> ri.get( "foo", "bar" ) ); - private static final FacadeMethod QUERY_BY_KEY = new FacadeMethod<>( "IndexHits query( String key, Object queryOrQueryObject )", ri -> ri.query( "foo", "bar" ) ); - private static final FacadeMethod QUERY = new FacadeMethod<>( "IndexHits query( Object queryOrQueryObject )", ri -> ri.query( "foo" ) ); - private static final FacadeMethod ADD = new FacadeMethod<>( "void add( T entity, String key, Object value )", ri -> ri.add( null, "foo", 42 ) ); - private static final FacadeMethod REMOVE_BY_KEY_AND_VALUE = new FacadeMethod<>( "void remove( T entity, String key, Object value )", ri -> ri.remove( null, "foo", 42 ) ); - private static final FacadeMethod REMOVE_BY_KEY = new FacadeMethod<>( "void remove( T entity, String key )", ri -> ri.remove( null, "foo" ) ); - private static final FacadeMethod REMOVE = new FacadeMethod<>( "void remove( T entity )", ri -> ri.remove( null ) ); - private static final FacadeMethod DELETE = new FacadeMethod<>( "void delete()", RelationshipIndex::delete ); - private static final FacadeMethod PUT_IF_ABSENT = new FacadeMethod<>( "T putIfAbsent( T entity, String key, Object value )", ri -> ri.putIfAbsent( null, "foo", 42 ) ); + GET_WITH_FILTER( new FacadeMethod<>( "IndexHits get( String key, Object valueOrNull, Node startNodeOrNull, Node endNodeOrNull )", + ri -> ri.get( "foo", 42, null, null ) ) ), + QUERY_BY_KEY_WITH_FILTER( + new FacadeMethod<>( "IndexHits query( String key, Object queryOrQueryObjectOrNull, Node startNodeOrNull, Node endNodeOrNull )", + ri -> ri.query( "foo", 42, null, null ) ) ), + QUERY_WITH_FILTER( new FacadeMethod<>( "IndexHits query( Object queryOrQueryObjectOrNull, Node startNodeOrNull, Node endNodeOrNull )", + ri -> ri.query( 42, null, null ) ) ), + GET( new FacadeMethod<>( "IndexHits get( String key, Object value )", ri -> ri.get( "foo", "bar" ) ) ), + QUERY_BY_KEY( new FacadeMethod<>( "IndexHits query( String key, Object queryOrQueryObject )", ri -> ri.query( "foo", "bar" ) ) ), + QUERY( new FacadeMethod<>( "IndexHits query( Object queryOrQueryObject )", ri -> ri.query( "foo" ) ) ), + ADD( new FacadeMethod<>( "void add( T entity, String key, Object value )", ri -> ri.add( null, "foo", 42 ) ) ), + REMOVE_BY_KEY_AND_VALUE( new FacadeMethod<>( "void remove( T entity, String key, Object value )", ri -> ri.remove( null, "foo", 42 ) ) ), + REMOVE_BY_KEY( new FacadeMethod<>( "void remove( T entity, String key )", ri -> ri.remove( null, "foo" ) ) ), + REMOVE( new FacadeMethod<>( "void remove( T entity )", ri -> ri.remove( null ) ) ), + DELETE( new FacadeMethod<>( "void delete()", RelationshipIndex::delete ) ), + PUT_IF_ABSENT( new FacadeMethod<>( "T putIfAbsent( T entity, String key, Object value )", ri -> ri.putIfAbsent( null, "foo", 42 ) ) ); + + private final FacadeMethod facadeMethod; + + RelationshipIndexFacadeMethods( FacadeMethod facadeMethod ) + { + this.facadeMethod = facadeMethod; + } - static final Iterable> ALL_RELATIONSHIP_INDEX_FACADE_METHODS = - unmodifiableCollection( - asList( - GET_WITH_FILTER, - QUERY_BY_KEY_WITH_FILTER, - QUERY_WITH_FILTER, - GET, - QUERY_BY_KEY, - QUERY, - ADD, - REMOVE_BY_KEY_AND_VALUE, - REMOVE_BY_KEY, - REMOVE, - DELETE, - PUT_IF_ABSENT - ) ); + @Override + public void accept( RelationshipIndex relationshipIndex ) + { + facadeMethod.accept( relationshipIndex ); + } - private RelationshipIndexFacadeMethods() + @Override + public String toString() { + return facadeMethod.toString(); } } diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/AbstractMandatoryTransactionsTest.java b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/AbstractMandatoryTransactionsTest.java index bf95317753102..d0e689b33551b 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/AbstractMandatoryTransactionsTest.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/AbstractMandatoryTransactionsTest.java @@ -60,13 +60,13 @@ public void obtainEntityInTerminatedTransaction( Consumer f ) protected abstract T obtainEntityInTransaction( GraphDatabaseService graphDatabaseService ); - public static void assertFacadeMethodsThrowNotInTransaction( T entity, Iterable> methods ) + public static void assertFacadeMethodsThrowNotInTransaction( T entity, Consumer[] methods ) { - for ( FacadeMethod method : methods ) + for ( Consumer method : methods ) { try { - method.call( entity ); + method.accept( entity ); fail( "Transactions are mandatory, also for reads: " + method ); } @@ -77,15 +77,15 @@ public static void assertFacadeMethodsThrowNotInTransaction( T entity, Itera } } - public void assertFacadeMethodsThrowAfterTerminate( Iterable> methods ) + public void assertFacadeMethodsThrowAfterTerminate( Consumer[] methods ) { - for ( final FacadeMethod method : methods ) + for ( final Consumer method : methods ) { obtainEntityInTerminatedTransaction( entity -> { try { - method.call( entity ); + method.accept( entity ); fail( "Transaction was terminated, yet not exception thrown in: " + method ); } diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintCreatorFacadeMethods.java b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintCreatorFacadeMethods.java index d9c18d26f7c7c..6fdfc121874f3 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintCreatorFacadeMethods.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintCreatorFacadeMethods.java @@ -19,23 +19,31 @@ */ package org.neo4j.graphdb; -import org.neo4j.graphdb.schema.ConstraintCreator; +import java.util.function.Consumer; -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableCollection; +import org.neo4j.graphdb.schema.ConstraintCreator; -public class ConstraintCreatorFacadeMethods +public enum ConstraintCreatorFacadeMethods implements Consumer { - private static final FacadeMethod UNIQUE = new FacadeMethod<>( "ConstraintCreator assertPropertyIsUnique()", self -> self.assertPropertyIsUnique( "property" ) ); - private static final FacadeMethod CREATE = new FacadeMethod<>( "ConstraintDefinition create()", ConstraintCreator::create ); + UNIQUE( new FacadeMethod<>( "ConstraintCreator assertPropertyIsUnique()", self -> self.assertPropertyIsUnique( "property" ) ) ), + CREATE( new FacadeMethod<>( "ConstraintDefinition create()", ConstraintCreator::create ) ); + + private final FacadeMethod facadeMethod; + + ConstraintCreatorFacadeMethods( FacadeMethod facadeMethod ) + { + this.facadeMethod = facadeMethod; + } - static final Iterable> ALL_CONSTRAINT_CREATOR_FACADE_METHODS = - unmodifiableCollection( asList( - UNIQUE, - CREATE - ) ); + @Override + public void accept( ConstraintCreator constraintCreator ) + { + facadeMethod.accept( constraintCreator ); + } - private ConstraintCreatorFacadeMethods() + @Override + public String toString() { + return facadeMethod.toString(); } } diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintDefinitionFacadeMethods.java b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintDefinitionFacadeMethods.java index 4fcdad3246801..4dc849d78509c 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintDefinitionFacadeMethods.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/ConstraintDefinitionFacadeMethods.java @@ -19,30 +19,35 @@ */ package org.neo4j.graphdb; +import java.util.function.Consumer; + import org.neo4j.graphdb.schema.ConstraintDefinition; import org.neo4j.graphdb.schema.ConstraintType; -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableCollection; - -public class ConstraintDefinitionFacadeMethods +public enum ConstraintDefinitionFacadeMethods implements Consumer { - private static final FacadeMethod GET_LABEL = new FacadeMethod<>( "Label getLabel()", ConstraintDefinition::getLabel ); - private static final FacadeMethod GET_RELATIONSHIP_TYPE = new FacadeMethod<>( "RelationshipType getRelationshipType()", ConstraintDefinition::getRelationshipType ); - private static final FacadeMethod DROP = new FacadeMethod<>( "void drop()", ConstraintDefinition::drop ); - private static final FacadeMethod IS_CONSTRAINT_TYPE = new FacadeMethod<>( "boolean isConstraintType( ConstraintType type )", self -> self.isConstraintType( ConstraintType.UNIQUENESS ) ); - private static final FacadeMethod GET_PROPERTY_KEYS = new FacadeMethod<>( "Iterable getPropertyKeys()", ConstraintDefinition::getPropertyKeys ); + GET_LABEL( new FacadeMethod<>( "Label getLabel()", ConstraintDefinition::getLabel ) ), + GET_RELATIONSHIP_TYPE( new FacadeMethod<>( "RelationshipType getRelationshipType()", ConstraintDefinition::getRelationshipType ) ), + DROP( new FacadeMethod<>( "void drop()", ConstraintDefinition::drop ) ), + IS_CONSTRAINT_TYPE( new FacadeMethod<>( "boolean isConstraintType( ConstraintType type )", self -> self.isConstraintType( ConstraintType.UNIQUENESS ) ) ), + GET_PROPERTY_KEYS( new FacadeMethod<>( "Iterable getPropertyKeys()", ConstraintDefinition::getPropertyKeys ) ); + + private final FacadeMethod facadeMethod; + + ConstraintDefinitionFacadeMethods( FacadeMethod facadeMethod ) + { + this.facadeMethod = facadeMethod; + } - static final Iterable> ALL_CONSTRAINT_DEFINITION_FACADE_METHODS = - unmodifiableCollection( asList( - GET_LABEL, - GET_RELATIONSHIP_TYPE, - GET_PROPERTY_KEYS, - DROP, - IS_CONSTRAINT_TYPE - ) ); + @Override + public void accept( ConstraintDefinition constraintDefinition ) + { + facadeMethod.accept( constraintDefinition ); + } - private ConstraintDefinitionFacadeMethods() + @Override + public String toString() { + return facadeMethod.toString(); } } diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/GraphDatabaseServiceFacadeMethods.java b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/GraphDatabaseServiceFacadeMethods.java index 6814dc3af1a00..4c84a77bcd6ca 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/GraphDatabaseServiceFacadeMethods.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/graphdb/GraphDatabaseServiceFacadeMethods.java @@ -19,53 +19,50 @@ */ package org.neo4j.graphdb; -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableCollection; +import java.util.function.Consumer; + import static org.neo4j.graphdb.FacadeMethod.consume; import static org.neo4j.graphdb.Label.label; -import static org.neo4j.helpers.collection.Iterators.loop; /** * Test convenience: all the methods on GraphDatabaseService, callable using generic interface */ -public class GraphDatabaseServiceFacadeMethods +public enum GraphDatabaseServiceFacadeMethods implements Consumer { - static final FacadeMethod CREATE_NODE = new FacadeMethod<>( "Node createNode()", GraphDatabaseService::createNode ); - static final FacadeMethod CREATE_NODE_WITH_LABELS = new FacadeMethod<>( "Node createNode( Label... labels )", gds -> gds.createNode( label( "FOO" ) ) ); - static final FacadeMethod GET_NODE_BY_ID = new FacadeMethod<>( "Node getNodeById( long id )", gds -> gds.getNodeById( 42 ) ); - static final FacadeMethod GET_RELATIONSHIP_BY_ID = new FacadeMethod<>( "Relationship getRelationshipById( long id )", gds -> gds.getRelationshipById( 42 ) ); - static final FacadeMethod GET_ALL_NODES = new FacadeMethod<>( "Iterable getAllNodes()", gds -> consume( gds.getAllNodes() ) ); - static final FacadeMethod FIND_NODES_BY_LABEL_AND_PROPERTY_DEPRECATED = new FacadeMethod<>( - "ResourceIterator findNodeByLabelAndProperty( Label label, String key, Object value )", gds -> consume( gds.findNodes( label( "bar" ), "baz", 23 ) ) ); - static final FacadeMethod FIND_NODES_BY_LABEL = new FacadeMethod<>( - "ResourceIterator findNodes( Label label )", gds -> consume( gds.findNodes( label( "bar" ) ) ) ); - static final FacadeMethod GET_ALL_LABELS = new FacadeMethod<>( "Iterable