KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > storage > search > implementation > NodeSearchQuery


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9  */

10 package org.mmbase.storage.search.implementation;
11
12 import java.util.*;
13 import org.mmbase.core.*;
14 import org.mmbase.module.core.MMObjectBuilder;
15 import org.mmbase.module.core.VirtualBuilder;
16 import org.mmbase.module.corebuilders.InsRel;
17 import org.mmbase.storage.search.*;
18
19 /**
20  * A <code>NodeSearchQuery</code> implements a <code>SearchQuery</code>
21  * that retrieves nodes of one specified nodetype.
22  * <p>
23  * The constructor creates the query with all persistent fields belonging to
24  * the specified nodetype excluding byte[] type fields.
25  * Use {@link #getField(CoreField) getField()} to retrieve each of these fields.
26  * <p>
27  * Once an instance is constructed, it is not possible to add more fields/steps.
28  * Consequently calling one of these methods always results in an
29  * <code>UnsupportedOperationException</code>:
30  * <ul>
31  * <li>{@link #addStep(MMObjectBuilder) addStep()}
32  * <li>{@link #addRelationStep(InsRel,MMObjectBuilder) addRelationStep()}
33  * <li>{@link #addField(Step,CoreField) addField()}
34  * <li>{@link #addAggregatedField(Step,CoreField,int) addAggregatedField()}
35  * </ul>
36  *
37  * @author Rob van Maris
38  * @version $Id: NodeSearchQuery.java,v 1.13 2006/02/09 12:04:19 johannes Exp $
39  * @since MMBase-1.7
40  */

41 public class NodeSearchQuery extends BasicSearchQuery implements SearchQuery {
42
43     /** Builder for the specified nodetype. */
44     private MMObjectBuilder builder = null;
45
46     /** Map, maps fields to stepfields. */
47     private Map stepFields = new HashMap();
48
49
50     /**
51      * Creator.
52      *
53      * @param builder The builder for the nodetype, must not be a
54      * {@link org.mmbase.module.core.VirtualBuilder virtual} builder.
55      * @throws IllegalArgumentException When an invalid argument is supplied.
56      */

57     public NodeSearchQuery(MMObjectBuilder builder) {
58         if (builder == null) {
59             throw new IllegalArgumentException JavaDoc("Invalid builder value: " + builder);
60         }
61         if (builder instanceof VirtualBuilder) {
62             throw new IllegalArgumentException JavaDoc("Invalid builder type, because this is a virtual builder: " + builder.getClass().getName());
63         }
64         Step step = super.addStep(builder);
65         addFields(step);
66         this.builder = builder;
67     }
68
69     /*
70     NodeSearchQuery(SearchQuery searchQuery) {
71         super(searchQuery);
72         List steps = searchQuery.getSteps();
73         if (steps.size() != 1) throw new IllegalArgumentException("Given search-query cannot be a NodeSearchQuery");
74         BasicStep step = (BasicStep) steps.get(0);
75         fields.clear();
76         addFields(step);
77         builder = step.getBuilder();
78     }
79     */

80
81     protected void copySteps(SearchQuery q) {
82         // no need, can be done by clone
83
}
84
85
86     protected void copyFields(SearchQuery q) {
87         // no need, can be done by clone
88
}
89     /**
90      * Returns the stepfield corresponding to the specified field.
91      *
92      * @param field The field.
93      * @return The corresponding stepfield.
94      * @throws IllegalArgumentException When the field is not a
95      * persistent field of the associated nodetype.
96      */

97     public BasicStepField getField(CoreField field) {
98         BasicStepField stepField = (BasicStepField) stepFields.get(field);
99         if (stepField == null) {
100             // Not found.
101
throw new IllegalArgumentException JavaDoc("Not a persistent field of builder " + builder.getTableName() + ": " + field + " in " + stepFields);
102         }
103         return stepField;
104     }
105
106     /**
107      * Returns the builder for the specified nodetype.
108      *
109      * @return The builder.
110      */

111     public MMObjectBuilder getBuilder() {
112         return builder;
113     }
114
115     // javadoc is inherited
116
public BasicStep addStep(MMObjectBuilder builder) {
117         throw new UnsupportedOperationException JavaDoc(
118         "Adding more steps to NodeSearchQuery not supported.");
119     }
120
121     // javadoc is inherited
122
public BasicRelationStep addRelationStep(InsRel builder, MMObjectBuilder nextBuilder) {
123         throw new UnsupportedOperationException JavaDoc("Adding more steps to NodeSearchQuery not supported.");
124     }
125
126     // javadoc is inherited
127
public BasicStepField addField(Step step, CoreField fieldDefs) {
128         if (builder != null) { // this means: inited already.
129
throw new UnsupportedOperationException JavaDoc("Adding more fields to NodeSearchQuery not supported.");
130         } else {
131             return super.addField(step, fieldDefs);
132         }
133     }
134     // MM
135
protected void mapField(CoreField field, StepField stepField) {
136         stepFields.put(field, stepField);
137     }
138
139     // javadoc is inherited
140
public BasicAggregatedField addAggregatedField(Step step, CoreField fieldDefs, int aggregationType) {
141         throw new UnsupportedOperationException JavaDoc("Adding more fields to NodeSearchQuery not supported.");
142     }
143
144 }
145
Popular Tags