Skip to content

Commit

Permalink
Remove kernel session.
Browse files Browse the repository at this point in the history
Remove kernel session abstraction since it did not bring any additional
value. Switch to direct transaction usage instead.
  • Loading branch information
MishaDemianenko committed Jun 8, 2018
1 parent 67bc868 commit a323648
Show file tree
Hide file tree
Showing 43 changed files with 399 additions and 713 deletions.
Expand Up @@ -28,10 +28,10 @@
import org.neo4j.internal.kernel.api.Kernel; import org.neo4j.internal.kernel.api.Kernel;
import org.neo4j.internal.kernel.api.NodeCursor; import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.Read; 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.TokenWrite;
import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.Transaction;
import org.neo4j.internal.kernel.api.Write; 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.internal.kernel.api.security.LoginContext;
import org.neo4j.test.rule.DatabaseRule; import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.EmbeddedDatabaseRule; import org.neo4j.test.rule.EmbeddedDatabaseRule;
Expand All @@ -42,26 +42,26 @@
import static org.neo4j.graphdb.Direction.BOTH; import static org.neo4j.graphdb.Direction.BOTH;
import static org.neo4j.graphdb.Direction.INCOMING; import static org.neo4j.graphdb.Direction.INCOMING;
import static org.neo4j.graphdb.Direction.OUTGOING; import static org.neo4j.graphdb.Direction.OUTGOING;
import static org.neo4j.internal.kernel.api.Transaction.Type.implicit;


public class CompiledExpandUtilsTest public class CompiledExpandUtilsTest
{ {
@Rule @Rule
public DatabaseRule db = new EmbeddedDatabaseRule() public DatabaseRule db = new EmbeddedDatabaseRule()
.withSetting( GraphDatabaseSettings.dense_node_threshold, "1" ); .withSetting( GraphDatabaseSettings.dense_node_threshold, "1" );


private Session session() private Transaction transaction() throws TransactionFailureException
{ {
DependencyResolver resolver = this.db.getDependencyResolver(); 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 @Test
public void shouldComputeDegreeWithoutType() throws Exception public void shouldComputeDegreeWithoutType() throws Exception
{ {
// GIVEN // GIVEN
Session session = session();
long node; long node;
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = transaction() )
{ {
Write write = tx.dataWrite(); Write write = tx.dataWrite();
node = write.nodeCreate(); node = write.nodeCreate();
Expand All @@ -80,7 +80,7 @@ public void shouldComputeDegreeWithoutType() throws Exception
tx.success(); tx.success();
} }


try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = transaction() )
{ {
Read read = tx.dataRead(); Read read = tx.dataRead();
CursorFactory cursors = tx.cursors(); CursorFactory cursors = tx.cursors();
Expand All @@ -97,10 +97,9 @@ public void shouldComputeDegreeWithoutType() throws Exception
public void shouldComputeDegreeWithType() throws Exception public void shouldComputeDegreeWithType() throws Exception
{ {
// GIVEN // GIVEN
Session session = session();
long node; long node;
int in, out, loop; int in, out, loop;
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = transaction() )
{ {
Write write = tx.dataWrite(); Write write = tx.dataWrite();
node = write.nodeCreate(); node = write.nodeCreate();
Expand All @@ -118,7 +117,7 @@ public void shouldComputeDegreeWithType() throws Exception
tx.success(); tx.success();
} }


try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = transaction() )
{ {
Read read = tx.dataRead(); Read read = tx.dataRead();
CursorFactory cursors = tx.cursors(); CursorFactory cursors = tx.cursors();
Expand Down
Expand Up @@ -19,12 +19,13 @@
*/ */
package org.neo4j.internal.kernel.api; package org.neo4j.internal.kernel.api;


import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.internal.kernel.api.security.LoginContext; import org.neo4j.internal.kernel.api.security.LoginContext;


/** /**
* The Kernel. * The Kernel.
*/ */
public interface Kernel public interface Kernel
{ {
Session beginSession( LoginContext loginContext ); <T extends Transaction> T beginTransaction( Transaction.Type type, LoginContext loginContext ) throws TransactionFailureException;
} }

This file was deleted.

Expand Up @@ -68,7 +68,7 @@ public void shouldFindConstraintsBySchema() throws Exception
// GIVEN // GIVEN
addConstraints( "FOO", "prop" ); addConstraints( "FOO", "prop" );


try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
int label = tx.tokenWrite().labelGetOrCreateForName( "FOO" ); int label = tx.tokenWrite().labelGetOrCreateForName( "FOO" );
int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" );
Expand All @@ -90,7 +90,7 @@ public void shouldFindConstraintsByLabel() throws Exception
// GIVEN // GIVEN
addConstraints( "FOO", "prop1", "FOO", "prop2" ); addConstraints( "FOO", "prop1", "FOO", "prop2" );


try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
int label = tx.tokenWrite().labelGetOrCreateForName( "FOO" ); int label = tx.tokenWrite().labelGetOrCreateForName( "FOO" );


Expand All @@ -117,7 +117,7 @@ public void shouldBeAbleCheckExistenceOfConstraints() throws Exception
tx.success(); tx.success();
} }


try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
int label = tx.tokenWrite().labelGetOrCreateForName( "FOO" ); int label = tx.tokenWrite().labelGetOrCreateForName( "FOO" );
int prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop1" ); int prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop1" );
Expand All @@ -135,7 +135,7 @@ public void shouldFindAllConstraints() throws Exception
// GIVEN // GIVEN
addConstraints( "FOO", "prop1", "BAR", "prop2", "BAZ", "prop3" ); addConstraints( "FOO", "prop1", "BAR", "prop2", "BAZ", "prop3" );


try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
//WHEN //WHEN
List<ConstraintDescriptor> constraints = asList( tx.schemaRead().constraintsGetAll() ); List<ConstraintDescriptor> constraints = asList( tx.schemaRead().constraintsGetAll() );
Expand Down Expand Up @@ -169,7 +169,7 @@ public void shouldCheckUniquenessWhenAddingLabel() throws Exception
} }


int label; int label;
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
label = tx.tokenWrite().labelGetOrCreateForName( "FOO" ); label = tx.tokenWrite().labelGetOrCreateForName( "FOO" );


Expand All @@ -189,7 +189,7 @@ public void shouldCheckUniquenessWhenAddingLabel() throws Exception
} }


//Verify //Verify
try ( Transaction tx = session.beginTransaction(); try ( Transaction tx = beginTransaction();
NodeCursor nodeCursor = tx.cursors().allocateNodeCursor() ) NodeCursor nodeCursor = tx.cursors().allocateNodeCursor() )
{ {
//Node without conflict //Node without conflict
Expand Down Expand Up @@ -227,7 +227,7 @@ public void shouldCheckUniquenessWhenAddingProperties() throws Exception
} }


int property; int property;
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
property = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); property = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" );


Expand All @@ -247,7 +247,7 @@ public void shouldCheckUniquenessWhenAddingProperties() throws Exception
} }


//Verify //Verify
try ( Transaction tx = session.beginTransaction(); try ( Transaction tx = beginTransaction();
NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(); NodeCursor nodeCursor = tx.cursors().allocateNodeCursor();
PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor() ) PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor() )
{ {
Expand Down
Expand Up @@ -46,7 +46,7 @@ public abstract class ExplicitIndexCursorWritesTestBase<G extends KernelAPIWrite
public void shouldCreateExplicitNodeIndexEagerly() throws Exception public void shouldCreateExplicitNodeIndexEagerly() throws Exception
{ {
// When // When
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
HashMap<String,String> config = new HashMap<>(); HashMap<String,String> config = new HashMap<>();
Expand All @@ -68,7 +68,7 @@ public void shouldCreateExplicitNodeIndexEagerly() throws Exception
public void shouldCreateExplicitNodeIndexLazily() throws Exception public void shouldCreateExplicitNodeIndexLazily() throws Exception
{ {
// When // When
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
HashMap<String,String> config = new HashMap<>(); HashMap<String,String> config = new HashMap<>();
Expand All @@ -90,7 +90,7 @@ public void shouldCreateExplicitNodeIndexLazily() throws Exception
public void shouldAddNodeToExplicitIndex() throws Exception public void shouldAddNodeToExplicitIndex() throws Exception
{ {
long nodeId; long nodeId;
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
nodeId = tx.dataWrite().nodeCreate(); nodeId = tx.dataWrite().nodeCreate();
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
Expand All @@ -115,7 +115,7 @@ public void shouldRemoveNodeFromExplicitIndex() throws Exception
long nodeId = addNodeToExplicitIndex(); long nodeId = addNodeToExplicitIndex();


// When // When
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId ); indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId );
Expand All @@ -139,14 +139,14 @@ public void shouldHandleRemoveNodeFromExplicitIndexTwice() throws Exception
long nodeId = addNodeToExplicitIndex(); long nodeId = addNodeToExplicitIndex();


// When // When
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId ); indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId );
tx.success(); tx.success();
} }


try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId ); indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId );
Expand All @@ -170,7 +170,7 @@ public void shouldRemoveNonExistingNodeFromExplicitIndex() throws Exception
long nodeId = addNodeToExplicitIndex(); long nodeId = addNodeToExplicitIndex();


// When // When
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId + 1 ); indexWrite.nodeRemoveFromExplicitIndex( INDEX_NAME, nodeId + 1 );
Expand All @@ -192,7 +192,7 @@ public void shouldRemoveNonExistingNodeFromExplicitIndex() throws Exception
public void shouldCreateExplicitRelationshipIndexEagerly() throws Exception public void shouldCreateExplicitRelationshipIndexEagerly() throws Exception
{ {
// When // When
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
HashMap<String,String> config = new HashMap<>(); HashMap<String,String> config = new HashMap<>();
Expand All @@ -214,7 +214,7 @@ public void shouldCreateExplicitRelationshipIndexEagerly() throws Exception
public void shouldCreateExplicitRelationshipIndexLazily() throws Exception public void shouldCreateExplicitRelationshipIndexLazily() throws Exception
{ {
// When // When
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
HashMap<String,String> config = new HashMap<>(); HashMap<String,String> config = new HashMap<>();
Expand All @@ -240,15 +240,15 @@ public void shouldCreateExplicitIndexTwice() throws Exception
config.put( "type", "exact" ); config.put( "type", "exact" );
config.put( "provider", "lucene" ); config.put( "provider", "lucene" );


try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.nodeExplicitIndexCreateLazily( INDEX_NAME, config ); indexWrite.nodeExplicitIndexCreateLazily( INDEX_NAME, config );
tx.success(); tx.success();
} }


// When // When
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.nodeExplicitIndexCreateLazily( INDEX_NAME, config ); indexWrite.nodeExplicitIndexCreateLazily( INDEX_NAME, config );
Expand All @@ -274,7 +274,7 @@ public void shouldAddRelationshipToExplicitIndex() throws Exception
ctx.success(); ctx.success();
} }


try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.relationshipAddToExplicitIndex( INDEX_NAME, relId, KEY, VALUE ); indexWrite.relationshipAddToExplicitIndex( INDEX_NAME, relId, KEY, VALUE );
Expand All @@ -298,7 +298,7 @@ public void shouldRemoveRelationshipFromExplicitIndex() throws Exception
long relId = addRelationshipToExplicitIndex(); long relId = addRelationshipToExplicitIndex();


// When // When
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId ); indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId );
Expand All @@ -322,14 +322,14 @@ public void shouldHandleRemoveRelationshipFromExplicitIndexTwice() throws Except
long relId = addRelationshipToExplicitIndex(); long relId = addRelationshipToExplicitIndex();


// When // When
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId ); indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId );
tx.success(); tx.success();
} }


try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId ); indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId );
Expand All @@ -353,7 +353,7 @@ public void shouldRemoveNonExistingRelationshipFromExplicitIndex() throws Except
long relId = addRelationshipToExplicitIndex(); long relId = addRelationshipToExplicitIndex();


// When // When
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId + 1 ); indexWrite.relationshipRemoveFromExplicitIndex( INDEX_NAME, relId + 1 );
Expand All @@ -374,7 +374,7 @@ public void shouldRemoveNonExistingRelationshipFromExplicitIndex() throws Except
private long addNodeToExplicitIndex() throws Exception private long addNodeToExplicitIndex() throws Exception
{ {
long nodeId; long nodeId;
try ( Transaction tx = session.beginTransaction() ) try ( Transaction tx = beginTransaction() )
{ {
nodeId = tx.dataWrite().nodeCreate(); nodeId = tx.dataWrite().nodeCreate();
ExplicitIndexWrite indexWrite = tx.indexWrite(); ExplicitIndexWrite indexWrite = tx.indexWrite();
Expand Down

0 comments on commit a323648

Please sign in to comment.