001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: DropSequence.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.database.queries;
009:
010: import com.uwyn.rife.database.Datasource;
011: import com.uwyn.rife.database.capabilities.Capabilities;
012: import com.uwyn.rife.database.exceptions.DbQueryException;
013: import com.uwyn.rife.database.exceptions.SequenceNameRequiredException;
014: import com.uwyn.rife.database.exceptions.UnsupportedSqlFeatureException;
015: import com.uwyn.rife.template.Template;
016: import com.uwyn.rife.template.TemplateFactory;
017: import com.uwyn.rife.tools.StringUtils;
018:
019: /**
020: * Object representation of a SQL "DROP SEQUENCE" query.
021: *
022: * <p>This object may be used to dynamically construct a SQL statement in a
023: * database-independent fashion. After it is finished, it may be executed using
024: * {@link com.uwyn.rife.database.DbQueryManager#executeUpdate(Query)
025: * DbQueryManager.executeUpdate()}.
026: *
027: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
028: * @author Steven Grimm (koreth[remove] at midwinter dot com)
029: * @version $Revision: 3634 $
030: * @since 1.0
031: */
032: public class DropSequence extends AbstractQuery implements Cloneable {
033: private String mName = null;
034:
035: public DropSequence(Datasource datasource) {
036: super (datasource);
037:
038: if (null == datasource)
039: throw new IllegalArgumentException(
040: "datasource can't be null.");
041:
042: clear();
043: }
044:
045: public void clear() {
046: super .clear();
047:
048: mName = null;
049: }
050:
051: public String getName() {
052: return mName;
053: }
054:
055: public Capabilities getCapabilities() {
056: return null;
057: }
058:
059: public String getSql() throws DbQueryException {
060: if (null == mSql) {
061: if (null == mName) {
062: throw new SequenceNameRequiredException("DropSequence");
063: } else {
064: Template template = TemplateFactory.SQL
065: .get("sql."
066: + StringUtils
067: .encodeClassname(mDatasource
068: .getAliasedDriver())
069: + ".drop_sequence");
070:
071: if (template.hasValueId("NAME")) {
072: template.setValue("NAME", mName);
073: }
074:
075: mSql = template.getBlock("QUERY");
076: if (0 == mSql.length()) {
077: throw new UnsupportedSqlFeatureException(
078: "DROP SEQUENCE", mDatasource
079: .getAliasedDriver());
080: }
081:
082: assert mSql != null;
083: assert mSql.length() > 0;
084: }
085: }
086:
087: return mSql;
088: }
089:
090: public DropSequence name(String name) {
091: if (null == name)
092: throw new IllegalArgumentException("name can't be null.");
093: if (0 == name.length())
094: throw new IllegalArgumentException("name can't be empty.");
095:
096: clearGenerated();
097: mName = name;
098:
099: return this ;
100: }
101:
102: public DropSequence clone() {
103: return (DropSequence) super.clone();
104: }
105: }
|