Skip to content

Commit 5b5e833

Browse files
authored
Merge pull request #282 from eclipse/include-apache-tinkerpop
Include apache tinkerpop as graph
2 parents f8dab49 + 0e667ca commit 5b5e833

File tree

90 files changed

+9443
-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.

90 files changed

+9443
-0
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
1111
=== Added
1212

1313
- Include between query support at MongoDB
14+
- Include Graph as Apache TinkerPop
1415

1516
=== Changed
1617

README.adoc

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,118 @@ SolrTemplate template;
17011701
List<Person> people = template.solr("age:@age AND type:@type AND _entity:@entity", params);
17021702
----
17031703

1704+
1705+
=== Graph (Apache Tinkerpop)
1706+
1707+
Currently, the Jakarta NoSQL doesn't define an API for Graph database types but Eclipse JNoSQL provides a Graph template to explore the specific behavior of this NoSQL type.
1708+
1709+
Eclipse JNoSQL offers a mapping implementation for Graph NoSQL types:
1710+
1711+
[source,xml]
1712+
----
1713+
<dependency>
1714+
<groupId>org.eclipse.jnosql.mapping</groupId>
1715+
<artifactId>jnosql-mapping-graph</artifactId>
1716+
<version>1.1.1</version>
1717+
</dependency>
1718+
----
1719+
1720+
Despite the other three NoSQL types, Eclipse JNoSQL API does not offer a communication layer for Graph NoSQL types. Instead, it integrates with https://tinkerpop.apache.org/[Apache Tinkerpop 3.x].
1721+
1722+
[source,java]
1723+
----
1724+
@Inject
1725+
GraphTemplate template;
1726+
...
1727+
1728+
Category java = Category.of("Java");
1729+
Book effectiveJava = Book.of("Effective Java");
1730+
1731+
template.insert(java);
1732+
template.insert(effectiveJava);
1733+
EdgeEntity edge = template.edge(java, "is", software);
1734+
1735+
Stream<Book> books = template.getTraversalVertex()
1736+
.hasLabel("Category")
1737+
.has("name", "Java")
1738+
.in("is")
1739+
.hasLabel("Book")
1740+
.getResult();
1741+
----
1742+
1743+
Apache TinkerPop is database agnostic. Thus, you can change the database in your application with no or minimal impact on source code.
1744+
1745+
You can define the database settings using the https://microprofile.io/microprofile-config/[MicroProfile Config] specification, so you can add properties and overwrite it in the environment following the https://12factor.net/config[Twelve-Factor App].
1746+
1747+
[source,properties]
1748+
----
1749+
jnosql.graph.provider=<CLASS-DRIVER>
1750+
jnosql.provider.host=<HOST>
1751+
jnosql.provider.user=<USER>
1752+
jnosql.provider.password=<PASSWORD>
1753+
----
1754+
1755+
TIP: The ```jnosql.graph.provider``` property is necessary when you have more than one driver in the classpath. Otherwise, it will take the first one.
1756+
1757+
These configuration settings are the default behavior. Nevertheless, there is an option to programmatically configure these settings. Create a class that implements the ```Supplier<Graph>```, then define it using the ```@Alternative``` and ```@Priority``` annotations.
1758+
1759+
[source,java]
1760+
----
1761+
@Alternative
1762+
@Priority(Interceptor.Priority.APPLICATION)
1763+
public class ManagerSupplier implements Supplier<Graph> {
1764+
1765+
@Produces
1766+
public Graph get() {
1767+
Graph graph = ...; // from a provider
1768+
return graph;
1769+
}
1770+
}
1771+
----
1772+
1773+
You can work with several document database instances through CDI qualifier. To identify each database instance, make a `Graph` visible for CDI by putting the ```@Produces``` and the ```@Database``` annotations in the method.
1774+
1775+
[source,java]
1776+
----
1777+
@Inject
1778+
@Database(value = DatabaseType.GRAPH, provider = "databaseA")
1779+
private GraphTemplate templateA;
1780+
1781+
@Inject
1782+
@Database(value = DatabaseType.GRAPH, provider = "databaseB")
1783+
private GraphTemplate templateB;
1784+
1785+
// producers methods
1786+
@Produces
1787+
@Database(value = DatabaseType.GRAPH, provider = "databaseA")
1788+
public Graph getManagerA() {
1789+
return manager;
1790+
}
1791+
1792+
@Produces
1793+
@Database(value = DatabaseType.GRAPH, provider = "databaseB")
1794+
public Graph getManagerB() {
1795+
return manager;
1796+
}
1797+
----
1798+
1799+
1800+
Eclipse JNoSQL does not provide https://mvnrepository.com/artifact/org.apache.tinkerpop/gremlin-core[Apache Tinkerpop 3 dependency]; check if the provider does. Otherwise, do it manually.
1801+
1802+
[source,xml]
1803+
----
1804+
<dependency>
1805+
<groupId>org.apache.tinkerpop</groupId>
1806+
<artifactId>jnosql-gremlin-core</artifactId>
1807+
<version>${tinkerpop.version}</version>
1808+
</dependency>
1809+
<dependency>
1810+
<groupId>org.apache.tinkerpop</groupId>
1811+
<artifactId>jnosql-gremlin-groovy</artifactId>
1812+
<version>${tinkerpop.version}</version>
1813+
</dependency>
1814+
----
1815+
17041816
== Getting Help
17051817

17061818
Having trouble with Eclipse JNoSQL databases? We’d love to help!
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] ;

0 commit comments

Comments
 (0)