Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public class RedisGraphExample {
RedisGraph graph = new RedisGraph();

Map<String, Object> params = new HashMap<>();
params.put("age", 30);
params.put("name", "amit");
params.put("age", 30);
params.put("name", "amit");

// send queries to a specific graph called "social"
graph.query("social","CREATE (:person{name:'roi',age:32})");
graph.query("social","CREATE (:person{name:$name,age:$age})", params);
// send queries to a specific graph called "social"
graph.query("social","CREATE (:person{name:'roi',age:32})");
graph.query("social","CREATE (:person{name:$name,age:$age})", params);
graph.query("social","MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)");

ResultSet resultSet = graph.query("social", "MATCH (a:person)-[r:knows]->(b:person) RETURN a, r, b");
Expand Down
29 changes: 12 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@

<name>JRedisGraph</name>
<description>Official client for Redis-Graph</description>
<url>https://oss.redislabs.com/redisgraph</url>
<url>https://redisgraph.io</url>

<organization>
<name>RedisLabs</name>
<url>www.redislabs.com</url>
</organization>
<ciManagement>
<system>CircleCI</system>
<url>https://circleci.com/gh/RedisLabs/JRedisGraph</url>
<url>https://circleci.com/gh/RedisGraph/JRedisGraph</url>
</ciManagement>
<issueManagement>
<url>https://github.com/RedisLabs/JRedisGraph/issues</url>
<url>https://github.com/RedisGraph/JRedisGraph/issues</url>
<system>Github</system>
</issueManagement>
<scm>
<url>https://github.com/RedisLabs/JRedisGraph</url>
<connection>scm:git:git://github.com/RedisLabs/JRedisGraph.git</connection>
<developerConnection>scm:git:git@github.com:RedisLabs/JRedisGraph.git</developerConnection>
<url>https://github.com/RedisGraph/JRedisGraph</url>
<connection>scm:git:git://github.com/RedisGraph/JRedisGraph.git</connection>
<developerConnection>scm:git:git@github.com:RedisGraph/JRedisGraph.git</developerConnection>
</scm>
<developers>
<developer>
Expand All @@ -48,17 +48,6 @@
</licenses>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
Expand All @@ -69,6 +58,12 @@
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/redislabs/redisgraph/impl/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static String prepareQuery(String query, Map<String, Object> params){

private static String arrayToString(Object[] arr) {
StringBuilder sb = new StringBuilder().append('[');
sb.append(String.join(", ", Arrays.stream(arr).map(obj->valueToString(obj)).collect(Collectors.toList())));
sb.append(String.join(", ", Arrays.stream(arr).map(Utils::valueToString).collect(Collectors.toList())));
sb.append(']');
return sb.toString();
}
Expand Down Expand Up @@ -119,22 +119,22 @@ private static String valueToString(Object value) {
* @return formatter procedure call
*/
public static String prepareProcedure(String procedure, List<String> args , Map<String, List<String>> kwargs){
args = args.stream().map( s -> Utils.quoteString(s)).collect(Collectors.toList());
args = args.stream().map( Utils::quoteString).collect(Collectors.toList());
StringBuilder queryStringBuilder = new StringBuilder();
queryStringBuilder.append("CALL ").append(procedure).append("(");
queryStringBuilder.append("CALL ").append(procedure).append('(');
int i = 0;
for (; i < args.size() - 1; i++) {
queryStringBuilder.append(args.get(i)).append(",");
queryStringBuilder.append(args.get(i)).append(',');
}
if (i == args.size()-1) {
queryStringBuilder.append(args.get(i));
}
queryStringBuilder.append(")");
queryStringBuilder.append(')');
List<String> kwargsList = kwargs.getOrDefault("y", null);
if(kwargsList != null){
i = 0;
for (; i < kwargsList.size() - 1; i++) {
queryStringBuilder.append(kwargsList.get(i)).append(",");
queryStringBuilder.append(kwargsList.get(i)).append(',');

}
queryStringBuilder.append(kwargsList.get(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
public abstract class AbstractRedisGraph implements RedisGraph {



/**
* Inherited classes should return a Jedis connection, with respect to their context
* @return Jedis connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class ContextedRedisGraph extends AbstractRedisGraph implements RedisGraphContext, RedisGraphCacheHolder {

private Jedis connectionContext;
private final Jedis connectionContext;
private RedisGraphCaches caches;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class RedisGraph extends AbstractRedisGraph implements RedisGraphContextGenerator {

private final Pool<Jedis> client;
private RedisGraphCaches caches = new RedisGraphCaches();
private final RedisGraphCaches caches = new RedisGraphCaches();

/**
* Creates a client running on the local machine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public HeaderImpl(List<List<Object>> raw) {
*/
@Override
public List<String> getSchemaNames() {
if (schemaNames.size() == 0) {
if (schemaNames.isEmpty()) {
buildSchema();
}
return schemaNames;
Expand All @@ -47,7 +47,7 @@ public List<String> getSchemaNames() {
*/
@Override
public List<ResultSetColumnTypes> getSchemaTypes() {
if (schemaTypes.size() == 0) {
if (schemaTypes.isEmpty()) {
buildSchema();
}
return schemaTypes;
Expand Down
13 changes: 8 additions & 5 deletions src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,17 @@ public void testHeader(){

ResultSet queryResult = api.query("social", "MATCH (a:person)-[r:knows]->(b:person) RETURN a,r, a.age");

Assert.assertNotNull(queryResult.getHeader());
Header header = queryResult.getHeader();

Assert.assertNotNull(header);
Assert.assertEquals("HeaderImpl{"
+ "schemaTypes=[COLUMN_SCALAR, COLUMN_SCALAR, COLUMN_SCALAR], "
+ "schemaNames=[a, r, a.age]}", header.toString());
// Assert.assertEquals(-1901778507, header.hashCode());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DvirDukhan something is strange about the HeaderImpl.hashCode(), it's not deterministic, on each run the value is different despite the fact that the values are the same


List<String> schemaNames = header.getSchemaNames();

Assert.assertNotNull(schemaNames);

Assert.assertEquals(3, schemaNames.size());

Assert.assertEquals("a", schemaNames.get(0));
Assert.assertEquals("r", schemaNames.get(1));
Assert.assertEquals("a.age", schemaNames.get(2));
Expand Down Expand Up @@ -315,6 +317,7 @@ public void testRecord(){
}


@Ignore
@Test
public void tinyTestMultiThread(){
ResultSet resultSet = api.query("social", "CREATE ({name:'roi',age:32})");
Expand All @@ -340,7 +343,7 @@ public void testMultiThread(){

Property<String> nameProperty = new Property<>("name", "roi");
Property<Integer> ageProperty = new Property<>("age", 32);
Property<String> lastNameProperty =new Property<>("lastName", "a");
Property<String> lastNameProperty = new Property<>("lastName", "a");

Node expectedNode = new Node();
expectedNode.setId(0);
Expand Down