KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > query > UpdateQuery


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.query;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.apache.cayenne.exp.Expression;
26 import org.apache.cayenne.map.ObjEntity;
27
28 /**
29  * Object encapsulating an UPDATE statement. Note that updated attributes are expressed in
30  * terms of DbAttribute names.
31  */

32 public class UpdateQuery extends QualifiedQuery {
33
34     protected Map JavaDoc updAttributes = new HashMap JavaDoc();
35
36     /** Creates empty UpdateQuery. */
37     public UpdateQuery() {
38     }
39
40     private void init(Object JavaDoc root, Expression qualifier) {
41         setRoot(root);
42         setQualifier(qualifier);
43     }
44
45     /**
46      * Creates a UpdateQuery with null qualifier, for the specifed ObjEntity
47      *
48      * @param root the ObjEntity this UpdateQuery is for.
49      */

50     public UpdateQuery(ObjEntity root) {
51         this(root, null);
52     }
53
54     /**
55      * Creates a UpdateQuery for the specifed ObjEntity with the given qualifier
56      *
57      * @param root the ObjEntity this UpdateQuery is for.
58      * @param qualifier an Expression indicating which objects will be updated
59      */

60     public UpdateQuery(ObjEntity root, Expression qualifier) {
61         init(root, qualifier);
62     }
63
64     /**
65      * Creates a UpdateQuery with null qualifier, for the entity which uses the given
66      * class.
67      *
68      * @param rootClass the Class of objects this UpdateQuery is for.
69      */

70     public UpdateQuery(Class JavaDoc rootClass) {
71         this(rootClass, null);
72     }
73
74     /**
75      * Creates a UpdateQuery for the entity which uses the given class, with the given
76      * qualifier.
77      *
78      * @param rootClass the Class of objects this UpdateQuery is for.
79      * @param qualifier an Expression indicating which objects will be updated
80      */

81     public UpdateQuery(Class JavaDoc rootClass, Expression qualifier) {
82         init(rootClass, qualifier);
83     }
84
85     /** Creates UpdateQuery with <code>objEntityName</code> parameter. */
86     public UpdateQuery(String JavaDoc objEntityName) {
87         this(objEntityName, null);
88     }
89
90     /**
91      * Creates UpdateQuery with <code>objEntityName</code> and <code>qualifier</code>
92      * parameters.
93      */

94     public UpdateQuery(String JavaDoc objEntityName, Expression qualifier) {
95         init(objEntityName, qualifier);
96     }
97
98     /**
99      * Calls "makeUpdate" on the visitor.
100      *
101      * @since 1.2
102      */

103     public SQLAction createSQLAction(SQLActionVisitor visitor) {
104         return visitor.updateAction(this);
105     }
106
107     public void addUpdAttribute(String JavaDoc attrName, Object JavaDoc updatedValue) {
108         updAttributes.put(attrName, updatedValue);
109     }
110
111     /** Returns a map of updated attributes */
112     public Map JavaDoc getUpdAttributes() {
113         return updAttributes;
114     }
115 }
116
Popular Tags