From b4176533d010951bd017d5cea0b17e662a353c98 Mon Sep 17 00:00:00 2001 From: hopecee Date: Fri, 19 Jan 2018 22:17:32 +0100 Subject: [PATCH] Support for String.startsWith() and .endsWith() --- .../neo4j/query/QueryToCypherMapper.java | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/datanucleus/store/neo4j/query/QueryToCypherMapper.java b/src/main/java/org/datanucleus/store/neo4j/query/QueryToCypherMapper.java index 2fa34e5..b37054f 100644 --- a/src/main/java/org/datanucleus/store/neo4j/query/QueryToCypherMapper.java +++ b/src/main/java/org/datanucleus/store/neo4j/query/QueryToCypherMapper.java @@ -956,17 +956,49 @@ else if ("matches".equals(operation)) if (neo4jExprArgs == null || neo4jExprArgs.isEmpty() || neo4jExprArgs.size() > 2) { throw new NucleusException("Method String.matches has to have 1 args"); - } - else - { + } + else + { String propName = invokedFieldExpr.getFieldName(); String value = neo4jExprArgs.get(0).toString(); String cypherText = propName + " =~ '" + value + "'"; Neo4jExpression neo4jExpr = new Neo4jBooleanExpression(cypherText); stack.push(neo4jExpr); return neo4jExpr; - } - } + } + } + else if ("startsWith".equals(operation)) + { + if (neo4jExprArgs == null || neo4jExprArgs.isEmpty() || neo4jExprArgs.size() > 2) + { + throw new NucleusException("Method String.matches has to have 1 args"); + } + else + { + String propName = invokedFieldExpr.getFieldName(); + String value = neo4jExprArgs.get(0).toString(); + String cypherText = propName + " STARTS WITH '" + value + "'"; + Neo4jExpression neo4jExpr = new Neo4jBooleanExpression(cypherText); + stack.push(neo4jExpr); + return neo4jExpr; + } + } + else if ("endsWith".equals(operation)) + { + if (neo4jExprArgs == null || neo4jExprArgs.isEmpty() || neo4jExprArgs.size() > 2) + { + throw new NucleusException("Method String.matches has to have 1 args"); + } + else + { + String propName = invokedFieldExpr.getFieldName(); + String value = neo4jExprArgs.get(0).toString(); + String cypherText = propName + " ENDS WITH '" + value + "'"; + Neo4jExpression neo4jExpr = new Neo4jBooleanExpression(cypherText); + stack.push(neo4jExpr); + return neo4jExpr; + } + } else if (Numeric.class.isAssignableFrom(invokedFieldExpr.getMemberMetaData().getType())) { }