Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small refactor to allow adding more check types
- Loading branch information
1 parent
64ba396
commit 569e4d4
Showing
8 changed files
with
240 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 0 additions & 195 deletions
195
tools/src/main/java/org/neo4j/tools/txlog/CheckType.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tools/src/main/java/org/neo4j/tools/txlog/checktypes/CheckType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,57 @@ | |||
/* | |||
* Copyright (c) 2002-2015 "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 Affero 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 Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.tools.txlog.checktypes; | |||
|
|||
import org.neo4j.kernel.impl.store.record.Abstract64BitRecord; | |||
import org.neo4j.kernel.impl.transaction.command.Command; | |||
import org.neo4j.kernel.impl.transaction.command.Command.NodeCommand; | |||
import org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand; | |||
|
|||
/** | |||
* Type of command ({@link NodeCommand}, {@link PropertyCommand}, ...) to check during transaction log verification. | |||
* This class exists to mitigate the absence of interfaces for commands with before and after state. | |||
* It also provides an alternative equality check instead of {@link Abstract64BitRecord#equals(Object)} that only | |||
* checks {@linkplain Abstract64BitRecord#getLongId() entity id}. | |||
* | |||
* @param <C> the type of command to check | |||
* @param <R> the type of records that this command contains | |||
*/ | |||
public abstract class CheckType<C extends Command, R extends Abstract64BitRecord> | |||
{ | |||
private final Class<C> recordClass; | |||
|
|||
CheckType( Class<C> recordClass ) | |||
{ | |||
this.recordClass = recordClass; | |||
} | |||
|
|||
public Class<C> commandClass() | |||
{ | |||
return recordClass; | |||
} | |||
|
|||
public abstract R before( C command ); | |||
|
|||
public abstract R after( C command ); | |||
|
|||
public abstract boolean equal( R record1, R record2 ); | |||
|
|||
public abstract String name(); | |||
} |
14 changes: 14 additions & 0 deletions
14
tools/src/main/java/org/neo4j/tools/txlog/checktypes/CheckTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
package org.neo4j.tools.txlog.checktypes; | |||
|
|||
import org.neo4j.kernel.impl.store.record.Abstract64BitRecord; | |||
import org.neo4j.kernel.impl.transaction.command.Command; | |||
|
|||
public class CheckTypes | |||
{ | |||
public static final NodeCheckType NODE = new NodeCheckType(); | |||
public static final PropertyCheckType PROPERTY = new PropertyCheckType(); | |||
|
|||
@SuppressWarnings( "unchecked" ) | |||
public static final CheckType<? extends Command, ? extends Abstract64BitRecord>[] CHECK_TYPES = | |||
new CheckType[]{NODE, PROPERTY}; | |||
} |
46 changes: 46 additions & 0 deletions
46
tools/src/main/java/org/neo4j/tools/txlog/checktypes/NodeCheckType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
package org.neo4j.tools.txlog.checktypes; | |||
|
|||
import java.util.Objects; | |||
|
|||
import org.neo4j.kernel.impl.store.record.NodeRecord; | |||
import org.neo4j.kernel.impl.transaction.command.Command; | |||
|
|||
class NodeCheckType extends CheckType<Command.NodeCommand,NodeRecord> | |||
{ | |||
NodeCheckType() | |||
{ | |||
super( Command.NodeCommand.class ); | |||
} | |||
|
|||
@Override | |||
public NodeRecord before( Command.NodeCommand command ) | |||
{ | |||
return command.getBefore(); | |||
} | |||
|
|||
@Override | |||
public NodeRecord after( Command.NodeCommand command ) | |||
{ | |||
return command.getAfter(); | |||
} | |||
|
|||
@Override | |||
public boolean equal( NodeRecord record1, NodeRecord record2 ) | |||
{ | |||
Objects.requireNonNull( record1 ); | |||
Objects.requireNonNull( record2 ); | |||
|
|||
return record1.getId() == record2.getId() && | |||
record1.inUse() == record2.inUse() && | |||
record1.getNextProp() == record2.getNextProp() && | |||
record1.getNextRel() == record2.getNextRel() && | |||
record1.isDense() == record2.isDense() && | |||
record1.getLabelField() == record2.getLabelField(); | |||
} | |||
|
|||
@Override | |||
public String name() | |||
{ | |||
return "node"; | |||
} | |||
} |
Oops, something went wrong.