/
JDOQLQuery.java
126 lines (109 loc) · 3.37 KB
/
JDOQLQuery.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package org.datanucleus.store.cassandra.query;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.datanucleus.ObjectManager;
import org.datanucleus.exceptions.NucleusUserException;
import org.datanucleus.query.evaluator.JDOQLEvaluator;
import org.datanucleus.query.evaluator.JavaQueryEvaluator;
import org.datanucleus.store.ExecutionContext;
import org.datanucleus.store.cassandra.CassandraManagedConnection;
import org.datanucleus.store.query.AbstractJDOQLQuery;
import org.datanucleus.util.NucleusLogger;
public class JDOQLQuery extends AbstractJDOQLQuery {
/**
* Constructs a new query instance that uses the given persistence manager.
*
* @param om
* the associated ExecutiongContext for this query.
*/
public JDOQLQuery(ExecutionContext ec) {
this(ec, (JDOQLQuery) null);
}
/**
* Constructs a new query instance having the same criteria as the given
* query.
*
* @param om
* The Executing Manager
* @param q
* The query from which to copy criteria.
*/
public JDOQLQuery(ExecutionContext ec, JDOQLQuery q) {
super(ec, q);
}
/**
* Constructor for a JDOQL query where the query is specified using the
* "Single-String" format.
*
* @param ec
* The execution context
* @param query
* The query string
*/
public JDOQLQuery(ExecutionContext ec, String query) {
super(ec, query);
}
@Override
protected Object performExecute(Map parameters) {
if (range != null && !range.equals("")) {
// Range is of the format "from, to"
String[] fromTo = range.split(",");
if (fromTo.length != 2) {
throw new NucleusUserException("Malformed RANGE clause: "
+ range);
}
try {
fromInclNo = Long.parseLong(fromTo[0].trim());
} catch (Exception e) {
throw new NucleusUserException("Malformed RANGE clause: "
+ range);
}
try {
toExclNo = Long.parseLong(fromTo[1].trim());
} catch (Exception e) {
throw new NucleusUserException("Malformed RANGE clause: "
+ range);
}
}
//
CassandraManagedConnection mconn = (CassandraManagedConnection) ec
.getStoreManager().getConnection(ec);
try {
long startTime = System.currentTimeMillis();
if (NucleusLogger.QUERY.isDebugEnabled()) {
NucleusLogger.QUERY.debug(LOCALISER.msg("021046", "JDOQL",
getSingleStringQuery(), null));
}
List candidates = null;
if (candidateCollection != null) {
candidates = new ArrayList(candidateCollection);
} else if (candidateExtent != null) {
candidates = new ArrayList();
Iterator iter = candidateExtent.iterator();
while (iter.hasNext()) {
candidates.add(iter.next());
}
} else {
candidates = CassandraQuery.getObjectsOfCandidateType(ec,
mconn, candidateClass, subclasses, ignoreCache,
fromInclNo, toExclNo);
}
// Apply any result restrictions to the results
JavaQueryEvaluator resultMapper = new JDOQLEvaluator(this,
candidates, compilation, parameters, ec
.getClassLoaderResolver());
Collection results = resultMapper.execute(true, true, true, true,
true);
if (NucleusLogger.QUERY.isDebugEnabled()) {
NucleusLogger.QUERY.debug(LOCALISER.msg("021074", "JDOQL", ""
+ (System.currentTimeMillis() - startTime)));
}
return results;
} finally {
mconn.release();
}
}
}