updating SQL plugin with latest Quantum code
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / bookmarks / Bookmark.java
index e746898..a52eb49 100644 (file)
@@ -1,25 +1,34 @@
 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());
@@ -31,25 +40,8 @@ public class Bookmark {
                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() {
@@ -94,7 +86,7 @@ public class Bookmark {
         */
        public void setConnect(String connect) {
                if (connect == null) {
-                       connect = "";
+                       connect = ""; //$NON-NLS-1$
                }
                this.connect = connect;
        }
@@ -105,7 +97,7 @@ public class Bookmark {
         */
        public void setDriver(String driver) {
                if (driver == null) {
-                       driver = "";
+                       driver = ""; //$NON-NLS-1$
                }
                this.driver = driver;
        }
@@ -116,7 +108,7 @@ public class Bookmark {
         */
        public void setDriverFile(String driverFile) {
                if (driverFile == null) {
-                       driverFile = "";
+                       driverFile = ""; //$NON-NLS-1$
                }
                this.driverFile = driverFile;
        }
@@ -127,7 +119,7 @@ public class Bookmark {
         */
        public void setPassword(String password) {
                if (password == null) {
-                       password = "";
+                       password = ""; //$NON-NLS-1$
                }
                this.password = password;
        }
@@ -138,7 +130,7 @@ public class Bookmark {
         */
        public void setUsername(String username) {
                if (username == null) {
-                       username = "";
+                       username = ""; //$NON-NLS-1$
                }
                this.username = username;
        }
@@ -157,46 +149,46 @@ public class Bookmark {
         */
        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();
        }
        
@@ -216,4 +208,34 @@ public class Bookmark {
                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);
+    }
 }