@SuppressWarnings( "unused" ) // called from compiled code public static long unboxRelationshipOrNull( VirtualRelationshipValue value ) { if ( value == null ) { return -1L; } return value.id(); }
@Override public int computeHash() { return Long.hashCode( id() ); }
@Override public int compareTo( VirtualValue other, Comparator<AnyValue> comparator ) { if ( !(other instanceof VirtualRelationshipValue) ) { throw new IllegalArgumentException( "Cannot compare different virtual values" ); } VirtualRelationshipValue otherNode = (VirtualRelationshipValue) other; return Long.compare( id(), otherNode.id() ); }
@SuppressWarnings( "unused" ) // called from compiled code public static long extractLong( Object obj ) { if ( obj == null || obj == NO_VALUE ) { return -1L; } else if ( obj instanceof VirtualNodeValue ) { return ((VirtualNodeValue) obj).id(); } else if ( obj instanceof VirtualRelationshipValue ) { return ((VirtualRelationshipValue) obj).id(); } else if ( obj instanceof Long ) { return (Long) obj; } else { throw new IllegalArgumentException( format( "Can not be converted to long: %s", obj.getClass().getName() ) ); } }
@Override public AnyValue mapRelationship( VirtualRelationshipValue value ) { if ( value instanceof RelationshipValue ) { return value; } return ValueUtils.fromRelationshipProxy( proxySpi.newRelationshipProxy( value.id() ) ); }
@Override public Relationship mapRelationship( VirtualRelationshipValue value ) { assert !(value instanceof RelationshipReference); if ( value instanceof RelationshipProxyWrappingValue ) { // this is the back door through which "virtual relationships" slip return ((RelationshipProxyWrappingValue) value).relationshipProxy(); } return new RelationshipProxy( proxySPI, value.id() ); }
public static RelationshipValue materializeRelationshipValue( EmbeddedProxySPI proxySpi, Object anyValue ) { // Null check has to be done outside by the generated code if ( anyValue instanceof RelationshipValue ) { return (RelationshipValue) anyValue; } else if ( anyValue instanceof VirtualRelationshipValue ) { return ValueUtils.fromRelationshipProxy( proxySpi.newRelationshipProxy( ((VirtualRelationshipValue) anyValue).id() ) ); } else if ( anyValue instanceof Relationship ) { return ValueUtils.fromRelationshipProxy( (Relationship) anyValue ); } throw new IllegalArgumentException( "Do not know how to materialize relationship value from type " + anyValue.getClass().getName() ); }
if ( ((VirtualRelationshipValue) value).id() == -1 )
public static LongValue id( AnyValue item ) { if ( item instanceof VirtualNodeValue ) { return longValue( ((VirtualNodeValue) item).id() ); } else if ( item instanceof VirtualRelationshipValue ) { return longValue( ((VirtualRelationshipValue) item).id() ); } else { throw new CypherTypeException( format( "Expected %s to be a node or relationship, but it was `%s`", item, item.getClass().getSimpleName() ), null ); } }
public static MapValue properties( AnyValue in, DbAccess access ) { if ( in instanceof VirtualNodeValue ) { return access.nodeAsMap( ((VirtualNodeValue) in).id() ); } else if ( in instanceof VirtualRelationshipValue ) { return access.relationshipAsMap( ((VirtualRelationshipValue) in).id() ); } else if ( in instanceof MapValue ) { return (MapValue) in; } else { throw new CypherTypeException( format( "Expected a node, a relationship or a literal map but got %s", in ), null ); } }
public static ListValue keys( AnyValue in, DbAccess access ) { if ( in instanceof VirtualNodeValue ) { return extractKeys( access, access.nodePropertyIds( ((VirtualNodeValue) in).id() ) ); } else if ( in instanceof VirtualRelationshipValue ) { return extractKeys( access, access.relationshipPropertyIds( ((VirtualRelationshipValue) in).id() ) ); } else if ( in instanceof MapValue ) { return ((MapValue) in).keys(); } else { throw new CypherTypeException( format( "Expected a node, a relationship or a literal map but got %s", in ), null ); } }
public static BooleanValue propertyExists( String key, AnyValue container, DbAccess dbAccess ) { if ( container instanceof VirtualNodeValue ) { return dbAccess.nodeHasProperty( ((VirtualNodeValue) container).id(), dbAccess.propertyKey( key ) ) ? TRUE : FALSE; } else if ( container instanceof VirtualRelationshipValue ) { return dbAccess.relationshipHasProperty( ((VirtualRelationshipValue) container).id(), dbAccess.propertyKey( key ) ) ? TRUE : FALSE; } else if ( container instanceof MapValue ) { return ((MapValue) container).get( key ) != NO_VALUE ? TRUE : FALSE; } else { throw new CypherTypeException( format( "Expected %s to be a property container", container), null ); } }
private static Value asPoint( DbAccess access, VirtualRelationshipValue relationshipValue ) { MapValueBuilder builder = new MapValueBuilder(); for ( String key : POINT_KEYS ) { Value value = access.relationshipProperty( relationshipValue.id(), access.propertyKey( key ) ); if ( value == NO_VALUE ) { continue; } builder.add( key, value ); } return PointValue.fromMap( builder.build() ); }
public static AnyValue materializeAnyValueResult( EmbeddedProxySPI proxySpi, Object anyValue ) { if ( anyValue instanceof VirtualNodeValue ) { if ( anyValue instanceof NodeValue ) { return (AnyValue) anyValue; } return ValueUtils.fromNodeProxy( proxySpi.newNodeProxy( ((VirtualNodeValue) anyValue).id() ) ); } if ( anyValue instanceof VirtualRelationshipValue ) { if ( anyValue instanceof RelationshipValue ) { return (AnyValue) anyValue; } return ValueUtils.fromRelationshipProxy( proxySpi.newRelationshipProxy( ((VirtualRelationshipValue) anyValue).id() ) ); } // If it is a list or map, run it through a ValueMapper that will create proxy objects for entities if needed. // This will first do a dry run and return as it is if no conversion is needed. // If in the future we will always create proxy objects directly whenever we create values we can skip this // Doing this conversion lazily instead, by wrapping with TransformedListValue or TransformedMapValue is probably not a // good idea because of the complexities involved (see TOMBSTONE in VirtualValues about why TransformedListValue was killed). // NOTE: There is also a case where a ListValue can be storable (ArrayValueListValue) where no conversion is needed if ( (anyValue instanceof ListValue && !((ListValue) anyValue).storable()) || anyValue instanceof MapValue ) { return CompiledMaterializeValueMapper.mapAnyValue( proxySpi, (AnyValue) anyValue ); } return (AnyValue) anyValue; }
public static AnyValue containerIndex( AnyValue container, AnyValue index, DbAccess dbAccess ) { if ( container instanceof VirtualNodeValue ) { return dbAccess.nodeProperty( ((VirtualNodeValue) container).id(), dbAccess.propertyKey( asString( index ) ) ); } else if ( container instanceof VirtualRelationshipValue ) { return dbAccess.relationshipProperty( ((VirtualRelationshipValue) container).id(), dbAccess.propertyKey( asString( index ) ) ); } if ( container instanceof MapValue ) { return mapAccess( (MapValue) container, index ); } else if ( container instanceof SequenceValue ) { return listAccess( (SequenceValue) container, index ); } else { throw new CypherTypeException( format( "`%s` is not a collection or a map. Element access is only possible by performing a collection " + "lookup using an integer index, or by performing a map lookup using a string key (found: %s[%s])", container, container, index ), null ); } }
.relationshipProperty( ((VirtualRelationshipValue) container).id(), dbAccess.propertyKey( key ) );
@SuppressWarnings( "unused" ) // called from compiled code public static long unboxRelationshipOrNull( VirtualRelationshipValue value ) { if ( value == null ) { return -1L; } return value.id(); }
@Override public int computeHash() { return Long.hashCode( id() ); }