package net.sourceforge.phpdt.sql.bookmarks; import java.sql.Connection; import net.sourceforge.phpdt.sql.sql.ConnectionEstablisher; import net.sourceforge.phpdt.sql.sql.MultiSQLServer; /** * @author root * Class Bookmark holds the "static" information of a bookmark, that is the data that * is saved and loaded from the external file and describes a bookmark. This info will * be filled up by the end user. */ public class Bookmark { String name = ""; //$NON-NLS-1$ String username = ""; //$NON-NLS-1$ String password = ""; //$NON-NLS-1$ String connect = ""; //$NON-NLS-1$ String driver = ""; //$NON-NLS-1$ String type = ""; //$NON-NLS-1$ String driverFile = ""; //$NON-NLS-1$ String schema = ""; //$NON-NLS-1$ private ConnectionEstablisher connectionEstablisher; public Bookmark() { this(MultiSQLServer.getInstance()); } public Bookmark(ConnectionEstablisher connectionEstablisher) { this.connectionEstablisher = connectionEstablisher; } public Bookmark(Bookmark data) { setName(data.getName()); setUsername(data.getUsername()); setPassword(data.getPassword()); setConnect(data.getConnect()); setDriver(data.getDriver()); setType(data.getType()); setDriverFile(data.getDriverFile()); } /** * Returns the JDBC URL. * @return String */ public String getConnect() { return connect; } /** * Returns the driver. * @return String */ public String getDriver() { return driver; } /** * Returns the driverFile. * @return String */ public String getDriverFile() { return driverFile; } /** * Returns the password. * @return String */ public String getPassword() { return password; } /** * Returns the username. * @return String */ public String getUsername() { return username; } /** * Sets the connect. * @param connect The connect to set */ public void setConnect(String connect) { if (connect == null) { connect = ""; //$NON-NLS-1$ } this.connect = connect; } /** * Sets the driver. * @param driver The driver to set */ public void setDriver(String driver) { if (driver == null) { driver = ""; //$NON-NLS-1$ } this.driver = driver; } /** * Sets the driverFile. * @param driverFile The driverFile to set */ public void setDriverFile(String driverFile) { if (driverFile == null) { driverFile = ""; //$NON-NLS-1$ } this.driverFile = driverFile; } /** * Sets the password. * @param password The password to set */ public void setPassword(String password) { if (password == null) { password = ""; //$NON-NLS-1$ } this.password = password; } /** * Sets the username. * @param username The username to set */ public void setUsername(String username) { if (username == null) { username = ""; //$NON-NLS-1$ } this.username = username; } /** * Returns the name. * @return String */ public String getName() { return name; } /** * Sets the name. * @param name The name to set */ public void setName(String name) { if (name == null) { name = ""; //$NON-NLS-1$ } this.name = name; } public boolean isEmpty() { if (name.equals("") && //$NON-NLS-1$ username.equals("") && //$NON-NLS-1$ password.equals("") && //$NON-NLS-1$ connect.equals("") && //$NON-NLS-1$ driver.equals("") && //$NON-NLS-1$ type.equals("") && //$NON-NLS-1$ driverFile.equals("")) { //$NON-NLS-1$ return true; } return false; } public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("["); //$NON-NLS-1$ buffer.append("name="); //$NON-NLS-1$ buffer.append(name); buffer.append(", "); //$NON-NLS-1$ buffer.append("username="); //$NON-NLS-1$ buffer.append(username); buffer.append(", "); //$NON-NLS-1$ buffer.append("password=****"); //$NON-NLS-1$ buffer.append(", "); //$NON-NLS-1$ buffer.append("connect="); //$NON-NLS-1$ buffer.append(connect); buffer.append(", "); //$NON-NLS-1$ buffer.append("driver="); //$NON-NLS-1$ buffer.append(driver); buffer.append(", "); //$NON-NLS-1$ buffer.append("type="); //$NON-NLS-1$ buffer.append(type); buffer.append(", "); //$NON-NLS-1$ buffer.append("driverFile="); //$NON-NLS-1$ buffer.append(driverFile); buffer.append("]"); //$NON-NLS-1$ return buffer.toString(); } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getSchema() { return schema; } public void setSchema(String schema) { this.schema = schema; } protected Connection connection = null; /** * Returns the connection object. Will automatically connect if not connected. * @return the Connection object associated with the current JDBC source. * */ public Connection getConnection() { // We autoconnect if needed. (After all, reusability is a myth :) if (connection == null) connection = this.connectionEstablisher.connect(this); return connection; } /** * @return true if the BookmarkNode is connected to a JDBC source */ public boolean isConnected() { return (connection != null); } /** * Sets the connection member. From that moment on the BookmarkNode is "connected" (open) * @param connection : a valid connection to a JDBC source */ public void setConnection(Connection connection) { this.connection = connection; } public void disconnect() { this.connectionEstablisher.disconnect(this, this.connection); } }