diff --git a/src/main/java/com/redislabs/redisgraph/graph_entities/Edge.java b/src/main/java/com/redislabs/redisgraph/graph_entities/Edge.java index f7c0135..6eebdf8 100644 --- a/src/main/java/com/redislabs/redisgraph/graph_entities/Edge.java +++ b/src/main/java/com/redislabs/redisgraph/graph_entities/Edge.java @@ -10,8 +10,8 @@ public class Edge extends GraphEntity { //members private String relationshipType; - private int source; - private int destination; + private long source; + private long destination; //getters & setters @@ -34,14 +34,14 @@ public void setRelationshipType(String relationshipType) { /** * @return The id of the source node */ - public int getSource() { + public long getSource() { return source; } /** * @param source - The id of the source node to be set */ - public void setSource(int source) { + public void setSource(long source) { this.source = source; } @@ -49,7 +49,7 @@ public void setSource(int source) { * * @return the id of the destination node */ - public int getDestination() { + public long getDestination() { return destination; } @@ -57,7 +57,7 @@ public int getDestination() { * * @param destination - The id of the destination node to be set */ - public void setDestination(int destination) { + public void setDestination(long destination) { this.destination = destination; } diff --git a/src/main/java/com/redislabs/redisgraph/graph_entities/GraphEntity.java b/src/main/java/com/redislabs/redisgraph/graph_entities/GraphEntity.java index 99120ba..61b9dbe 100644 --- a/src/main/java/com/redislabs/redisgraph/graph_entities/GraphEntity.java +++ b/src/main/java/com/redislabs/redisgraph/graph_entities/GraphEntity.java @@ -8,90 +8,78 @@ * A graph entity has an id and a set of properties. The properties are mapped and accessed by their names. */ public abstract class GraphEntity { - - - //members - - protected int id; + protected long id; protected final Map propertyMap = new HashMap<>(); //setters & getters /** - * * @return entity id */ - public int getId() { + public long getId() { return id; } /** - * * @param id - entity id to be set */ - public void setId(int id) { + public void setId(long id) { this.id = id; } /** * Adds a property to the entity, by composing name, type and value to a property object + * * @param name * @param value */ - public void addProperty(String name, Object value){ - + public void addProperty(String name, Object value) { addProperty(new Property(name, value)); - } /** - * * @return Entity's property names, as a Set */ - public Set getEntityPropertyNames(){ + public Set getEntityPropertyNames() { return propertyMap.keySet(); } /** * Add a property to the entity + * * @param property */ - public void addProperty (Property property){ + public void addProperty(Property property) { propertyMap.put(property.getName(), property); } /** - * * @return number of properties */ - public int getNumberOfProperties(){ + public int getNumberOfProperties() { return propertyMap.size(); } /** - * * @param propertyName - property name as lookup key (String) * @return property object, or null if key is not found */ - public Property getProperty(String propertyName){ + public Property getProperty(String propertyName) { return propertyMap.get(propertyName); } /** - * * @param name - the name of the property to be removed */ - public void removeProperty(String name){ - + public void removeProperty(String name) { propertyMap.remove(name); - } @Override diff --git a/src/main/java/com/redislabs/redisgraph/graph_entities/Property.java b/src/main/java/com/redislabs/redisgraph/graph_entities/Property.java index c007555..2f481d0 100644 --- a/src/main/java/com/redislabs/redisgraph/graph_entities/Property.java +++ b/src/main/java/com/redislabs/redisgraph/graph_entities/Property.java @@ -11,7 +11,6 @@ public class Property { //members private String name; - private T value; @@ -66,6 +65,11 @@ public void setValue(T value) { this.value = value; } + private boolean valueEquals(Object value1, Object value2) { + if(value1 instanceof Integer) value1 = Long.valueOf(((Integer) value1).longValue()); + if(value2 instanceof Integer) value2 = Long.valueOf(((Integer) value2).longValue()); + return Objects.equals(value1, value2); + } @Override public boolean equals(Object o) { @@ -73,7 +77,7 @@ public boolean equals(Object o) { if (!(o instanceof Property)) return false; Property property = (Property) o; return Objects.equals(name, property.name) && - Objects.equals(value, property.value); + valueEquals(value, property.value); } @Override diff --git a/src/main/java/com/redislabs/redisgraph/impl/resultset/ResultSetImpl.java b/src/main/java/com/redislabs/redisgraph/impl/resultset/ResultSetImpl.java index 442573b..7b4a70b 100644 --- a/src/main/java/com/redislabs/redisgraph/impl/resultset/ResultSetImpl.java +++ b/src/main/java/com/redislabs/redisgraph/impl/resultset/ResultSetImpl.java @@ -161,7 +161,7 @@ private Node deserializeNode(List rawNodeData) { * @param rawEntityId raw representation of entity id to be set to the graph entity */ private void deserializeGraphEntityId(GraphEntity graphEntity, Object rawEntityId) { - int id = ((Long) rawEntityId).intValue(); + long id = (Long) rawEntityId; graphEntity.setId(id); } @@ -183,8 +183,8 @@ private Edge deserializeEdge(List rawEdgeData) { redisGraph); edge.setRelationshipType(relationshipType); - edge.setSource((int) (long) rawEdgeData.get(2)); - edge.setDestination((int) (long) rawEdgeData.get(3)); + edge.setSource( (long) rawEdgeData.get(2)); + edge.setDestination( (long) rawEdgeData.get(3)); deserializeGraphEntityProperties(edge, (List>) rawEdgeData.get(4)); @@ -233,7 +233,7 @@ private Object deserializeScalar(List rawScalarData) { case VALUE_DOUBLE: return Double.parseDouble(SafeEncoder.encode((byte[]) obj)); case VALUE_INTEGER: - return ((Long) obj).intValue(); + return (Long) obj; case VALUE_STRING: return SafeEncoder.encode((byte[]) obj); case VALUE_ARRAY: diff --git a/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java b/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java index 44b4453..48c0f03 100644 --- a/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java +++ b/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java @@ -298,8 +298,8 @@ public void testRecord(){ "r.place", "r.since", "r.doubleValue", "r.boolValue", "r.nullValue"), record.keys()); Assert.assertEquals(Arrays.asList(expectedNode, expectedEdge, - name, age, doubleValue, true, null, - place, since, doubleValue, false, null), + name, (long)age, doubleValue, true, null, + place, (long)since, doubleValue, false, null), record.values()); Node a = record.getValue("a"); @@ -309,8 +309,8 @@ public void testRecord(){ Assert.assertEquals( "roi", record.getString(2)); Assert.assertEquals( "32", record.getString(3)); - Assert.assertEquals( 32L, ((Integer)(record.getValue(3))).longValue()); - Assert.assertEquals( 32L, ((Integer)record.getValue("a.age")).longValue()); + Assert.assertEquals( 32L, ((Long)record.getValue(3)).longValue()); + Assert.assertEquals( 32L, ((Long)record.getValue("a.age")).longValue()); Assert.assertEquals( "roi", record.getString("a.name")); Assert.assertEquals( "32", record.getString("a.age")); @@ -372,7 +372,7 @@ public void testMultiThread(){ Record record = resultSet.next(); Assert.assertFalse(resultSet.hasNext()); Assert.assertEquals(Arrays.asList("a", "r", "a.age"), record.keys()); - Assert.assertEquals(Arrays.asList(expectedNode, expectedEdge, 32), record.values()); + Assert.assertEquals(Arrays.asList(expectedNode, expectedEdge, 32L), record.values()); } //test for update in local cache @@ -530,7 +530,7 @@ public void testMultiExec(){ // Redis incr command Assert.assertEquals(Long.class, results.get(3).getClass()); - Assert.assertEquals((long)2, results.get(3)); + Assert.assertEquals(2L, results.get(3)); // Redis get command Assert.assertEquals(String.class, results.get(4).getClass()); @@ -676,8 +676,8 @@ public void testContextedAPI() { "r.place", "r.since", "r.doubleValue", "r.boolValue", "r.nullValue"), record.keys()); Assert.assertEquals(Arrays.asList(expectedNode, expectedEdge, - name, age, doubleValue, true, null, - place, since, doubleValue, false, null), + name, (long)age, doubleValue, true, null, + place, (long)since, doubleValue, false, null), record.values()); Node a = record.getValue("a"); @@ -687,8 +687,8 @@ public void testContextedAPI() { Assert.assertEquals("roi", record.getString(2)); Assert.assertEquals("32", record.getString(3)); - Assert.assertEquals(32L, ((Integer) (record.getValue(3))).longValue()); - Assert.assertEquals(32L, ((Integer) record.getValue("a.age")).longValue()); + Assert.assertEquals(32L, ((Long) (record.getValue(3))).longValue()); + Assert.assertEquals(32L, ((Long) record.getValue("a.age")).longValue()); Assert.assertEquals("roi", record.getString("a.name")); Assert.assertEquals("32", record.getString("a.age")); } @@ -741,7 +741,7 @@ public void testArraySupport() { expectedANode.addLabel("person"); Property aNameProperty = new Property("name", "a"); Property aAgeProperty = new Property("age", 32); - Property aListProperty = new Property("array", Arrays.asList(0,1,2)); + Property aListProperty = new Property("array", Arrays.asList(0L, 1L, 2L)); expectedANode.addProperty(aNameProperty); expectedANode.addProperty(aAgeProperty); expectedANode.addProperty(aListProperty); @@ -752,7 +752,7 @@ public void testArraySupport() { expectedBNode.addLabel("person"); Property bNameProperty = new Property("name", "b"); Property bAgeProperty = new Property("age", 30); - Property bListProperty = new Property("array", Arrays.asList(3,4,5)); + Property bListProperty = new Property("array", Arrays.asList(3L, 4L, 5L)); expectedBNode.addProperty(bNameProperty); expectedBNode.addProperty(bAgeProperty); expectedBNode.addProperty(bListProperty); @@ -786,7 +786,7 @@ public void testArraySupport() { List x = record.getValue("x"); - Assert.assertEquals(Arrays.asList(0,1,2), x); + Assert.assertEquals(Arrays.asList(0L, 1L, 2L), x); // test collect resultSet = api.query("social", "MATCH(n) return collect(n) as x"); @@ -825,11 +825,11 @@ record = resultSet.next(); // check record Assert.assertEquals(3, resultSet.size()); - for (int i = 0; i < 3; i++) { + for (long i = 0; i < 3; i++) { Assert.assertTrue(resultSet.hasNext()); record = resultSet.next(); Assert.assertEquals(Arrays.asList("x"), record.keys()); - Assert.assertEquals(i, (int) record.getValue("x")); + Assert.assertEquals(i, (long)record.getValue("x")); } @@ -881,14 +881,16 @@ public void testPath(){ @Test public void testParameters(){ Object[] parameters = {1, 2.3, true, false, null, "str", Arrays.asList(1,2,3), new Integer[]{1,2,3}}; - Map param = new HashMap<>(); + Object[] expected_anwsers = {1L, 2.3, true, false, null, "str", Arrays.asList(1L, 2L, 3L), new Long[]{1L, 2L, 3L}}; + Map params = new HashMap<>(); for (int i=0; i < parameters.length; i++) { - Object expected = parameters[i]; - param.put("param", expected); - ResultSet resultSet = api.query("social", "RETURN $param", param); + Object param = parameters[i]; + params.put("param", param); + ResultSet resultSet = api.query("social", "RETURN $param", params); Assert.assertEquals(1, resultSet.size()); Record r = resultSet.next(); Object o = r.getValue(0); + Object expected = expected_anwsers[i]; if(i == parameters.length-1) { expected = Arrays.asList((Object[])expected); } @@ -941,4 +943,15 @@ record = resultSet.next(); Assert.assertNull(record.getValue(0)); } + + @Test + public void test64bitnumber(){ + long value = 1 << 40; + Map params = new HashMap(); + params.put("val", value); + ResultSet resultSet = api.query("social","CREATE (n {val:$val}) RETURN n.val", params); + Assert.assertEquals(1, resultSet.size()); + Record r = resultSet.next(); + Assert.assertEquals(Long.valueOf(value), r.getValue(0)); + } }