1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.query.xwql.internal.hql; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
import javax.inject.Singleton; |
25 |
|
|
26 |
|
import org.xwiki.query.jpql.internal.JPQLParser; |
27 |
|
import org.xwiki.query.jpql.node.Start; |
28 |
|
import org.xwiki.query.xwql.internal.QueryAnalyzer; |
29 |
|
import org.xwiki.query.xwql.internal.QueryContext; |
30 |
|
import org.xwiki.query.xwql.internal.QueryTranslator; |
31 |
|
import org.xwiki.query.Query; |
32 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
33 |
|
import org.xwiki.component.annotation.Component; |
34 |
|
|
35 |
|
@Component |
36 |
|
@Named("hql") |
37 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 8 |
Complexity Density: 0.5 |
|
38 |
|
public class XWQLtoHQLTranslator implements QueryTranslator |
39 |
|
{ |
40 |
|
@Inject |
41 |
|
protected DocumentAccessBridge documentAccessBridge; |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 5 |
Complexity Density: 0.38 |
|
43 |
1032 |
@Override... |
44 |
|
public String translate(String input) throws Exception |
45 |
|
{ |
46 |
1032 |
input = input.trim(); |
47 |
1032 |
String lcInput = input.toLowerCase(); |
48 |
1032 |
String addition = "select doc.fullName from Document as doc "; |
49 |
1032 |
if (lcInput.startsWith("where") || lcInput.startsWith("order") || lcInput.length() == 0) { |
50 |
18 |
input = addition + input; |
51 |
1014 |
} else if (lcInput.startsWith("from")) { |
52 |
186 |
input = addition + "," + input.substring(4); |
53 |
|
} |
54 |
1032 |
JPQLParser parser = new JPQLParser(); |
55 |
1032 |
Start tree = parser.parse(input); |
56 |
1032 |
QueryContext context = new QueryContext(tree, getDocumentAccessBridge()); |
57 |
|
|
58 |
1032 |
tree.apply(new QueryAnalyzer(context)); |
59 |
|
|
60 |
1032 |
Printer printer = getPrinter(context); |
61 |
1032 |
return printer.print(); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
1000 |
@Override... |
65 |
|
public String getOutputLanguage() |
66 |
|
{ |
67 |
1000 |
return Query.HQL; |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
1032 |
protected Printer getPrinter(QueryContext context)... |
71 |
|
{ |
72 |
1032 |
return new Printer(context, this); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
1000 |
public DocumentAccessBridge getDocumentAccessBridge()... |
76 |
|
{ |
77 |
1000 |
return documentAccessBridge; |
78 |
|
} |
79 |
|
} |