KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > accesslayer > sql > SqlDeleteByQuery


1 package org.apache.ojb.broker.accesslayer.sql;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
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 import org.apache.ojb.broker.metadata.ClassDescriptor;
19 import org.apache.ojb.broker.metadata.FieldDescriptor;
20 import org.apache.ojb.broker.platforms.Platform;
21 import org.apache.ojb.broker.query.Criteria;
22 import org.apache.ojb.broker.query.Query;
23 import org.apache.ojb.broker.util.SqlHelper.PathInfo;
24 import org.apache.ojb.broker.util.logging.Logger;
25
26 /**
27  * Model a DELETE by Query Statement
28  *
29  * @author Thomas Mahler
30  * @version $Id: SqlDeleteByQuery.java,v 1.15.2.2 2005/12/22 18:25:51 brj Exp $
31  */

32 public class SqlDeleteByQuery extends SqlQueryStatement
33 {
34
35     /**
36      * Constructor for SqlDeleteByQuery.
37      * @param cld
38      */

39     public SqlDeleteByQuery(Platform pf, ClassDescriptor cld, Query query, Logger logger)
40     {
41         super(pf, cld, query, logger);
42     }
43
44     /**
45      * @see org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement#buildStatement()
46      */

47     protected String JavaDoc buildStatement()
48     {
49         StringBuffer JavaDoc stmt = new StringBuffer JavaDoc();
50         StringBuffer JavaDoc where = new StringBuffer JavaDoc();
51
52         Criteria crit = this.getQuery().getCriteria();
53
54         stmt.append("DELETE FROM ");
55         stmt.append(getSearchClassDescriptor().getFullTableName());
56         appendWhereClause(where, crit, stmt);
57
58         return stmt.toString();
59     }
60
61     /* (non-Javadoc)
62      * @see org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement#getColName(org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.TableAlias, org.apache.ojb.broker.util.SqlHelper.PathInfo, boolean)
63      */

64     protected String JavaDoc getColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean translate)
65     {
66         FieldDescriptor fld = null;
67         String JavaDoc result;
68
69         if (translate)
70         {
71             fld = getFieldDescriptor(aTableAlias, aPathInfo);
72         }
73
74         if (fld != null)
75         {
76             // BRJ : No alias for delete
77
result = fld.getColumnName();
78         }
79         else
80         {
81             result = aPathInfo.column;
82         }
83
84        return result;
85    }
86
87 }
88
Popular Tags