private OutputMapper mapper( Class<?> clazz ) throws ProcedureException { return new OutputMappers( new TypeMappers() ).mapper( clazz ); }
@Test public void shouldMapCorrectly() throws Throwable { // Given TypeChecker mapper = new TypeMappers().checkerFor( javaClass ); // When Object converted = mapper.typeCheck( javaValue ); // Then assertEquals( expectedNeoValue, converted ); }
@Test public void shouldDetectCorrectType() throws Throwable { // When Neo4jTypes.AnyType type = new TypeMappers().toNeo4jType( javaClass ); // Then assertEquals( neoType, type ); }
return toList( converterFor( type ), type ); throw javaToNeoMappingError( javaType );
TypeMappers.TypeChecker checker = typeMappers.checkerFor( field.getGenericType() ); MethodHandle getter = lookup.unreflectGetter( field ); FieldMapper fieldMapper = new FieldMapper( getter, checker );
public List<Neo4jTypes.AnyType> inputTypesFor( Method method ) throws ProcedureException { Type[] types = method.getGenericParameterTypes(); List<Neo4jTypes.AnyType> neoTypes = new ArrayList<>( types.length ); for ( Type type : types ) { neoTypes.add( typeMappers.toNeo4jType( type ) ); } return neoTypes; }
public AnyType toNeo4jType( Type type ) throws ProcedureException { return converterFor( type ).type; }
/** * We don't have Node, Relationship, Property available down here - and don't strictly want to, * we want the procedures to be independent of which Graph API is being used (and we don't want * them to get tangled up with kernel code). So, we only register the "core" type system here, * scalars and collection types. Node, Relationship, Path and any other future graph types should * be registered from the outside in the same place APIs to work with those types is registered. */ private void registerScalarsAndCollections() { registerType( String.class, TO_STRING ); registerType( long.class, TO_INTEGER ); registerType( Long.class, TO_INTEGER ); registerType( double.class, TO_FLOAT ); registerType( Double.class, TO_FLOAT ); registerType( Number.class, TO_NUMBER ); registerType( boolean.class, TO_BOOLEAN ); registerType( Boolean.class, TO_BOOLEAN ); registerType( Map.class, TO_MAP ); registerType( List.class, TO_LIST ); registerType( Object.class, TO_ANY ); registerType( byte[].class, TO_BYTEARRAY ); registerType( ZonedDateTime.class, new DefaultValueConverter( NTDateTime, ZonedDateTime.class ) ); registerType( LocalDateTime.class, new DefaultValueConverter( NTLocalDateTime, LocalDateTime.class ) ); registerType( LocalDate.class, new DefaultValueConverter( NTDate, LocalDate.class ) ); registerType( OffsetTime.class, new DefaultValueConverter( NTTime, OffsetTime.class ) ); registerType( LocalTime.class, new DefaultValueConverter( NTLocalTime, LocalTime.class ) ); registerType( TemporalAmount.class, new DefaultValueConverter( NTDuration, TemporalAmount.class ) ); }
public TypeMappers( EmbeddedProxySPI proxySPI ) { super( proxySPI ); registerScalarsAndCollections(); }
TypeMappers.TypeChecker valueConverter = typeMappers.checkerFor( returnType ); MethodHandle creator = lookup.unreflect( method ); MethodHandle resultMethod = lookup.unreflect( result );
return toList( converterFor( type ), type ); throw javaToNeoMappingError( javaType );
public List<Neo4jTypes.AnyType> inputTypesFor( Method method ) throws ProcedureException { Type[] types = method.getGenericParameterTypes(); List<Neo4jTypes.AnyType> neoTypes = new ArrayList<>( types.length ); for ( Type type : types ) { neoTypes.add( typeMappers.toNeo4jType( type ) ); } return neoTypes; }
public TypeChecker checkerFor( Type javaType ) throws ProcedureException { return converterFor( javaType ); }
/** * 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, Neo4jTypes.AnyType type ) { typeMappers.registerType( javaClass, new TypeMappers.DefaultValueConverter( type, javaClass ) ); }
public TypeMappers( EmbeddedProxySPI proxySPI ) { super( proxySPI ); registerScalarsAndCollections(); }
public Procedures( EmbeddedProxySPI proxySPI, ThrowingConsumer<Procedures,ProcedureException> builtin, File pluginDir, Log log, ProcedureConfig config ) { this.builtin = builtin; this.pluginDir = pluginDir; this.log = log; this.typeMappers = new TypeMappers( proxySPI ); this.compiler = new ReflectiveProcedureCompiler( typeMappers, safeComponents, allComponents, log, config ); }
TypeMappers.TypeChecker typeChecker = typeMappers.checkerFor( returnType ); String description = description( method ); UserFunction function = method.getAnnotation( UserFunction.class );
DefaultValueConverter valueConverter = typeMappers.converterFor( type ); Optional<DefaultParameterValue> defaultValue = valueConverter.defaultValue( parameter );
/** * We don't have Node, Relationship, Property available down here - and don't strictly want to, * we want the procedures to be independent of which Graph API is being used (and we don't want * them to get tangled up with kernel code). So, we only register the "core" type system here, * scalars and collection types. Node, Relationship, Path and any other future graph types should * be registered from the outside in the same place APIs to work with those types is registered. */ private void registerScalarsAndCollections() { registerType( String.class, TO_STRING ); registerType( long.class, TO_INTEGER ); registerType( Long.class, TO_INTEGER ); registerType( double.class, TO_FLOAT ); registerType( Double.class, TO_FLOAT ); registerType( Number.class, TO_NUMBER ); registerType( boolean.class, TO_BOOLEAN ); registerType( Boolean.class, TO_BOOLEAN ); registerType( Map.class, TO_MAP ); registerType( List.class, TO_LIST ); registerType( Object.class, TO_ANY ); registerType( byte[].class, TO_BYTEARRAY ); registerType( ZonedDateTime.class, new DefaultValueConverter( NTDateTime, ZonedDateTime.class ) ); registerType( LocalDateTime.class, new DefaultValueConverter( NTLocalDateTime, LocalDateTime.class ) ); registerType( LocalDate.class, new DefaultValueConverter( NTDate, LocalDate.class ) ); registerType( OffsetTime.class, new DefaultValueConverter( NTTime, OffsetTime.class ) ); registerType( LocalTime.class, new DefaultValueConverter( NTLocalTime, LocalTime.class ) ); registerType( TemporalAmount.class, new DefaultValueConverter( NTDuration, TemporalAmount.class ) ); }
@Test public void shouldMapSimpleFunctionWithString() throws Throwable { // When Method echo = ClassWithProcedureWithSimpleArgs.class.getMethod( "echo", String.class ); List<Neo4jTypes.AnyType> signature = new MethodSignatureCompiler( new TypeMappers() ).inputTypesFor( echo ); // THen assertThat(signature, contains( Neo4jTypes.NTString)); }