Skip to content

Commit

Permalink
Rename Neo4jValue to DefaultParameterValue
Browse files Browse the repository at this point in the history
Since that was how it was used.
  • Loading branch information
thobe committed Jan 30, 2018
1 parent b5c251e commit 195d1ae
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 190 deletions.
Expand Up @@ -38,7 +38,7 @@ import org.neo4j.kernel.api.proc.{Neo4jTypes, QualifiedName => KernelQualifiedNa
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor
import org.neo4j.kernel.api.schema.index.{IndexDescriptor => KernelIndexDescriptor}
import org.neo4j.kernel.impl.proc.Neo4jValue
import org.neo4j.kernel.impl.proc.DefaultParameterValue
import org.neo4j.procedure.Mode

import scala.collection.JavaConverters._
Expand Down Expand Up @@ -179,7 +179,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper, logger: Inter
"Unable to execute procedure, because it requires an unrecognized execution mode: " + mode.name(), null )
}

private def asCypherValue(neo4jValue: Neo4jValue) = CypherValue(neo4jValue.value, asCypherType(neo4jValue.neo4jType()))
private def asCypherValue(neo4jValue: DefaultParameterValue) = CypherValue(neo4jValue.value, asCypherType(neo4jValue.neo4jType()))

private def asCypherType(neoType: AnyType): CypherType = neoType match {
case Neo4jTypes.NTString => symbols.CTString
Expand Down
Expand Up @@ -35,7 +35,7 @@ import org.neo4j.kernel.api.proc.Neo4jTypes.AnyType
import org.neo4j.kernel.api.proc.{Neo4jTypes, QualifiedName => KernelQualifiedName}
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema.index.{IndexDescriptor => KernelIndexDescriptor}
import org.neo4j.kernel.impl.proc.Neo4jValue
import org.neo4j.kernel.impl.proc.DefaultParameterValue
import org.neo4j.procedure.Mode

import scala.collection.JavaConverters._
Expand Down Expand Up @@ -172,7 +172,7 @@ class TransactionBoundPlanContext(readOperationsSupplier: () => ReadOperations,
"Unable to execute procedure, because it requires an unrecognized execution mode: " + mode.name(), null)
}

private def asCypherValue(neo4jValue: Neo4jValue) = CypherValue(neo4jValue.value,
private def asCypherValue(neo4jValue: DefaultParameterValue) = CypherValue(neo4jValue.value,
asCypherType(neo4jValue.neo4jType()))

private def asCypherType(neoType: AnyType): CypherType = neoType match {
Expand Down
Expand Up @@ -33,7 +33,7 @@ import org.neo4j.kernel.api.proc.Neo4jTypes.AnyType
import org.neo4j.kernel.api.proc.{Neo4jTypes, QualifiedName => KernelQualifiedName}
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema.index.{IndexDescriptor => KernelIndexDescriptor}
import org.neo4j.kernel.impl.proc.Neo4jValue
import org.neo4j.kernel.impl.proc.DefaultParameterValue
import org.neo4j.procedure.Mode

import scala.collection.JavaConverters._
Expand Down Expand Up @@ -175,7 +175,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper, logger: Inter
"Unable to execute procedure, because it requires an unrecognized execution mode: " + mode.name(), null)
}

private def asCypherValue(neo4jValue: Neo4jValue) = CypherValue(neo4jValue.value,
private def asCypherValue(neo4jValue: DefaultParameterValue) = CypherValue(neo4jValue.value,
asCypherType(neo4jValue.neo4jType()))

private def asCypherType(neoType: AnyType): CypherType = neoType match {
Expand Down
Expand Up @@ -22,7 +22,7 @@
import java.util.Objects;
import java.util.Optional;

import org.neo4j.kernel.impl.proc.Neo4jValue;
import org.neo4j.kernel.impl.proc.DefaultParameterValue;

import static java.util.Objects.requireNonNull;

Expand All @@ -34,7 +34,7 @@ public static FieldSignature inputField( String name, Neo4jTypes.AnyType type )
return new FieldSignature( name, type, null, false );
}

public static FieldSignature inputField( String name, Neo4jTypes.AnyType type, Neo4jValue defaultValue )
public static FieldSignature inputField( String name, Neo4jTypes.AnyType type, DefaultParameterValue defaultValue )
{
return new FieldSignature( name, type, requireNonNull( defaultValue, "defaultValue" ), false );
}
Expand All @@ -51,10 +51,10 @@ public static FieldSignature outputField( String name, Neo4jTypes.AnyType type,

private final String name;
private final Neo4jTypes.AnyType type;
private final Neo4jValue defaultValue;
private final DefaultParameterValue defaultValue;
private final boolean deprecated;

private FieldSignature( String name, Neo4jTypes.AnyType type, Neo4jValue defaultValue, boolean deprecated )
private FieldSignature( String name, Neo4jTypes.AnyType type, DefaultParameterValue defaultValue, boolean deprecated )
{
this.name = requireNonNull( name, "name" );
this.type = requireNonNull( type, "type" );
Expand All @@ -81,7 +81,7 @@ public Neo4jTypes.AnyType neo4jType()
return type;
}

public Optional<Neo4jValue> defaultValue()
public Optional<DefaultParameterValue> defaultValue()
{
return Optional.ofNullable( defaultValue );
}
Expand Down
Expand Up @@ -62,7 +62,7 @@
import org.neo4j.kernel.impl.proc.ProcedureTransactionProvider;
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.impl.proc.TerminationGuardProvider;
import org.neo4j.kernel.impl.proc.TypeMappers.SimpleConverter;
import org.neo4j.kernel.impl.proc.TypeMappers.DefaultValueConverter;
import org.neo4j.kernel.impl.query.QueryExecutionEngine;
import org.neo4j.kernel.impl.store.StoreId;
import org.neo4j.kernel.impl.transaction.log.files.LogFileCreationMonitor;
Expand Down Expand Up @@ -249,11 +249,11 @@ private Procedures setupProcedures( PlatformModule platform, EditionModule editi
platform.life.add( procedures );
platform.dependencies.satisfyDependency( procedures );

procedures.registerType( Node.class, new SimpleConverter( NTNode, Node.class ) );
procedures.registerType( Relationship.class, new SimpleConverter( NTRelationship, Relationship.class ) );
procedures.registerType( Path.class, new SimpleConverter( NTPath, Path.class ) );
procedures.registerType( Geometry.class, new SimpleConverter( NTGeometry, Geometry.class ) );
procedures.registerType( Point.class, new SimpleConverter( NTPoint, Point.class ) );
procedures.registerType( Node.class, NTNode );
procedures.registerType( Relationship.class, NTRelationship );
procedures.registerType( Path.class, NTPath );
procedures.registerType( Geometry.class, NTGeometry );
procedures.registerType( Point.class, NTPoint );

// Register injected public API components
Log proceduresLog = platform.logging.getUserLog( Procedures.class );
Expand Down
Expand Up @@ -24,12 +24,12 @@

import org.neo4j.kernel.api.proc.Neo4jTypes;

public class Neo4jValue
public class DefaultParameterValue
{
private final Object value;
private final Neo4jTypes.AnyType type;

public Neo4jValue( Object value, Neo4jTypes.AnyType type )
public DefaultParameterValue( Object value, Neo4jTypes.AnyType type )
{
this.value = value;
this.type = type;
Expand All @@ -45,40 +45,45 @@ public Neo4jTypes.AnyType neo4jType()
return type;
}

public static Neo4jValue ntString( String value )
public static DefaultParameterValue ntString( String value )
{
return new Neo4jValue( value, Neo4jTypes.NTString );
return new DefaultParameterValue( value, Neo4jTypes.NTString );
}

public static Neo4jValue ntInteger( long value )
static DefaultParameterValue ntInteger( long value )
{
return new Neo4jValue( value, Neo4jTypes.NTInteger );
return new DefaultParameterValue( value, Neo4jTypes.NTInteger );
}

public static Neo4jValue ntFloat( double value )
static DefaultParameterValue ntFloat( double value )
{
return new Neo4jValue( value, Neo4jTypes.NTFloat );
return new DefaultParameterValue( value, Neo4jTypes.NTFloat );
}

public static Neo4jValue ntBoolean( boolean value )
static DefaultParameterValue ntBoolean( boolean value )
{
return new Neo4jValue( value, Neo4jTypes.NTBoolean );
return new DefaultParameterValue( value, Neo4jTypes.NTBoolean );
}

public static Neo4jValue ntMap( Map<String,Object> value )
static DefaultParameterValue ntMap( Map<String,Object> value )
{
return new Neo4jValue( value, Neo4jTypes.NTMap );
return new DefaultParameterValue( value, Neo4jTypes.NTMap );
}

public static Neo4jValue ntList( List<?> value, Neo4jTypes.AnyType inner )
static DefaultParameterValue ntList( List<?> value, Neo4jTypes.AnyType inner )
{
return new Neo4jValue( value, Neo4jTypes.NTList( inner ) );
return new DefaultParameterValue( value, Neo4jTypes.NTList( inner ) );
}

static DefaultParameterValue nullValue( Neo4jTypes.AnyType type )
{
return new DefaultParameterValue( null, type );
}

@Override
public String toString()
{
return "Neo4jValue{" +
return "DefaultParameterValue{" +
"value=" + value +
", type=" + type +
'}';
Expand All @@ -96,14 +101,13 @@ public boolean equals( Object o )
return false;
}

Neo4jValue that = (Neo4jValue) o;
DefaultParameterValue that = (DefaultParameterValue) o;

if ( value != null ? !value.equals( that.value ) : that.value != null )
{
return false;
}
return type.equals( that.type );

}

@Override
Expand Down
Expand Up @@ -24,11 +24,11 @@

import org.neo4j.kernel.api.proc.Neo4jTypes;

import static org.neo4j.kernel.impl.proc.Neo4jValue.ntList;
import static org.neo4j.kernel.impl.proc.DefaultParameterValue.ntList;
import static org.neo4j.kernel.impl.proc.ParseUtil.parseList;


public class ListConverter implements Function<String,Neo4jValue>
public class ListConverter implements Function<String,DefaultParameterValue>
{
private final Type type;
private final Neo4jTypes.AnyType neoType;
Expand All @@ -40,7 +40,7 @@ public ListConverter( Type type, Neo4jTypes.AnyType neoType )
}

@Override
public Neo4jValue apply( String s )
public DefaultParameterValue apply( String s )
{
String value = s.trim();
if ( value.equalsIgnoreCase( "null" ) )
Expand Down
Expand Up @@ -21,18 +21,18 @@

import java.util.function.Function;

import static org.neo4j.kernel.impl.proc.Neo4jValue.ntMap;
import static org.neo4j.kernel.impl.proc.DefaultParameterValue.ntMap;
import static org.neo4j.kernel.impl.proc.ParseUtil.parseMap;

/**
* A naive implementation of a Cypher-map/json parser. If you find yourself using this
* for parsing huge json-document in a place where performance matters - you probably need
* to rethink your decision.
*/
public class MapConverter implements Function<String,Neo4jValue>
public class MapConverter implements Function<String,DefaultParameterValue>
{
@Override
public Neo4jValue apply( String s )
public DefaultParameterValue apply( String s )
{
String value = s.trim();
if ( value.equalsIgnoreCase( "null" ) )
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.proc.FieldSignature;
import org.neo4j.kernel.api.proc.Neo4jTypes;
import org.neo4j.kernel.impl.proc.TypeMappers.NeoValueConverter;
import org.neo4j.kernel.impl.proc.TypeMappers.DefaultValueConverter;
import org.neo4j.procedure.Name;

import static org.neo4j.kernel.api.proc.FieldSignature.inputField;
Expand All @@ -54,8 +54,7 @@ public List<Neo4jTypes.AnyType> inputTypesFor( Method method ) throws ProcedureE
List<Neo4jTypes.AnyType> neoTypes = new ArrayList<>( types.length );
for ( Type type : types )
{
NeoValueConverter valueConverter = typeMappers.converterFor( type );
neoTypes.add( valueConverter.type() );
neoTypes.add( typeMappers.toNeo4jType( type ) );
}

return neoTypes;
Expand Down Expand Up @@ -92,8 +91,8 @@ public List<FieldSignature> signatureFor( Method method ) throws ProcedureExcept

try
{
NeoValueConverter valueConverter = typeMappers.converterFor( type );
Optional<Neo4jValue> defaultValue = valueConverter.defaultValue( parameter );
DefaultValueConverter valueConverter = typeMappers.converterFor( type );
Optional<DefaultParameterValue> defaultValue = valueConverter.defaultValue( parameter );
//it is not allowed to have holes in default values
if ( seenDefault && !defaultValue.isPresent() )
{
Expand Down
Expand Up @@ -98,18 +98,18 @@ public List<FieldSignature> signature()
private static class FieldMapper
{
private final MethodHandle getter;
private final TypeMappers.NeoValueConverter mapper;
private final TypeMappers.TypeChecker checker;

FieldMapper( MethodHandle getter, TypeMappers.NeoValueConverter mapper )
FieldMapper( MethodHandle getter, TypeMappers.TypeChecker checker )
{
this.getter = getter;
this.mapper = mapper;
this.checker = checker;
}

Object apply( Object record ) throws ProcedureException
{
Object invoke = getValue( record );
return mapper.toNeoValue( invoke );
return checker.typeCheck( invoke );
}

private Object getValue( Object record ) throws ProcedureException
Expand Down Expand Up @@ -196,12 +196,12 @@ public OutputMapper mapper( Class<?> userClass ) throws ProcedureException

try
{
TypeMappers.NeoValueConverter mapper = typeMappers.converterFor( field.getGenericType() );
TypeMappers.TypeChecker checker = typeMappers.checkerFor( field.getGenericType() );
MethodHandle getter = lookup.unreflectGetter( field );
FieldMapper fieldMapper = new FieldMapper( getter, mapper );
FieldMapper fieldMapper = new FieldMapper( getter, checker );

fieldMappers[i] = fieldMapper;
signature[i] = FieldSignature.outputField( field.getName(), mapper.type(), field.isAnnotationPresent( Deprecated.class ) );
signature[i] = FieldSignature.outputField( field.getName(), checker.type(), field.isAnnotationPresent( Deprecated.class ) );
}
catch ( ProcedureException e )
{
Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.neo4j.kernel.api.proc.CallableUserAggregationFunction;
import org.neo4j.kernel.api.proc.CallableUserFunction;
import org.neo4j.kernel.api.proc.Context;
import org.neo4j.kernel.api.proc.Neo4jTypes;
import org.neo4j.kernel.api.proc.ProcedureSignature;
import org.neo4j.kernel.api.proc.QualifiedName;
import org.neo4j.kernel.api.proc.UserFunctionSignature;
Expand Down Expand Up @@ -213,13 +214,16 @@ public void registerFunction( Class<?> func, boolean overrideCurrentImplementati
}

/**
* Registers a type and how to convert it to a Neo4jType
* @param javaClass the class of the native type
* @param toNeo the conversion to Neo4jTypes
* Registers a type and its mapping to Neo4jTypes
*
* @param javaClass
* the class of the native type
* @param type
* the mapping to Neo4jTypes
*/
public void registerType( Class<?> javaClass, TypeMappers.NeoValueConverter toNeo )
public void registerType( Class<?> javaClass, Neo4jTypes.AnyType type )
{
typeMappers.registerType( javaClass, toNeo );
typeMappers.registerType( javaClass, new TypeMappers.DefaultValueConverter( type, javaClass ) );
}

/**
Expand Down

0 comments on commit 195d1ae

Please sign in to comment.