KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > db > orm > sqlgen > DbSqlUpdate


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.db.orm.sqlgen;
4
5 import jodd.db.orm.DbEntityDescriptor;
6
7 import java.util.Map JavaDoc;
8
9 /**
10  * Generates simple update queries.
11  */

12 public class DbSqlUpdate implements DbSqlGenerator {
13
14     protected DbDynamicSqlTemplate template;
15
16     /**
17      * Defines update query for specified item.
18      * @param object
19      * @param onlyExisting if <code>true</code> null properties will be ignored.
20      * @param conditions object that will produce where part
21      */

22     public DbSqlUpdate(Object JavaDoc object, boolean onlyExisting, Object JavaDoc conditions) {
23         //template = new DbDynamicSqlTemplate("update $T{t -} set $U{t} $W{where .c}"); // without table alias
24
if (onlyExisting == true) {
25             template = new DbDynamicSqlTemplate("update $T{t} set $U{t} $W{where !t.c}");
26         } else {
27             template = new DbDynamicSqlTemplate("update $T{t} set $U{+t} $W{where !t.c}");
28         }
29         template.use("t", object).use("c", conditions);
30     }
31
32     /**
33      * Defines update query for specified item.
34      * @param object
35      * @param onlyExisting if <code>true</code> null properties will be ignored.
36      * @param conditions string that will be added to the query for where part
37      */

38     public DbSqlUpdate(Object JavaDoc object, boolean onlyExisting, String JavaDoc conditions) {
39         if (conditions == null) {
40             conditions = "";
41         }
42         if (onlyExisting == true) {
43             template = new DbDynamicSqlTemplate("update $T{t -} set $U{t} " + conditions);
44         } else {
45             template = new DbDynamicSqlTemplate("update $T{t -} set $U{+t} " + conditions);
46         }
47         template.use("t", object);
48     }
49
50     // ---------------------------------------------------------------- interface
51

52     public String JavaDoc generateQuery() {
53         return template.generateQuery();
54     }
55
56     public Map JavaDoc<String JavaDoc, Object JavaDoc> getQueryParameters() {
57         return template.getQueryParameters();
58     }
59
60     public Map JavaDoc<String JavaDoc, String JavaDoc[]> getColumnData() {
61         return template.getColumnData();
62     }
63 }
64
Popular Tags