Skip to content

New results api #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e96240d
Implement new results api
boggle Nov 21, 2015
96ca6d6
Remove isType() methods in favour of using the type system on session
boggle Dec 2, 2015
bceea08
Add Node.hasLabel() and Rel.hasType() for consistency with MapLike.ha…
boggle Dec 2, 2015
fcce7b5
Introduce internal.AsValue to reduce number of instance of tests in V…
boggle Dec 2, 2015
b3950f1
Added some tests
pontusmelke Dec 2, 2015
e76f32f
Restructuring *Like interfaces
boggle Dec 2, 2015
8252d4c
Added more tests
pontusmelke Dec 3, 2015
18b1c29
Add Value.is{True|False} and some fixups
boggle Dec 3, 2015
2acd366
Test and document out of bounds behavior
pontusmelke Dec 4, 2015
4965d93
Removed count from Result API
pontusmelke Dec 4, 2015
5b80b22
Retain fails if not at the beginning
pontusmelke Dec 4, 2015
12e3529
More documentation and minor clean up.
pontusmelke Dec 4, 2015
175239f
Unified toString of all Values
pontusmelke Dec 4, 2015
f800713
Throw ClientException if not calling next before reading data.
pontusmelke Dec 4, 2015
34555d5
Add (property|field)count (Also: Rename PropertyAccessor to PropertyM…
boggle Dec 5, 2015
d6ed7ff
Introduce immutable annotation
boggle Dec 5, 2015
de8f7d1
Rename statement text to template
boggle Dec 5, 2015
72a092e
Update Immutable annotation to be documented
boggle Dec 8, 2015
35ac610
Add mapping variant of retain
boggle Dec 8, 2015
3a11bc3
Complete set of Values.valueAs{Type} functions
boggle Dec 8, 2015
82037e7
Move package v1.internal to internal
boggle Dec 8, 2015
86d70ea
Add fieldIndex
boggle Dec 8, 2015
6f1b9f6
Record.equals
boggle Dec 8, 2015
90313f2
Rewire how toString() works and some refactoring around Value impleme…
boggle Dec 9, 2015
e1d696e
Add missing RecordAccessor methods: index, field(String), field(int)
boggle Dec 9, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.v1.internal.value;
package org.neo4j.driver.internal;

import org.neo4j.driver.v1.Value;
import org.neo4j.driver.v1.internal.types.TypeConstructor;

public interface InternalValue extends Value
public interface AsValue
{
TypeConstructor typeConstructor();
/**
* Retrieve a value representation of this
*
* @see Value
* @return {@link Value} that represents this
*/
Value asValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.v1.internal;
package org.neo4j.driver.internal;

import org.neo4j.driver.v1.Identity;

public class Identities
{
public static Identity identity( long raw )
{
return new SimpleIdentity( raw );
return new InternalIdentity( raw );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.v1.internal;
package org.neo4j.driver.internal;

import java.util.Collection;
import java.util.Map;

import org.neo4j.driver.internal.util.Extract;
import org.neo4j.driver.internal.util.Iterables;
import org.neo4j.driver.internal.value.MapValue;
import org.neo4j.driver.v1.Entity;
import org.neo4j.driver.v1.Function;
import org.neo4j.driver.v1.Identity;
import org.neo4j.driver.v1.Property;
import org.neo4j.driver.v1.Value;
import org.neo4j.driver.v1.Values;

public abstract class SimpleEntity implements Entity
import static org.neo4j.driver.v1.Values.valueAsIs;

public abstract class InternalEntity implements Entity, AsValue
{
private final Identity id;
private final Map<String,Value> properties;

public SimpleEntity( Identity id, Map<String,Value> properties )
public InternalEntity( Identity id, Map<String, Value> properties )
{
this.id = id;
this.properties = properties;
Expand All @@ -43,21 +50,19 @@ public Identity identity()
}

@Override
public Collection<String> propertyKeys()
public Property property( String key )
{
return properties.keySet();
return InternalProperty.of( key, value( key ) );
}

@Override
public Value property( String key )
public int propertyCount()
{
return properties.get( key );
return properties.size();
}

@Override
public int propertyCount()
public Value asValue()
{
return properties.size();
return new MapValue( properties );
}

@Override
Expand All @@ -72,7 +77,7 @@ public boolean equals( Object o )
return false;
}

SimpleEntity that = (SimpleEntity) o;
InternalEntity that = (InternalEntity) o;

return id.equals( that.id );

Expand All @@ -92,4 +97,47 @@ public String toString()
", properties=" + properties +
'}';
}

@Override
public boolean containsKey( String key )
{
return properties.containsKey( key );
}

@Override
public Iterable<String> keys()
{
return properties.keySet();
}

@Override
public Value value( String key )
{
Value value = properties.get( key );
return value == null ? Values.NULL : value;
}

@Override
public Iterable<Value> values()
{
return properties.values();
}

@Override
public <T> Iterable<T> values( Function<Value,T> mapFunction )
{
return Iterables.map( properties.values(), mapFunction );
}

@Override
public Iterable<Property<Value>> properties()
{
return properties( valueAsIs() );
}

@Override
public <V> Iterable<Property<V>> properties( final Function<Value, V> Function )
{
return Extract.properties( this, Function );
}
}
110 changes: 110 additions & 0 deletions driver/src/main/java/org/neo4j/driver/internal/InternalField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* Copyright (c) 2002-2015 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.internal;

import java.util.Objects;

import org.neo4j.driver.v1.Field;
import org.neo4j.driver.v1.Function;
import org.neo4j.driver.v1.Property;

public class InternalField<V> implements Field<V>
{
private final int index;
private final String key;
private final V value;

public InternalField( String key, int index, V value )
{
if ( key == null )
{
throw new IllegalArgumentException( "null key" );
}
if ( value == null )
{
throw new IllegalArgumentException( "null value" );
}
this.index = index;
this.key = key;
this.value = value;
}

public String key()
{
return key;
}

public V value()
{
return value;
}

@Override
public int index()
{
return index;
}

@Override
public Property<V> asProperty()
{
return InternalProperty.of( key, value );
}

@Override
public String toString()
{
return String.format( "%s: %s", key, Objects.toString( value ) );
}

public String toString( Function<V, String> printValue )
{
return String.format( "%s: %s", key, printValue.apply( value ) );
}

@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}

InternalField<?> that = (InternalField<?>) o;
return index == that.index && key.equals( that.key ) && value.equals( that.value );
}

@Override
public int hashCode()
{
int result = index;
result = 31 * result + key.hashCode();
result = 31 * result + value.hashCode();
return result;
}

public static <V> Field<V> of( String key, int index, V value )
{
return new InternalField<>( key, index, value );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.v1.internal;
package org.neo4j.driver.internal;

import org.neo4j.driver.internal.value.IdentityValue;
import org.neo4j.driver.v1.Identity;
import org.neo4j.driver.v1.Value;

public class SimpleIdentity implements Identity
public class InternalIdentity implements Identity, AsValue
{
private final long raw;

public SimpleIdentity( long raw )
public InternalIdentity( long raw )
{
this.raw = raw;
}

@Override
public Value asValue()
{
return new IdentityValue( this );
}

@Override
public String toString()
{
Expand All @@ -47,7 +55,7 @@ public boolean equals( Object o )
return false;
}

SimpleIdentity that = (SimpleIdentity) o;
InternalIdentity that = (InternalIdentity) o;

return raw == that.raw;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.v1.internal;
package org.neo4j.driver.internal;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

import org.neo4j.driver.internal.value.NodeValue;
import org.neo4j.driver.v1.Identity;
import org.neo4j.driver.v1.Node;
import org.neo4j.driver.v1.Value;

/**
* {@link Node} implementation that directly contains labels and properties.
*/
public class SimpleNode extends SimpleEntity implements Node
public class InternalNode extends InternalEntity implements Node
{
private final Collection<String> labels;

public SimpleNode( long id )
public InternalNode( long id )
{
this( id, Collections.<String>emptyList(), Collections.<String,Value>emptyMap() );
}

public SimpleNode( long id, Collection<String> labels, Map<String,Value> properties )
public InternalNode( long id, Collection<String> labels, Map<String, Value> properties )
{
this( Identities.identity( id ), labels, properties );
}

public SimpleNode( Identity identity, Collection<String> labels, Map<String,Value> properties )
public InternalNode( Identity identity, Collection<String> labels, Map<String, Value> properties )
{
super( identity, properties );
this.labels = labels;
Expand All @@ -55,10 +56,22 @@ public Collection<String> labels()
return labels;
}

@Override
public boolean hasLabel( String label )
{
return labels.contains( label );
}

@Override
public Value asValue()
{
return new NodeValue( this );
}

@Override
public String toString()
{
return "node<" + identity() + '>';
return String.format( "node<%s>", identity() );
}

@Override
Expand All @@ -77,7 +90,7 @@ public boolean equals( Object o )
return false;
}

SimpleNode that = (SimpleNode) o;
InternalNode that = (InternalNode) o;

return !(labels != null ? !labels.equals( that.labels ) : that.labels != null);

Expand Down
Loading