Skip to content

Commit

Permalink
Remove unused methods and test token create arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Jan 18, 2018
1 parent 4d2bdd4 commit 2f4d4ec
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 64 deletions.
Expand Up @@ -147,7 +147,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional
val labelArray = new Array[TextValue](labelSet.numberOfLabels()) val labelArray = new Array[TextValue](labelSet.numberOfLabels())
var i = 0 var i = 0
while (i < labelSet.numberOfLabels()) { while (i < labelSet.numberOfLabels()) {
labelArray(i) = Values.stringValue(tokenRead.labelGetName(labelSet.label(i))) labelArray(i) = Values.stringValue(tokenRead.nodeLabelName(labelSet.label(i)))
i += 1 i += 1
} }
VirtualValues.list(labelArray: _*) VirtualValues.list(labelArray: _*)
Expand All @@ -164,7 +164,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional
} }


override def getOrCreateLabelId(labelName: String): Int = { override def getOrCreateLabelId(labelName: String): Int = {
val id = tokenRead.labelGetForName(labelName) val id = tokenRead.nodeLabel(labelName)
if (id != KeyReadOperations.NO_SUCH_LABEL) id if (id != KeyReadOperations.NO_SUCH_LABEL) id
else tokenWrite.labelGetOrCreateForName(labelName) else tokenWrite.labelGetOrCreateForName(labelName)
} }
Expand Down
Expand Up @@ -30,19 +30,13 @@ public interface TokenRead
int NO_TOKEN = -1; int NO_TOKEN = -1;


/** /**
* Returns the name corresponding to given token * Returns the name of a label given its label id
* @param token The token associated with the name *
* @return The name corresponding to the token * @param labelId The label id
* @throws LabelNotFoundKernelException if the token doesn't exist in the database * @return The name of the label
*/ * @throws LabelNotFoundKernelException if no label is associates with this id
String labelGetName( int token ) throws LabelNotFoundKernelException;

/**
* Returns the token corresponding to the provided name
* @param name The name associated with the token
* @return The token corresponding withe
*/ */
int labelGetForName( String name ); String nodeLabelName( int labelId ) throws LabelNotFoundKernelException;


/** /**
* Return the id of the provided label, or NO_TOKEN if the label isn't known to the graph. * Return the id of the provided label, or NO_TOKEN if the label isn't known to the graph.
Expand Down Expand Up @@ -75,5 +69,5 @@ public interface TokenRead
* @return The name of the key * @return The name of the key
* @throws PropertyKeyIdNotFoundKernelException if no key is associated with the id * @throws PropertyKeyIdNotFoundKernelException if no key is associated with the id
*/ */
String propertyKeyGetName( int propertyKeyId ) throws PropertyKeyIdNotFoundKernelException; String propertyKeyName( int propertyKeyId ) throws PropertyKeyIdNotFoundKernelException;
} }
Expand Up @@ -37,10 +37,4 @@ public interface TokenWrite
int propertyKeyGetOrCreateForName( String propertyKeyName ) throws IllegalTokenNameException; int propertyKeyGetOrCreateForName( String propertyKeyName ) throws IllegalTokenNameException;


int relationshipTypeGetOrCreateForName( String relationshipTypeName ) throws IllegalTokenNameException; int relationshipTypeGetOrCreateForName( String relationshipTypeName ) throws IllegalTokenNameException;

void labelCreateForName( String labelName, int id ) throws IllegalTokenNameException, TooManyLabelsException;

void propertyKeyCreateForName( String propertyKeyName, int id ) throws IllegalTokenNameException;

void relationshipTypeCreateForName( String relationshipTypeName, int id ) throws IllegalTokenNameException;
} }
Expand Up @@ -669,7 +669,7 @@ private NeoStoreKernelModule buildKernel( LogFiles logFiles, TransactionAppender
constraintIndexCreator, databaseSchemaState, explicitIndexStore, cpuClockRef, heapAllocationRef ) ); constraintIndexCreator, databaseSchemaState, explicitIndexStore, cpuClockRef, heapAllocationRef ) );


TransactionHooks hooks = new TransactionHooks(); TransactionHooks hooks = new TransactionHooks();
KernelToken token = new KernelToken( storageEngine ); KernelToken token = new KernelToken( storageEngine.storeReadLayer() );


KernelTransactions kernelTransactions = life.add( new KernelTransactions( statementLocksFactory, KernelTransactions kernelTransactions = life.add( new KernelTransactions( statementLocksFactory,
constraintIndexCreator, statementOperationParts, schemaWriteGuard, transactionHeaderInformationFactory, constraintIndexCreator, statementOperationParts, schemaWriteGuard, transactionHeaderInformationFactory,
Expand Down
Expand Up @@ -380,7 +380,7 @@ public Iterable<String> getPropertyKeys()
nodes.properties( properties ); nodes.properties( properties );
while ( properties.next() ) while ( properties.next() )
{ {
keys.add( token.propertyKeyGetName( properties.propertyKey() )); keys.add( token.propertyKeyName( properties.propertyKey() ));
} }
} }
catch ( PropertyKeyIdNotFoundKernelException e ) catch ( PropertyKeyIdNotFoundKernelException e )
Expand Down Expand Up @@ -457,7 +457,7 @@ public Map<String,Object> getAllProperties()
nodes.properties( propertyCursor ); nodes.properties( propertyCursor );
while ( propertyCursor.next() ) while ( propertyCursor.next() )
{ {
properties.put( token.propertyKeyGetName( propertyCursor.propertyKey() ), properties.put( token.propertyKeyName( propertyCursor.propertyKey() ),
propertyCursor.propertyValue().asObjectCopy() ); propertyCursor.propertyValue().asObjectCopy() );
} }
} }
Expand Down Expand Up @@ -640,7 +640,7 @@ public void removeLabel( Label label )
KernelTransaction transaction = spi.kernelTransaction(); KernelTransaction transaction = spi.kernelTransaction();
try ( Statement ignore = transaction.acquireStatement() ) try ( Statement ignore = transaction.acquireStatement() )
{ {
int labelId = transaction.tokenRead().labelGetForName( label.name() ); int labelId = transaction.tokenRead().nodeLabel( label.name() );
if ( labelId != KeyReadOperations.NO_SUCH_LABEL ) if ( labelId != KeyReadOperations.NO_SUCH_LABEL )
{ {
transaction.dataWrite().nodeRemoveLabel( getId(), labelId ); transaction.dataWrite().nodeRemoveLabel( getId(), labelId );
Expand All @@ -667,7 +667,7 @@ public boolean hasLabel( Label label )
try ( Statement ignore = transaction.acquireStatement(); try ( Statement ignore = transaction.acquireStatement();
NodeCursor nodes = transaction.cursors().allocateNodeCursor() ) NodeCursor nodes = transaction.cursors().allocateNodeCursor() )
{ {
int labelId = transaction.tokenRead().labelGetForName( label.name() ); int labelId = transaction.tokenRead().nodeLabel( label.name() );
if ( labelId == NO_SUCH_LABEL ) if ( labelId == NO_SUCH_LABEL )
{ {
return false; return false;
Expand All @@ -690,7 +690,7 @@ public Iterable<Label> getLabels()
ArrayList<Label> list = new ArrayList<>( labelSet.numberOfLabels() ); ArrayList<Label> list = new ArrayList<>( labelSet.numberOfLabels() );
for ( int i = 0; i < labelSet.numberOfLabels(); i++ ) for ( int i = 0; i < labelSet.numberOfLabels(); i++ )
{ {
list.add( label( tokenRead.labelGetName( labelSet.label( i ) ) ) ); list.add( label( tokenRead.nodeLabelName( labelSet.label( i ) ) ) );
} }
return list; return list;
} }
Expand Down
Expand Up @@ -675,7 +675,7 @@ private ResourceIterator<Node> allNodesWithLabel( final Label myLabel )
KernelTransaction ktx = statementContext.getKernelTransactionBoundToThisThread( true ); KernelTransaction ktx = statementContext.getKernelTransactionBoundToThisThread( true );
Statement statement = ktx.acquireStatement(); Statement statement = ktx.acquireStatement();


int labelId = ktx.tokenRead().labelGetForName( myLabel.name() ); int labelId = ktx.tokenRead().nodeLabel( myLabel.name() );
if ( labelId == NO_SUCH_LABEL ) if ( labelId == NO_SUCH_LABEL )
{ {
statement.close(); statement.close();
Expand Down
Expand Up @@ -20,21 +20,19 @@
package org.neo4j.kernel.impl.newapi; package org.neo4j.kernel.impl.newapi;


import org.neo4j.internal.kernel.api.Token; import org.neo4j.internal.kernel.api.Token;
import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException; import org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException;
import org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException; import org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException;
import org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException; import org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException;
import org.neo4j.internal.kernel.api.exceptions.schema.TooManyLabelsException; import org.neo4j.internal.kernel.api.exceptions.schema.TooManyLabelsException;
import org.neo4j.storageengine.api.StorageEngine;
import org.neo4j.storageengine.api.StoreReadLayer; import org.neo4j.storageengine.api.StoreReadLayer;


public class KernelToken implements Token public class KernelToken implements Token
{ {
private final StoreReadLayer store; private final StoreReadLayer store;


public KernelToken( StorageEngine engine ) public KernelToken( StoreReadLayer store )
{ {
store = engine.storeReadLayer(); this.store = store;
} }


@Override @Override
Expand All @@ -52,37 +50,13 @@ public int propertyKeyGetOrCreateForName( String propertyKeyName ) throws Illega
@Override @Override
public int relationshipTypeGetOrCreateForName( String relationshipTypeName ) throws IllegalTokenNameException public int relationshipTypeGetOrCreateForName( String relationshipTypeName ) throws IllegalTokenNameException
{ {
throw new UnsupportedOperationException( "not implemented" ); return store.propertyKeyGetOrCreateForName( checkValidTokenName( relationshipTypeName ) );
} }


@Override @Override
public void labelCreateForName( String labelName, int id ) throws IllegalTokenNameException, TooManyLabelsException public String nodeLabelName( int labelId ) throws LabelNotFoundKernelException
{ {
throw new UnsupportedOperationException( "not implemented" ); return store.labelGetName( labelId );
}

@Override
public String labelGetName( int token ) throws LabelNotFoundKernelException
{
return store.labelGetName( token );
}

@Override
public int labelGetForName( String name )
{
return store.labelGetForName( name );
}

@Override
public void propertyKeyCreateForName( String propertyKeyName, int id ) throws IllegalTokenNameException
{
throw new UnsupportedOperationException( "not implemented" );
}

@Override
public void relationshipTypeCreateForName( String relationshipTypeName, int id ) throws IllegalTokenNameException
{
throw new UnsupportedOperationException( "not implemented" );
} }


@Override @Override
Expand All @@ -104,7 +78,7 @@ public int propertyKey( String name )
} }


@Override @Override
public String propertyKeyGetName( int propertyKeyId ) throws PropertyKeyIdNotFoundKernelException public String propertyKeyName( int propertyKeyId ) throws PropertyKeyIdNotFoundKernelException
{ {
return store.propertyKeyGetName( propertyKeyId ); return store.propertyKeyGetName( propertyKeyId );
} }
Expand Down
Expand Up @@ -101,7 +101,7 @@ static Instances kernelTransactionWithInternals( SecurityContext securityContext
Clocks.systemClock(), new AtomicReference<>( CpuClock.NOT_AVAILABLE ), new AtomicReference<>( HeapAllocation.NOT_AVAILABLE ), NULL, Clocks.systemClock(), new AtomicReference<>( CpuClock.NOT_AVAILABLE ), new AtomicReference<>( HeapAllocation.NOT_AVAILABLE ), NULL,
LockTracer.NONE, LockTracer.NONE,
PageCursorTracerSupplier.NULL, PageCursorTracerSupplier.NULL,
storageEngine, new CanWrite(), new KernelToken( storageEngine ), new Cursors(), AutoIndexing.UNSUPPORTED, mock( storageEngine, new CanWrite(), new KernelToken( storeReadLayer ), new Cursors(), AutoIndexing.UNSUPPORTED, mock(
ExplicitIndexStore.class) ); ExplicitIndexStore.class) );


StatementLocks statementLocks = new SimpleStatementLocks( new NoOpClient() ); StatementLocks statementLocks = new SimpleStatementLocks( new NoOpClient() );
Expand Down
Expand Up @@ -589,7 +589,7 @@ private static KernelTransactions createTransactions( StorageEngine storageEngin
return new KernelTransactions( statementLocksFactory, null, statementOperations, null, DEFAULT, commitProcess, null, null, new TransactionHooks(), return new KernelTransactions( statementLocksFactory, null, statementOperations, null, DEFAULT, commitProcess, null, null, new TransactionHooks(),
mock( TransactionMonitor.class ), availabilityGuard, tracers, storageEngine, new Procedures(), transactionIdStore, clock, mock( TransactionMonitor.class ), availabilityGuard, tracers, storageEngine, new Procedures(), transactionIdStore, clock,
new AtomicReference<>( CpuClock.NOT_AVAILABLE ), new AtomicReference<>( HeapAllocation.NOT_AVAILABLE ), new CanWrite(), new AtomicReference<>( CpuClock.NOT_AVAILABLE ), new AtomicReference<>( HeapAllocation.NOT_AVAILABLE ), new CanWrite(),
new KernelToken( storageEngine ), new Cursors(), AutoIndexing.UNSUPPORTED, mock( ExplicitIndexStore.class ) ); new KernelToken( storageEngine.storeReadLayer() ), new Cursors(), AutoIndexing.UNSUPPORTED, mock( ExplicitIndexStore.class ) );
} }


private static TestKernelTransactions createTestTransactions( StorageEngine storageEngine, private static TestKernelTransactions createTestTransactions( StorageEngine storageEngine,
Expand All @@ -601,7 +601,7 @@ private static TestKernelTransactions createTestTransactions( StorageEngine stor
null, DEFAULT, null, DEFAULT,
commitProcess, null, null, new TransactionHooks(), mock( TransactionMonitor.class ), commitProcess, null, null, new TransactionHooks(), mock( TransactionMonitor.class ),
availabilityGuard, tracers, storageEngine, new Procedures(), transactionIdStore, clock, availabilityGuard, tracers, storageEngine, new Procedures(), transactionIdStore, clock,
new CanWrite(), new KernelToken( storageEngine ), new Cursors(), AutoIndexing.UNSUPPORTED ); new CanWrite(), new KernelToken( storageEngine.storeReadLayer() ), new Cursors(), AutoIndexing.UNSUPPORTED );
} }


private static TransactionCommitProcess newRememberingCommitProcess( final TransactionRepresentation[] slot ) private static TransactionCommitProcess newRememberingCommitProcess( final TransactionRepresentation[] slot )
Expand Down
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.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 <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.newapi;

import org.junit.Test;

import org.neo4j.function.ThrowingAction;
import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException;
import org.neo4j.storageengine.api.StoreReadLayer;
import org.neo4j.test.assertion.Assert;

import static org.mockito.Mockito.mock;

public class KernelTokenArgumentTest
{
private KernelToken token = new KernelToken( mock( StoreReadLayer.class ) );

@Test
public void labelGetOrCreateForName() throws Exception
{
assertIllegalToken( () -> token.labelGetOrCreateForName( null ) );
assertIllegalToken( () -> token.labelGetOrCreateForName( "" ) );
}

@Test
public void propertyKeyGetOrCreateForName() throws Exception
{
assertIllegalToken( () -> token.propertyKeyGetOrCreateForName( null ) );
assertIllegalToken( () -> token.propertyKeyGetOrCreateForName( "" ) );
}

@Test
public void relationshipTypeGetOrCreateForName() throws Exception
{
assertIllegalToken( () -> token.relationshipTypeGetOrCreateForName( null ) );
assertIllegalToken( () -> token.relationshipTypeGetOrCreateForName( "" ) );
}

private void assertIllegalToken( ThrowingAction<KernelException> f ) throws Exception
{
Assert.assertException( f, IllegalTokenNameException.class );
}
}
Expand Up @@ -110,7 +110,7 @@ public void setUp() throws InvalidTransactionTypeKernelException
allStoreHolder = new AllStoreHolder( engine, storageStatement, transaction, cursors, mock( allStoreHolder = new AllStoreHolder( engine, storageStatement, transaction, cursors, mock(
ExplicitIndexStore.class ) ); ExplicitIndexStore.class ) );
operations = new Operations( allStoreHolder, mock( IndexTxStateUpdater.class ), operations = new Operations( allStoreHolder, mock( IndexTxStateUpdater.class ),
storageStatement, transaction, new KernelToken( engine ), cursors, autoindexing, storageStatement, transaction, new KernelToken( storeReadLayer ), cursors, autoindexing,
mock( NodeSchemaMatcher.class ) ); mock( NodeSchemaMatcher.class ) );
operations.initialize(); operations.initialize();
} }
Expand Down

0 comments on commit 2f4d4ec

Please sign in to comment.