Skip to content

Commit

Permalink
Merged descriptor interfaces with only implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Jan 30, 2017
1 parent 967645a commit bb9a7a7
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 171 deletions.
Expand Up @@ -22,36 +22,76 @@
import org.neo4j.kernel.api.TokenNameLookup;
import org.neo4j.kernel.api.schema_new.SchemaDescriptor;

import static java.lang.String.format;

/**
* Internal representation of a graph constraint, including the schema unit it targets (eg. label-property combination)
* and the how that schema unit is constrained (eg. "has to exist", or "must be unique").
*/
public interface ConstraintDescriptor
public class ConstraintDescriptor
{
enum Type { UNIQUE, EXISTS }
public enum Type { UNIQUE, EXISTS }

public interface Supplier
{
ConstraintDescriptor getConstraintDescriptor();
}

SchemaDescriptor schema();
private final SchemaDescriptor schema;
private final ConstraintDescriptor.Type type;

Type type();
ConstraintDescriptor( SchemaDescriptor schema, Type type )
{
this.schema = schema;
this.type = type;
}

// METHODS

public SchemaDescriptor schema()
{
return schema;
}

public Type type()
{
return type;
}

/**
* @param tokenNameLookup used for looking up names for token ids.
* @return a user friendly description of what this index indexes.
*/
String userDescription( TokenNameLookup tokenNameLookup );

public String userDescription( TokenNameLookup tokenNameLookup )
{
return format( "Constraint( %s, %s )", type.name(), schema.userDescription( tokenNameLookup ) );
}

/**
* Checks whether a constraint descriptor Supplier supplies this constraint descriptor.
* @param supplier supplier to get a constraint descriptor from
* @return true if the supplied constraint descriptor equals this constraint descriptor
*/
default boolean isSame( Supplier supplier )
public boolean isSame( Supplier supplier )
{
return this.equals( supplier.getConstraintDescriptor() );
}

interface Supplier
@Override
public boolean equals( Object o )
{
ConstraintDescriptor getConstraintDescriptor();
if ( o != null && o instanceof ConstraintDescriptor )
{
ConstraintDescriptor that = (ConstraintDescriptor)o;
return this.type() == that.type() && this.schema().equals( that.schema() );
}
return false;
}

@Override
public int hashCode()
{
return type.hashCode() & schema.hashCode();
}
}
Expand Up @@ -28,21 +28,21 @@ public class ConstraintDescriptorFactory
{
public static ConstraintDescriptor existsForLabel( int labelId, int... propertyIds )
{
return new ConstraintDescriptorImpl( SchemaDescriptorFactory.forLabel( labelId, propertyIds ), EXISTS );
return new ConstraintDescriptor( SchemaDescriptorFactory.forLabel( labelId, propertyIds ), EXISTS );
}

public static ConstraintDescriptor existsForRelType( int relTypeId, int... propertyIds )
{
return new ConstraintDescriptorImpl( SchemaDescriptorFactory.forRelType( relTypeId, propertyIds ), EXISTS );
return new ConstraintDescriptor( SchemaDescriptorFactory.forRelType( relTypeId, propertyIds ), EXISTS );
}

public static ConstraintDescriptor uniqueForLabel( int labelId, int... propertyIds )
{
return new ConstraintDescriptorImpl( SchemaDescriptorFactory.forLabel( labelId, propertyIds ), UNIQUE );
return new ConstraintDescriptor( SchemaDescriptorFactory.forLabel( labelId, propertyIds ), UNIQUE );
}

public static ConstraintDescriptor uniqueForRelType( int relTypeId, int... propertyIds )
{
return new ConstraintDescriptorImpl( SchemaDescriptorFactory.forRelType( relTypeId, propertyIds ), UNIQUE );
return new ConstraintDescriptor( SchemaDescriptorFactory.forRelType( relTypeId, propertyIds ), UNIQUE );
}
}

This file was deleted.

Expand Up @@ -22,40 +22,82 @@
import org.neo4j.kernel.api.TokenNameLookup;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;

import static java.lang.String.format;

/**
* Internal representation of a graph index, including the schema unit it targets (eg. label-property combination)
* and the type of index. UNIQUE indexes are used to back uniqueness constraints.
*
* This will be renamed to IndexDescriptor, once the old org.neo4j.kernel.api.schema.IndexDescriptor is completely
* removed.
*/
public interface NewIndexDescriptor
public class NewIndexDescriptor
{
enum Type { GENERAL, UNIQUE }
public enum Type { GENERAL, UNIQUE }

public interface Supplier
{
NewIndexDescriptor getNewIndexDescriptor();
}

Type type();
private final LabelSchemaDescriptor schema;
private final NewIndexDescriptor.Type type;

NewIndexDescriptor( LabelSchemaDescriptor schema, Type type )
{
this.schema = schema;
this.type = type;
}

// METHODS

public Type type()
{
return type;
}

/**
* This method currently returns the specific LabelSchemaDescriptor, as we do not support indexes on relations.
* When we do, consider down-typing this to a SchemaDescriptor.
*/
LabelSchemaDescriptor schema();
public LabelSchemaDescriptor schema()
{
return schema;
}

/**
* @param tokenNameLookup used for looking up names for token ids.
* @return a user friendly description of what this index indexes.
*/
String userDescription( TokenNameLookup tokenNameLookup );
public String userDescription( TokenNameLookup tokenNameLookup )
{
return format( "Index( %s, %s )", type.name(), schema.userDescription( tokenNameLookup ) );
}

/**
* Checks whether a constraint descriptor Supplier supplies this constraint descriptor.
* @param supplier supplier to get a constraint descriptor from
* @return true if the supplied constraint descriptor equals this constraint descriptor
* Checks whether an index descriptor Supplier supplies this index descriptor.
* @param supplier supplier to get a index descriptor from
* @return true if the supplied index descriptor equals this index descriptor
*/
default boolean isSame( Supplier supplier )
public boolean isSame( Supplier supplier )
{
return this.equals( supplier.getNewIndexDescriptor() );
}

interface Supplier
@Override
public boolean equals( Object o )
{
NewIndexDescriptor getNewIndexDescriptor();
if ( o != null && o instanceof NewIndexDescriptor )
{
NewIndexDescriptor that = (NewIndexDescriptor)o;
return this.type() == that.type() && this.schema().equals( that.schema() );
}
return false;
}

@Override
public int hashCode()
{
return type.hashCode() & schema.hashCode();
}
}
Expand Up @@ -28,11 +28,11 @@ public class NewIndexDescriptorFactory
{
public static NewIndexDescriptor forLabel( int labelId, int... propertyIds )
{
return new NewIndexDescriptorImpl( SchemaDescriptorFactory.forLabel( labelId, propertyIds ), GENERAL );
return new NewIndexDescriptor( SchemaDescriptorFactory.forLabel( labelId, propertyIds ), GENERAL );
}

public static NewIndexDescriptor uniqueForLabel( int labelId, int... propertyIds )
{
return new NewIndexDescriptorImpl( SchemaDescriptorFactory.forLabel( labelId, propertyIds ), UNIQUE );
return new NewIndexDescriptor( SchemaDescriptorFactory.forLabel( labelId, propertyIds ), UNIQUE );
}
}

This file was deleted.

Expand Up @@ -19,8 +19,6 @@
*/
package org.neo4j.kernel.impl.storemigration.legacystore.v21.propertydeduplication;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down

0 comments on commit bb9a7a7

Please sign in to comment.