001: package net.sourceforge.squirrel_sql.client.session.mainpanel;
002:
003: /*
004: * Copyright (C) 2003-2004 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: import java.util.Date;
023:
024: import net.sourceforge.squirrel_sql.fw.util.StringUtilities;
025:
026: /**
027: * This JavaBean is the object stored in The <TT>SQLHistoryComboBox</TT>. It
028: * represents an SQL query.
029: *
030: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
031: */
032: public class SQLHistoryItem implements Serializable, Cloneable {
033: /**
034: *
035: */
036: private static final long serialVersionUID = 1L;
037:
038: /** The SQL. */
039: private String _sql;
040:
041: private java.util.Date _lastUsageTime;
042:
043: /**
044: * Cleaned up vesion of the SQL. Appropriate for displaying in
045: * a combobox.
046: */
047: private String _shortSql;
048: private String _aliasName;
049:
050: /**
051: * Default ctor.
052: */
053: public SQLHistoryItem() {
054: this ("", "");
055: }
056:
057: /**
058: * Ctor specifying the SQL.
059: *
060: * @param sql The SQL statement.
061: *
062: * @throws IllegalArgumentException
063: * Thrown if a <TT>null</TT> SQL statement passed.
064: */
065: public SQLHistoryItem(String sql, String aliasName) {
066: super ();
067: if (sql == null) {
068: throw new IllegalArgumentException("sql == null");
069: }
070:
071: _aliasName = aliasName;
072:
073: if (0 < sql.length()) {
074: _lastUsageTime = new Date();
075: }
076:
077: setSQL(sql);
078: }
079:
080: /**
081: * Two objects of this class are considered equal if the SQL that they
082: * represent is equal.
083: *
084: * @param rhs The object that this object is being compared to.
085: */
086: @Override
087: public boolean equals(Object rhs) {
088: boolean rc = false;
089: if (this == rhs) {
090: rc = true;
091: } else if (rhs != null && rhs.getClass().equals(getClass())) {
092: rc = ((SQLHistoryItem) rhs).getSQL().equals(getSQL());
093: }
094: return rc;
095: }
096:
097: @Override
098: public int hashCode() {
099: return getSQL().hashCode();
100: }
101:
102: /**
103: * Return a copy of this object.
104: *
105: * @return The cloned object.
106: */
107: @Override
108: public Object clone() {
109: try {
110: return super .clone();
111: } catch (CloneNotSupportedException ex) {
112: throw new InternalError(ex.getMessage()); // Impossible.
113: }
114: }
115:
116: /**
117: * Retrieve a string representation of this object. A cleaned up version
118: * of the SQL is used.
119: *
120: * @return A string representation of this object.
121: */
122: @Override
123: public String toString() {
124: return _shortSql;
125: }
126:
127: /**
128: * Retrieve the SQL.
129: *
130: * @return The SQL.
131: */
132: public String getSQL() {
133: return _sql;
134: }
135:
136: /**
137: * Set the SQL.
138: *
139: * @param sql The SQL statement.
140: *
141: * @throws IllegalArgumentException
142: * Thrown if a <TT>null</TT> SQL statement passed.
143: */
144: public void setSQL(String sql) {
145: if (sql == null) {
146: throw new IllegalArgumentException("sql == null");
147: }
148:
149: _sql = sql.trim();
150: _shortSql = StringUtilities.cleanString(sql);
151: }
152:
153: public Date getLastUsageTime() {
154: return _lastUsageTime;
155: }
156:
157: public void setLastUsageTime(Date _creationTime) {
158: this ._lastUsageTime = _creationTime;
159: }
160:
161: public String getAliasName() {
162: return _aliasName;
163: }
164:
165: public void setAliasName(String _aliasName) {
166: this._aliasName = _aliasName;
167: }
168: }
|