Clover Coverage Report - SmartWeb
Coverage timestamp: Sun Jun 8 2008 21:20:12 CEST
../../../img/srcFileCovDistChart0.png 29% of files have more coverage
55   138   15   5,5
8   109   0,27   10
10     1,5  
1    
 
  QueryImpl       Line # 29 55 15 0% 0.0
 
No Tests
 
1    //$Id: QueryImpl.java 8524 2005-11-04 21:28:49Z steveebersole $
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    * default implementation of the <tt>Query</tt> interface, for "ordinary" HQL
24    * queries (not collection filters)
25    *
26    * @see CollectionFilterImpl
27    * @author gperrone
28    */
 
29    public class QueryImpl extends AbstractQueryImpl {
30   
31    private Map lockModes = new HashMap(2);
32   
33   
 
34  0 toggle public QueryImpl(String queryString, FlushMode flushMode, SessionImplementor session, ParameterMetadata parameterMetadata) {
35  0 super(queryString, flushMode, session, parameterMetadata);
36    }
37   
 
38  0 toggle public QueryImpl(String queryString, SessionImplementor session, ParameterMetadata parameterMetadata) {
39  0 this(queryString, null, session, parameterMetadata);
40    }
41   
 
42  0 toggle 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   
 
53  0 toggle public ScrollableResults scroll() throws HibernateException {
54  0 return scroll(ScrollMode.SCROLL_INSENSITIVE);
55    }
56   
 
57  0 toggle 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   
 
70  0 toggle 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   
 
81  0 toggle 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   
 
92  0 toggle public Query setLockMode(String alias, LockMode lockMode) {
93  0 lockModes.put(alias, lockMode);
94  0 return this;
95    }
96   
 
97  0 toggle protected Map getLockModes() {
98  0 return lockModes;
99    }
100   
101    /**
102    * TODO documentation
103    *
104    * @return
105    */
 
106  0 toggle 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    // SET NAMED PARAMS
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    // SET POSITIONAL PARAMS
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    }