1 |
|
|
2 |
|
package org.hibernate.impl; |
3 |
|
|
4 |
|
import java.util.HashMap; |
5 |
|
import java.util.Iterator; |
6 |
|
import java.util.List; |
7 |
|
import java.util.Map; |
8 |
|
import java.util.Set; |
9 |
|
import org.hibernate.FlushMode; |
10 |
|
import org.hibernate.HibernateException; |
11 |
|
import org.hibernate.LockMode; |
12 |
|
import org.hibernate.Query; |
13 |
|
import org.hibernate.ScrollMode; |
14 |
|
import org.hibernate.ScrollableResults; |
15 |
|
import org.hibernate.Session; |
16 |
|
import org.hibernate.engine.QueryParameters; |
17 |
|
import org.hibernate.engine.SessionImplementor; |
18 |
|
import org.hibernate.engine.TypedValue; |
19 |
|
import org.hibernate.engine.query.ParameterMetadata; |
20 |
|
import org.hibernate.type.Type; |
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
@see |
27 |
|
@author |
28 |
|
|
|
|
| 0% |
Uncovered Elements: 73 (73) |
Complexity: 15 |
Complexity Density: 0,27 |
|
29 |
|
public class QueryImpl extends AbstractQueryImpl { |
30 |
|
|
31 |
|
private Map lockModes = new HashMap(2); |
32 |
|
|
33 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
34 |
0
|
public QueryImpl(String queryString, FlushMode flushMode, SessionImplementor session, ParameterMetadata parameterMetadata) {... |
35 |
0
|
super(queryString, flushMode, session, parameterMetadata); |
36 |
|
} |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
0
|
public QueryImpl(String queryString, SessionImplementor session, ParameterMetadata parameterMetadata) {... |
39 |
0
|
this(queryString, null, session, parameterMetadata); |
40 |
|
} |
41 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
42 |
0
|
public Iterator iterate() throws HibernateException {... |
43 |
0
|
verifyParameters(); |
44 |
0
|
Map namedParams = getNamedParams(); |
45 |
0
|
before(); |
46 |
0
|
try { |
47 |
0
|
return getSession().iterate(expandParameterLists(namedParams), getQueryParameters(namedParams)); |
48 |
|
} finally { |
49 |
0
|
after(); |
50 |
|
} |
51 |
|
} |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
0
|
public ScrollableResults scroll() throws HibernateException {... |
54 |
0
|
return scroll(ScrollMode.SCROLL_INSENSITIVE); |
55 |
|
} |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
57 |
0
|
public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException {... |
58 |
0
|
verifyParameters(); |
59 |
0
|
Map namedParams = getNamedParams(); |
60 |
0
|
before(); |
61 |
0
|
QueryParameters qp = getQueryParameters(namedParams); |
62 |
0
|
qp.setScrollMode(scrollMode); |
63 |
0
|
try { |
64 |
0
|
return getSession().scroll(expandParameterLists(namedParams), qp); |
65 |
|
} finally { |
66 |
0
|
after(); |
67 |
|
} |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
70 |
0
|
public List list() throws HibernateException {... |
71 |
0
|
verifyParameters(); |
72 |
0
|
Map namedParams = getNamedParams(); |
73 |
0
|
before(); |
74 |
0
|
try { |
75 |
0
|
return getSession().list(expandParameterLists(namedParams), getQueryParameters(namedParams)); |
76 |
|
} finally { |
77 |
0
|
after(); |
78 |
|
} |
79 |
|
} |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
81 |
0
|
public int executeUpdate() throws HibernateException {... |
82 |
0
|
verifyParameters(); |
83 |
0
|
Map namedParams = getNamedParams(); |
84 |
0
|
before(); |
85 |
0
|
try { |
86 |
0
|
return getSession().executeUpdate(expandParameterLists(namedParams), getQueryParameters(namedParams)); |
87 |
|
} finally { |
88 |
0
|
after(); |
89 |
|
} |
90 |
|
} |
91 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
92 |
0
|
public Query setLockMode(String alias, LockMode lockMode) {... |
93 |
0
|
lockModes.put(alias, lockMode); |
94 |
0
|
return this; |
95 |
|
} |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
0
|
protected Map getLockModes() {... |
98 |
0
|
return lockModes; |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
@return |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 6 |
Complexity Density: 0,26 |
|
106 |
0
|
public int count() {... |
107 |
0
|
StringBuffer hqlQuery = new StringBuffer(this.getQueryString().toUpperCase()); |
108 |
0
|
StringBuffer hqlQueryBuffer = new StringBuffer(); |
109 |
0
|
hqlQueryBuffer.append("SELECT COUNT(*) "); |
110 |
0
|
int start = hqlQuery.indexOf("FROM"); |
111 |
0
|
int stop = hqlQuery.indexOf("ORDER BY"); |
112 |
0
|
if (stop >= 0) { |
113 |
0
|
hqlQueryBuffer.append(this.getQueryString().substring(start, stop)); |
114 |
|
} else { |
115 |
0
|
hqlQueryBuffer.append(this.getQueryString().substring(start)); |
116 |
|
} |
117 |
0
|
Query countQuery = ((Session)this.session).createQuery(hqlQueryBuffer.toString()); |
118 |
|
|
119 |
0
|
Map parameters = this.getNamedParams(); |
120 |
0
|
Set parameterNames = parameters.keySet(); |
121 |
0
|
Iterator iter = parameterNames.iterator(); |
122 |
0
|
while (iter.hasNext()) { |
123 |
0
|
String name = (String)iter.next(); |
124 |
0
|
TypedValue typedValue = (TypedValue)parameters.get(name); |
125 |
0
|
countQuery.setParameter(name, typedValue.getValue(), typedValue.getType()); |
126 |
|
} |
127 |
|
|
128 |
0
|
List paramTypes = this.getTypes(); |
129 |
0
|
List paramValues = this.getValues(); |
130 |
0
|
if (paramTypes != null && paramTypes.size() > 0) { |
131 |
0
|
for (int i = 0; i < paramTypes.size(); i++) { |
132 |
0
|
countQuery.setParameter(i, paramValues.get(i), (Type)paramTypes.get(i)); |
133 |
|
} |
134 |
|
} |
135 |
0
|
int count = ((Long)countQuery.uniqueResult()).intValue(); |
136 |
0
|
return count; |
137 |
|
} |
138 |
|
} |