KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > expressions > SQLDeleteStatement


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.expressions;
23
24 import java.io.*;
25 import oracle.toplink.essentials.exceptions.*;
26 import oracle.toplink.essentials.queryframework.*;
27 import oracle.toplink.essentials.internal.databaseaccess.DatabaseCall;
28 import oracle.toplink.essentials.internal.sessions.AbstractSession;
29
30 /**
31  * <p><b>Purpose</b>: Print DELETE statement.
32  * <p><b>Responsibilities</b>:<ul>
33  * <li> Print DELETE statement.
34  * </ul>
35  * @author Dorin Sandu
36  * @since TOPLink/Java 1.0
37  */

38 public class SQLDeleteStatement extends SQLModifyStatement {
39
40     /**
41      * Append the string containing the SQL insert string for the given table.
42      */

43     public DatabaseCall buildCall(AbstractSession session) {
44         SQLCall call = new SQLCall();
45         call.returnNothing();
46
47         Writer writer = new CharArrayWriter(100);
48         try {
49             writer.write("DELETE ");
50             writer.write("FROM ");
51             writer.write(getTable().getQualifiedName());
52
53             if (getWhereClause() != null) {
54                 writer.write(" WHERE ");
55                 ExpressionSQLPrinter printer = new ExpressionSQLPrinter(session, getTranslationRow(), call, false);
56                 printer.setWriter(writer);
57                 printer.printExpression(getWhereClause());
58             }
59
60             call.setSQLString(writer.toString());
61         } catch (IOException exception) {
62             throw ValidationException.fileError(exception);
63         }
64         return call;
65     }
66 }
67
Popular Tags