diff --git a/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/codegen/CompiledExpandUtilsTest.java b/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/codegen/CompiledExpandUtilsTest.java index 3ba8c99cea6e9..501927cf0a87c 100644 --- a/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/codegen/CompiledExpandUtilsTest.java +++ b/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/codegen/CompiledExpandUtilsTest.java @@ -28,10 +28,10 @@ import org.neo4j.internal.kernel.api.Kernel; import org.neo4j.internal.kernel.api.NodeCursor; import org.neo4j.internal.kernel.api.Read; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.TokenWrite; import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.Write; +import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.security.LoginContext; import org.neo4j.test.rule.DatabaseRule; import org.neo4j.test.rule.EmbeddedDatabaseRule; @@ -42,6 +42,7 @@ import static org.neo4j.graphdb.Direction.BOTH; import static org.neo4j.graphdb.Direction.INCOMING; import static org.neo4j.graphdb.Direction.OUTGOING; +import static org.neo4j.internal.kernel.api.Transaction.Type.implicit; public class CompiledExpandUtilsTest { @@ -49,19 +50,18 @@ public class CompiledExpandUtilsTest public DatabaseRule db = new EmbeddedDatabaseRule() .withSetting( GraphDatabaseSettings.dense_node_threshold, "1" ); - private Session session() + private Transaction transaction() throws TransactionFailureException { DependencyResolver resolver = this.db.getDependencyResolver(); - return resolver.resolveDependency( Kernel.class ).beginSession( LoginContext.AUTH_DISABLED ); + return resolver.resolveDependency( Kernel.class ).beginTransaction( implicit, LoginContext.AUTH_DISABLED ); } @Test public void shouldComputeDegreeWithoutType() throws Exception { // GIVEN - Session session = session(); long node; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = transaction() ) { Write write = tx.dataWrite(); node = write.nodeCreate(); @@ -80,7 +80,7 @@ public void shouldComputeDegreeWithoutType() throws Exception tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = transaction() ) { Read read = tx.dataRead(); CursorFactory cursors = tx.cursors(); @@ -97,10 +97,9 @@ public void shouldComputeDegreeWithoutType() throws Exception public void shouldComputeDegreeWithType() throws Exception { // GIVEN - Session session = session(); long node; int in, out, loop; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = transaction() ) { Write write = tx.dataWrite(); node = write.nodeCreate(); @@ -118,7 +117,7 @@ public void shouldComputeDegreeWithType() throws Exception tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = transaction() ) { Read read = tx.dataRead(); CursorFactory cursors = tx.cursors(); diff --git a/community/kernel-api/src/main/java/org/neo4j/internal/kernel/api/Kernel.java b/community/kernel-api/src/main/java/org/neo4j/internal/kernel/api/Kernel.java index 5cf723a54b533..0a6145cc7d34d 100644 --- a/community/kernel-api/src/main/java/org/neo4j/internal/kernel/api/Kernel.java +++ b/community/kernel-api/src/main/java/org/neo4j/internal/kernel/api/Kernel.java @@ -19,6 +19,7 @@ */ package org.neo4j.internal.kernel.api; +import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.security.LoginContext; /** @@ -26,5 +27,5 @@ */ public interface Kernel { - Session beginSession( LoginContext loginContext ); + T beginTransaction( Transaction.Type type, LoginContext loginContext ) throws TransactionFailureException; } diff --git a/community/kernel-api/src/main/java/org/neo4j/internal/kernel/api/Session.java b/community/kernel-api/src/main/java/org/neo4j/internal/kernel/api/Session.java deleted file mode 100644 index dd3f154b3f9d9..0000000000000 --- a/community/kernel-api/src/main/java/org/neo4j/internal/kernel/api/Session.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2002-2018 "Neo4j," - * Neo4j Sweden AB [http://neo4j.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 . - */ -package org.neo4j.internal.kernel.api; - -import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; - -/** - * A Session is used to gain - */ -public interface Session extends AutoCloseable -{ - /** - * Begin new explicit transaction. - * - * @return The new transaction - */ - Transaction beginTransaction() throws TransactionFailureException; - - /** - * Begin new transaction. - * - * @param type The type of transaction - * @return The new transaction - */ - Transaction beginTransaction( Transaction.Type type ) throws TransactionFailureException; - - @Override - void close(); -} diff --git a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/ConstraintTestBase.java b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/ConstraintTestBase.java index 3c431ef09dc9b..2cb07241dd37e 100644 --- a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/ConstraintTestBase.java +++ b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/ConstraintTestBase.java @@ -68,7 +68,7 @@ public void shouldFindConstraintsBySchema() throws Exception // GIVEN addConstraints( "FOO", "prop" ); - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int label = tx.tokenWrite().labelGetOrCreateForName( "FOO" ); int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); @@ -90,7 +90,7 @@ public void shouldFindConstraintsByLabel() throws Exception // GIVEN addConstraints( "FOO", "prop1", "FOO", "prop2" ); - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int label = tx.tokenWrite().labelGetOrCreateForName( "FOO" ); @@ -117,7 +117,7 @@ public void shouldBeAbleCheckExistenceOfConstraints() throws Exception tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int label = tx.tokenWrite().labelGetOrCreateForName( "FOO" ); int prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop1" ); @@ -135,7 +135,7 @@ public void shouldFindAllConstraints() throws Exception // GIVEN addConstraints( "FOO", "prop1", "BAR", "prop2", "BAZ", "prop3" ); - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { //WHEN List constraints = asList( tx.schemaRead().constraintsGetAll() ); @@ -169,7 +169,7 @@ public void shouldCheckUniquenessWhenAddingLabel() throws Exception } int label; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { label = tx.tokenWrite().labelGetOrCreateForName( "FOO" ); @@ -189,7 +189,7 @@ public void shouldCheckUniquenessWhenAddingLabel() throws Exception } //Verify - try ( Transaction tx = session.beginTransaction(); + try ( Transaction tx = beginTransaction(); NodeCursor nodeCursor = tx.cursors().allocateNodeCursor() ) { //Node without conflict @@ -227,7 +227,7 @@ public void shouldCheckUniquenessWhenAddingProperties() throws Exception } int property; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { property = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); @@ -247,7 +247,7 @@ public void shouldCheckUniquenessWhenAddingProperties() throws Exception } //Verify - try ( Transaction tx = session.beginTransaction(); + try ( Transaction tx = beginTransaction(); NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(); PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor() ) { diff --git a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/ExplicitIndexCursorWritesTestBase.java b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/ExplicitIndexCursorWritesTestBase.java index 36d5cb44fdefa..9290239c74973 100644 --- a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/ExplicitIndexCursorWritesTestBase.java +++ b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/ExplicitIndexCursorWritesTestBase.java @@ -46,7 +46,7 @@ public abstract class ExplicitIndexCursorWritesTestBase config = new HashMap<>(); @@ -68,7 +68,7 @@ public void shouldCreateExplicitNodeIndexEagerly() throws Exception public void shouldCreateExplicitNodeIndexLazily() throws Exception { // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); HashMap config = new HashMap<>(); @@ -90,7 +90,7 @@ public void shouldCreateExplicitNodeIndexLazily() throws Exception public void shouldAddNodeToExplicitIndex() throws Exception { long nodeId; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { nodeId = tx.dataWrite().nodeCreate(); ExplicitIndexWrite indexWrite = tx.indexWrite(); @@ -115,7 +115,7 @@ public void shouldRemoveNodeFromExplicitIndex() throws Exception long nodeId = addNodeToExplicitIndex(); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId ); @@ -139,14 +139,14 @@ public void shouldHandleRemoveNodeFromExplicitIndexTwice() throws Exception long nodeId = addNodeToExplicitIndex(); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId ); tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId ); @@ -170,7 +170,7 @@ public void shouldRemoveNonExistingNodeFromExplicitIndex() throws Exception long nodeId = addNodeToExplicitIndex(); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId + 1 ); @@ -192,7 +192,7 @@ public void shouldRemoveNonExistingNodeFromExplicitIndex() throws Exception public void shouldCreateExplicitRelationshipIndexEagerly() throws Exception { // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); HashMap config = new HashMap<>(); @@ -214,7 +214,7 @@ public void shouldCreateExplicitRelationshipIndexEagerly() throws Exception public void shouldCreateExplicitRelationshipIndexLazily() throws Exception { // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); HashMap config = new HashMap<>(); @@ -240,7 +240,7 @@ public void shouldCreateExplicitIndexTwice() throws Exception config.put( "type", "exact" ); config.put( "provider", "lucene" ); - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); indexWrite.nodeExplicitIndexCreateLazily( INDEX_NAME, config ); @@ -248,7 +248,7 @@ public void shouldCreateExplicitIndexTwice() throws Exception } // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); indexWrite.nodeExplicitIndexCreateLazily( INDEX_NAME, config ); @@ -274,7 +274,7 @@ public void shouldAddRelationshipToExplicitIndex() throws Exception ctx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); indexWrite.relationshipAddToExplicitIndex( INDEX_NAME, relId, KEY, VALUE ); @@ -298,7 +298,7 @@ public void shouldRemoveRelationshipFromExplicitIndex() throws Exception long relId = addRelationshipToExplicitIndex(); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId ); @@ -322,14 +322,14 @@ public void shouldHandleRemoveRelationshipFromExplicitIndexTwice() throws Except long relId = addRelationshipToExplicitIndex(); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId ); tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId ); @@ -353,7 +353,7 @@ public void shouldRemoveNonExistingRelationshipFromExplicitIndex() throws Except long relId = addRelationshipToExplicitIndex(); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId + 1 ); @@ -374,7 +374,7 @@ public void shouldRemoveNonExistingRelationshipFromExplicitIndex() throws Except private long addNodeToExplicitIndex() throws Exception { long nodeId; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { nodeId = tx.dataWrite().nodeCreate(); ExplicitIndexWrite indexWrite = tx.indexWrite(); diff --git a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/GraphPropertiesTestBase.java b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/GraphPropertiesTestBase.java index 60ac9346e8279..9aedb0eaeaf74 100644 --- a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/GraphPropertiesTestBase.java +++ b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/GraphPropertiesTestBase.java @@ -38,7 +38,7 @@ public abstract class GraphPropertiesTestBase cursors ); @@ -95,7 +100,6 @@ public void closeTransaction() throws Exception { tx.success(); tx.close(); - session.close(); } @AfterClass diff --git a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/KernelAPIWriteTestBase.java b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/KernelAPIWriteTestBase.java index 607fba8021d3e..b9080ab9003a7 100644 --- a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/KernelAPIWriteTestBase.java +++ b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/KernelAPIWriteTestBase.java @@ -19,7 +19,6 @@ */ package org.neo4j.internal.kernel.api; -import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.rules.TemporaryFolder; @@ -27,6 +26,7 @@ import java.io.IOException; import org.neo4j.graphdb.GraphDatabaseService; +import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.security.LoginContext; /** @@ -45,7 +45,6 @@ public abstract class KernelAPIWriteTestBase ext public void shouldCreateNode() throws Exception { long node; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { node = tx.dataWrite().nodeCreate(); tx.success(); @@ -72,7 +72,7 @@ public void shouldCreateNode() throws Exception public void shouldRollbackOnFailure() throws Exception { long node; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { node = tx.dataWrite().nodeCreate(); tx.failure(); @@ -94,7 +94,7 @@ public void shouldRemoveNode() throws Exception { long node = createNode(); - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { tx.dataWrite().nodeDelete( node ); tx.success(); @@ -118,12 +118,12 @@ public void shouldNotRemoveNodeThatDoesNotExist() throws Exception { long node = 0; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { assertFalse( tx.dataWrite().nodeDelete( node ) ); tx.failure(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { assertFalse( tx.dataWrite().nodeDelete( node ) ); tx.success(); @@ -138,7 +138,7 @@ public void shouldAddLabelNode() throws Exception long node = createNode(); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int labelId = tx.token().labelGetOrCreateForName( labelName ); assertTrue( tx.dataWrite().nodeAddLabel( node, labelId ) ); @@ -154,7 +154,7 @@ public void shouldAddLabelNodeOnce() throws Exception { long node = createNodeWithLabel( labelName ); - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int labelId = tx.token().labelGetOrCreateForName( labelName ); assertFalse( tx.dataWrite().nodeAddLabel( node, labelId ) ); @@ -169,7 +169,7 @@ public void shouldRemoveLabel() throws Exception { long nodeId = createNodeWithLabel( labelName ); - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int labelId = tx.token().labelGetOrCreateForName( labelName ); assertTrue( tx.dataWrite().nodeRemoveLabel( nodeId, labelId ) ); @@ -184,7 +184,7 @@ public void shouldNotAddLabelToNonExistingNode() throws Exception { long node = 1337L; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int labelId = tx.token().labelGetOrCreateForName( labelName ); exception.expect( KernelException.class ); @@ -198,14 +198,14 @@ public void shouldRemoveLabelOnce() throws Exception int labelId; long nodeId = createNodeWithLabel( labelName ); - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { labelId = tx.token().labelGetOrCreateForName( labelName ); assertTrue( tx.dataWrite().nodeRemoveLabel( nodeId, labelId ) ); tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { labelId = tx.token().labelGetOrCreateForName( labelName ); assertFalse( tx.dataWrite().nodeRemoveLabel( nodeId, labelId ) ); @@ -222,7 +222,7 @@ public void shouldAddPropertyToNode() throws Exception long node = createNode(); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().nodeSetProperty( node, token, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); @@ -240,7 +240,7 @@ public void shouldRollbackSetNodeProperty() throws Exception long node = createNode(); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().nodeSetProperty( node, token, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); @@ -259,7 +259,7 @@ public void shouldThrowWhenSettingPropertyOnDeletedNode() throws Exception deleteNode( node ); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); tx.dataWrite().nodeSetProperty( node, token, stringValue( "hello" ) ); @@ -278,7 +278,7 @@ public void shouldUpdatePropertyToNode() throws Exception long node = createNodeWithProperty( propertyKey, 42 ); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().nodeSetProperty( node, token, stringValue( "hello" ) ), @@ -297,7 +297,7 @@ public void shouldRemovePropertyFromNode() throws Exception long node = createNodeWithProperty( propertyKey, 42 ); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().nodeRemoveProperty( node, token ), @@ -316,7 +316,7 @@ public void shouldRemoveNonExistingPropertyFromNode() throws Exception long node = createNode(); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().nodeRemoveProperty( node, token ), equalTo( NO_VALUE ) ); @@ -334,7 +334,7 @@ public void shouldRemovePropertyFromNodeTwice() throws Exception long node = createNodeWithProperty( propertyKey, 42 ); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().nodeRemoveProperty( node, token ), @@ -355,7 +355,7 @@ public void shouldUpdatePropertyToNodeInTransaction() throws Exception long node = createNode(); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().nodeSetProperty( node, token, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); @@ -376,7 +376,7 @@ public void shouldRemoveReSetAndTwiceRemovePropertyOnNode() throws Exception // when - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int prop = tx.token().propertyKeyGetOrCreateForName( propertyKey ); tx.dataWrite().nodeRemoveProperty( node, prop ); @@ -398,7 +398,7 @@ public void shouldNotWriteWhenSettingPropertyToSameValue() throws Exception long nodeId = createNodeWithProperty( propertyKey, theValue.asObject() ); // When - Transaction tx = session.beginTransaction(); + Transaction tx = beginTransaction(); int property = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().nodeSetProperty( nodeId, property, theValue ), equalTo( theValue ) ); tx.success(); @@ -415,7 +415,7 @@ public void shouldSetAndReadLargeByteArrayPropertyToNode() throws Exception Value largeByteArray = Values.of( new byte[100_000] ); // When - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { prop = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().nodeSetProperty( node, prop, largeByteArray ), equalTo( NO_VALUE ) ); @@ -423,7 +423,7 @@ public void shouldSetAndReadLargeByteArrayPropertyToNode() throws Exception } // Then - try ( Transaction tx = session.beginTransaction(); + try ( Transaction tx = beginTransaction(); NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(); PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor() ) { diff --git a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/RelationshipTransactionStateTestBase.java b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/RelationshipTransactionStateTestBase.java index 778e0da5f8b46..0ede7afbac548 100644 --- a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/RelationshipTransactionStateTestBase.java +++ b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/RelationshipTransactionStateTestBase.java @@ -62,7 +62,7 @@ public void shouldSeeSingleRelationshipInTransaction() throws Exception { int label; long n1, n2; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { n1 = tx.dataWrite().nodeCreate(); n2 = tx.dataWrite().nodeCreate(); @@ -74,7 +74,7 @@ public void shouldSeeSingleRelationshipInTransaction() throws Exception tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { long r = tx.dataWrite().relationshipCreate( n1, label, n2 ); try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor() ) @@ -98,7 +98,7 @@ public void shouldNotSeeSingleRelationshipWhichWasDeletedInTransaction() throws { int label; long n1, n2, r; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { n1 = tx.dataWrite().nodeCreate(); n2 = tx.dataWrite().nodeCreate(); @@ -111,7 +111,7 @@ public void shouldNotSeeSingleRelationshipWhichWasDeletedInTransaction() throws tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { assertTrue( "should delete relationship", tx.dataWrite().relationshipDelete( r ) ); try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor() ) @@ -131,7 +131,7 @@ public void shouldScanRelationshipInTransaction() throws Exception int type; long n1, n2; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { n1 = tx.dataWrite().nodeCreate(); n2 = tx.dataWrite().nodeCreate(); @@ -142,7 +142,7 @@ public void shouldScanRelationshipInTransaction() throws Exception tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { long r = tx.dataWrite().relationshipCreate( n1, type, n2 ); try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor() ) @@ -161,7 +161,7 @@ public void shouldNotScanRelationshipWhichWasDeletedInTransaction() throws Excep int type; long n1, n2, r; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { n1 = tx.dataWrite().nodeCreate(); n2 = tx.dataWrite().nodeCreate(); @@ -174,7 +174,7 @@ public void shouldNotScanRelationshipWhichWasDeletedInTransaction() throws Excep tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { assertTrue( "should delete relationship", tx.dataWrite().relationshipDelete( r ) ); try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor() ) @@ -190,14 +190,14 @@ public void shouldNotScanRelationshipWhichWasDeletedInTransaction() throws Excep public void shouldSeeRelationshipInTransaction() throws Exception { long n1, n2; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { n1 = tx.dataWrite().nodeCreate(); n2 = tx.dataWrite().nodeCreate(); tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int label = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); long r = tx.dataWrite().relationshipCreate( n1, label, n2 ); @@ -221,7 +221,7 @@ public void shouldSeeRelationshipInTransaction() throws Exception public void shouldNotSeeRelationshipDeletedInTransaction() throws Exception { long n1, n2, r; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { n1 = tx.dataWrite().nodeCreate(); n2 = tx.dataWrite().nodeCreate(); @@ -232,7 +232,7 @@ public void shouldNotSeeRelationshipDeletedInTransaction() throws Exception tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { tx.dataWrite().relationshipDelete( r ); try ( NodeCursor node = tx.cursors().allocateNodeCursor(); @@ -252,14 +252,14 @@ public void shouldNotSeeRelationshipDeletedInTransaction() throws Exception public void shouldSeeRelationshipInTransactionBeforeCursorInitialization() throws Exception { long n1, n2; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { n1 = tx.dataWrite().nodeCreate(); n2 = tx.dataWrite().nodeCreate(); tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int label = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); long r = tx.dataWrite().relationshipCreate( n1, label, n2 ); @@ -331,7 +331,7 @@ public void shouldTraverseDenseNodeViaGroupsWithDetachedReferences() throws Exce @Test public void shouldSeeNewRelationshipPropertyInTransaction() throws Exception { - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { String propKey1 = "prop1"; String propKey2 = "prop2"; @@ -384,7 +384,7 @@ public void shouldSeeAddedPropertyFromExistingRelationshipWithoutPropertiesInTra // Given long relationshipId; String propKey = "prop1"; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); relationshipId = write.relationshipCreate( write.nodeCreate(), @@ -393,7 +393,7 @@ public void shouldSeeAddedPropertyFromExistingRelationshipWithoutPropertiesInTra } // When/Then - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { int propToken = tx.token().propertyKeyGetOrCreateForName( propKey ); assertEquals( tx.dataWrite().relationshipSetProperty( relationshipId, propToken, stringValue( "hello" ) ), @@ -433,7 +433,7 @@ public void shouldSeeAddedPropertyFromExistingRelationshipWithPropertiesInTransa String propKey2 = "prop2"; int propToken1; int propToken2; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); relationshipId = write.relationshipCreate( write.nodeCreate(), @@ -445,7 +445,7 @@ public void shouldSeeAddedPropertyFromExistingRelationshipWithPropertiesInTransa } // When/Then - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { propToken2 = tx.token().propertyKeyGetOrCreateForName( propKey2 ); assertEquals( tx.dataWrite().relationshipSetProperty( relationshipId, propToken2, stringValue( "world" ) ), @@ -496,7 +496,7 @@ public void shouldSeeUpdatedPropertyFromExistingRelationshipWithPropertiesInTran long relationshipId; String propKey = "prop1"; int propToken; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); relationshipId = write.relationshipCreate( write.nodeCreate(), @@ -508,7 +508,7 @@ public void shouldSeeUpdatedPropertyFromExistingRelationshipWithPropertiesInTran } // When/Then - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { assertEquals( tx.dataWrite().relationshipSetProperty( relationshipId, propToken, stringValue( "world" ) ), stringValue( "hello" ) ); @@ -545,7 +545,7 @@ public void shouldNotSeeRemovedPropertyInTransaction() throws Exception long relationshipId; String propKey = "prop1"; int propToken; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); relationshipId = write.relationshipCreate( write.nodeCreate(), @@ -557,7 +557,7 @@ public void shouldNotSeeRemovedPropertyInTransaction() throws Exception } // When/Then - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { assertEquals( tx.dataWrite().relationshipRemoveProperty( relationshipId, propToken ), stringValue( "hello" ) ); @@ -589,7 +589,7 @@ public void shouldSeeRemovedThenAddedPropertyInTransaction() throws Exception long relationshipId; String propKey = "prop1"; int propToken; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); relationshipId = write.relationshipCreate( write.nodeCreate(), @@ -601,7 +601,7 @@ public void shouldSeeRemovedThenAddedPropertyInTransaction() throws Exception } // When/Then - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { assertEquals( tx.dataWrite().relationshipRemoveProperty( relationshipId, propToken ), stringValue( "hello" ) ); @@ -689,7 +689,7 @@ public void shouldCountFromTxState() throws Exception @Test public void groupCursorShouldSeeNewTypes() throws Exception { - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); long start = write.nodeCreate(); @@ -754,7 +754,7 @@ public void groupCursorShouldAddToCountFromTxState() throws Exception long start; long existingRelationship; int type; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); start = write.nodeCreate(); @@ -763,7 +763,7 @@ public void groupCursorShouldAddToCountFromTxState() throws Exception tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); long newRelationship = write.relationshipCreate( start, type, write.nodeCreate() ); @@ -795,7 +795,7 @@ public void groupCursorShouldSeeBothOldAndNewRelationshipsFromSparseNode() throw long start; long existingRelationship; int one; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); start = write.nodeCreate(); @@ -804,7 +804,7 @@ public void groupCursorShouldSeeBothOldAndNewRelationshipsFromSparseNode() throw tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); int two = tx.tokenWrite().relationshipTypeGetOrCreateForName( "TWO" ); @@ -853,7 +853,7 @@ public void groupCursorShouldSeeBothOldAndNewRelationshipsFromDenseNode() throws long start; long existingRelationship; int one, bulk; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); start = write.nodeCreate(); @@ -867,7 +867,7 @@ public void groupCursorShouldSeeBothOldAndNewRelationshipsFromDenseNode() throws tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); int two = tx.tokenWrite().relationshipTypeGetOrCreateForName( "TWO" ); @@ -923,7 +923,7 @@ public void groupCursorShouldNewRelationshipBetweenAlreadyConnectedSparseNodes() long end; long existingRelationship; int type; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); start = write.nodeCreate(); @@ -933,7 +933,7 @@ public void groupCursorShouldNewRelationshipBetweenAlreadyConnectedSparseNodes() tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); long newRelationship = write.relationshipCreate( start, type, write.nodeCreate() ); @@ -967,7 +967,7 @@ public void groupCursorShouldNewRelationshipBetweenAlreadyConnectedDenseNodes() long end; long existingRelationship; int type, bulk; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); start = write.nodeCreate(); @@ -982,7 +982,7 @@ public void groupCursorShouldNewRelationshipBetweenAlreadyConnectedDenseNodes() tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); long newRelationship = write.relationshipCreate( start, type, write.nodeCreate() ); @@ -1028,7 +1028,7 @@ else if ( t == bulk ) public void shouldCountNewRelationships() throws Exception { int relationship; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); relationship = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); @@ -1036,7 +1036,7 @@ public void shouldCountNewRelationships() throws Exception tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); write.relationshipCreate( write.nodeCreate(), relationship, write.nodeCreate() ); @@ -1054,7 +1054,7 @@ public void shouldNotCountRemovedRelationships() throws Exception { int relationshipId; long relationship; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); relationshipId = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); @@ -1062,7 +1062,7 @@ public void shouldNotCountRemovedRelationships() throws Exception tx.success(); } - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); write.relationshipDelete( relationship ); @@ -1128,7 +1128,7 @@ private void assertNoRelationships( RelationshipDirection direction, Relationshi private void traverseWithoutGroups( RelationshipTestSupport.StartNode start, boolean detached ) throws Exception { - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Map expectedCounts = modifyStartNodeRelationships( start, tx ); @@ -1161,7 +1161,7 @@ private void traverseWithoutGroups( RelationshipTestSupport.StartNode start, boo private void traverseViaGroups( RelationshipTestSupport.StartNode start, boolean detached ) throws Exception { - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Read read = tx.dataRead(); Map expectedCounts = modifyStartNodeRelationships( start, tx ); @@ -1276,7 +1276,7 @@ public void hasPropertiesShouldSeeNewlyCreatedProperties() throws Exception { // Given long relationship; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); @@ -1287,7 +1287,7 @@ public void hasPropertiesShouldSeeNewlyCreatedProperties() throws Exception } // Then - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() ) { @@ -1305,7 +1305,7 @@ public void hasPropertiesShouldSeeNewlyCreatedProperties() throws Exception @Test public void hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedRelationship() throws Exception { - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); @@ -1329,7 +1329,7 @@ public void hasPropertiesShouldSeeNewlyRemovedProperties() throws Exception // Given long relationship; int prop1, prop2, prop3; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); @@ -1344,7 +1344,7 @@ public void hasPropertiesShouldSeeNewlyRemovedProperties() throws Exception } // Then - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() ) { @@ -1367,7 +1367,7 @@ public void propertyTypeShouldBeTxStateAware() throws Exception { // Given long relationship; - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); @@ -1376,7 +1376,7 @@ public void propertyTypeShouldBeTxStateAware() throws Exception } // Then - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = beginTransaction() ) { try ( RelationshipScanCursor relationships = tx.cursors().allocateRelationshipScanCursor(); PropertyCursor properties = tx.cursors().allocatePropertyCursor() ) @@ -1429,7 +1429,7 @@ private void assertCount( int count, RelationshipDirection direction, Consumer provider ) { - try ( Session session = kernelSupplier.get().beginSession( AUTH_DISABLED ); - Transaction transaction = session.beginTransaction( Transaction.Type.implicit ) ) + try ( Transaction transaction = kernelSupplier.get().beginTransaction( implicit, AUTH_DISABLED ) ) { IndexDescriptor index = ((KernelTransaction) transaction).indexUniqueCreate( schema, provider ); transaction.success(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/core/IsolatedTransactionTokenCreator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/core/IsolatedTransactionTokenCreator.java index 45d87ff648d29..d70caf80f0997 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/core/IsolatedTransactionTokenCreator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/core/IsolatedTransactionTokenCreator.java @@ -23,7 +23,6 @@ import java.util.function.Supplier; import org.neo4j.internal.kernel.api.Kernel; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.Transaction.Type; import org.neo4j.internal.kernel.api.exceptions.KernelException; @@ -53,14 +52,11 @@ abstract class IsolatedTransactionTokenCreator implements TokenCreator public synchronized int createToken( String name ) throws KernelException { Kernel kernel = kernelSupplier.get(); - try ( Session session = kernel.beginSession( LoginContext.AUTH_DISABLED ) ) + try ( Transaction transaction = kernel.beginTransaction( Type.implicit, LoginContext.AUTH_DISABLED ) ) { - try ( Transaction transaction = session.beginTransaction( Type.implicit ) ) - { - int id = createKey( transaction, name ); - transaction.success(); - return id; - } + int id = createKey( transaction, name ); + transaction.success(); + return id; } } @@ -68,8 +64,7 @@ public synchronized int createToken( String name ) throws KernelException public synchronized void createTokens( String[] names, int[] ids, IntPredicate filter ) throws KernelException { Kernel kernel = kernelSupplier.get(); - try ( Session session = kernel.beginSession( LoginContext.AUTH_DISABLED ); - Transaction tx = session.beginTransaction( Type.implicit ) ) + try ( Transaction tx = kernel.beginTransaction( Type.implicit, LoginContext.AUTH_DISABLED ) ) { for ( int i = 0; i < ids.length; i++ ) { @@ -82,6 +77,5 @@ public synchronized void createTokens( String[] names, int[] ids, IntPredicate f } } - abstract int createKey( Transaction transaction, String name ) - throws IllegalTokenNameException, TooManyLabelsException; + abstract int createKey( Transaction transaction, String name ) throws IllegalTokenNameException, TooManyLabelsException; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/factory/ClassicCoreSPI.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/factory/ClassicCoreSPI.java index 369042cce84b3..7280c266ddd7d 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/factory/ClassicCoreSPI.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/factory/ClassicCoreSPI.java @@ -177,7 +177,7 @@ public KernelTransaction beginTransaction( KernelTransaction.Type type, LoginCon try { availability.assertDatabaseAvailable(); - KernelTransaction kernelTx = dataSource.kernelAPI.get().newTransaction( type, loginContext, timeout ); + KernelTransaction kernelTx = dataSource.kernelAPI.get().beginTransaction( type, loginContext, timeout ); kernelTx.registerCloseListener( txId -> dataSource.threadToTransactionBridge.unbindTransactionFromCurrentThread() ); dataSource.threadToTransactionBridge.bindTransactionToCurrentThread( kernelTx ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/ExplicitIndexStore.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/ExplicitIndexStore.java index b1fc2b5d1edbf..9b9bcede3e254 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/ExplicitIndexStore.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/ExplicitIndexStore.java @@ -33,7 +33,6 @@ import org.neo4j.graphdb.TransactionFailureException; import org.neo4j.helpers.collection.MapUtil; import org.neo4j.internal.kernel.api.Kernel; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException; import org.neo4j.kernel.api.KernelTransaction; @@ -176,8 +175,7 @@ private Map getOrCreateIndexConfig( } // We were the first one here, let's create this config - try ( Session session = kernel.get().beginSession( AUTH_DISABLED ); - Transaction transaction = session.beginTransaction( Transaction.Type.implicit ); + try ( Transaction transaction = kernel.get().beginTransaction( Transaction.Type.implicit, AUTH_DISABLED ); Statement statement = ((KernelTransaction)transaction).acquireStatement() ) { switch ( entityType ) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/KernelSession.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/KernelSession.java deleted file mode 100644 index 77d0fd78f7e5a..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/KernelSession.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2002-2018 "Neo4j," - * Neo4j Sweden AB [http://neo4j.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 . - */ -package org.neo4j.kernel.impl.newapi; - -import org.neo4j.internal.kernel.api.Session; -import org.neo4j.internal.kernel.api.Transaction; -import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; -import org.neo4j.internal.kernel.api.security.LoginContext; -import org.neo4j.kernel.api.InwardKernel; -import org.neo4j.kernel.api.KernelTransaction; - -/** - * Implements a Kernel API Session. - */ -class KernelSession implements Session -{ - private final InwardKernel kernel; - private final LoginContext loginContext; - - KernelSession( InwardKernel kernel, LoginContext loginContext ) - { - this.kernel = kernel; - this.loginContext = loginContext; - } - - @Override - public Transaction beginTransaction() throws TransactionFailureException - { - return beginTransaction( Transaction.Type.explicit ); - } - - @Override - public Transaction beginTransaction( KernelTransaction.Type type ) throws TransactionFailureException - { - return kernel.newTransaction( type, loginContext ); - } - - @Override - public void close() - { - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NewKernel.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NewKernel.java deleted file mode 100644 index cb31073e3bf2f..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NewKernel.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2002-2018 "Neo4j," - * Neo4j Sweden AB [http://neo4j.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 . - */ -package org.neo4j.kernel.impl.newapi; - -import org.neo4j.internal.kernel.api.Kernel; -import org.neo4j.internal.kernel.api.security.LoginContext; -import org.neo4j.kernel.api.InwardKernel; - -/** - * This is a temporary implementation of the Kernel API, used to enable early testing. The plan is to merge this - * class with org.neo4j.kernel.impl.api.Kernel. - */ -public class NewKernel implements Kernel -{ - private final InwardKernel kernel; - - private volatile boolean isRunning; - - public NewKernel( InwardKernel kernel ) - { - this.kernel = kernel; - this.isRunning = false; - } - - @Override - public KernelSession beginSession( LoginContext loginContext ) - { - assert isRunning : "kernel is not running, so it is not possible to use it"; - return new KernelSession( kernel, loginContext ); - } - - public void start() - { - isRunning = true; - } - - public void stop() - { - if ( !isRunning ) - { - throw new IllegalStateException( "kernel is not running, so it is not possible to stop it" ); - } - isRunning = false; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/proc/ProcedureGDBFacadeSPI.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/proc/ProcedureGDBFacadeSPI.java index ebe8efefa3de7..aec060925c1bb 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/proc/ProcedureGDBFacadeSPI.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/proc/ProcedureGDBFacadeSPI.java @@ -21,7 +21,6 @@ import java.io.File; import java.net.URL; -import java.util.Map; import org.neo4j.function.ThrowingFunction; import org.neo4j.graphdb.DependencyResolver; @@ -30,11 +29,11 @@ import org.neo4j.graphdb.event.TransactionEventHandler; import org.neo4j.graphdb.security.URLAccessValidationError; import org.neo4j.internal.kernel.api.Kernel; +import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.security.LoginContext; import org.neo4j.internal.kernel.api.security.SecurityContext; import org.neo4j.kernel.GraphDatabaseQueryService; import org.neo4j.kernel.api.KernelTransaction; -import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.kernel.api.explicitindex.AutoIndexing; import org.neo4j.kernel.impl.coreapi.CoreAPIAvailabilityGuard; import org.neo4j.kernel.impl.factory.DataSourceModule; @@ -170,7 +169,7 @@ public KernelTransaction beginTransaction( KernelTransaction.Type type, LoginCon try { availability.assertDatabaseAvailable(); - KernelTransaction kernelTx = sourceModule.kernelAPI.get().newTransaction( type, this.securityContext, timeout ); + KernelTransaction kernelTx = sourceModule.kernelAPI.get().beginTransaction( type, this.securityContext, timeout ); kernelTx.registerCloseListener( txId -> sourceModule.threadToTransactionBridge.unbindTransactionFromCurrentThread() ); sourceModule.threadToTransactionBridge.bindTransactionToCurrentThread( kernelTx ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelSchemaStateFlushingTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelSchemaStateFlushingTest.java index 5e6c8da035027..cc2fcfbaf2703 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelSchemaStateFlushingTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelSchemaStateFlushingTest.java @@ -28,12 +28,10 @@ import org.neo4j.internal.kernel.api.IndexReference; import org.neo4j.internal.kernel.api.Kernel; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.exceptions.KernelException; import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor; -import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; import org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper; @@ -42,6 +40,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.junit.Assert.assertEquals; +import static org.neo4j.internal.kernel.api.Transaction.Type.implicit; import static org.neo4j.internal.kernel.api.security.LoginContext.AUTH_DISABLED; public class KernelSchemaStateFlushingTest @@ -51,7 +50,19 @@ public class KernelSchemaStateFlushingTest private GraphDatabaseAPI db; private Kernel kernel; - private Session session; + + @Before + public void setup() + { + db = dbRule.getGraphDatabaseAPI(); + kernel = db.getDependencyResolver().resolveDependency( Kernel.class ); + } + + @After + public void after() + { + db.shutdown(); + } @Test public void shouldKeepSchemaStateIfSchemaIsNotModified() throws TransactionFailureException @@ -137,7 +148,7 @@ public void shouldInvalidateSchemaStateOnDropConstraint() throws Exception private ConstraintDescriptor createConstraint() throws KernelException { - try ( Transaction transaction = session.beginTransaction( KernelTransaction.Type.implicit ) ) + try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { ConstraintDescriptor descriptor = transaction.schemaWrite().uniquePropertyConstraintCreate( SchemaDescriptorFactory.forLabel( 1, 1 ) ); @@ -148,7 +159,7 @@ private ConstraintDescriptor createConstraint() throws KernelException private void dropConstraint( ConstraintDescriptor descriptor ) throws KernelException { - try ( Transaction transaction = session.beginTransaction( KernelTransaction.Type.implicit ) ) + try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { transaction.schemaWrite().constraintDrop( descriptor ); transaction.success(); @@ -157,7 +168,7 @@ private void dropConstraint( ConstraintDescriptor descriptor ) throws KernelExce private IndexReference createIndex() throws KernelException { - try ( Transaction transaction = session.beginTransaction( KernelTransaction.Type.implicit ) ) + try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { IndexReference reference = transaction.schemaWrite().indexCreate( SchemaDescriptorFactory.forLabel( 1, 1 ) ); @@ -168,7 +179,7 @@ private IndexReference createIndex() throws KernelException private void dropIndex( IndexReference reference ) throws KernelException { - try ( Transaction transaction = session.beginTransaction( KernelTransaction.Type.implicit ) ) + try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { transaction.schemaWrite().indexDrop( reference ); transaction.success(); @@ -178,7 +189,7 @@ private void dropIndex( IndexReference reference ) throws KernelException private void awaitIndexOnline( IndexReference descriptor, String keyForProbing ) throws IndexNotFoundKernelException, TransactionFailureException { - try ( Transaction transaction = session.beginTransaction( KernelTransaction.Type.implicit ) ) + try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { SchemaIndexTestHelper.awaitIndexOnline( transaction.schemaRead(), descriptor ); transaction.success(); @@ -188,7 +199,7 @@ private void awaitIndexOnline( IndexReference descriptor, String keyForProbing ) private void awaitSchemaStateCleared( String keyForProbing ) throws TransactionFailureException { - try ( Transaction transaction = session.beginTransaction( KernelTransaction.Type.implicit ) ) + try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { while ( transaction.schemaRead().schemaStateGetOrCreate( keyForProbing, ignored -> null ) != null ) { @@ -200,7 +211,7 @@ private void awaitSchemaStateCleared( String keyForProbing ) throws TransactionF private String commitToSchemaState( String key, String value ) throws TransactionFailureException { - try ( Transaction transaction = session.beginTransaction( KernelTransaction.Type.implicit ) ) + try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { String result = getOrCreateFromState( transaction, key, value ); transaction.success(); @@ -213,18 +224,4 @@ private String getOrCreateFromState( Transaction tx, String key, final String va return tx.schemaRead().schemaStateGetOrCreate( key, from -> value ); } - @Before - public void setup() - { - db = dbRule.getGraphDatabaseAPI(); - kernel = db.getDependencyResolver().resolveDependency( Kernel.class ); - session = kernel.beginSession( AUTH_DISABLED ); - } - - @After - public void after() - { - session.close(); - db.shutdown(); - } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java index 2189fd4f62eff..4247180a84f94 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java @@ -29,11 +29,9 @@ import org.neo4j.internal.kernel.api.Kernel; import org.neo4j.internal.kernel.api.SchemaRead; import org.neo4j.internal.kernel.api.SchemaWrite; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.TokenRead; import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException; -import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException; import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.internal.kernel.api.schema.SchemaDescriptor; @@ -318,22 +316,10 @@ public void shouldCreateConstraintIndexForSpecifiedProvider() throws Exception verifyNoMoreInteractions( schemaRead ); } - private class StubKernel implements Kernel, Session + private class StubKernel implements Kernel { private final List transactions = new ArrayList<>(); - @Override - public Transaction beginTransaction() throws TransactionFailureException - { - return remember( createTransaction() ); - } - - @Override - public Transaction beginTransaction( Transaction.Type type ) throws TransactionFailureException - { - return remember( createTransaction() ); - } - private KernelTransaction remember( KernelTransactionImplementation kernelTransaction ) { transactions.add( kernelTransaction ); @@ -341,14 +327,9 @@ private KernelTransaction remember( KernelTransactionImplementation kernelTransa } @Override - public Session beginSession( LoginContext loginContext ) - { - return this; - } - - @Override - public void close() + public Transaction beginTransaction( Transaction.Type type, LoginContext loginContext ) { + return remember( createTransaction() ); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexPopulationJobTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexPopulationJobTest.java index 462015d9ae62b..6c3f8e062fc16 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexPopulationJobTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexPopulationJobTest.java @@ -40,14 +40,12 @@ import org.neo4j.helpers.collection.Visitor; import org.neo4j.internal.kernel.api.InternalIndexState; import org.neo4j.internal.kernel.api.Kernel; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException; import org.neo4j.internal.kernel.api.exceptions.schema.TooManyLabelsException; import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.internal.kernel.api.schema.SchemaDescriptor; -import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.index.IndexPopulator; import org.neo4j.kernel.api.index.IndexUpdater; @@ -94,6 +92,7 @@ import static org.neo4j.helpers.collection.Iterators.asSet; import static org.neo4j.helpers.collection.MapUtil.genericMap; import static org.neo4j.helpers.collection.MapUtil.map; +import static org.neo4j.internal.kernel.api.Transaction.Type.implicit; import static org.neo4j.internal.kernel.api.security.LoginContext.AUTH_DISABLED; import static org.neo4j.kernel.api.index.IndexEntryUpdate.add; import static org.neo4j.kernel.impl.api.index.IndexingService.NO_MONITOR; @@ -113,7 +112,6 @@ public class IndexPopulationJobTest private final String age = "age"; private Kernel kernel; - private Session session; private IndexStoreView indexStoreView; private DatabaseSchemaState stateHolder; private int labelId; @@ -124,11 +122,10 @@ public void before() throws Exception db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder() .setConfig( GraphDatabaseSettings.record_id_batch_size, "1" ).newGraphDatabase(); kernel = db.getDependencyResolver().resolveDependency( Kernel.class ); - session = kernel.beginSession( AUTH_DISABLED ); stateHolder = new DatabaseSchemaState( NullLogProvider.getInstance() ); indexStoreView = indexStoreView(); - try ( Transaction tx = session.beginTransaction( KernelTransaction.Type.implicit ) ) + try ( Transaction tx = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { labelId = tx.tokenWrite().labelGetOrCreateForName( FIRST.name() ); tx.tokenWrite().labelGetOrCreateForName( SECOND.name() ); @@ -139,7 +136,6 @@ public void before() throws Exception @After public void after() { - session.close(); db.shutdown(); } @@ -626,7 +622,7 @@ private IndexPopulationJob newIndexPopulationJob( FailedIndexProxyFactory failur private IndexDescriptor indexDescriptor( Label label, String propertyKey, boolean constraint ) throws TransactionFailureException, IllegalTokenNameException, TooManyLabelsException { - try ( Transaction tx = session.beginTransaction( KernelTransaction.Type.implicit ) ) + try ( Transaction tx = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { int labelId = tx.tokenWrite().labelGetOrCreateForName( label.name() ); int propertyKeyId = tx.tokenWrite().propertyKeyGetOrCreateForName( propertyKey ); @@ -655,7 +651,7 @@ private long createNode( Map properties, Label... labels ) private int getPropertyKeyForName( String name ) throws TransactionFailureException { - try ( Transaction tx = session.beginTransaction( KernelTransaction.Type.implicit ) ) + try ( Transaction tx = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { int result = tx.tokenRead().propertyKey( name ); tx.success(); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/CompositeUniquenessConstraintValidationIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/CompositeUniquenessConstraintValidationIT.java index d5367ab819a7e..faec9a9fa0121 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/CompositeUniquenessConstraintValidationIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/CompositeUniquenessConstraintValidationIT.java @@ -33,12 +33,11 @@ import org.neo4j.internal.kernel.api.Kernel; import org.neo4j.internal.kernel.api.NodeCursor; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.exceptions.KernelException; +import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.security.LoginContext; import org.neo4j.kernel.api.KernelTransaction; -import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory; import org.neo4j.kernel.internal.GraphDatabaseAPI; @@ -101,14 +100,12 @@ public CompositeUniquenessConstraintValidationIT( TestParams params ) private Transaction transaction; private GraphDatabaseAPI graphDatabaseAPI; protected Kernel kernel; - protected Session session; @Before public void setup() throws Exception { graphDatabaseAPI = dbRule.getGraphDatabaseAPI(); kernel = graphDatabaseAPI.getDependencyResolver().resolveDependency( Kernel.class ); - session = kernel.beginSession( LoginContext.AUTH_DISABLED ); newTransaction(); transaction.schemaWrite().uniquePropertyConstraintCreate( forLabel( label, propertyIds() ) ); @@ -128,7 +125,7 @@ public void clean() throws Exception .constraintDrop( ConstraintDescriptorFactory.uniqueForLabel( label, propertyIds() ) ); commit(); - try ( Transaction tx = session.beginTransaction( Transaction.Type.implicit ); + try ( Transaction tx = kernel.beginTransaction( Transaction.Type.implicit, LoginContext.AUTH_DISABLED ); NodeCursor node = tx.cursors().allocateNodeCursor() ) { tx.dataRead().allNodesScan( node ); @@ -320,7 +317,7 @@ private void newTransaction() throws KernelException { fail( "tx already opened" ); } - transaction = session.beginTransaction( KernelTransaction.Type.implicit ); + transaction = kernel.beginTransaction( KernelTransaction.Type.implicit, LoginContext.AUTH_DISABLED ); } protected void commit() throws TransactionFailureException diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/KernelIntegrationTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/KernelIntegrationTest.java index 890262a1d5f5c..a8278dcb2bf77 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/KernelIntegrationTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/KernelIntegrationTest.java @@ -19,9 +19,6 @@ */ package org.neo4j.kernel.impl.api.integrationtest; -import org.eclipse.collections.api.iterator.IntIterator; -import org.eclipse.collections.api.set.primitive.MutableIntSet; -import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -38,14 +35,12 @@ import org.neo4j.internal.kernel.api.PropertyCursor; import org.neo4j.internal.kernel.api.RelationshipScanCursor; import org.neo4j.internal.kernel.api.SchemaWrite; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.TokenWrite; import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.Write; import org.neo4j.internal.kernel.api.exceptions.KernelException; import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.security.LoginContext; -import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.dbms.DbmsOperations; import org.neo4j.kernel.api.security.AnonymousContext; import org.neo4j.kernel.impl.api.KernelImpl; @@ -58,6 +53,7 @@ import org.neo4j.values.storable.Value; import static java.util.Collections.emptyIterator; +import static org.neo4j.internal.kernel.api.Transaction.Type.implicit; import static org.neo4j.internal.kernel.api.helpers.RelationshipSelections.allIterator; import static org.neo4j.internal.kernel.api.helpers.RelationshipSelections.incomingIterator; import static org.neo4j.internal.kernel.api.helpers.RelationshipSelections.outgoingIterator; @@ -75,7 +71,6 @@ public abstract class KernelIntegrationTest protected GraphDatabaseAPI db; ThreadToStatementContextBridge statementContextSupplier; protected Kernel kernel; - protected Session session; protected IndexingService indexingService; private Transaction transaction; @@ -83,43 +78,37 @@ public abstract class KernelIntegrationTest protected TokenWrite tokenWriteInNewTransaction() throws KernelException { - session = kernel.beginSession( AnonymousContext.writeToken() ); - transaction = session.beginTransaction( KernelTransaction.Type.implicit ); + transaction = kernel.beginTransaction( implicit, AnonymousContext.writeToken() ); return transaction.tokenWrite(); } protected Write dataWriteInNewTransaction() throws KernelException { - session = kernel.beginSession( AnonymousContext.write() ); - transaction = session.beginTransaction( KernelTransaction.Type.implicit ); + transaction = kernel.beginTransaction( implicit, AnonymousContext.write() ); return transaction.dataWrite(); } protected SchemaWrite schemaWriteInNewTransaction() throws KernelException { - session = kernel.beginSession( AUTH_DISABLED ); - transaction = session.beginTransaction( KernelTransaction.Type.implicit ); + transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ); return transaction.schemaWrite(); } protected Procedures procs() throws TransactionFailureException { - session = kernel.beginSession( AnonymousContext.read() ); - transaction = session.beginTransaction( KernelTransaction.Type.implicit ); + transaction = kernel.beginTransaction( implicit, AnonymousContext.read() ); return transaction.procedures(); } protected Transaction newTransaction() throws TransactionFailureException { - session = kernel.beginSession( AnonymousContext.read() ); - transaction = session.beginTransaction( KernelTransaction.Type.implicit ); + transaction = kernel.beginTransaction( implicit, AnonymousContext.read() ); return transaction; } protected Transaction newTransaction( LoginContext loginContext ) throws TransactionFailureException { - session = kernel.beginSession( loginContext ); - transaction = session.beginTransaction( KernelTransaction.Type.implicit ); + transaction = kernel.beginTransaction( implicit, loginContext ); return transaction; } @@ -213,84 +202,6 @@ protected void restartDb() throws TransactionFailureException startDb(); } - boolean nodeHasLabel( Transaction transaction, long node, int label ) - { - try ( NodeCursor cursor = transaction.cursors().allocateNodeCursor() ) - { - transaction.dataRead().singleNode( node, cursor ); - return cursor.next() && cursor.hasLabel( label ); - } - } - - boolean nodeHasProperty( Transaction transaction, long node, int property ) - { - try ( NodeCursor cursor = transaction.cursors().allocateNodeCursor(); - PropertyCursor properties = transaction.cursors().allocatePropertyCursor() ) - { - transaction.dataRead().singleNode( node, cursor ); - if ( !cursor.next() ) - { - return false; - } - else - { - cursor.properties( properties ); - while ( properties.next() ) - { - if ( properties.propertyKey() == property ) - { - return true; - } - } - return false; - } - } - } - - Value nodeGetProperty( Transaction transaction, long node, int property ) - { - try ( NodeCursor cursor = transaction.cursors().allocateNodeCursor(); - PropertyCursor properties = transaction.cursors().allocatePropertyCursor() ) - { - transaction.dataRead().singleNode( node, cursor ); - if ( !cursor.next() ) - { - return NO_VALUE; - } - else - { - cursor.properties( properties ); - while ( properties.next() ) - { - if ( properties.propertyKey() == property ) - { - return properties.propertyValue(); - } - } - return NO_VALUE; - } - } - } - - IntIterator nodeGetPropertyKeys( Transaction transaction, long node ) - { - try ( NodeCursor cursor = transaction.cursors().allocateNodeCursor(); - PropertyCursor properties = transaction.cursors().allocatePropertyCursor() ) - { - MutableIntSet props = new IntHashSet(); - transaction.dataRead().singleNode( node, cursor ); - if ( cursor.next() ) - { - cursor.properties( properties ); - while ( properties.next() ) - { - props.add( properties.propertyKey() ); - } - } - return props.intIterator(); - } - } - Value relationshipGetProperty( Transaction transaction, long relationship, int property ) { try ( RelationshipScanCursor cursor = transaction.cursors().allocateRelationshipScanCursor(); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodeGetUniqueFromIndexSeekIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodeGetUniqueFromIndexSeekIT.java index e11ed17bf837f..27cf739878a0a 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodeGetUniqueFromIndexSeekIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodeGetUniqueFromIndexSeekIT.java @@ -36,6 +36,7 @@ import org.neo4j.values.storable.Value; import org.neo4j.values.storable.Values; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.neo4j.internal.kernel.api.IndexQuery.exact; @@ -87,7 +88,7 @@ public void shouldFindMatchingNode() throws Exception commit(); // then - assertTrue( "Created node was not found", nodeId == foundId ); + assertEquals( "Created node was not found", nodeId, foundId ); } @Test @@ -124,7 +125,7 @@ public void shouldCompositeFindMatchingNode() throws Exception commit(); // then - assertTrue( "Created node was not found", nodeId == foundId ); + assertEquals( "Created node was not found", nodeId, foundId ); } @Test @@ -180,7 +181,7 @@ public void shouldBlockUniqueIndexSeekFromCompetingTransaction() throws Exceptio Runnable runnableForThread2 = () -> { latch.waitForAllToStart(); - try ( Transaction tx = session.beginTransaction() ) + try ( Transaction tx = kernel.beginTransaction( Transaction.Type.implicit, LoginContext.AUTH_DISABLED ) ) { tx.dataRead().lockingNodeUniqueIndexSeek( index, exact( propertyId1, value ) ); tx.success(); @@ -198,14 +199,8 @@ public void shouldBlockUniqueIndexSeekFromCompetingTransaction() throws Exceptio thread2.start(); latch.startAndWaitForAllToStart(); - //noinspection UnusedLabel - spinUntilBlocking: - for (; ; ) + while ( (thread2.getState() != Thread.State.TIMED_WAITING) && (thread2.getState() != Thread.State.WAITING) ) { - if ( thread2.getState() == Thread.State.TIMED_WAITING || thread2.getState() == Thread.State.WAITING ) - { - break; - } Thread.yield(); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/RelationshipIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/RelationshipIT.java index 51abee571b2ca..83933b833c782 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/RelationshipIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/RelationshipIT.java @@ -33,6 +33,7 @@ import org.neo4j.graphdb.Direction; import org.neo4j.helpers.collection.Iterators; import org.neo4j.internal.kernel.api.Transaction; +import org.neo4j.internal.kernel.api.security.LoginContext; import org.neo4j.kernel.api.security.AnonymousContext; import org.neo4j.test.rule.concurrent.OtherThreadRule; @@ -43,6 +44,7 @@ import static org.neo4j.graphdb.Direction.BOTH; import static org.neo4j.graphdb.Direction.INCOMING; import static org.neo4j.graphdb.Direction.OUTGOING; +import static org.neo4j.internal.kernel.api.Transaction.Type.implicit; public class RelationshipIT extends KernelIntegrationTest { @@ -200,7 +202,7 @@ private void assertRelsInSeparateTx( final long refNode, final Direction both, f { assertTrue( otherThread.execute( state -> { - try ( Transaction ktx = session.beginTransaction() ) + try ( Transaction ktx = kernel.beginTransaction( implicit, LoginContext.AUTH_DISABLED ) ) { assertRels( nodeGetRelationships( ktx, refNode, both ), longs ); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/core/ManyPropertyKeysIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/core/ManyPropertyKeysIT.java index d668d09e2ee5f..84e1b28c9375e 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/core/ManyPropertyKeysIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/core/ManyPropertyKeysIT.java @@ -31,11 +31,11 @@ import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Transaction; import org.neo4j.helpers.collection.Iterables; +import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.tracing.cursor.context.EmptyVersionContextSupplier; import org.neo4j.kernel.api.InwardKernel; import org.neo4j.kernel.api.KernelTransaction; -import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.kernel.api.security.AnonymousContext; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.impl.store.NeoStores; @@ -169,7 +169,7 @@ private Node createNodeWithProperty( GraphDatabaseService db, String key, Object private int propertyKeyCount( GraphDatabaseAPI db ) throws TransactionFailureException { InwardKernel kernelAPI = db.getDependencyResolver().resolveDependency( InwardKernel.class ); - try ( KernelTransaction tx = kernelAPI.newTransaction( KernelTransaction.Type.implicit, AnonymousContext.read() ) ) + try ( KernelTransaction tx = kernelAPI.beginTransaction( KernelTransaction.Type.implicit, AnonymousContext.read() ) ) { return tx.tokenRead().propertyKeyCount(); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/NeoStoresTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/NeoStoresTest.java index 2e7753b7a80c0..36b044ae02216 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/NeoStoresTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/NeoStoresTest.java @@ -934,7 +934,7 @@ private void initializeStores( File storeDir, Map additionalConfi private void startTx() throws TransactionFailureException { - tx = ds.getKernel().newTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); + tx = ds.getKernel().beginTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); transaction = ((KernelTransactionImplementation) tx).txState(); } diff --git a/community/neo4j/src/test/java/schema/IndexPopulationFlipRaceIT.java b/community/neo4j/src/test/java/schema/IndexPopulationFlipRaceIT.java index ad8b90148463a..136503568178a 100644 --- a/community/neo4j/src/test/java/schema/IndexPopulationFlipRaceIT.java +++ b/community/neo4j/src/test/java/schema/IndexPopulationFlipRaceIT.java @@ -28,8 +28,6 @@ import org.neo4j.helpers.collection.Pair; import org.neo4j.internal.kernel.api.IndexReference; import org.neo4j.internal.kernel.api.Kernel; -import org.neo4j.internal.kernel.api.Session; -import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory; import org.neo4j.kernel.api.security.AnonymousContext; import org.neo4j.test.rule.DatabaseRule; @@ -40,6 +38,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertEquals; import static org.neo4j.graphdb.Label.label; +import static org.neo4j.internal.kernel.api.Transaction.Type.implicit; public class IndexPopulationFlipRaceIT { @@ -138,8 +137,7 @@ private void verifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes( int i, P throws Exception { Kernel kernel = db.getDependencyResolver().resolveDependency( Kernel.class ); - try ( Session session = kernel.beginSession( AnonymousContext.read() ); - org.neo4j.internal.kernel.api.Transaction tx = session.beginTransaction( KernelTransaction.Type.implicit ) ) + try ( org.neo4j.internal.kernel.api.Transaction tx = kernel.beginTransaction( implicit, AnonymousContext.read() ) ) { int labelAId = tx.tokenRead().nodeLabel( labelA( i ).name() ); int keyAId = tx.tokenRead().propertyKey( keyA( i ) ); diff --git a/community/server/src/test/java/org/neo4j/server/rest/domain/GraphDbHelper.java b/community/server/src/test/java/org/neo4j/server/rest/domain/GraphDbHelper.java index d62027965d673..7340b0b3f59df 100644 --- a/community/server/src/test/java/org/neo4j/server/rest/domain/GraphDbHelper.java +++ b/community/server/src/test/java/org/neo4j/server/rest/domain/GraphDbHelper.java @@ -41,8 +41,6 @@ import org.neo4j.helpers.collection.Iterables; import org.neo4j.helpers.collection.MapUtil; import org.neo4j.internal.kernel.api.Kernel; -import org.neo4j.internal.kernel.api.Read; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.kernel.api.security.AnonymousContext; import org.neo4j.server.database.Database; @@ -65,8 +63,7 @@ public GraphDbHelper( Database database ) public int getNumberOfNodes() { Kernel kernel = database.getGraph().getDependencyResolver().resolveDependency( Kernel.class ); - try ( Session session = kernel.beginSession( AnonymousContext.read() ); - org.neo4j.internal.kernel.api.Transaction tx = session.beginTransaction( org.neo4j.internal.kernel.api.Transaction.Type.implicit ) ) + try ( org.neo4j.internal.kernel.api.Transaction tx = kernel.beginTransaction( implicit, AnonymousContext.read() ) ) { return Math.toIntExact( tx.dataRead().nodesGetCount() ); } @@ -79,8 +76,7 @@ public int getNumberOfNodes() public int getNumberOfRelationships() { Kernel kernel = database.getGraph().getDependencyResolver().resolveDependency( Kernel.class ); - try ( Session session = kernel.beginSession( AnonymousContext.read() ); - org.neo4j.internal.kernel.api.Transaction tx = session.beginTransaction( org.neo4j.internal.kernel.api.Transaction.Type.implicit ) ) + try ( org.neo4j.internal.kernel.api.Transaction tx = kernel.beginTransaction( implicit, AnonymousContext.read() ) ) { return Math.toIntExact( tx.dataRead().relationshipsGetCount() ); } diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/ClusterDiscoveryIT.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/ClusterDiscoveryIT.java index cefd6755d5b7d..fb544e53fa721 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/ClusterDiscoveryIT.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/ClusterDiscoveryIT.java @@ -34,7 +34,6 @@ import org.neo4j.causalclustering.discovery.Cluster; import org.neo4j.internal.kernel.api.Kernel; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.Transaction.Type; import org.neo4j.internal.kernel.api.exceptions.ProcedureException; @@ -127,8 +126,7 @@ private List> getMembers( GraphDatabaseFacade db ) throws Tra ProcedureException { Kernel kernel = db.getDependencyResolver().resolveDependency( Kernel.class ); - try ( Session session = kernel.beginSession( AnonymousContext.read() ); - Transaction tx = session.beginTransaction( Type.implicit ) ) + try ( Transaction tx = kernel.beginTransaction( Type.implicit, AnonymousContext.read() ) ) { // when List currentMembers = diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/ClusterOverviewIT.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/ClusterOverviewIT.java index 557c2a0cb5060..1b632cb9d797b 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/ClusterOverviewIT.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/ClusterOverviewIT.java @@ -53,7 +53,6 @@ import org.neo4j.causalclustering.discovery.procedures.ClusterOverviewProcedure; import org.neo4j.collection.RawIterator; import org.neo4j.internal.kernel.api.Kernel; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.Transaction.Type; import org.neo4j.internal.kernel.api.exceptions.KernelException; @@ -378,7 +377,7 @@ private List clusterOverview( GraphDatabaseFacade db ) Kernel kernel = db.getDependencyResolver().resolveDependency( Kernel.class ); List infos = new ArrayList<>(); - try ( Session session = kernel.beginSession( AnonymousContext.read() ); Transaction tx = session.beginTransaction( Type.implicit ) ) + try ( Transaction tx = kernel.beginTransaction( Type.implicit, AnonymousContext.read() ) ) { RawIterator itr = tx.procedures().procedureCallRead( procedureName( "dbms", "cluster", ClusterOverviewProcedure.PROCEDURE_NAME ), null ); diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/InstalledProtocolsProcedureIT.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/InstalledProtocolsProcedureIT.java index 50abb96c9bf61..feb11f4ab1c82 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/InstalledProtocolsProcedureIT.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/InstalledProtocolsProcedureIT.java @@ -38,7 +38,6 @@ import org.neo4j.causalclustering.discovery.procedures.InstalledProtocolsProcedureTest; import org.neo4j.collection.RawIterator; import org.neo4j.internal.kernel.api.Kernel; -import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.exceptions.ProcedureException; import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; @@ -111,7 +110,7 @@ private List installedProtocols( GraphDatabaseFacade db, String wa { List infos = new LinkedList<>(); Kernel kernel = db.getDependencyResolver().resolveDependency( Kernel.class ); - try ( Session session = kernel.beginSession( AnonymousContext.read() ); Transaction tx = session.beginTransaction( Transaction.Type.implicit ) ) + try ( Transaction tx = kernel.beginTransaction( Transaction.Type.implicit, AnonymousContext.read() ) ) { RawIterator itr = tx.procedures().procedureCallRead( procedureName( "dbms", "cluster", InstalledProtocolsProcedure.PROCEDURE_NAME ), null ); diff --git a/integrationtests/src/test/java/org/neo4j/storeupgrade/StoreUpgradeIT.java b/integrationtests/src/test/java/org/neo4j/storeupgrade/StoreUpgradeIT.java index 559110e5fa48a..14032e2e232a0 100644 --- a/integrationtests/src/test/java/org/neo4j/storeupgrade/StoreUpgradeIT.java +++ b/integrationtests/src/test/java/org/neo4j/storeupgrade/StoreUpgradeIT.java @@ -92,6 +92,7 @@ import static org.junit.Assert.fail; import static org.neo4j.consistency.store.StoreAssertions.assertConsistentStore; import static org.neo4j.helpers.collection.Iterables.count; +import static org.neo4j.internal.kernel.api.Transaction.Type.implicit; import static org.neo4j.kernel.impl.ha.ClusterManager.allSeesAllAsAvailable; import static org.neo4j.kernel.impl.ha.ClusterManager.clusterOfSize; @@ -427,7 +428,7 @@ private static void checkInstance( Store store, GraphDatabaseAPI db ) throws Ker private static void checkIndexCounts( Store store, GraphDatabaseAPI db ) throws KernelException { InwardKernel kernel = db.getDependencyResolver().resolveDependency( InwardKernel.class ); - try ( KernelTransaction tx = kernel.newTransaction( KernelTransaction.Type.implicit, AnonymousContext.read() ); + try ( KernelTransaction tx = kernel.beginTransaction( implicit, AnonymousContext.read() ); Statement ignore = tx.acquireStatement() ) { SchemaRead schemaRead = tx.schemaRead();