Skip to content

Commit

Permalink
Add before state to token commands
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Dec 22, 2015
1 parent b9317d9 commit da47716
Show file tree
Hide file tree
Showing 25 changed files with 386 additions and 211 deletions.
Expand Up @@ -63,21 +63,22 @@ public TransactionRepresentation representation( byte[] additionalHeader, int ma
public void propertyKey( int id, String key, int... dynamicIds )
{
Command.PropertyKeyTokenCommand command = new Command.PropertyKeyTokenCommand();
command.init( withName( new PropertyKeyTokenRecord( id ), dynamicIds, key ) );
command.init( new PropertyKeyTokenRecord( id ), withName( new PropertyKeyTokenRecord( id ), dynamicIds, key ) );
addCommand( command );
}

public void label( int id, String name, int... dynamicIds )
{
Command.LabelTokenCommand command = new Command.LabelTokenCommand();
command.init( withName( new LabelTokenRecord( id ), dynamicIds, name ) );
command.init( new LabelTokenRecord( id ), withName( new LabelTokenRecord( id ), dynamicIds, name ) );
addCommand( command );
}

public void relationshipType( int id, String label, int... dynamicIds )
{
Command.RelationshipTypeTokenCommand command = new Command.RelationshipTypeTokenCommand();
command.init( withName( new RelationshipTypeTokenRecord( id ), dynamicIds, label ) );
command.init( new RelationshipTypeTokenRecord( id ),
withName( new RelationshipTypeTokenRecord( id ), dynamicIds, label ) );
addCommand( command );
}

Expand All @@ -88,10 +89,10 @@ public void update( NeoStoreRecord before, NeoStoreRecord after )
addCommand( command );
}

public void update( LabelTokenRecord labelToken )
public void update( LabelTokenRecord before, LabelTokenRecord after )
{
Command.LabelTokenCommand command = new Command.LabelTokenCommand();
command.init( labelToken );
command.init( before, after );
addCommand( command );
}

Expand All @@ -110,13 +111,13 @@ public void create( NodeRecord node )
public void create( LabelTokenRecord labelToken )
{
labelToken.setCreated();
update( labelToken );
update( new LabelTokenRecord( labelToken.getId() ), labelToken );
}

public void create( PropertyKeyTokenRecord token )
{
token.setCreated();
update( token );
update( new PropertyKeyTokenRecord( token.getId() ), token );
}

public void create( RelationshipGroupRecord group )
Expand All @@ -131,10 +132,10 @@ public void update( NodeRecord before, NodeRecord node )
add( before, node );
}

public void update( PropertyKeyTokenRecord token )
public void update( PropertyKeyTokenRecord before, PropertyKeyTokenRecord after )
{
token.setInUse( true );
add( token );
after.setInUse( true );
add( before, after );
}

public void delete( NodeRecord node )
Expand Down Expand Up @@ -258,17 +259,17 @@ public void add( PropertyRecord before, PropertyRecord property )
addCommand( command );
}

public void add( RelationshipTypeTokenRecord record )
public void add( RelationshipTypeTokenRecord before, RelationshipTypeTokenRecord after )
{
Command.RelationshipTypeTokenCommand command = new Command.RelationshipTypeTokenCommand();
command.init( record );
command.init( before, after );
addCommand( command );
}

public void add( PropertyKeyTokenRecord record )
public void add( PropertyKeyTokenRecord before, PropertyKeyTokenRecord after )
{
Command.PropertyKeyTokenCommand command = new Command.PropertyKeyTokenCommand();
command.init( record );
command.init( before, after );
addCommand( command );
}

Expand Down
Expand Up @@ -63,21 +63,22 @@ public TransactionRepresentation representation( byte[] additionalHeader, int ma
public void propertyKey( int id, String key, int... dynamicIds )
{
Command.PropertyKeyTokenCommand command = new Command.PropertyKeyTokenCommand();
command.init( withName( new PropertyKeyTokenRecord( id ), dynamicIds, key ) );
command.init( new PropertyKeyTokenRecord( id ), withName( new PropertyKeyTokenRecord( id ), dynamicIds, key ) );
addCommand( command );
}

public void label( int id, String name, int... dynamicIds )
{
Command.LabelTokenCommand command = new Command.LabelTokenCommand();
command.init( withName( new LabelTokenRecord( id ), dynamicIds, name ) );
command.init( new LabelTokenRecord( id ), withName( new LabelTokenRecord( id ), dynamicIds, name ) );
addCommand( command );
}

public void relationshipType( int id, String label, int... dynamicIds )
{
Command.RelationshipTypeTokenCommand command = new Command.RelationshipTypeTokenCommand();
command.init( withName( new RelationshipTypeTokenRecord( id ), dynamicIds, label ) );
command.init( new RelationshipTypeTokenRecord( id ),
withName( new RelationshipTypeTokenRecord( id ), dynamicIds, label ) );
addCommand( command );
}

Expand All @@ -88,10 +89,10 @@ public void update( NeoStoreRecord before, NeoStoreRecord after )
addCommand( command );
}

public void update( LabelTokenRecord labelToken )
public void update( LabelTokenRecord before, LabelTokenRecord after )
{
Command.LabelTokenCommand command = new Command.LabelTokenCommand();
command.init( labelToken );
command.init( before, after );
addCommand( command );
}

Expand All @@ -110,13 +111,13 @@ public void create( NodeRecord node )
public void create( LabelTokenRecord labelToken )
{
labelToken.setCreated();
update( labelToken );
update( new LabelTokenRecord( labelToken.getId() ), labelToken );
}

public void create( PropertyKeyTokenRecord token )
{
token.setCreated();
update( token );
update( new PropertyKeyTokenRecord( token.getId() ), token );
}

public void create( RelationshipGroupRecord group )
Expand All @@ -131,10 +132,10 @@ public void update( NodeRecord before, NodeRecord node )
add( before, node );
}

public void update( PropertyKeyTokenRecord token )
public void update( PropertyKeyTokenRecord before, PropertyKeyTokenRecord after )
{
token.setInUse( true );
add( token );
after.setInUse( true );
add( before, after );
}

public void delete( NodeRecord node )
Expand Down Expand Up @@ -233,7 +234,7 @@ private void addSchema( Collection<DynamicRecord> beforeRecords, Collection<Dyna
public void add( NodeRecord before, NodeRecord after )
{
Command.NodeCommand command = new Command.NodeCommand();
command.init( before, after );
command.init( before, after );
addCommand( command );
}

Expand All @@ -258,17 +259,17 @@ public void add( PropertyRecord before, PropertyRecord property )
addCommand( command );
}

public void add( RelationshipTypeTokenRecord record )
public void add( RelationshipTypeTokenRecord before, RelationshipTypeTokenRecord after )
{
Command.RelationshipTypeTokenCommand command = new Command.RelationshipTypeTokenCommand();
command.init( record );
command.init( before, after );
addCommand( command );
}

public void add( PropertyKeyTokenRecord record )
public void add( PropertyKeyTokenRecord before, PropertyKeyTokenRecord after )
{
Command.PropertyKeyTokenCommand command = new Command.PropertyKeyTokenCommand();
command.init( record );
command.init( before, after );
addCommand( command );
}

Expand Down
Expand Up @@ -32,4 +32,19 @@ protected String simpleName()
{
return "Label";
}
}

@Override
public LabelTokenRecord clone()
{
LabelTokenRecord labelTokenRecord = new LabelTokenRecord( getId() );
labelTokenRecord.setInUse( inUse() );
if ( isCreated() )
{
labelTokenRecord.setCreated();
}
labelTokenRecord.setIsLight( isLight() );
labelTokenRecord.setNameId( getNameId() );
labelTokenRecord.addNameRecords( getNameRecords() );
return labelTokenRecord;
}
}
Expand Up @@ -50,4 +50,21 @@ protected void additionalToString( StringBuilder buf )
{
buf.append( ",propCount=" ).append( propCount );
}


@Override
public PropertyKeyTokenRecord clone()
{
PropertyKeyTokenRecord propertyKeyTokenRecord = new PropertyKeyTokenRecord( getId() );
propertyKeyTokenRecord.setInUse( inUse() );
if ( isCreated() )
{
propertyKeyTokenRecord.setCreated();
}
propertyKeyTokenRecord.setIsLight( isLight() );
propertyKeyTokenRecord.setNameId( getNameId() );
propertyKeyTokenRecord.addNameRecords( getNameRecords() );
propertyKeyTokenRecord.setPropertyCount( getPropertyCount() );
return propertyKeyTokenRecord;
}
}
Expand Up @@ -31,4 +31,19 @@ protected String simpleName()
{
return "RelationshipType";
}

@Override
public RelationshipTypeTokenRecord clone()
{
RelationshipTypeTokenRecord relationshipTypeTokenRecord = new RelationshipTypeTokenRecord( getId() );
relationshipTypeTokenRecord.setInUse( inUse() );
if ( isCreated() )
{
relationshipTypeTokenRecord.setCreated();
}
relationshipTypeTokenRecord.setIsLight( isLight() );
relationshipTypeTokenRecord.setNameId( getNameId() );
relationshipTypeTokenRecord.addNameRecords( getNameRecords() );
return relationshipTypeTokenRecord;
}
}
Expand Up @@ -271,7 +271,6 @@ public NeoStoreRecord getAfter()

public static class PropertyKeyTokenCommand extends TokenCommand<PropertyKeyTokenRecord>
{

@Override
public boolean handle( CommandVisitor handler ) throws IOException
{
Expand Down Expand Up @@ -331,30 +330,36 @@ public long getRelId()

public static abstract class TokenCommand<RECORD extends TokenRecord> extends Command
{
protected RECORD record;
protected RECORD after;
private RECORD before;

public TokenCommand<RECORD> init( RECORD record )
public TokenCommand<RECORD> init( RECORD before, RECORD after )
{
setup( record.getId(), Mode.fromRecordState( record ) );
this.record = record;
setup( after.getId(), Mode.fromRecordState( after ) );
this.before = before;
this.after = after;
return this;
}

public RECORD getRecord()
public RECORD getBefore()
{
return before;
}

public RECORD getAfter()
{
return record;
return after;
}

@Override
public String toString()
{
return record.toString();
return beforeAndAfterToString( before, after );
}
}

public static class RelationshipTypeTokenCommand extends TokenCommand<RelationshipTypeTokenRecord>
{

@Override
public boolean handle( CommandVisitor handler ) throws IOException
{
Expand All @@ -364,7 +369,6 @@ public boolean handle( CommandVisitor handler ) throws IOException

public static class LabelTokenCommand extends TokenCommand<LabelTokenRecord>
{

@Override
public boolean handle( CommandVisitor handler ) throws IOException
{
Expand Down
Expand Up @@ -176,7 +176,7 @@ private void track( CommonAbstractStore store, Collection<? extends Abstract64Bi
void trackToken( TokenStore<RECORD, TOKEN> tokenStore, TokenCommand<RECORD> tokenCommand )
{
track( tokenStore, tokenCommand );
track( tokenStore.getNameStore(), tokenCommand.getRecord().getNameRecords() );
track( tokenStore.getNameStore(), tokenCommand.getAfter().getNameRecords() );
}

private static class HighId
Expand Down
Expand Up @@ -112,21 +112,21 @@ public boolean visitRelationshipGroupCommand( Command.RelationshipGroupCommand c
@Override
public boolean visitRelationshipTypeTokenCommand( Command.RelationshipTypeTokenCommand command ) throws IOException
{
neoStores.getRelationshipTypeTokenStore().updateRecord( command.getRecord() );
neoStores.getRelationshipTypeTokenStore().updateRecord( command.getAfter() );
return false;
}

@Override
public boolean visitLabelTokenCommand( Command.LabelTokenCommand command ) throws IOException
{
neoStores.getLabelTokenStore().updateRecord( command.getRecord() );
neoStores.getLabelTokenStore().updateRecord( command.getAfter() );
return false;
}

@Override
public boolean visitPropertyKeyTokenCommand( Command.PropertyKeyTokenCommand command ) throws IOException
{
neoStores.getPropertyKeyTokenStore().updateRecord( command.getRecord() );
neoStores.getPropertyKeyTokenStore().updateRecord( command.getAfter() );
return false;
}

Expand Down
Expand Up @@ -161,7 +161,7 @@ else if ( inUseFlag != Record.NOT_IN_USE.byteValue() )
record.addNameRecord( dr );
}
Command.RelationshipTypeTokenCommand command = new Command.RelationshipTypeTokenCommand();
command.init( record );
command.init( null, record );
return command;
}

Expand Down Expand Up @@ -189,7 +189,7 @@ else if ( inUseFlag != Record.NOT_IN_USE.byteValue() )
return null;
}
Command.PropertyKeyTokenCommand command = new Command.PropertyKeyTokenCommand();
command.init( record );
command.init( null, record );
return command;
}

Expand Down
Expand Up @@ -192,7 +192,7 @@ else if ( inUseFlag != Record.NOT_IN_USE.byteValue() )
record.addNameRecord( dr );
}
Command.RelationshipTypeTokenCommand command = new Command.RelationshipTypeTokenCommand();
command.init( record );
command.init( null, record );
return command;
}

Expand Down Expand Up @@ -224,7 +224,7 @@ else if ( inUseFlag != Record.NOT_IN_USE.byteValue() )
record.addNameRecord( dr );
}
Command.LabelTokenCommand command = new Command.LabelTokenCommand();
command.init( record );
command.init( null, record );
return command;
}

Expand Down Expand Up @@ -252,7 +252,7 @@ else if ( inUseFlag != Record.NOT_IN_USE.byteValue() )
return null;
}
Command.PropertyKeyTokenCommand command = new Command.PropertyKeyTokenCommand();
command.init( record );
command.init( null, record );
return command;
}

Expand Down

0 comments on commit da47716

Please sign in to comment.