01: package org.apache.ojb.broker.accesslayer.sql;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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: * Constructor for SqlDeleteByQuery.
36: * @param cld
37: */
38: public SqlDeleteByQuery(Platform pf, ClassDescriptor cld,
39: Query query, Logger logger) {
40: super (pf, cld, query, logger);
41: }
42:
43: /**
44: * @see org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement#buildStatement()
45: */
46: protected String buildStatement() {
47: StringBuffer stmt = new StringBuffer();
48: StringBuffer where = new StringBuffer();
49:
50: Criteria crit = this .getQuery().getCriteria();
51:
52: stmt.append("DELETE FROM ");
53: stmt.append(getSearchClassDescriptor().getFullTableName());
54: appendWhereClause(where, crit, stmt);
55:
56: return stmt.toString();
57: }
58:
59: /* (non-Javadoc)
60: * @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)
61: */
62: protected String getColName(TableAlias aTableAlias,
63: PathInfo aPathInfo, boolean translate) {
64: FieldDescriptor fld = null;
65: String result;
66:
67: if (translate) {
68: fld = getFieldDescriptor(aTableAlias, aPathInfo);
69: }
70:
71: if (fld != null) {
72: // BRJ : No alias for delete
73: result = fld.getColumnName();
74: } else {
75: result = aPathInfo.column;
76: }
77:
78: return result;
79: }
80:
81: }
|