Skip to content

Commit 1541e1a

Browse files
committed
feat: create apache tinkerpop in the project
Signed-off-by: Otavio Santana <[email protected]>
1 parent f8dab49 commit 1541e1a

File tree

88 files changed

+9330
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+9330
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
grammar JDQL;
2+
3+
statement : select_statement | update_statement | delete_statement;
4+
5+
select_statement : select_clause? from_clause? where_clause? orderby_clause?;
6+
update_statement : UPDATE entity_name set_clause where_clause?;
7+
delete_statement : DELETE from_clause where_clause?;
8+
9+
from_clause : FROM entity_name;
10+
11+
where_clause : WHERE conditional_expression;
12+
13+
set_clause : SET update_item (COMMA update_item)*;
14+
update_item : state_field_path_expression EQ (scalar_expression | NULL);
15+
16+
select_clause : SELECT select_list;
17+
select_list
18+
: state_field_path_expression (COMMA state_field_path_expression)*
19+
| aggregate_expression
20+
;
21+
aggregate_expression : COUNT '(' THIS ')';
22+
23+
orderby_clause : ORDER BY orderby_item (COMMA orderby_item)*;
24+
orderby_item : state_field_path_expression (ASC | DESC)?;
25+
26+
conditional_expression
27+
// highest to lowest precedence
28+
: LPAREN conditional_expression RPAREN
29+
| null_comparison_expression
30+
| in_expression
31+
| between_expression
32+
| like_expression
33+
| comparison_expression
34+
| NOT conditional_expression
35+
| conditional_expression AND conditional_expression
36+
| conditional_expression OR conditional_expression
37+
;
38+
39+
comparison_expression : scalar_expression comparison_operator scalar_expression;
40+
comparison_operator : EQ | GT | GTEQ | LT | LTEQ | NEQ;
41+
42+
between_expression : scalar_expression NOT? BETWEEN scalar_expression AND scalar_expression;
43+
like_expression : scalar_expression NOT? LIKE (STRING | input_parameter);
44+
45+
in_expression : state_field_path_expression NOT? IN '(' in_item (',' in_item)* ')';
46+
in_item : literal | enum_literal | input_parameter; // could simplify to just literal
47+
48+
null_comparison_expression : state_field_path_expression IS NOT? NULL;
49+
50+
scalar_expression
51+
// highest to lowest precedence
52+
: LPAREN scalar_expression RPAREN
53+
| primary_expression
54+
| scalar_expression MUL scalar_expression
55+
| scalar_expression DIV scalar_expression
56+
| scalar_expression PLUS scalar_expression
57+
| scalar_expression MINUS scalar_expression
58+
| scalar_expression CONCAT scalar_expression
59+
;
60+
61+
primary_expression
62+
: function_expression
63+
| special_expression
64+
| state_field_path_expression
65+
| enum_literal
66+
| input_parameter
67+
| literal
68+
;
69+
70+
function_expression
71+
: ('abs(' | 'ABS(') scalar_expression ')'
72+
| ('length(' | 'LENGTH(') scalar_expression ')'
73+
| ('lower(' | 'LOWER(') scalar_expression ')'
74+
| ('upper(' | 'UPPER(') scalar_expression ')'
75+
| ('left(' | 'LEFT(') scalar_expression ',' scalar_expression ')'
76+
| ('right(' | 'RIGHT(') scalar_expression ',' scalar_expression ')'
77+
;
78+
79+
special_expression
80+
: LOCAL_DATE
81+
| LOCAL_DATETIME
82+
| LOCAL_TIME
83+
| TRUE
84+
| FALSE
85+
;
86+
87+
state_field_path_expression : IDENTIFIER (DOT IDENTIFIER)* | FULLY_QUALIFIED_IDENTIFIER;
88+
89+
entity_name : IDENTIFIER; // no ambiguity
90+
91+
enum_literal : IDENTIFIER (DOT IDENTIFIER)* | FULLY_QUALIFIED_IDENTIFIER; // ambiguity with state_field_path_expression resolvable semantically
92+
93+
input_parameter : COLON IDENTIFIER | QUESTION INTEGER;
94+
95+
literal : STRING | INTEGER | DOUBLE;
96+
97+
// Tokens defined to be case-insensitive using character classes
98+
SELECT : [sS][eE][lL][eE][cC][tT];
99+
UPDATE : [uU][pP][dD][aA][tT][eE];
100+
DELETE : [dD][eE][lL][eE][tT][eE];
101+
FROM : [fF][rR][oO][mM];
102+
WHERE : [wW][hH][eE][rR][eE];
103+
SET : [sS][eE][tT];
104+
ORDER : [oO][rR][dD][eE][rR];
105+
BY : [bB][yY];
106+
NOT : [nN][oO][tT];
107+
IN : [iI][nN];
108+
IS : [iI][sS];
109+
NULL : [nN][uU][lL][lL];
110+
COUNT : [cC][oO][uU][nN][tT];
111+
TRUE : [tT][rR][uU][eE];
112+
FALSE : [fF][aA][lL][sS][eE];
113+
ASC : [aA][sS][cC];
114+
DESC : [dD][eE][sS][cC];
115+
AND : [aA][nN][dD];
116+
OR : [oO][rR];
117+
LOCAL_DATE : [lL][oO][cC][aA][lL] [dD][aA][tT][eE];
118+
LOCAL_DATETIME : [lL][oO][cC][aA][lL] [dD][aA][tT][eE][tT][iI][mM][eE];
119+
LOCAL_TIME : [lL][oO][cC][aA][lL] [tT][iI][mM][eE];
120+
BETWEEN : [bB][eE][tT][wW][eE][eE][nN];
121+
LIKE : [lL][iI][kK][eE];
122+
THIS : [tT][hH][iI][sS];
123+
LOCAL : [lL][oO][cC][aA][lL];
124+
DATE : [dD][aA][tT][eE];
125+
DATETIME : [dD][aA][tT][eE][tT][iI][mM][eE];
126+
TIME : [tT][iI][mM][eE];
127+
128+
// Operators
129+
EQ : '=';
130+
GT : '>';
131+
LT : '<';
132+
NEQ : '<>';
133+
GTEQ : '>=';
134+
LTEQ : '<=';
135+
PLUS : '+';
136+
MINUS : '-';
137+
MUL : '*';
138+
DIV : '/';
139+
CONCAT : '||';
140+
141+
// Special Characters
142+
COMMA : ',';
143+
DOT : '.';
144+
LPAREN : '(';
145+
RPAREN : ')';
146+
COLON : ':';
147+
QUESTION : '?';
148+
149+
// Identifier and literals
150+
FULLY_QUALIFIED_IDENTIFIER : [a-zA-Z_][a-zA-Z0-9_]* (DOT [a-zA-Z_][a-zA-Z0-9_]*)+;
151+
IDENTIFIER : [a-zA-Z_][a-zA-Z0-9_]*;
152+
STRING : '\'' ( ~('\'' | '\\') | '\\' . | '\'\'' )* '\'' // single quoted strings with embedded single quotes handled
153+
| '"' ( ~["\\] | '\\' . )* '"' ; // double quoted strings
154+
INTEGER : '-'?[0-9]+;
155+
DOUBLE : '-'?[0-9]+'.'[0-9]* | '-'?'.'[0-9]+;
156+
157+
// Whitespace and Comments
158+
WS : [ \t\r\n]+ -> skip ;
159+
LINE_COMMENT : '//' ~[\r\n]* -> skip;
160+
BLOCK_COMMENT : '/*' .*? '*/' -> skip;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
grammar Method;
2+
select: selectStart where? order? EOF;
3+
deleteBy: 'deleteBy' where? EOF;
4+
5+
selectStart: 'find' limit 'By' | 'findBy' | 'countAll' | 'countBy' | 'existsBy';
6+
where: condition (and condition| or condition)* ;
7+
condition: eq | gt | gte | lt | lte | between | in | like | truth | untruth | nullable | contains | endsWith | startsWith;
8+
order: 'OrderBy' orderName (orderName)*;
9+
orderName: variable | variable asc | variable desc;
10+
limit: firstLimit | firstOne;
11+
firstLimit : 'First' limitNumber;
12+
firstOne: 'First';
13+
and: 'And';
14+
or: 'Or';
15+
asc: 'Asc';
16+
desc: 'Desc';
17+
truth: variable 'True';
18+
untruth: variable 'False';
19+
eq: variable | variable ignoreCase? not? 'Equals'?;
20+
gt: variable ignoreCase? not? 'GreaterThan';
21+
gte: variable ignoreCase? not? 'GreaterThanEqual';
22+
lt: variable ignoreCase? not? 'LessThan';
23+
lte: variable ignoreCase? not? 'LessThanEqual';
24+
between: variable ignoreCase? not? 'Between';
25+
in: variable ignoreCase? not? 'In';
26+
like: variable ignoreCase? not? 'Like';
27+
contains: variable ignoreCase? not? 'Contains';
28+
endsWith: variable ignoreCase? not? 'EndsWith';
29+
startsWith: variable ignoreCase? not? 'StartsWith';
30+
nullable: variable ignoreCase? not? 'Null';
31+
ignoreCase: 'IgnoreCase';
32+
not: 'Not';
33+
variable: ANY_NAME;
34+
limitNumber: INT;
35+
ANY_NAME: [a-zA-Z_.][a-zA-Z_.0-9-]*;
36+
WS: [ \t\r\n]+ -> skip ;
37+
INT: [0-9]+;
38+
fragment ESC : '\\' (["\\/bfnrt] | UNICODE) ;
39+
fragment UNICODE : 'u' HEX HEX HEX HEX ;
40+
fragment HEX : [0-9a-fA-F] ;

jnosql-tinkerpop/pom.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright (c) 2022 Contributors to the Eclipse Foundation
4+
~ All rights reserved. This program and the accompanying materials
5+
~ are made available under the terms of the Eclipse Public License v1.0
6+
~ and Apache License v2.0 which accompanies this distribution.
7+
~ The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
8+
~ and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
9+
~
10+
~ You may elect to redistribute this code under either of these licenses.
11+
~
12+
~ Contributors:
13+
~
14+
~ Otavio Santana
15+
-->
16+
17+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
19+
<modelVersion>4.0.0</modelVersion>
20+
<parent>
21+
<groupId>org.eclipse.jnosql.mapping</groupId>
22+
<artifactId>jnosql-mapping-parent</artifactId>
23+
<version>1.1.2-SNAPSHOT</version>
24+
</parent>
25+
26+
<artifactId>jnosql-mapping-graph</artifactId>
27+
28+
<properties>
29+
<antlr4.version>4.9.3</antlr4.version>
30+
<!-- it's required by the 'org.neo4j' libraries -->
31+
<argLine> --add-opens java.base/java.lang=ALL-UNNAMED --add-exports java.base/sun.nio.ch=ALL-UNNAMED </argLine>
32+
33+
</properties>
34+
35+
<dependencies>
36+
<dependency>
37+
<groupId>${project.groupId}</groupId>
38+
<artifactId>jnosql-mapping-semistructured</artifactId>
39+
<version>${project.version}</version>
40+
<exclusions>
41+
<exclusion>
42+
<groupId>org.antlr</groupId>
43+
<artifactId>antlr4-runtime</artifactId>
44+
</exclusion>
45+
</exclusions>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.apache.tinkerpop</groupId>
49+
<artifactId>gremlin-core</artifactId>
50+
<version>${tinkerpop.version}</version>
51+
<scope>provided</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.apache.tinkerpop</groupId>
55+
<artifactId>neo4j-gremlin</artifactId>
56+
<version>${tinkerpop.version}</version>
57+
<scope>test</scope>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.neo4j</groupId>
61+
<artifactId>neo4j-tinkerpop-api-impl</artifactId>
62+
<version>${neo4j.connector.version}</version>
63+
<scope>test</scope>
64+
</dependency>
65+
</dependencies>
66+
67+
<build>
68+
<plugins>
69+
<plugin>
70+
<groupId>org.antlr</groupId>
71+
<artifactId>antlr4-maven-plugin</artifactId>
72+
<version>${antlr4.version}</version>
73+
<configuration>
74+
<sourceDirectory>antlr4</sourceDirectory>
75+
</configuration>
76+
<executions>
77+
<execution>
78+
<goals>
79+
<goal>antlr4</goal>
80+
</goals>
81+
</execution>
82+
</executions>
83+
</plugin>
84+
</plugins>
85+
</build>
86+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2022 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.communication.graph;
16+
17+
import org.apache.tinkerpop.gremlin.structure.Vertex;
18+
import org.eclipse.jnosql.communication.semistructured.CommunicationEntity;
19+
20+
import java.util.function.Function;
21+
22+
public enum CommunicationEntityConverter implements Function<Vertex, CommunicationEntity>{
23+
INSTANCE;
24+
25+
26+
@Override
27+
public CommunicationEntity apply(Vertex vertex) {
28+
var entity = CommunicationEntity.of(vertex.label());
29+
vertex.properties().forEachRemaining(p -> entity.add(p.key(), p.value()));
30+
entity.add(DefaultGraphDatabaseManager.ID_PROPERTY, vertex.id());
31+
return entity;
32+
}
33+
}

0 commit comments

Comments
 (0)