001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Florent Guillaume
011 */
012
013package org.nuxeo.ecm.core.storage.sql.jdbc.db;
014
015import java.io.Serializable;
016
017/**
018 * A {@code DELETE} statement.
019 *
020 * @author Florent Guillaume
021 */
022public class Delete implements Serializable {
023
024    private static final long serialVersionUID = 1L;
025
026    protected final Table table;
027
028    private String where;
029
030    public Delete(Table table) {
031        this.table = table;
032    }
033
034    public void setWhere(String where) {
035        this.where = where;
036    }
037
038    public String getStatement() {
039        StringBuilder buf = new StringBuilder(50);
040        buf.append("DELETE FROM ");
041        buf.append(table.getQuotedName());
042        if (where != null && where.length() != 0) {
043            buf.append(" WHERE ");
044            buf.append(where);
045        }
046        return buf.toString();
047    }
048}