class="com.quantum.QuantumPlugin">
<runtime>
- <!-- <library name="lib/xercesImpl.jar">
- <export name="*"/>
- </library>
- <library name="lib/xmlParserAPIs.jar">
- <export name="*"/>
- </library> -->
<library name="quantum.jar">
<export name="*"/>
</library>
</runtime>
<requires>
<import plugin="org.eclipse.core.runtime.compatibility"/>
- <import plugin="org.eclipse.core.runtime.compatibility"/>
<import plugin="org.eclipse.ui.ide"/>
<import plugin="org.eclipse.ui.views"/>
<import plugin="org.eclipse.jface.text"/>
</view>
<view
name="%tableview.name"
- icon="icons/table.gif"
+ icon="icons/table.gif"
category="com.quantum.views"
class="com.quantum.view.tableview.TableView"
id="com.quantum.view.tableview.TableView">
class="com.quantum.editors.SQLEditor"
id="com.quantum.editors.SQLEditor">
</editor>
- <editor
+ <!-- <editor
name="Table Data Editor"
icon="icons/greentable.gif"
class="com.quantum.editors.dataeditor.DataEditor"
id="com.quantum.editors.dataeditor.DataEditor">
- </editor>
+ </editor> -->
</extension>
<!-- Preferences -->
<extension
tableview.ViewNameFinalDecoration=)
tableview.BookmarkSeparator=:
tableview.ViewNameInitialDecoration=\ (
-tableview.phpselect = PHP Select...
-tableview.phpupdate = PHP Update...
-tableview.phpinsert = PHP Insert...
-tableview.phpdelete = PHP Delete...
+tableview.phpselect = PHP SELECT to Clipboard...
+tableview.phpupdate = PHP UPDATE to Clipboard...
+tableview.phpinsert = PHP INSERT to Clipboard...
+tableview.phpdelete = PHP DELETE to Clipboard...
filedialog.preferences = Preferences (*.ini)
filedialog.allfiles = All Files (*.*)
filedialog.sqlFiles = SQL query (*.sql)
* Returns the driver.
* @return String
*/
- public String getDriver() {
+ String getDriver() {
return driver;
}
* Returns the driverFile.
* @return String
*/
- public String getDriverFile() {
+ String getDriverFile() {
return driverFile;
}
* Sets the driver.
* @param driver The driver to set
*/
- public void setDriver(String driver) {
+ void setDriver(String driver) {
if (driver == null) {
driver = ""; //$NON-NLS-1$
}
* Sets the driverFile.
* @param driverFile The driverFile to set
*/
- public void setDriverFile(String driverFile) {
+ void setDriverFile(String driverFile) {
if (driverFile == null) {
driverFile = ""; //$NON-NLS-1$
}
return true;
}
-
+
+ public void setJDBCDriver(JDBCDriver jdbcDriver) {
+ jdbcDriver = BookmarkCollection.getInstance().findDriver(jdbcDriver);
+ setDriver(jdbcDriver.getClassName());
+ setDriverFile(jdbcDriver.getJarFileName());
+ }
+
+ public JDBCDriver getJDBCDriver() {
+ return BookmarkCollection.getInstance().findDriver(getDriver(), getDriverFile());
+ }
}
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
+import java.util.Set;
import java.util.Vector;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
import com.quantum.IQuantumConstants;
import com.quantum.Messages;
import com.quantum.model.xml.ModelToXMLConverter;
import com.quantum.sql.metadata.MetaDataXMLInterface;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
/**
* The collection of database bookmarks that the Quantum plug-in knows about.
* This collection is loaded by the QuantumPlugin class before any Quantum plugin
private List bookmarks = new Vector();
private boolean changed = false;
private PropertyChangeSupport support = new PropertyChangeSupport(this);
+ private Set drivers = Collections.synchronizedSet(new HashSet());
private BookmarkCollection() {
}
newBookmarks.add(bookmark);
}
i++;
+ this.drivers.add(new JDBCDriver(bookmark.getDriver(), driverFile));
}
if (overwrite) {
this.bookmarks = newBookmarks;
public void exportXML(Element root) {
System.out.println("Bookmarks: Saving to Element"); //$NON-NLS-1$
Element bookmarkRoot = MetaDataXMLInterface.createElementText(root,"bookmarks", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ for (Iterator i = this.drivers.iterator(); i.hasNext(); ) {
+ JDBCDriver driver = (JDBCDriver) i.next();
+ ModelToXMLConverter.getInstance().convert(bookmarkRoot, driver);
+ }
for (int i = 0; i < bookmarks.size(); i++) {
Bookmark b = (Bookmark) bookmarks.get(i);
ModelToXMLConverter.getInstance().convert(bookmarkRoot, b);
public void importXML(Element root) {
this.changed = true;
System.out.println("Bookmarks: Loading from Element"); //$NON-NLS-1$
- Vector newBookmarks = new Vector();
+ importDrivers(root);
+ Vector newBookmarks = importBookmarks(root);
+ this.bookmarks.addAll(newBookmarks);
+ this.support.firePropertyChange("bookmarks", null, null);
+ }
+
+ /**
+ * @param root
+ * @return
+ */
+ private void importDrivers(Element root) {
+ NodeList nodes = root.getElementsByTagName("jdbcDriver"); //$NON-NLS-1$
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Element driver = (Element) nodes.item(i);
+ addDriver(new JDBCDriver(
+ driver.getAttribute("className"),
+ driver.getAttribute("jarFileName"),
+ driver.getAttribute("name"),
+ driver.getAttribute("version")));
+ }
+ }
+
+ /**
+ * @param driver
+ */
+ public void addDriver(JDBCDriver driver) {
+ if (!this.drivers.contains(driver)) {
+ this.drivers.add(driver);
+ this.support.firePropertyChange("drivers", null, driver);
+ }
+ }
+
+ /**
+ * @param root
+ * @return
+ */
+ private Vector importBookmarks(Element root) {
+ Vector newBookmarks = new Vector();
NodeList nodes = root.getElementsByTagName("bookmark"); //$NON-NLS-1$
for (int i = 0; i < nodes.getLength(); i++) {
Bookmark bookmark = new Bookmark();
bookmark.setAutoCommit(Boolean.TRUE.toString().equalsIgnoreCase(
MetaDataXMLInterface.getElementText(column,"autoCommit", "True"))); //$NON-NLS-1$
bookmark.setAutoCommitPreference(MetaDataXMLInterface.getElementText(column,"autoCommitPreference", IQuantumConstants.autoCommitTrue)); //$NON-NLS-1$
- bookmark.setDriver(MetaDataXMLInterface.getElementText(column,"driver")); //$NON-NLS-1$
bookmark.addSchema(MetaDataXMLInterface.getElementText(column,"schema")); //$NON-NLS-1$
bookmark.setType(MetaDataXMLInterface.getElementText(column,"type")); //$NON-NLS-1$
- bookmark.setDriverFile(MetaDataXMLInterface.getElementText(column,"driverLocation")); //$NON-NLS-1$
NodeList children = column.getElementsByTagName(Messages.getString("ExportXMLAction.OtherSchemas"));
+
+ String driverClassName = MetaDataXMLInterface.getElementText(column,"driver"); //$NON-NLS-1$
+ String driverFile = MetaDataXMLInterface.getElementText(column,"driverLocation"); //$NON-NLS-1$
+
+ bookmark.setJDBCDriver(new JDBCDriver(driverClassName, driverFile));
+
if (children.getLength() > 0) {
importSchemas((Element) children.item(0), bookmark);
}
importQuickList(bookmark, column);
importQueryList(bookmark, column);
}
- this.bookmarks.addAll(newBookmarks);
- this.support.firePropertyChange("bookmarks", null, null);
- }
+ return newBookmarks;
+ }
- private void importSchemas(Element otherSchemas, Bookmark bookmark) {
+ private void importSchemas(Element otherSchemas, Bookmark bookmark) {
Vector vector = MetaDataXMLInterface.getVectorText(otherSchemas, Messages.getString("ExportXMLAction.SchemaName"));
List list = new ArrayList();
for (Iterator i = vector.iterator(); i.hasNext();) {
public Bookmark[] getBookmarks() {
return (Bookmark[]) this.bookmarks.toArray(new Bookmark[this.bookmarks.size()]);
}
+
+ public JDBCDriver[] getJDBCDrivers() {
+ return (JDBCDriver[]) this.drivers.toArray(new JDBCDriver[this.drivers.size()]);
+ }
/**
* @return
*/
return copyName;
}
+ /**
+ * @param driver
+ * @param driverFile
+ */
+ public JDBCDriver findDriver(String driverClassName, String driverFile) {
+ JDBCDriver temp = new JDBCDriver(driverClassName, driverFile);
+ return findDriver(temp);
+ }
+
+ /**
+ * @param temp
+ * @return
+ */
+ public JDBCDriver findDriver(JDBCDriver temp) {
+ JDBCDriver result = null;
+ for (Iterator i = this.drivers.iterator(); result == null && i.hasNext();) {
+ JDBCDriver driver = (JDBCDriver) i.next();
+ if (temp.equals(driver)) {
+ result = driver;
+ }
+ }
+ if (result == null) {
+ addDriver(temp);
+ result = temp;
+ }
+ return result;
+ }
+
}
--- /dev/null
+package com.quantum.model;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.sql.Driver;
+
+import com.quantum.util.JarUtil;
+
+
+/**
+ * @author BC
+ */
+public class JDBCDriver {
+ private String name;
+ private String version;
+ private String className;
+ private String jarFileName;
+ private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
+ /**
+ * @param className
+ * @param jarFileName
+ */
+ public JDBCDriver(String className, String jarFileName) {
+ super();
+ this.className = className;
+ this.jarFileName = jarFileName;
+ }
+ /**
+ *
+ */
+ public JDBCDriver() {
+ }
+ /**
+ * @param className
+ * @param jarFileName
+ * @param name
+ * @param version
+ */
+ public JDBCDriver(String className, String jarFileName, String name, String version) {
+ this.name = name;
+ this.version = version;
+ this.className = className;
+ this.jarFileName = jarFileName;
+ }
+ /**
+ * @return Returns the className.
+ */
+ public String getClassName() {
+ return this.className;
+ }
+ /**
+ * @param className The className to set.
+ */
+ public void setClassName(String className) {
+ if (className != null && !className.equals(this.className)) {
+ String original = this.className;
+ this.className = className;
+ this.propertyChangeSupport.firePropertyChange("className", original, className);
+ }
+ }
+ /**
+ * @return Returns the jarFileName.
+ */
+ public String getJarFileName() {
+ return this.jarFileName;
+ }
+ /**
+ * @param jarFileName The jarFileName to set.
+ */
+ public void setJarFileName(String jarFileName) {
+ if (jarFileName != null && !jarFileName.equals(this.jarFileName)) {
+ String original = this.jarFileName;
+ this.jarFileName = jarFileName;
+ this.propertyChangeSupport.firePropertyChange("jarFileName", original, jarFileName);
+ }
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return this.name == null || this.name.trim().length() == 0 ? getClassName() : this.name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ if (name != null && !name.equals(this.name)) {
+ String original = this.name;
+ this.name = name;
+ this.propertyChangeSupport.firePropertyChange("name", original, name);
+ }
+ }
+ /**
+ * @return Returns the version.
+ */
+ public String getVersion() {
+ return this.version;
+ }
+ /**
+ * @param version The version to set.
+ */
+ public void setVersion(String version) {
+ if (version != null && !version.equals(this.version)) {
+ String original = this.version;
+ this.version = version;
+ this.propertyChangeSupport.firePropertyChange("version", original, version);
+ }
+ }
+
+ public boolean equals(Object object) {
+ if (super.equals(object)) {
+ return true;
+ } else if (object == null) {
+ return false;
+ } else if (getClass() != object.getClass()) {
+ return false;
+ } else {
+ JDBCDriver that = (JDBCDriver) object;
+
+ if (this.className == null && that.className != null) {
+ return false;
+ } else if (this.className != null && !this.className.equals(that.className)) {
+ return false;
+ } else if (this.jarFileName == null && that.jarFileName != null) {
+ return false;
+ } else if (this.jarFileName != null && !this.jarFileName.equals(that.jarFileName)) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ }
+ public int hashCode() {
+ int hashCode = 31;
+ if (this.className != null) {
+ hashCode ^= this.className.hashCode();
+ }
+ if (this.jarFileName != null) {
+ hashCode ^= this.jarFileName.hashCode();
+ }
+ return hashCode;
+ }
+
+ public Driver getDriver() {
+ return JarUtil.loadDriver(getJarFileName(), getClassName());
+ }
+ /**
+ * @param listener
+ */
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ this.propertyChangeSupport.addPropertyChangeListener(listener);
+ }
+ /**
+ * @param propertyName
+ * @param listener
+ */
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ this.propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
+ }
+ /**
+ * @param arg0
+ */
+ public void removePropertyChangeListener(PropertyChangeListener arg0) {
+ this.propertyChangeSupport.removePropertyChangeListener(arg0);
+ }
+ /**
+ * @param arg0
+ * @param arg1
+ */
+ public void removePropertyChangeListener(String arg0, PropertyChangeListener arg1) {
+ this.propertyChangeSupport.removePropertyChangeListener(arg0, arg1);
+ }
+}
import com.quantum.adapters.AdapterFactory;
import com.quantum.adapters.DriverInfo;
import com.quantum.model.Bookmark;
+import com.quantum.model.BookmarkCollection;
+import com.quantum.model.JDBCDriver;
import com.quantum.view.bookmark.TreeNode;
import org.eclipse.swt.SWT;
int index = this.type.getSelectionIndex();
bookmark.setType(this.adapters[index].getDriverType());
bookmark.setConnect(this.jdbcURL.getText());
- bookmark.setDriver(this.driverName.getText());
- bookmark.setDriverFile(this.driverPath.getText());
+ JDBCDriver jdbcDriver = BookmarkCollection.getInstance().findDriver(
+ this.driverName.getText(), this.driverPath.getText());
+ bookmark.setJDBCDriver(jdbcDriver);
if (this.autoCommit.getSelectionIndex() >= 0)
bookmark.setAutoCommitPreference(this.autoCommit.getItem(this.autoCommit.getSelectionIndex()));
return super.performOk();
else if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitSaved))
this.autoCommit.select(2);
- this.driverName.setText(bookmark.getDriver());
+ this.driverName.setText(bookmark.getJDBCDriver().getClassName());
this.jdbcURL.setText(bookmark.getConnect());
- this.driverPath.setText(bookmark.getDriverFile());
+ this.driverPath.setText(bookmark.getJDBCDriver().getJarFileName());
}
}
package com.quantum.sql;
import java.io.ByteArrayOutputStream;
-import java.io.File;
import java.io.InputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Driver;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.Hashtable;
import java.util.Properties;
import java.util.Vector;
import com.quantum.model.Bookmark;
import com.quantum.model.ConnectionException;
import com.quantum.model.Entity;
+import com.quantum.model.JDBCDriver;
import com.quantum.model.PasswordFinder;
import com.quantum.sql.metadata.MetaDataJDBCInterface;
import com.quantum.sql.metadata.ObjectMetaData;
public static final String USERNAME = "user"; //$NON-NLS-1$
public static final String PASSWORD = "password"; //$NON-NLS-1$
private static MultiSQLServer instance = null;
- private Hashtable classLoaderCache = new Hashtable();
boolean running = true;
- public MultiSQLServer() {
- //start();
+ private MultiSQLServer() {
}
public synchronized static MultiSQLServer getInstance() {
if (instance == null) {
throws ConnectionException {
LogProxy log = LogProxy.getInstance();
log.addText(LogProxy.QUERY, "Connecting to: " + bookmark.getName()); //$NON-NLS-1$
- URL urls[] = new URL[1];
try {
- String driverFile = bookmark.getDriverFile();
- URLClassLoader loader =
- (URLClassLoader) classLoaderCache.get(driverFile);
- if (loader == null) {
- urls[0] = new File(driverFile).toURL();
- loader = new URLClassLoader(urls);
- classLoaderCache.put(driverFile, loader);
- System.out.println("Creating new classloader"); //$NON-NLS-1$
- } else {
- System.out.println("Using classloader in cache"); //$NON-NLS-1$
- }
- Class driverClass = loader.loadClass(bookmark.getDriver());
- Driver driver = (Driver) driverClass.newInstance();
- Properties props = new Properties();
- props.put(USERNAME, bookmark.getUsername());
- props.put(PASSWORD, password);
- Connection connection =
- driver.connect(bookmark.getConnect(), props);
- if (connection == null) {
- throw new ConnectionException("Error: Driver returned a null connection: " + bookmark.toString()); //$NON-NLS-1$
+ JDBCDriver jdbcDriver = bookmark.getJDBCDriver();
+ Driver driver = jdbcDriver.getDriver();
+ Connection connection = null;
+ if (driver != null) {
+ Properties props = new Properties();
+ props.put(USERNAME, bookmark.getUsername());
+ props.put(PASSWORD, password);
+ connection =
+ driver.connect(bookmark.getConnect(), props);
+ if (connection == null) {
+ throw new ConnectionException("Error: Driver returned a null connection: " + bookmark.toString()); //$NON-NLS-1$
+ }
+
+ DatabaseMetaData metaData = connection.getMetaData();
+ jdbcDriver.setName(metaData.getDriverName());
+ jdbcDriver.setVersion(metaData.getDriverVersion());
+ log.addText(LogProxy.RESULTS, "Connected to: " + bookmark.getName()); //$NON-NLS-1$
+ System.out.println("Connected"); //$NON-NLS-1$
}
- log.addText(LogProxy.RESULTS, "Connected to: " + bookmark.getName()); //$NON-NLS-1$
- System.out.println("Connected"); //$NON-NLS-1$
return connection;
} catch (SQLException e) {
throw new ConnectionException(e);
- } catch (MalformedURLException e) {
- throw new ConnectionException(e);
- } catch (ClassNotFoundException e) {
- throw new ConnectionException(e);
- } catch (InstantiationException e) {
- throw new ConnectionException(e);
- } catch (IllegalAccessException e) {
- throw new ConnectionException(e);
}
}
public SQLResults execute(Connection con, String s) throws SQLException {
--- /dev/null
+package com.quantum.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.sql.Driver;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+
+/**
+ * @author BC Holmes
+ */
+public class JarUtil {
+
+ private static Hashtable classLoaderCache = new Hashtable();
+
+ public static Driver loadDriver(String driverFile, String className) {
+ Driver result = null;
+ try {
+ File file = new File(driverFile);
+ if (file.exists() && file.isFile()) {
+ URLClassLoader loader = getURLClassLoader(file);
+ Class driverClass = loader.loadClass(className);
+ try {
+ result = (Driver) driverClass.newInstance();
+ } catch (ClassCastException e) {
+ }
+ }
+ } catch (MalformedURLException e) {
+ } catch (ClassNotFoundException e) {
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ }
+ return result;
+ }
+
+ public static String[] getAllDriverNames(String driverFile) {
+ List list = new ArrayList();
+ try {
+ File file = new File(driverFile);
+ URLClassLoader loader = getURLClassLoader(file);
+ JarFile jar = new JarFile(file);
+ for (Enumeration e = jar.entries(); e.hasMoreElements(); ) {
+ JarEntry entry = (JarEntry) e.nextElement();
+ String className = getClassNameFromFileName(entry.getName());
+ if (className != null) {
+ try {
+ Class driverClass = loader.loadClass(className);
+ if (Driver.class.isAssignableFrom(driverClass)) {
+ list.add(className);
+ }
+ } catch (ClassNotFoundException ex) {
+ }
+ }
+ }
+ } catch (IOException e) {
+ }
+ return (String[]) list.toArray(new String[list.size()]);
+ }
+
+ private static String getClassNameFromFileName(String name) {
+ String result = null;
+ if (name.endsWith(".class")) {
+ result = name.substring(0, name.length()-6).replace('/', '.').replace('\\', '.' );
+ }
+ return result;
+ }
+
+ /**
+ * @param file
+ * @return
+ * @throws MalformedURLException
+ */
+ private static URLClassLoader getURLClassLoader(File file) throws MalformedURLException {
+ String driverFile = file.getAbsolutePath();
+ URLClassLoader loader =
+ (URLClassLoader) classLoaderCache.get(driverFile);
+ if (loader == null) {
+ URL urls[] = new URL[1];
+ urls[0] = file.toURL();
+ loader = new URLClassLoader(urls);
+ classLoaderCache.put(driverFile, loader);
+ }
+ return loader;
+ }
+}