%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.portals.graffito.jcr.query.impl.QueryImpl |
|
|
1 | /* |
|
2 | * Copyright 2004-2005 The Apache Software Foundation or its licensors, |
|
3 | * as applicable. |
|
4 | * |
|
5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 | * you may not use this file except in compliance with the License. |
|
7 | * You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | ||
18 | package org.apache.portals.graffito.jcr.query.impl; |
|
19 | ||
20 | import java.util.ArrayList; |
|
21 | import java.util.Iterator; |
|
22 | ||
23 | import org.apache.portals.graffito.jcr.mapper.Mapper; |
|
24 | import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor; |
|
25 | import org.apache.portals.graffito.jcr.query.Filter; |
|
26 | import org.apache.portals.graffito.jcr.query.Query; |
|
27 | ||
28 | /** |
|
29 | * Default Query implementation |
|
30 | * |
|
31 | * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a> |
|
32 | * |
|
33 | */ |
|
34 | public class QueryImpl implements Query |
|
35 | { |
|
36 | ||
37 | private Filter filter; |
|
38 | ||
39 | ClassDescriptor classDescriptor; |
|
40 | ||
41 | 0 | private ArrayList orderByExpressions = new ArrayList(); |
42 | ||
43 | /** |
|
44 | * Constructor |
|
45 | * |
|
46 | * @param filter |
|
47 | * @param mapper |
|
48 | */ |
|
49 | public QueryImpl(Filter filter, Mapper mapper) |
|
50 | 0 | { |
51 | 0 | this.filter = filter; |
52 | 0 | classDescriptor = mapper.getClassDescriptor(filter.getFilterClass()); |
53 | 0 | } |
54 | ||
55 | /** |
|
56 | * @see org.apache.portals.graffito.jcr.query.Query#setFilter(org.apache.portals.graffito.jcr.query.Filter) |
|
57 | */ |
|
58 | public void setFilter(Filter filter) |
|
59 | { |
|
60 | 0 | this.filter = filter; |
61 | 0 | } |
62 | ||
63 | /** |
|
64 | * @see org.apache.portals.graffito.jcr.query.Query#getFilter() |
|
65 | */ |
|
66 | public Filter getFilter() |
|
67 | { |
|
68 | 0 | return this.filter; |
69 | } |
|
70 | ||
71 | public void addOrderByDescending(String fieldNameAttribute) |
|
72 | { |
|
73 | 0 | orderByExpressions.add("@" + this.getJcrFieldName(fieldNameAttribute) + " descending"); |
74 | 0 | } |
75 | ||
76 | /** |
|
77 | * |
|
78 | * @see org.apache.portals.graffito.jcr.query.Query#addOrderByAscending(java.lang.String) |
|
79 | */ |
|
80 | public void addOrderByAscending(String fieldNameAttribute) |
|
81 | { |
|
82 | 0 | orderByExpressions.add("@" + this.getJcrFieldName(fieldNameAttribute) + " ascending"); |
83 | 0 | } |
84 | ||
85 | public String getOrderByExpression() |
|
86 | { |
|
87 | ||
88 | 0 | if (orderByExpressions.size() == 0) |
89 | { |
|
90 | 0 | return ""; |
91 | } |
|
92 | ||
93 | 0 | String orderByExpression = "order by "; |
94 | 0 | Iterator iterator = orderByExpressions.iterator(); |
95 | 0 | int count=1; |
96 | 0 | while (iterator.hasNext()) |
97 | { |
|
98 | 0 | if (count > 1) |
99 | { |
|
100 | 0 | orderByExpression += " , "; |
101 | } |
|
102 | 0 | orderByExpression+= (String) iterator.next(); |
103 | 0 | count++; |
104 | } |
|
105 | ||
106 | 0 | return orderByExpression; |
107 | } |
|
108 | ||
109 | ||
110 | private String getJcrFieldName(String fieldAttribute) |
|
111 | { |
|
112 | ||
113 | 0 | return classDescriptor.getJcrName(fieldAttribute); |
114 | ||
115 | } |
|
116 | ||
117 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |