001: package net.sourceforge.squirrel_sql.plugins.sessionscript;
002:
003: /*
004: * Copyright (C) 2002-2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.io.Serializable;
022:
023: import net.sourceforge.squirrel_sql.fw.id.IHasIdentifier;
024: import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
025: import net.sourceforge.squirrel_sql.fw.sql.ISQLAlias;
026:
027: /**
028: * An SQL script run when a session is started.
029: *
030: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
031: */
032: public class AliasScript implements Serializable, IHasIdentifier {
033: /**
034: * The <TT>IIdentifier</TT> that uniquely identifies this object. This is
035: * actually the identifier of the <TT>ISQLALias</TT> that this script is
036: * for.
037: */
038: private IIdentifier _id;
039:
040: /** The SQL. */
041: private String _sql;
042:
043: /**
044: * Default ctor. Should only be used by to/from XML code.
045: */
046: public AliasScript() {
047: super ();
048: }
049:
050: /**
051: * Ctor specifying the <TT>ISQLAlias</TT>.
052: *
053: * @param alias <TT>ISQLAlias</TT> we have creatign this script for.
054: *
055: * @throws IllegalArgumentException
056: * Thrown if <TT>null</TT> <TT>ISQLAlias</TT> passed.
057: */
058: public AliasScript(ISQLAlias alias) {
059: super ();
060:
061: if (alias == null) {
062: throw new IllegalArgumentException("ISQLAlias == null");
063: }
064:
065: _id = alias.getIdentifier();
066: }
067:
068: /**
069: * Returns <TT>true</TT> if this objects is equal to the passed one. Two
070: * <TT>AliasScript</TT> objects are considered equal if they have the same
071: * identifier.
072: */
073: public boolean equals(Object rhs) {
074: boolean rc = false;
075: if (rhs != null && rhs.getClass().equals(getClass())) {
076: rc = ((AliasScript) rhs).getIdentifier().equals(
077: getIdentifier());
078: }
079: return rc;
080: }
081:
082: /**
083: * Returns a hash code value for this object.
084: */
085: public int hashCode() {
086: return getIdentifier().hashCode();
087: }
088:
089: /**
090: * Return the SQL as a string representaion of this object.
091: *
092: * @return The SQL as a string representation of this object.
093: */
094: public String toString() {
095: return _sql != null ? _sql : "";
096: }
097:
098: /**
099: * Return the identifier that uniquely identifies this object.
100: *
101: * @return the identifier that uniquely identifies this object.
102: */
103: public IIdentifier getIdentifier() {
104: return _id;
105: }
106:
107: /**
108: * Return the SQL to be run.
109: *
110: * @return the SQL to be run.
111: */
112: public String getSQL() {
113: return _sql;
114: }
115:
116: /**
117: * Set the identifier that uniquely identifies this object. This should
118: * be the ID of the <TT>ISQLALais</TT> that this script is for.
119: *
120: * @param the identifier that uniquely identifies this object.
121: */
122: public void setIdentifier(IIdentifier id) {
123: _id = id;
124: }
125:
126: /**
127: * Set the SQL to be run.
128: *
129: * @param value The SQL.
130: */
131: public void setSQL(String value) {
132: _sql = value;
133: }
134: }
|