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
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
+ * 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 = "";
- String username = "";
- String password = "";
- String connect = "";
- String driver = "";
- String type = "";
- String driverFile = "";
- String schema = "";
+ 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());
setDriverFile(data.getDriverFile());
}
- public Bookmark(
- String name,
- String username,
- String password,
- String connect,
- String driver,
- String type,
- String driverFile) {
- this.name = username;
- this.username = username;
- this.password = password;
- this.connect = connect;
- this.driver = driver;
- this.type = type;
- this.driverFile = driverFile;
- }
-
/**
- * Returns the connect.
+ * Returns the JDBC URL.
* @return String
*/
public String getConnect() {
*/
public void setConnect(String connect) {
if (connect == null) {
- connect = "";
+ connect = ""; //$NON-NLS-1$
}
this.connect = connect;
}
*/
public void setDriver(String driver) {
if (driver == null) {
- driver = "";
+ driver = ""; //$NON-NLS-1$
}
this.driver = driver;
}
*/
public void setDriverFile(String driverFile) {
if (driverFile == null) {
- driverFile = "";
+ driverFile = ""; //$NON-NLS-1$
}
this.driverFile = driverFile;
}
*/
public void setPassword(String password) {
if (password == null) {
- password = "";
+ password = ""; //$NON-NLS-1$
}
this.password = password;
}
*/
public void setUsername(String username) {
if (username == null) {
- username = "";
+ username = ""; //$NON-NLS-1$
}
this.username = username;
}
*/
public void setName(String name) {
if (name == null) {
- name = "";
+ name = ""; //$NON-NLS-1$
}
this.name = name;
}
public boolean isEmpty() {
- if (name.equals("") &&
- username.equals("") &&
- password.equals("") &&
- connect.equals("") &&
- driver.equals("") &&
- type.equals("") &&
- driverFile.equals("")) {
+ 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("[");
- buffer.append("name=");
+ buffer.append("["); //$NON-NLS-1$
+ buffer.append("name="); //$NON-NLS-1$
buffer.append(name);
- buffer.append(", ");
- buffer.append("username=");
+ buffer.append(", "); //$NON-NLS-1$
+ buffer.append("username="); //$NON-NLS-1$
buffer.append(username);
- buffer.append(", ");
- buffer.append("password=****");
- buffer.append(", ");
- buffer.append("connect=");
+ 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(", ");
- buffer.append("driver=");
+ buffer.append(", "); //$NON-NLS-1$
+ buffer.append("driver="); //$NON-NLS-1$
buffer.append(driver);
- buffer.append(", ");
- buffer.append("type=");
+ buffer.append(", "); //$NON-NLS-1$
+ buffer.append("type="); //$NON-NLS-1$
buffer.append(type);
- buffer.append(", ");
- buffer.append("driverFile=");
+ buffer.append(", "); //$NON-NLS-1$
+ buffer.append("driverFile="); //$NON-NLS-1$
buffer.append(driverFile);
- buffer.append("]");
+ buffer.append("]"); //$NON-NLS-1$
return buffer.toString();
}
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);
+ }
}