1 package net.sourceforge.phpdt.sql.bookmarks;
3 import java.sql.Connection;
5 import net.sourceforge.phpdt.sql.sql.ConnectionEstablisher;
6 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
10 * Class Bookmark holds the "static" information of a bookmark, that is the data that
11 * is saved and loaded from the external file and describes a bookmark. This info will
12 * be filled up by the end user.
14 public class Bookmark {
15 String name = ""; //$NON-NLS-1$
16 String username = ""; //$NON-NLS-1$
17 String password = ""; //$NON-NLS-1$
18 String connect = ""; //$NON-NLS-1$
19 String driver = ""; //$NON-NLS-1$
20 String type = ""; //$NON-NLS-1$
21 String driverFile = ""; //$NON-NLS-1$
22 String schema = ""; //$NON-NLS-1$
23 private ConnectionEstablisher connectionEstablisher;
26 this(MultiSQLServer.getInstance());
29 public Bookmark(ConnectionEstablisher connectionEstablisher) {
30 this.connectionEstablisher = connectionEstablisher;
33 public Bookmark(Bookmark data) {
34 setName(data.getName());
35 setUsername(data.getUsername());
36 setPassword(data.getPassword());
37 setConnect(data.getConnect());
38 setDriver(data.getDriver());
39 setType(data.getType());
40 setDriverFile(data.getDriverFile());
44 * Returns the JDBC URL.
47 public String getConnect() {
55 public String getDriver() {
60 * Returns the driverFile.
63 public String getDriverFile() {
68 * Returns the password.
71 public String getPassword() {
76 * Returns the username.
79 public String getUsername() {
85 * @param connect The connect to set
87 public void setConnect(String connect) {
88 if (connect == null) {
89 connect = ""; //$NON-NLS-1$
91 this.connect = connect;
96 * @param driver The driver to set
98 public void setDriver(String driver) {
100 driver = ""; //$NON-NLS-1$
102 this.driver = driver;
106 * Sets the driverFile.
107 * @param driverFile The driverFile to set
109 public void setDriverFile(String driverFile) {
110 if (driverFile == null) {
111 driverFile = ""; //$NON-NLS-1$
113 this.driverFile = driverFile;
118 * @param password The password to set
120 public void setPassword(String password) {
121 if (password == null) {
122 password = ""; //$NON-NLS-1$
124 this.password = password;
129 * @param username The username to set
131 public void setUsername(String username) {
132 if (username == null) {
133 username = ""; //$NON-NLS-1$
135 this.username = username;
142 public String getName() {
148 * @param name The name to set
150 public void setName(String name) {
152 name = ""; //$NON-NLS-1$
157 public boolean isEmpty() {
158 if (name.equals("") && //$NON-NLS-1$
159 username.equals("") && //$NON-NLS-1$
160 password.equals("") && //$NON-NLS-1$
161 connect.equals("") && //$NON-NLS-1$
162 driver.equals("") && //$NON-NLS-1$
163 type.equals("") && //$NON-NLS-1$
164 driverFile.equals("")) { //$NON-NLS-1$
169 public String toString() {
170 StringBuffer buffer = new StringBuffer();
171 buffer.append("["); //$NON-NLS-1$
172 buffer.append("name="); //$NON-NLS-1$
174 buffer.append(", "); //$NON-NLS-1$
175 buffer.append("username="); //$NON-NLS-1$
176 buffer.append(username);
177 buffer.append(", "); //$NON-NLS-1$
178 buffer.append("password=****"); //$NON-NLS-1$
179 buffer.append(", "); //$NON-NLS-1$
180 buffer.append("connect="); //$NON-NLS-1$
181 buffer.append(connect);
182 buffer.append(", "); //$NON-NLS-1$
183 buffer.append("driver="); //$NON-NLS-1$
184 buffer.append(driver);
185 buffer.append(", "); //$NON-NLS-1$
186 buffer.append("type="); //$NON-NLS-1$
188 buffer.append(", "); //$NON-NLS-1$
189 buffer.append("driverFile="); //$NON-NLS-1$
190 buffer.append(driverFile);
191 buffer.append("]"); //$NON-NLS-1$
192 return buffer.toString();
195 public String getType() {
199 public void setType(String type) {
203 public String getSchema() {
207 public void setSchema(String schema) {
208 this.schema = schema;
211 protected Connection connection = null;
213 * Returns the connection object. Will automatically connect if not connected.
214 * @return the Connection object associated with the current JDBC source.
217 public Connection getConnection() {
218 // We autoconnect if needed. (After all, reusability is a myth :)
219 if (connection == null) connection = this.connectionEstablisher.connect(this);
224 * @return true if the BookmarkNode is connected to a JDBC source
226 public boolean isConnected() {
227 return (connection != null);
231 * Sets the connection member. From that moment on the BookmarkNode is "connected" (open)
232 * @param connection : a valid connection to a JDBC source
234 public void setConnection(Connection connection) {
235 this.connection = connection;
238 public void disconnect() {
239 this.connectionEstablisher.disconnect(this, this.connection);