From: axelcl Date: Sat, 23 Oct 2004 10:51:49 +0000 (+0000) Subject: preparing new release X-Git-Url: http://git.phpeclipse.com?hp=f42d0ef9cab48c6a6f036d3040f99657f96b8539 preparing new release --- diff --git a/archive/net.sourceforge.phpeclipse.css.core/plugin.xml b/archive/net.sourceforge.phpeclipse.css.core/plugin.xml index abcc421..a18283f 100644 --- a/archive/net.sourceforge.phpeclipse.css.core/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.css.core/plugin.xml @@ -3,7 +3,7 @@ diff --git a/archive/net.sourceforge.phpeclipse.css.ui/plugin.xml b/archive/net.sourceforge.phpeclipse.css.ui/plugin.xml index 52e98d0..ac3d48a 100644 --- a/archive/net.sourceforge.phpeclipse.css.ui/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.css.ui/plugin.xml @@ -3,7 +3,7 @@ diff --git a/archive/net.sourceforge.phpeclipse.html.ui/plugin.xml b/archive/net.sourceforge.phpeclipse.html.ui/plugin.xml index b3ae727..a092e3f 100644 --- a/archive/net.sourceforge.phpeclipse.html.ui/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.html.ui/plugin.xml @@ -3,7 +3,7 @@ diff --git a/archive/net.sourceforge.phpeclipse.js.core/plugin.xml b/archive/net.sourceforge.phpeclipse.js.core/plugin.xml index aecad49..0b8e60b 100644 --- a/archive/net.sourceforge.phpeclipse.js.core/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.js.core/plugin.xml @@ -3,7 +3,7 @@ diff --git a/archive/net.sourceforge.phpeclipse.js.ui/plugin.xml b/archive/net.sourceforge.phpeclipse.js.ui/plugin.xml index c2be6b5..8922d35 100644 --- a/archive/net.sourceforge.phpeclipse.js.ui/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.js.ui/plugin.xml @@ -3,7 +3,7 @@ diff --git a/archive/net.sourceforge.phpeclipse.news/plugin.xml b/archive/net.sourceforge.phpeclipse.news/plugin.xml index b503f7f..3f6a712 100644 --- a/archive/net.sourceforge.phpeclipse.news/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.news/plugin.xml @@ -3,7 +3,7 @@ diff --git a/archive/net.sourceforge.phpeclipse.news/src/net/sourceforge/phpeclipse/news/Plugin.java b/archive/net.sourceforge.phpeclipse.news/src/net/sourceforge/phpeclipse/news/Plugin.java index 424e081..37e7b2e 100644 --- a/archive/net.sourceforge.phpeclipse.news/src/net/sourceforge/phpeclipse/news/Plugin.java +++ b/archive/net.sourceforge.phpeclipse.news/src/net/sourceforge/phpeclipse/news/Plugin.java @@ -1,5 +1,6 @@ package net.sourceforge.phpeclipse.news; +import java.io.File; import java.util.ArrayList; import java.util.Iterator; import java.util.Timer; @@ -104,7 +105,10 @@ public class Plugin extends AbstractUIPlugin { */ protected void initializeDefaultPreferences(IPreferenceStore store) { store.setDefault(REFRESH_INTERVAL_PREFERENCE, DEFAULT_REFRESH_INTERVAL); - store.setDefault(BROWSER_PREFERENCE, DEFAULT_BROWSER); + File file = new File(DEFAULT_BROWSER); + if (file.exists()) { + store.setDefault(BROWSER_PREFERENCE, DEFAULT_BROWSER); + } store.setDefault(BANNED_ITEMS_PREFERENCE, DEFAULT_BANNED_ITEMS); store.setDefault(FORCE_CACHE_PREFERENCE, DEFAULT_FORCE_CACHE); } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/big_syn_table.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/big_syn_table.gif new file mode 100644 index 0000000..cae707b Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/big_syn_table.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/checked.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/checked.gif new file mode 100644 index 0000000..00da14e Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/checked.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/foreignkey.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/foreignkey.gif index 983fc91..8bcad0f 100644 Binary files a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/foreignkey.gif and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/foreignkey.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/group.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/group.gif index b1b49a9..79ea8f6 100644 Binary files a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/group.gif and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/group.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/new_bookmark.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/new_bookmark.gif new file mode 100644 index 0000000..83ee11c Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/new_bookmark.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/new_bookmark_wizard.jpg b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/new_bookmark_wizard.jpg new file mode 100644 index 0000000..347cc9d Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/new_bookmark_wizard.jpg differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/unchecked.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/unchecked.gif new file mode 100644 index 0000000..7aa131a Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/unchecked.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.properties b/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.properties index 4991fe1..548c19d 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.properties +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.properties @@ -1,5 +1,5 @@ quantum.name = Quantum DB Utility -perspective.name = Quantum DB +perspective.name = PHP SQL (Quantum) sqllogview.name = Quantum SQL Log driverview.name = JDBC Driver View tableview.name = Quantum Table View diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml b/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml index 107cac6..8ca773a 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml @@ -3,7 +3,7 @@ @@ -13,17 +13,16 @@ - - - - - - + + + + + diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ImageStore.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ImageStore.java index 565de9f..8d3305c 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ImageStore.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ImageStore.java @@ -82,6 +82,7 @@ public class ImageStore { public static final String SUBSET = "subset"; public static final String SUCCESS = "success"; public static final String TABLE = "bigtable"; + public static final String SYNONYM_TABLE = "big_syn_table"; public static final String TABLE_DETAILS = "table_details"; public static final String TEMPLATE = "template"; public static final String TRIGGER = "trigger"; @@ -219,6 +220,7 @@ public class ImageStore { addImage(plugin, registry, url, SUBSET); addImage(plugin, registry, url, SUCCESS); addImage(plugin, registry, url, TABLE); + addImage(plugin, registry, url, SYNONYM_TABLE); addImage(plugin, registry, url, TABLE_DETAILS); addImage(plugin, registry, url, TEMPLATE); addImage(plugin, registry, url, TRIGGER); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumPlugin.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumPlugin.java index 3842086..ab4f399 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumPlugin.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumPlugin.java @@ -12,22 +12,14 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import com.quantum.model.BookmarkCollection; -import com.quantum.util.xml.XMLHelper; -import com.quantum.view.subset.SubsetContentProvider; - import org.eclipse.core.resources.ISavedState; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPluginDescriptor; import org.eclipse.core.runtime.Path; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.graphics.RGB; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; @@ -35,10 +27,15 @@ import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; +import com.quantum.model.BookmarkCollection; +import com.quantum.util.xml.XMLHelper; +import com.quantum.view.subset.SubsetContentProvider; + /** * Main class of the quantum plugin, sets defaults, saves and recovers state. * @author root @@ -57,7 +54,13 @@ public class QuantumPlugin extends AbstractUIPlugin { * @param descriptor */ public QuantumPlugin(IPluginDescriptor descriptor) { - super(descriptor); + this(); + } + /** + * This version is recommended for eclipse3.0 and above + */ + public QuantumPlugin(){ + super(); plugin = this; } @@ -109,9 +112,23 @@ public class QuantumPlugin extends AbstractUIPlugin { /* (non-Javadoc) * @see org.eclipse.core.runtime.Plugin#startup() + * This method is deprecated in Eclipse3.0 we must use start(BundleContext context): + * Migration completed. */ public void startup() throws CoreException { super.startup(); + startupMigrationTempMethod(); // To be removed later + } + + /** + * Used during startup Eclipse3.0 compatible + */ + public void start(BundleContext bundleContext) throws Exception { + super.start(bundleContext); + startupMigrationTempMethod(); // To be removed later + } + private void startupMigrationTempMethod() throws CoreException { + // the contents of this.startup() is moved to here to avoid code duplication - see this.start(BundleContext) ISavedState lastState = ResourcesPlugin.getWorkspace().addSaveParticipant( this, @@ -239,7 +256,8 @@ public class QuantumPlugin extends AbstractUIPlugin { * @throws MalformedURLException */ private URL getIconLocation() throws MalformedURLException { - URL installURL = getDescriptor().getInstallURL(); +// URL installURL = getDescriptor().getInstallURL(); + URL installURL = getBundle().getEntry("/"); return new URL(installURL, "icons/"); } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumResources.properties b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumResources.properties index cb2d1bb..5a7f4ea 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumResources.properties +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumResources.properties @@ -203,6 +203,8 @@ com.quantum.actions.ConnectAction.multiFailureMessage = {0} database(s) successf com.quantum.actions.DisconnectAction.text = Disconnect com.quantum.actions.DisconnectAction.message = Disconnected com.quantum.actions.ViewTableAction.text = View Table +com.quantum.actions.OpenDataEditorAction.text = Edit Table +com.quantum.actions.OpenDataVEditorAction.text = VEdit Table com.quantum.actions.OpenQueryAction.text = Open com.quantum.actions.RefreshBookmarkAction.text = Refresh com.quantum.actions.NextSequenceAction.text = Increment Sequence Value @@ -228,6 +230,7 @@ com.quantum.adapters.DatabaseAdapter.SYBASE = Sybase com.quantum.adapters.DatabaseAdapter.POINTBASE = Pointbase com.quantum.adapters.DatabaseAdapter.JDBC_ODBC_BRIDGE = JDBC-ODBC Bridge com.quantum.adapters.DatabaseAdapter.MS_SQL_SERVER = Microsoft SQL Server +com.quantum.adapters.DatabaseAdapter.DERBY = Apache Derby (Cloudscape) com.quantum.util.connection.ConnectionUtil.title = Connection Not Established com.quantum.util.connection.ConnectionUtil.message = The bookmark could not be connected. @@ -361,6 +364,7 @@ com.quantum.actions.ExecuteAction.text=Execute Against "{0}" com.quantum.actions.ExecuteAction.parsing=Parsing sql script... com.quantum.actions.ExecuteAction.autocommitTitle=Autocommit changed com.quantum.actions.ExecuteAction.autocommitMessage=The autocommit setting of the bookmark, {0} has been changed. +com.quantum.actions.CustomCopyAction.text = Custom Copy com.quantum.view.bookmark.CopyAction.text = Copy com.quantum.view.bookmark.DeleteAction.text = Delete @@ -374,6 +378,7 @@ com.quantum.view.bookmark.PasteAction.text = Paste com.quantum.view.bookmark.QuickListNode.labelName=Quick List com.quantum.view.bookmark.QueryListNode.labelName=Recent SQL Statements com.quantum.view.bookmark.RenameAction.text = Rename +com.quantum.view.bookmark.exportDataCSVAction.text=CSV Format com.quantum.view.bookmark.BookmarkViewActionGroup.sqlAction.text = SQL Statements @@ -388,8 +393,7 @@ com.quantum.view.tableview.NextPageAction.text=Next com.quantum.view.tableview.PreviousPageAction.text=Previous com.quantum.view.tableview.RefreshTableAction.text=Refresh com.quantum.view.tableview.ChangeEncodingAction.default=Default encoding -com.quantum.view.tableview.ChangeEncodingAction.utf8=UTF-8 encoding -com.quantum.view.tableview.ChangeEncodingAction.utf16=UTF-16 encoding +com.quantum.view.tableview.ChangeEncodingAction.encoding=encoding com.quantum.view.tableview.CloseResultSetAction.text=Close Result Set com.quantum.view.tableview.CloseAllResultSetsAction.text=Close All Result Sets com.quantum.view.tableview.CopyAction.text=Copy @@ -401,6 +405,8 @@ com.quantum.view.tableview.TableViewActionGroup.filterSort=Filter and Sort com.quantum.view.tableview.ResultSetViewer.position = {0} to {1} of {2} rows. com.quantum.view.tableview.ResultSetViewer.unknown = +com.quantum.view.tableview.TableViewActionGroup.otherEncodingsAction.text = Other Encodings... + com.quantum.wizards.URLSetupControl.text=JDBC Connection URL com.quantum.wizards.URLSetupControl.hostname=Host name: com.quantum.wizards.URLSetupControl.port=Port: diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/CustomCopyAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/CustomCopyAction.java index 3c0491b..071df6e 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/CustomCopyAction.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/CustomCopyAction.java @@ -7,6 +7,7 @@ package com.quantum.actions; import java.sql.SQLException; import java.util.Iterator; +import com.quantum.Messages; import com.quantum.QuantumPlugin; import com.quantum.model.Column; import com.quantum.model.EntityHolder; @@ -19,22 +20,18 @@ import com.quantum.view.bookmark.ColumnNode; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; -import org.eclipse.ui.IViewPart; import org.eclipse.ui.actions.SelectionListenerAction; public class CustomCopyAction extends SelectionListenerAction { private final int ind; - /** - * @param BookmarkView - */ - public CustomCopyAction(IViewPart view, int ind) { - super(null); + public CustomCopyAction( int ind ) { + super(Messages.getString(CustomCopyAction.class.getName() + ".text")); this.ind = ind; } public void run() { String copyText = ""; - Iterator iter = getSelectedNonResources().iterator(); + Iterator iter = getSelectedNonResources().iterator(); NthLevelConverter converter = new NthLevelConverter(); // Fill up the converter. We iterate the selection items while (iter.hasNext()) { @@ -74,4 +71,5 @@ public class CustomCopyAction extends SelectionListenerAction { new Object[] { copyText }, new Transfer[] { TextTransfer.getInstance()}); } + } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/AdapterFactory.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/AdapterFactory.java index 8ff6821..bd05994 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/AdapterFactory.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/AdapterFactory.java @@ -65,19 +65,20 @@ public class AdapterFactory { public static final String SYBASE = "SYBASE"; //$NON-NLS-1$ public static final String JDBC_ODBC_BRIDGE = "JDBC_ODBC_BRIDGE"; //$NON-NLS-1$ public static final String MS_SQL_SERVER = "MS_SQL_SERVER"; //$NON-NLS-1$ + public static final String DERBY = "DERBY"; //$NON-NLS-1$ private static final Map DRIVER_MAP = Collections.synchronizedMap(new HashMap()); static { DRIVER_MAP.put("com.ddtek.jdbc.informix.InformixDriver", new DriverInfo(INFORMIX)); DRIVER_MAP.put("com.ddtek.jdbc.db2.DB2Driver", new DriverInfo(DB2, "jdbc:datadirect:db2://${hostname}:${port};DatabaseName=${dbname}")); - DRIVER_MAP.put("com.ddtek.jdbc.oracle.OracleDriver", new DriverInfo(ORACLE)); + DRIVER_MAP.put("com.ddtek.jdbc.oracle.OracleDriver", new DriverInfo(ORACLE ,"jdbc:oracle:thin:@{hostname}:{port}:{dbname}")); DRIVER_MAP.put("com.ddtek.jdbc.sqlserver.SQLServerDriver", new DriverInfo(GENERIC)); DRIVER_MAP.put("com.ddtek.jdbc.sybase.SybaseDriver", new DriverInfo(SYBASE)); DRIVER_MAP.put("com.ibm.as400.access.AS400JDBCDriver", new DriverInfo(DB2AS400)); DRIVER_MAP.put("COM.ibm.db2.jdbc.app.DB2Driver", new DriverInfo(DB2, "jdbc:db2:{dbname}")); DRIVER_MAP.put("COM.ibm.db2.jdbc.net.DB2Driver", new DriverInfo(DB2, "jdbc:db2://{hostname}:{port}/{dbname}")); - DRIVER_MAP.put("com.inet.ora.OraDriver", new DriverInfo(ORACLE)); + DRIVER_MAP.put("com.inet.ora.OraDriver", new DriverInfo(ORACLE ,"jdbc:oracle:thin:@{hostname}:{port}:{dbname}")); DRIVER_MAP.put("com.inet.drda.DRDADriver", new DriverInfo(DB2, "jdbc:inetdb2:{hostname}:{port}?database={dbname}")); DRIVER_MAP.put("com.inet.syb.SybDriver", new DriverInfo(SYBASE)); DRIVER_MAP.put("com.inet.tds.TdsDriver", new DriverInfo(MS_SQL_SERVER)); @@ -89,13 +90,18 @@ public class AdapterFactory { DRIVER_MAP.put("com.sybase.jdbc2.jdbc.SybDriver", new DriverInfo(SYBASE, "jdbc:sybase:Tds:{hostname}:{port}/{dbname}")); DRIVER_MAP.put("com.sybase.jdbcx.SybDriver", new DriverInfo(SYBASE, "jdbc:sybase:Tds:{hostname}:{port}/{dbname}")); DRIVER_MAP.put("net.sourceforge.jtds.jdbc.Driver", new DriverInfo(MS_SQL_SERVER)); - DRIVER_MAP.put("oracle.jdbc.driver.OracleDriver", new DriverInfo(ORACLE)); + DRIVER_MAP.put("oracle.jdbc.driver.OracleDriver", new DriverInfo(ORACLE ,"jdbc:oracle:thin:@{hostname}:{port}:{dbname}")); + DRIVER_MAP.put("oracle.jdbc.OracleDriver", new DriverInfo(ORACLE ,"jdbc:oracle:thin:@{hostname}:{port}:{dbname}")); DRIVER_MAP.put("org.gjt.mm.mysql.Driver", new DriverInfo(MYSQL, "jdbc:mysql://{hostname}:{port}/{dbname}")); DRIVER_MAP.put("org.hsqldb.jdbcDriver", new DriverInfo(HSQLDB)); DRIVER_MAP.put("org.postgresql.Driver", new DriverInfo(POSTGRES, "jdbc:postgresql://{hostname}:{port}/{dbname}")); DRIVER_MAP.put("sun.jdbc.odbc.JdbcOdbcDriver", new DriverInfo(JDBC_ODBC_BRIDGE, "jdbc:odbc:{datasource}")); DRIVER_MAP.put("weblogic.jdbc.informix.InformixDriver", new DriverInfo(INFORMIX)); DRIVER_MAP.put("weblogic.jdbc.sqlserver.SybaseDriver", new DriverInfo(SYBASE)); + DRIVER_MAP.put("org.apache.derby.jdbc.driver20", new DriverInfo(DERBY, "jdbc:derby:{dbname}")); + DRIVER_MAP.put("org.apache.derby.jdbc.driver30", new DriverInfo(DERBY, "jdbc:derby:{dbname}")); + DRIVER_MAP.put("org.apache.derby.jdbc.EmbeddedDriver", new DriverInfo(DERBY, "jdbc:derby:{dbname}")); + } private static AdapterFactory instance; @@ -117,6 +123,7 @@ public class AdapterFactory { addAdapter(new GenericAdapter(POINTBASE)); addAdapter(new GenericAdapter(JDBC_ODBC_BRIDGE)); addAdapter(new MSSQLServerAdapter()); + addAdapter(new GenericAdapter(DERBY)); } private void addAdapter(DatabaseAdapter adapter) { this.adapters.put(adapter.getType(), adapter); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DatabaseAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DatabaseAdapter.java index 1917e9f..86472fa 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DatabaseAdapter.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DatabaseAdapter.java @@ -110,9 +110,11 @@ public abstract class DatabaseAdapter { } else if (type == java.sql.Types.DATE || type == java.sql.Types.TIMESTAMP){ string = string.trim(); //Check if we have to strip the millisecods - String sub = string.substring(string.length() - 2, string.length() - 1); - if (string.length() > 1 && sub.equals(".")) //$NON-NLS-1$ - string = string.substring(0, string.length() - 2); // strip the milliseconds + if (string.length() > 2) { + String sub = string.substring(string.length() - 2, string.length() - 1); + if (string.length() > 1 && sub.equals(".")) //$NON-NLS-1$ + string = string.substring(0, string.length() - 2); // strip the milliseconds + } return "'" + string + "'"; //$NON-NLS-1$ //$NON-NLS-2$ @@ -223,4 +225,14 @@ public abstract class DatabaseAdapter { public Map getDefaultConnectionParameters() { return new HashMap(); } + + /** + * Returns the SQL Query to get a list of the Sysnonyms for the current user (schema), of the given type + * @param schema The schema to get the query for + * @param type The type of the synonym to get. Types can be one from the Entity types + * @return - A String with the SQL query + */ + public String getShowSynonymsQuery(String schema, String type) { + return null; + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/OracleAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/OracleAdapter.java index 78d2cce..9ecaa16 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/OracleAdapter.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/OracleAdapter.java @@ -1,5 +1,8 @@ package com.quantum.adapters; +import java.util.HashMap; +import java.util.Map; + import com.quantum.Messages; import com.quantum.util.QuantumUtil; @@ -13,7 +16,7 @@ public class OracleAdapter extends DatabaseAdapter { return "SELECT SEQUENCE_OWNER, SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '" + qualifier + "'"; //$NON-NLS-1$ } public String getPrevValue(String sequence, String owner) { - return "SELECT LAST_NUMBER FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '" + owner + "' AND SEQUENCE_NAME = '" + sequence + "'"; //$NON-NLS-1$ //$NON-NLS-2$ + return "SELECT " + getQualifiedName(owner, sequence) + ".CURRVAL FROM DUAL"; } public String getNextValue(String sequence, String owner) { return "SELECT " + getQualifiedName(owner, sequence) + ".NEXTVAL FROM DUAL"; @@ -34,9 +37,13 @@ public class OracleAdapter extends DatabaseAdapter { public String quote(String string, int type, String typeString) { if (type == java.sql.Types.DATE || type == java.sql.Types.TIMESTAMP) { string = string.trim(); - String sub = string.substring(string.length()-2, string.length()-1); - if (string.length() > 1 && sub.equals(Messages.getString("OracleAdapter.._3"))) //$NON-NLS-1$ - string = string.substring(0,string.length()-2); + // Eliminate the fractions of seconds, if present + if (string.length() > 1) { + // If the third character from the end is a dot, it means it has fractions + String sub = string.substring(string.length()-2, string.length()-1); + if ( sub.equals(Messages.getString("."))) //$NON-NLS-1$ + string = string.substring(0,string.length()-2); + } return "TO_DATE('" + string + "','yyyy-mm-dd hh24:mi:ss')"; //$NON-NLS-1$ //$NON-NLS-2$ } // use the default (upper type) @@ -64,6 +71,24 @@ public class OracleAdapter extends DatabaseAdapter { public String getDefaultSchema(String userid) { return super.getDefaultSchema(userid).toUpperCase(); } - + + public Map getDefaultConnectionParameters() { + Map map = new HashMap(); + map.put("port", "1521"); + map.put("hostname", "localhost"); + return map; + } + + /* (non-Javadoc) + * @see com.quantum.adapters.DatabaseAdapter#getShowSynonymsQuery(java.lang.String, java.lang.String) + */ + public String getShowSynonymsQuery(String schema, String type) { + // The type string is the same as the one needed by Oracle. If it changes a switch would be needed. + return "select SYNONYM_NAME from ALL_SYNONYMS, ALL_OBJECTS where " + + " ALL_SYNONYMS.OWNER = '" + schema + "'" + + " and ALL_SYNONYMS.TABLE_OWNER = ALL_OBJECTS.OWNER" + + " and ALL_SYNONYMS.TABLE_NAME = ALL_OBJECTS.OBJECT_NAME" + + " and ALL_OBJECTS.OBJECT_TYPE = '" + type + "'" ; + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/PostgresAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/PostgresAdapter.java index 90bf17f..c31b5fe 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/PostgresAdapter.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/PostgresAdapter.java @@ -54,19 +54,20 @@ public class PostgresAdapter extends DatabaseAdapter { } public String getTableQuery(String table) { - return "SELECT OID, * FROM " + filterTableName(table); //$NON-NLS-1$ + return "SELECT * FROM " + filterTableName(table); //$NON-NLS-1$ } /** * @see com.quantum.adapters.DatabaseAdapter#filterTableName(java.lang.String) */ public String filterTableName(String tableName) { // If there is no mixed case, better not quote, it's prettier on display - if (tableName.equals(tableName.toUpperCase())) return tableName; - // We quote the table name (and only the table name) because it has mixed case + // Postgresql defaults to lower case identifiers + if (tableName.equals(tableName.toLowerCase())) return tableName; + // We quote the table name because it has mixed case if (QuantumUtil.getSchemaName(tableName).equals("")) { - return "\"" + tableName +"\""; //$NON-NLS-1$ + return "\"" + tableName + "\""; //$NON-NLS-1$ } else { - return QuantumUtil.getSchemaName(tableName) + ".\"" + + return "\"" + QuantumUtil.getSchemaName(tableName) + "\".\"" + QuantumUtil.getTableName(tableName) + "\""; } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Bookmark.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Bookmark.java index 8b3feef..6396940 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Bookmark.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Bookmark.java @@ -356,15 +356,15 @@ public class Bookmark implements Displayable { this.propertyChangeSupport.removePropertyChangeListener(listener); } - public void addQuickListEntry(String type, String schemaName, String name) { - Entity entity = EntityFactory.getInstance().create(this, schemaName, name, type); + public void addQuickListEntry(String type, String schemaName, String name, boolean isSynonym) { + Entity entity = EntityFactory.getInstance().create(this, schemaName, name, type, isSynonym); this.quickList.put(entity.getQualifiedName(), entity); this.propertyChangeSupport.firePropertyChange("quickList", null, null); this.changed = true; } public void addQuickListEntry(Entity entity) { - addQuickListEntry(entity.getType(), entity.getSchema(), entity.getName()); + addQuickListEntry(entity.getType(), entity.getSchema(), entity.getName(), entity.isSynonym()); } public void removeQuickListEntry(Entity entity) { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/BookmarkCollection.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/BookmarkCollection.java index 2f66b2e..873e42e 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/BookmarkCollection.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/BookmarkCollection.java @@ -335,7 +335,7 @@ private static final String SUN_JDBC_ODBC_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver if (Node.ELEMENT_NODE == childNodes.item(k).getNodeType()) { Element entity = (Element) childNodes.item(k); bookmark.addQuickListEntry(entity.getTagName(), - entity.getAttribute("schema"), entity.getAttribute("name")); + entity.getAttribute("schema"), entity.getAttribute("name"), entity.getAttribute("isSynonym").equals("true") ); } } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Column.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Column.java index 53923e4..bccabac 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Column.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Column.java @@ -5,7 +5,7 @@ package com.quantum.model; * @author bcholmes */ public interface Column { - public int getSize(); + public long getSize(); public int getPrimaryKeyOrder(); public boolean isPrimaryKey(); public String getName(); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ColumnImpl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ColumnImpl.java index 7944c2b..66a5674 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ColumnImpl.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ColumnImpl.java @@ -7,7 +7,7 @@ import com.quantum.util.sql.TypesHelper; */ class ColumnImpl implements Column, Comparable { - private int size; + private long size; private boolean nullable; private int primaryKeyOrder; private String name; @@ -19,7 +19,7 @@ class ColumnImpl implements Column, Comparable { private String remarks; ColumnImpl(Entity entity, String name, String typeName, int type, - int size, int numberOfFractionalDigits, boolean nullable, int position, + long size, int numberOfFractionalDigits, boolean nullable, int position, String remarks) { this.entity = entity; @@ -127,7 +127,7 @@ class ColumnImpl implements Column, Comparable { /** * @return */ - public int getSize() { + public long getSize() { return size; } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/DataType.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/DataType.java index 9640df1..5a1620b 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/DataType.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/DataType.java @@ -11,7 +11,7 @@ import com.quantum.util.sql.TypesHelper; public class DataType { private final int javaType; private final String databaseTypeName; - private final int precision; + private final long precision; private final String literalPrefix; private final String literalSuffix; private final String createParameters; @@ -26,7 +26,7 @@ public class DataType { * @param createParameters */ public DataType(final int javaType, final String databaseTypeName, - final int precision, final String literalPrefix, final String literalSuffix, + final long precision, final String literalPrefix, final String literalSuffix, final String createParameters) { super(); this.javaType = javaType; @@ -54,7 +54,7 @@ public class DataType { public String getLiteralSuffix() { return this.literalSuffix; } - public int getPrecision() { + public long getPrecision() { return this.precision; } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Database.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Database.java index 058c48d..29d1993 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Database.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Database.java @@ -167,6 +167,8 @@ public class Database { for (int i = 0; i < types.length; i++) { list.addAll(getEntitiesList(bookmark, connection, types[i], schema)); + // TODO: This should be polished so that synonyms can be shown with different icons as regular Entities + list.addAll(getSynonymsList(bookmark, connection, types[i], schema)); } return (Entity[]) list.toArray(new Entity[list.size()]); @@ -193,7 +195,7 @@ public class Database { tableName = (tableName == null) ? "" : tableName.trim(); if (tableName != null && tableName.length() > 0) { - Entity entity = EntityFactory.getInstance().create(bookmark, tempSchema, tableName, type); + Entity entity = EntityFactory.getInstance().create(bookmark, tempSchema, tableName, type, false); if (entity != null) { list.add(entity); } @@ -225,7 +227,7 @@ public class Database { : results.getElement(2, i).toString(); if (tableName != null && tableName.length() > 0) { Entity entity = EntityFactory.getInstance().create( - bookmark, schemaName, tableName, type); + bookmark, schemaName, tableName, type, false); if (entity != null) { list.add(entity); } @@ -234,6 +236,48 @@ public class Database { } return list; } + /** + * Returns a list with the synonym objects of the given type, using a query + * @param bookmark + * @param connection + * @param type + * @param schema + * @return + * @throws SQLException + */ + protected List getSynonymsList(Bookmark bookmark, Connection connection, String type, Schema schema) + throws SQLException { + + List list = new ArrayList(); + // We try first the JDBC driver + DatabaseMetaData metaData = connection.getMetaData(); + SQLResultSetResults results = null; + // Get the proper sql query to the appropiate type of entity + String sql = this.databaseAdapter.getShowSynonymsQuery(schema.getName(), type); + // If nothing returned, too bad, it seems there is no sql query for that database and entity type + if (sql != null) { + results = (SQLResultSetResults) MultiSQLServer.getInstance().execute( + bookmark, connection, sql, Integer.MAX_VALUE); + for (int i = 1, size = (results == null) ? 0 : results.getRowCount(); i <= size; i++) { + String schemaName = results.getColumnCount() == 1 + ? schema.getName() : results.getElement(1, i).toString(); + if (schemaName != null) { + schemaName = schemaName.trim(); + } + String tableName = results.getColumnCount() == 1 + ? results.getElement(1, i).toString() + : results.getElement(2, i).toString(); + if (tableName != null && tableName.length() > 0) { + Entity entity = EntityFactory.getInstance().create( + bookmark, schemaName, tableName, type, true); + if (entity != null) { + list.add(entity); + } + } + } + } + return list; +} public DataType[] getTypes() throws NotConnectedException, SQLException { DatabaseMetaData metaData = getMetaData(); @@ -244,7 +288,7 @@ public class Database { list.add(new DataType( results.getInt(TYPE_INFO_METADATA_DATA_TYPE), results.getString(TYPE_INFO_METADATA_TYPE_NAME), - results.getInt(TYPE_INFO_METADATA_PRECISION), + results.getLong(TYPE_INFO_METADATA_PRECISION), results.getString(TYPE_INFO_METADATA_LITERAL_PREFIX), results.getString(TYPE_INFO_METADATA_LITERAL_SUFFIX), results.getString(TYPE_INFO_METADATA_CREATE_PARMS) diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Entity.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Entity.java index 66632cc..e4fd8a2 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Entity.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Entity.java @@ -14,6 +14,8 @@ public interface Entity extends BookmarkHolder, Comparable { public String getName(); public String getSchema(); public String getType(); + public boolean isSynonym(); + public Column[] getColumns() throws NotConnectedException, SQLException; public Index[] getIndexes() throws NotConnectedException, SQLException; public Column getColumn(String columnName) throws NotConnectedException, SQLException; diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityFactory.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityFactory.java index de48c0f..f10fd2d 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityFactory.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityFactory.java @@ -17,17 +17,17 @@ public class EntityFactory { return EntityFactory.instance; } - public Entity create(Bookmark bookmark, String schema, String name, String type) { + public Entity create(Bookmark bookmark, String schema, String name, String type, boolean isSynonym) { if (type != null) { type = type.toUpperCase().trim(); } if (Entity.TABLE_TYPE.equals(type)) { - return new TableImpl(bookmark, schema, name); + return new TableImpl(bookmark, schema, name, isSynonym); } else if (Entity.VIEW_TYPE.equals(type)) { - return new ViewImpl(bookmark, schema, name); + return new ViewImpl(bookmark, schema, name, isSynonym); } else if (Entity.SEQUENCE_TYPE.equals(type)) { - return new SequenceImpl(bookmark, schema, name); + return new SequenceImpl(bookmark, schema, name, isSynonym); } else { return null; // throw new IllegalArgumentException("Unknown type: " + type); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityImpl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityImpl.java index 966329a..41ffad2 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityImpl.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityImpl.java @@ -48,12 +48,17 @@ abstract class EntityImpl implements Entity { private String type; private Bookmark bookmark; private Boolean exists = Boolean.TRUE; + private boolean isSynonym = false; // Tells if its a synonym or not + // Columns will be cached in this array, as sometimes asking for them to the JDBC driver is very costy + // (for example in Oracle when synonyms and remarks are asked for ) + private Column[] columns = null; - public EntityImpl(Bookmark bookmark, String schema, String name, String type) { + public EntityImpl(Bookmark bookmark, String schema, String name, String type, boolean isSynonym) { this.schema = schema; this.name = name; this.type = type; this.bookmark = bookmark; + this.isSynonym = isSynonym; } public Bookmark getBookmark() { return this.bookmark; @@ -73,26 +78,28 @@ abstract class EntityImpl implements Entity { } public Column getColumn(String columnName) throws NotConnectedException, SQLException { Column column = null; - Column[] columns = getColumns(); - for (int i = 0, length = (columns == null) ? 0 : columns.length; + if (this.columns == null) this.columns = getColumns(); + for (int i = 0, length = (this.columns == null) ? 0 : this.columns.length; column == null && i < length; i++) { - if (columnName != null && columnName.equals(columns[i].getName())) { - column = columns[i]; + if (columnName != null && columnName.equals(this.columns[i].getName())) { + column = this.columns[i]; } } return column; } public Column[] getColumns() throws NotConnectedException, SQLException { - + if (this.columns != null) return this.columns; Connection connection = this.bookmark.getConnection(); try { - return getColumnsFromMetaData(connection); + this.columns = getColumnsFromMetaData(connection); + return this.columns; } catch (SQLException e) { if (SQLStates.ODBC_DRIVER_NOT_CAPABLE.equals(e.getSQLState()) && AdapterFactory.JDBC_ODBC_BRIDGE.equals( getBookmark().getJDBCDriver().getType())) { - return getColumnsFromQuery(connection); + this.columns = getColumnsFromQuery(connection); + return this.columns; } else { throw e; } @@ -120,10 +127,7 @@ abstract class EntityImpl implements Entity { resultSet.getInt(COLUMN_METADATA_DECIMAL_DIGITS), "YES".equalsIgnoreCase(resultSet.getString(COLUMN_METADATA_IS_NULLABLE)), resultSet.getInt(COLUMN_METADATA_ORDINAL_POSITION), - getComments( - resultSet.getString(COLUMN_METADATA_REMARKS), - getQualifiedName(), - resultSet.getString(COLUMN_METADATA_COLUMN_NAME)) + resultSet.getString(COLUMN_METADATA_REMARKS) ); temp.put(column.getName(), column); } @@ -173,7 +177,7 @@ abstract class EntityImpl implements Entity { (String) rows[i].get(1), (String) rows[i].get(2), ((Integer) rows[i].get(7)).intValue(), - ((Integer) rows[i].get(3)).intValue(), + ((Long) rows[i].get(3)).longValue(), ((Integer) rows[i].get(4)).intValue(), "Nullable".equalsIgnoreCase((String) rows[i].get(5)), i+1, ""); @@ -187,6 +191,11 @@ abstract class EntityImpl implements Entity { * @param iniComment The already got comment * @param tableName The fully qualified table name * @param columnName The column name + * + * NO LONGER USED, there is a parameter (remarksReporting) in the JDBC connection that makes ORACLE return the + * remarks for tables and columns. Is slower, so an option will be used. + * + * The function is kept in case other JDBC drivers have the same problem */ private String getComments( String iniComment, String tableName, String columnName) { if (iniComment != null && iniComment.length() > 0) @@ -298,4 +307,12 @@ abstract class EntityImpl implements Entity { return this.getQualifiedName().compareTo(that.getQualifiedName()); } } + + /** + * @return Returns the isSynonym. + */ + public boolean isSynonym() { + return isSynonym; + } + } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/SequenceImpl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/SequenceImpl.java index 0443906..1b843f5 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/SequenceImpl.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/SequenceImpl.java @@ -1,8 +1,8 @@ package com.quantum.model; class SequenceImpl extends EntityImpl implements Sequence { - public SequenceImpl(Bookmark bookmark, String schema, String name) { - super(bookmark, schema, name, SEQUENCE_TYPE); + public SequenceImpl(Bookmark bookmark, String schema, String name, boolean isSynonym) { + super(bookmark, schema, name, SEQUENCE_TYPE, isSynonym); } public Column[] getColumns() { return new Column[0]; diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/TableImpl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/TableImpl.java index 87e5c85..c0440cc 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/TableImpl.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/TableImpl.java @@ -6,8 +6,8 @@ import com.quantum.sql.MultiSQLServer; class TableImpl extends EntityImpl implements Table { - public TableImpl(Bookmark bookmark, String schema, String name) { - super(bookmark, schema, name, TABLE_TYPE); + public TableImpl(Bookmark bookmark, String schema, String name, boolean isSynonym) { + super(bookmark, schema, name, TABLE_TYPE, isSynonym); } public Integer getSize() { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ViewImpl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ViewImpl.java index 565c2a7..2e85d52 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ViewImpl.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ViewImpl.java @@ -6,8 +6,8 @@ import com.quantum.sql.MultiSQLServer; class ViewImpl extends EntityImpl implements View { - public ViewImpl(Bookmark bookmark, String schema, String name) { - super(bookmark, schema, name, VIEW_TYPE); + public ViewImpl(Bookmark bookmark, String schema, String name, boolean isSynonym) { + super(bookmark, schema, name, VIEW_TYPE, isSynonym); } public Integer getSize() { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/xml/ModelToXMLConverter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/xml/ModelToXMLConverter.java index 075a1ad..e295b03 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/xml/ModelToXMLConverter.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/xml/ModelToXMLConverter.java @@ -101,6 +101,7 @@ public class ModelToXMLConverter { if (entity.getSchema() != null) { element.setAttribute("schema", entity.getSchema()); } + element.setAttribute("isSynonym", entity.isSynonym() ? "true" : "false"); if (recurse) { try { convert(element, entity.getColumns()); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/MultiSQLServer.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/MultiSQLServer.java index 8875a1d..1572da0 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/MultiSQLServer.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/MultiSQLServer.java @@ -9,12 +9,14 @@ import java.sql.Statement; import java.util.Properties; import com.quantum.Messages; +import com.quantum.adapters.AdapterFactory; import com.quantum.adapters.DatabaseAdapter; 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.util.sql.SQLInstructionBuilder; import com.quantum.view.LogProxy; @@ -115,11 +117,26 @@ public class MultiSQLServer implements ConnectionEstablisher { log.addText(LogProxy.QUERY, "Connecting to: " + bookmark.getName()); //$NON-NLS-1$ try { JDBCDriver jdbcDriver = bookmark.getJDBCDriver(); - Driver driver = jdbcDriver.getDriver(); + Driver driver = jdbcDriver.getDriver(); if (driver != null) { Properties props = new Properties(); props.put(USERNAME, bookmark.getUsername()); props.put(PASSWORD, password); + // TODO: This kind of things should really be made general-purpose + if (jdbcDriver.getType().equals(AdapterFactory.ORACLE)){ + // remarksReporting will make the JDBC driver return the remarks for the tables and + // the columns. It'll make getting the tables and columns much slower, so it should + // really be made into an option + // TODO: Make remark reporting into an option + props.put("remarksReporting", "true"); + // includeSynonyms will make the JDBC driver return the proper columns when querying + // about a synonym. If not given, synonyms will appear with no columns, exports of data + // containing synonyms will break, etc.n So it's needed from the moment you add the synonyms + // with the getSynonymsList() in the Database.getEntities() function. That could also be + // made into an option, but more logically when more databases are addedd + // TODO: Make including synonyms into an option + props.put("includeSynonyms", "true"); + } Connection connection = driver.connect(bookmark.getConnect(), props); if (connection == null) { @@ -134,7 +151,7 @@ public class MultiSQLServer implements ConnectionEstablisher { return connection; } else { throw new ConnectionException(Messages.getString( - ConnectionException.class, "couldNotInstaniateDriver", + ConnectionException.class, "couldNotInstantiateDriver", new Object[] { jdbcDriver.getClassName(), bookmark.getName() })); } } catch (SQLException e) { @@ -152,7 +169,7 @@ public class MultiSQLServer implements ConnectionEstablisher { } public SQLResultSetResults getMetaData(Entity entity, Connection connection) throws SQLException { - String query = "SELECT * FROM " + entity.getQuotedTableName() + " WHERE (1 = 0)"; //$NON-NLS-1$ //$NON-NLS-2$ + String query = SQLInstructionBuilder.buildSelectAllColumnsNoRows(entity); SQLResultSetResults results = null; if (connection != null) { Statement statement = connection.createStatement(); @@ -187,7 +204,7 @@ public class MultiSQLServer implements ConnectionEstablisher { long startTime = System.currentTimeMillis(); System.out.println("Executing"); //$NON-NLS-1$ LogProxy log = LogProxy.getInstance(); - log.addText(LogProxy.QUERY, "Executing Request [" + sql + "]"); //$NON-NLS-1$ //$NON-NLS-2$ + log.addText(LogProxy.QUERY, "SQL (" + bookmark.getName() + ") [" + sql + "]"); //$NON-NLS-1$ //$NON-NLS-2$ Statement statement = con.createStatement(); try { SQLResults results; diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLMetaDataResults.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLMetaDataResults.java index 3835511..4f7d988 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLMetaDataResults.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLMetaDataResults.java @@ -57,13 +57,19 @@ public class SQLMetaDataResults extends SQLResultSetResults { Vector row = new Vector(); row.addElement(metaData.getColumnName(i)); row.addElement(metaData.getColumnTypeName(i)); - int precision = metaData.getPrecision(i); + long precision = 0; + try { + precision = metaData.getPrecision(i); + } catch (Throwable t) { + // Do nothing. An exception can be generated by some very large row sizes, like BLOB in Oracle. + // Then getPrecision() will generate an exception. So we ignore it and go on. + } if (precision == 0) { precision = metaData.getColumnDisplaySize(i); } int scale = metaData.getScale(i); - row.addElement(new Integer(precision)); + row.addElement(new Long(precision)); row.addElement(new Integer(scale)); int nullable = metaData.isNullable(i); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLParser.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLParser.java deleted file mode 100644 index f583afa..0000000 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLParser.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.quantum.sql; - -import java.util.Vector; - -import com.quantum.sql.parser.SQLLexx; -import com.quantum.sql.parser.Token; - -public class SQLParser { - - /** - * Parses a query string into executable units. - * @param query - * @return a Vector of Strings, with the individual executable units. - */ - public static Vector parse(String query) { - Vector commands = new Vector(); - Vector groups = new Vector(); - try { - Vector tokens = SQLLexx.parse(query); - StringBuffer buffer = new StringBuffer(); - StringBuffer groupBuffer = new StringBuffer(); - for (int i = 0; i < tokens.size(); i++) { - Token t = (Token) tokens.elementAt(i); - if (t.getType() == Token.COMMENT) { - // ignore comments - } else if (t.getType() == Token.SEPARATOR) { - groupBuffer.append(t.getValue()); - String newCommand = buffer.toString().trim(); - if (!newCommand.equals("")) { //$NON-NLS-1$ - commands.addElement(newCommand); - } - buffer = new StringBuffer(); - } else if (t.getType() == Token.GROUP) { - // We don't append the group token because it may be misinterpreted - //groupBuffer.append(t.getValue()); - String newGroup = groupBuffer.toString().trim(); - if (!newGroup.equals("")) { //$NON-NLS-1$ - groups.addElement(newGroup); - //Groups have precedence over commands, so the preceding commands are erased - commands.clear(); - } - groupBuffer = new StringBuffer(); - } else { - // We append the tokens to the buffer until it's a separator or group. - buffer.append(t.getValue()); - groupBuffer.append(t.getValue()); - } - } - String newCommand = buffer.toString().trim(); - if (!newCommand.equals("")) { //$NON-NLS-1$ - commands.addElement(newCommand); - } - } catch (Throwable e) { - e.printStackTrace(); - } - Vector result = new Vector(); - result.addAll(groups); - result.addAll(commands); - return result; - } -} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLStandardResultSetResults.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLStandardResultSetResults.java index 1a21e00..6d0976d 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLStandardResultSetResults.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLStandardResultSetResults.java @@ -3,6 +3,7 @@ package com.quantum.sql; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.Reader; import java.io.UnsupportedEncodingException; import java.sql.Connection; @@ -91,22 +92,24 @@ public class SQLStandardResultSetResults extends SQLResultSetResults implements List row = new ArrayList(); for (int i = 1, length = columns.size(); i <= length; i++) { String value = null; - if (getColumn(i).getSize() < MAX_COLUMN_WIDTH) { - value = getEncodedString(set, getEncoding(), i); - } else { - try { + try { + if (set.getMetaData().getColumnType(i) == java.sql.Types.LONGVARBINARY) { + value = getEncodedStringFromBinaryStream(set, getEncoding(), i); + } else if (getColumn(i).getSize() < MAX_COLUMN_WIDTH) { + value = getEncodedString(set, getEncoding(), i); + } else { if ("".equals(getEncoding())) { //$NON-NLS-1$ value = getStringFromCharacterSteam(set, i); } else { value = getEncodedStringFromBinaryStream(set, getEncoding(), i); } - } catch (IOException e) { - value = set.getString(i); - } catch (RuntimeException e) { - // hack for mysql which doesn't implement - // character streams - value = set.getString(i); } + } catch (IOException e) { + value = set.getString(i); + } catch (RuntimeException e) { + // hack for mysql which doesn't implement + // character streams + value = set.getString(i); } if (value == null && !set.wasNull()) { value = set.getString(i); @@ -153,7 +156,10 @@ public class SQLStandardResultSetResults extends SQLResultSetResults implements } finally { binaryStream.close(); } - return new String(baos.toByteArray(), encoding); + if ("".equals(encoding)) + return new String(baos.toByteArray()); + else + return new String(baos.toByteArray(), encoding); } else { return null; } @@ -189,7 +195,6 @@ public class SQLStandardResultSetResults extends SQLResultSetResults implements } } - /** * @param set * @param encoding @@ -200,9 +205,12 @@ public class SQLStandardResultSetResults extends SQLResultSetResults implements private String getEncodedString(ResultSet set, String encoding, int index) throws SQLException { try { - return encoding == null || encoding.trim().length() == 0 - ? set.getString(index) - : new String(set.getBytes(index), encoding); + if (encoding == null || encoding.trim().length() == 0) { + return set.getString(index); + } + byte[] colBytes = set.getBytes(index); + if (colBytes == null) return null; + else return new String(colBytes, encoding); } catch (UnsupportedEncodingException e) { return set.getString(index); } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLVirtualResultSet.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLVirtualResultSet.java new file mode 100644 index 0000000..b1fea7a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLVirtualResultSet.java @@ -0,0 +1,234 @@ +/* + * Created on 20.08.2004 + * + * A Virtual Result Set. It's virtual because it doesn't has cache, + * but rather is tightly coupled with its RecordSet object, + * and mainly gives some added functionality, for use in + * virtual tables. It has SQLResults as a superclass mainly + * for conceptual reasons, it could be standalone. + */ +package com.quantum.sql; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import com.quantum.model.Column; +import com.quantum.model.Entity; +import com.quantum.model.NotConnectedException; +import com.quantum.util.StringMatrix; +import com.quantum.util.sql.SQLInstructionBuilder; + +/** + * @author Julen + * + */ +public class SQLVirtualResultSet extends SQLResults { + // The resultSet will be based on a query, that can be changed + private String query = ""; + private ResultSet resultSet = null; + private int knownNumberOfRows = 0; + + + /* (non-Javadoc) + * @see com.quantum.sql.SQLResults#isResultSet() + */ + public SQLVirtualResultSet(Entity entity) { + try { + // Cannot use "SELECT *" because that is not updatable, at least in some JDBC drivers + Initialize(SQLInstructionBuilder.buildSelect(entity, entity.getColumns(), null), + entity.getBookmark().getConnection(), + ResultSet.TYPE_SCROLL_SENSITIVE, + ResultSet.CONCUR_UPDATABLE); + + } catch (NotConnectedException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + public SQLVirtualResultSet(Entity entity, int type, int concurrency) { + try { + // Cannot use "SELECT *" because that is not updatable, at least in some JDBC drivers + Initialize(SQLInstructionBuilder.buildSelect(entity, entity.getColumns(), null), + entity.getBookmark().getConnection(), + type, + concurrency); + + } catch (NotConnectedException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + /** + * @param string + * @param connection + */ + private void Initialize(String query, Connection connection, int type, int concurrency) { + if (connection == null) return; + this.query = query; + try { + Statement statement = connection.createStatement(type, concurrency); + resultSet = statement.executeQuery(query); + // If the recordset is not empty, we know there is at least one row. This call may fall also + // because the recordset is not of the correct type to run isLast, so the resultSet may be valid. + if (!resultSet.isLast()) + knownNumberOfRows = 1; + } catch (SQLException e) { + return; + } + + + } + + public boolean isResultSet() { + return true; + } + + /** + * @return If the resultSet is open, that is, connected to a data source + */ + public boolean isOpen() { + return (resultSet != null); + } + + + /** + * @return Returns the knowNumberOfRows. + */ + public int getKnownNumberOfRows() { + return knownNumberOfRows; + } + /** + * @param index + * @param i + * @return + */ + public String getStringValue(int row, int column) { + if (resultSet == null) return null; + try { + // Rows and columns in resultSets are 1-based + resultSet.absolute(row+1); + actKnownNumberOfRows(); + return resultSet.getString(column+1); + } catch (SQLException e) { + e.printStackTrace(); + return null; + } + } + /** + * + */ + private void actKnownNumberOfRows() { + if (resultSet == null) return; + int nRowsNow; + try { + nRowsNow = resultSet.getRow() + (resultSet.isLast() ? 0 : 1); + knownNumberOfRows = Math.max( nRowsNow, knownNumberOfRows); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /** + * @param index + * @return + */ + public String[] getRowAsStringArray(int row) { + if (resultSet == null) return null; + try { + resultSet.absolute(row+1); + actKnownNumberOfRows(); + return getRowAsStringArray(); + } catch (SQLException e) { + e.printStackTrace(); + return null; + } + } + + /** + * @return + * + */ + public String[] getRowAsStringArray() { + String[] resultArray = null; + int numColumns; + try { + numColumns = resultSet.getMetaData().getColumnCount(); + resultArray = new String[numColumns]; + for (int i = 0; i < numColumns; i++) { + // Rows and columns in resultSets are 1-based + resultArray[i] = resultSet.getString(i+1); + } + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return resultArray; + } + + /** + * + */ + public boolean next(){ + try { + return resultSet.next(); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return false; + } + } + public boolean isLast() { + try { + return resultSet.isLast(); + } catch (SQLException e) { + e.printStackTrace(); + return true; + } + } + /** + * @return Names of the Columns of the ResultSet, in the order given + */ + public String[] getColumnNames() { + if (resultSet == null) return null; + String resultArray[] = null; + try { + int numColumns = resultSet.getMetaData().getColumnCount(); + resultArray = new String[numColumns]; + for (int i = 0; i < numColumns; i++) { + // Rows and columns in resultSets are 1-based + resultArray[i] = resultSet.getMetaData().getColumnName(i+1); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return resultArray; + } + /** + * @param columnIndex + * @param valueStr + */ + public boolean update(int row, int columnIndex, String valueStr) { + if (row < 0 || columnIndex < 0 ) return false; + try { + resultSet.absolute(row+1); + resultSet.updateString(columnIndex+1, valueStr); + resultSet.updateRow(); + return true; + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + + } + public void close(){ + try { + resultSet.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLLexx.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLLexx.java index 543b1ef..8c83886 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLLexx.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLLexx.java @@ -18,9 +18,20 @@ import java.util.Vector; * Lexx TV series. */ public class SQLLexx { - private static String endline = ";"; //$NON-NLS-1$ - private static String dash = "-"; //$NON-NLS-1$ - private static String group = "/"; //$NON-NLS-1$ + private final static char CHAR_EOL = '\n'; + private final static char CHAR_DASH = '-'; + private final static char CHAR_ESCAPE = '\\'; + private final static char CHAR_SEPARATOR = ';'; + + private final static int CONDITION_WHITESPACE = 1; + private final static int CONDITION_IDENTIFIER = 2; + private final static int CONDITION_IDENTIFIER_INITIAL = 3; + private final static int CONDITION_LITERAL_SIMPLE_QUOTE = 4; + private final static int CONDITION_LITERAL_DOUBLE_QUOTE = 5; + private final static int CONDITION_NUMERIC = 6; + private final static int CONDITION_EOL = 7; + + /** * Parses a SQL text into tokens. * @param text @@ -34,124 +45,75 @@ public class SQLLexx { int offset = p.getOffset(); char c = p.getNext(); // Adds END_OF_LINE token - if (c == '\n') { - tokens.addElement(new Token(Token.END_OF_LINE, "\n", offset, offset + 1)); + if (c == CHAR_EOL) { + tokens.addElement(new Token(Token.END_OF_LINE, CHAR_EOL, offset)); } // Adds WHITESPACE token; - else if (Character.isWhitespace(c)) { - StringBuffer value = new StringBuffer(); - while (Character.isWhitespace(c) && !p.isDone()) { - value.append(c); - c = p.getNext(); - } - // done because of is done - if (Character.isWhitespace(c)) { - value.append(c); - } else if (!p.isDone()){ - p.back(); - } + else if (CheckCondition( c, CONDITION_WHITESPACE)) + { + StringBuffer value = AddTokenWhile(p, c, CONDITION_WHITESPACE); tokens.addElement(new Token(Token.WHITESPACE, value.toString(), offset, offset + value.length())); // Adds IDENTIFIER token (can be reserved SQL word or not); - } else if (Character.isLetter(c) || c == '_' || c == '$') { - StringBuffer value = new StringBuffer(); - while ((Character.isLetterOrDigit(c) || c == '_' || c == '$') && !p.isDone()) { - value.append(c); - c = p.getNext(); - } - if ((Character.isLetterOrDigit(c) || c == '_')) { - value.append(c); - } else if (!p.isDone()){ - p.back(); - } + } else if (CheckCondition( c , CONDITION_IDENTIFIER_INITIAL)) + { + StringBuffer value = AddTokenWhile(p, c, CONDITION_IDENTIFIER); tokens.addElement(new Token(Token.IDENTIFIER, value.toString(), offset, offset + value.length())); // Adds LITERAL token; - } else if (c == '\'') { - StringBuffer value = new StringBuffer(); - value.append(c); - if (!p.isDone()) { - c = p.getNext(); - while (c != '\'' && c != '\n' && !p.isDone()) { - value.append(c); - c = p.getNext(); - } - if (c == '\'' || p.isDone()) { - value.append(c); - } else if (!p.isDone()){ - p.back(); - } - } + } else if (CheckCondition(c, CONDITION_LITERAL_SIMPLE_QUOTE)) { + StringBuffer value = AddTokenUntil(p, c, CONDITION_LITERAL_SIMPLE_QUOTE); + tokens.addElement(new Token(Token.LITERAL, value.toString(), offset, offset + value.length())); + // Adds LITERAL token; + } else if (CheckCondition(c, CONDITION_LITERAL_DOUBLE_QUOTE)) { + StringBuffer value = AddTokenUntil(p, c, CONDITION_LITERAL_SIMPLE_QUOTE); tokens.addElement(new Token(Token.LITERAL, value.toString(), offset, offset + value.length())); - // Adds COMMENT token (or SYMBOL (dash) if only one dash); - } else if (c == '-') { - p.mark(); + // Adds NUMERIC token; + } else if (Character.isDigit(c)) { + StringBuffer value = AddTokenWhile(p, c, CONDITION_NUMERIC); + tokens.addElement(new Token(Token.NUMERIC, value.toString(), offset, offset + value.length())); + // Adds COMMENT token if two dashes (or SYMBOL (dash) if only one dash); + } else if (c == CHAR_DASH) { if (p.isDone()) { - tokens.addElement(new Token(Token.SYMBOL, dash, offset, offset + 1)); + tokens.addElement(new Token(Token.SYMBOL, new Character(CHAR_DASH).toString(), offset, offset + 1)); } else { - char next = p.getNext(); - if (next == '-') { - StringBuffer value = new StringBuffer("--"); //$NON-NLS-1$ - if (!p.isDone()) { - c = p.getNext(); - while (c != '\n' && !p.isDone()) { - value.append(c); - c = p.getNext(); - } - if (p.isDone()) { - value.append(c); - } else { - p.back(); - } - } + char next = p.peek(); + if (next == CHAR_DASH) { + StringBuffer value = AddTokenUntil(p, CHAR_DASH, CONDITION_EOL); tokens.addElement(new Token(Token.COMMENT, value.toString(), offset, offset + value.length())); } else { - tokens.addElement(new Token(Token.SYMBOL, dash, offset, offset + 1)); - p.reset(); + tokens.addElement(new Token(Token.SYMBOL, new Character(CHAR_DASH).toString(), offset, offset + 1)); } + } + // Determine if the ';' is escaped or not + } else if (c == CHAR_ESCAPE) { + if (p.peek() == CHAR_SEPARATOR) { + p.getNext(); // We advance the pointer so the separator is not marked again + // We DON´T SAVE the scape character in the tokens. + // For correct sintax highlighting we set the offset to +2 + // This is so far the only case when a character is eliminated and not saved to the tokens. + // That means it won´t be sent to the database when executed. + // This is to allow definitions of procedures with ';' as an end-of-sentence, + // not as an execution symbol for SQL. + tokens.addElement(new Token(Token.SYMBOL, new Character(CHAR_SEPARATOR).toString() , offset, offset + 2)); + } else { + tokens.addElement(new Token(Token.SYMBOL, new Character(CHAR_ESCAPE).toString() , offset, offset + 1)); } // Adds SEPARATOR token (;), considers the rest of the line as COMMENT token; - } else if (c == ';') { - tokens.addElement(new Token(Token.SEPARATOR, endline, offset, offset + 1)); - StringBuffer value = new StringBuffer(); + } else if (c == CHAR_SEPARATOR) { + tokens.addElement(new Token(Token.SEPARATOR, new Character(CHAR_SEPARATOR).toString(), offset, offset + 1)); + // The rest of the line will be a comment if (!p.isDone()) { - c = p.getNext(); - while (c != '\n' && !p.isDone()) { - value.append(c); - c = p.getNext(); - } - if (p.isDone()) { - value.append(c); - } else { - p.back(); - } - // We add to the offset so as to skip the initial ';' + StringBuffer value = AddTokenUntil(p, "", CONDITION_EOL); + // We add to the offset so as to skip the initial ';' offset++; tokens.addElement(new Token(Token.COMMENT, value.toString(), offset, offset + value.length())); } - // Adds NUMERIC token; - } else if (Character.isDigit(c)) { - StringBuffer value = new StringBuffer(); - while ((Character.isDigit(c) || c == '.') && !p.isDone()) { - value.append(c); - c = p.getNext(); - } - if ((Character.isDigit(c) || c == '.')) { - value.append(c); - } else { - p.back(); - } - tokens.addElement(new Token(Token.NUMERIC, value.toString(), offset, offset + value.length())); - // Adds COMMENT token (or GROUP (slash) if only one slash); + // Adds COMMENT token, for several lines; } else if (c == '/') { - p.mark(); // If we have '/*', it's a comment till '*/' found or eof if (p.peek() == '*') { tokens.addElement(tokenizeComment(p, offset)); } else { - // It's not '/*' , so it's a group token - // BCH ??? what's this business about groups? - // Shouldn't '/' be a divide operator? - tokens.addElement(new Token(Token.SYMBOL, new String(new char[] {c}) /*group*/, offset, offset + 1)); - p.reset(); + tokens.addElement(new Token(Token.SYMBOL, new String(new char[] {c}) , offset, offset + 1)); } // Adds SYMBOL token; } else { @@ -169,6 +131,84 @@ public class SQLLexx { return tokens; } /** + * Searchs for a token end, UNTIL the condition is true, or a newline, or the end of the StringPointer + * The end character is also addedd to the StringBuffer + * @param p + * @param s A string with the first character from the token, already extracted from the StringPointer + * @param condition + * @return a StringBuffer with the complete token + */ + private static StringBuffer AddTokenUntil(StringPointer p, String s, int condition) { + StringBuffer value = new StringBuffer(s); + if (p.isDone()) return value; + for(;;) { + char c = p.getNext(); + if (c != CHAR_EOL) value.append(c); + if (CheckCondition (c, condition) || c == CHAR_EOL || p.isDone()) { + break; + } + } + return value; + } + private static StringBuffer AddTokenUntil(StringPointer p, char c, int condition) { + return AddTokenUntil(p, new Character(c).toString(), condition); + } + /** + * Searchs for a token end, WHILE the condition is true, or the end or the StringPointer. + * @param p The StringPointer where the original stream is + * @param s A string with the first character from the token, already extracted from the StringPointer + * @param condition The condition to end the token + * @return a StringBuffer with the complete token + */ + private static StringBuffer AddTokenWhile(StringPointer p, String s, int condition) { + StringBuffer value = new StringBuffer(s); + if (p.isDone()) return value; + for(;;) { + char c = p.getNext(); + if (CheckCondition (c, condition)) { + value.append(c); + if (p.isDone()) break; + } + else + { + p.back(); + break; + } + } + return value; + } + private static StringBuffer AddTokenWhile(StringPointer p, char c, int condition) { + return AddTokenWhile(p, new Character(c).toString(), condition); + } + /** + * Returns true if the character meets the condition, and false if not. + * New conditions should be defined in this function + * @param c The character to check the condition + * @param condition The condition to check + * @return + */ + private static boolean CheckCondition(char c, int condition) { + switch (condition) { + case CONDITION_WHITESPACE: + return Character.isWhitespace(c); + case CONDITION_IDENTIFIER_INITIAL: + return (Character.isLetter(c) || c == '$' || c == '#'); + case CONDITION_IDENTIFIER: + return (Character.isLetter(c) || Character.isDigit(c) || c == '_' || c == '$' || c == '#'); + case CONDITION_LITERAL_SIMPLE_QUOTE: + return (c == '\''); + case CONDITION_LITERAL_DOUBLE_QUOTE: + return (c == '\"'); + case CONDITION_NUMERIC: + return (Character.isDigit(c) || c == '.'); + case CONDITION_EOL: + return (c == CHAR_EOL); + default: + break; + } + return false; + } + /** * @param tokens * @param p * @param offset diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLParser.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLParser.java index 4bb97cb..9911716 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLParser.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLParser.java @@ -28,16 +28,6 @@ public class SQLParser { commands.addElement(newCommand); } buffer = new StringBuffer(); - } else if (t.getType() == Token.GROUP) { - // We don't append the group token because it may be misinterpreted - //groupBuffer.append(t.getValue()); - String newGroup = groupBuffer.toString().trim(); - if (!newGroup.equals("")) { //$NON-NLS-1$ - groups.addElement(newGroup); - //Groups have precedence over commands, so the preceding commands are erased - commands.clear(); - } - groupBuffer = new StringBuffer(); } else { // We append the tokens to the buffer until it's a separator or group. buffer.append(t.getValue()); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/Token.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/Token.java index 438ce5c..d6531ba 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/Token.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/Token.java @@ -8,12 +8,18 @@ public class Token { public static final char COMMENT = 'C'; public static final char WHITESPACE = 'W'; public static final char NUMERIC = 'N'; - public static final char GROUP = 'G'; public static final char END_OF_LINE = 'E'; private char type; private int start; private int end; private String value; + + public Token(char type, char value, int start) { + this.type = type; + this.value = new Character(value).toString(); + this.start = start; + this.end = start + 1; + } public Token(char type, String value, int start, int end) { this.type = type; this.value = value; diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ui/dialog/ExceptionDisplayDialog.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ui/dialog/ExceptionDisplayDialog.java index 51e85dd..888e77e 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ui/dialog/ExceptionDisplayDialog.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ui/dialog/ExceptionDisplayDialog.java @@ -224,7 +224,7 @@ public class ExceptionDisplayDialog extends Dialog { * * @param parentShell - * the parent shell of the dialog, or null if none - * @param dialogTitle the title to use for this dialog, + * @param title the title to use for this dialog, * or null to indicate that the default title should be used * @param message the message to show in this dialog, * or null to indicate that the error's message should be shown diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/StringMatrix.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/StringMatrix.java index d680939..85c6b92 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/StringMatrix.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/StringMatrix.java @@ -9,8 +9,9 @@ import java.util.Vector; /** * @author jparrai * Generic class to hold a Matrix of Strings, that is a Vector of Vectors of Strings. - * The first Vector "line" is supposed to have headers to the values of the rest. + * The first StringMatrix "line" is supposed to have headers to the values of the rest. * Those headers will always be case insensitive + * Rows start at 0 */ public class StringMatrix { private final int DEFAULT_COLUMNS = 10; @@ -94,19 +95,33 @@ public class StringMatrix { matrix.clear(); } /** - * Adds a String to the row indicated, to the column that matches the key + * Adds a String to the row indicated, to the column that matches the key + * The matrix will grow to acomodate the indexes, so be careful * @param value : The string to be added - * @param row : The row to + * @param row : The row to update */ public void addAt(String key, String value, int row) { grow(row); Vector rowVector = (Vector) matrix.get(row); int ind = header.indexOf(key); if (ind < 0) return; - if (rowVector.size() < ind+1) rowVector.setSize(ind); + if (rowVector.size() <= ind) rowVector.setSize(ind); rowVector.add(ind, value); } /** + * Adds a String in the location specified. + * The matrix will grow to acomodate the indexes, so be careful + * @param column Column selected + * @param row row selected + * @param value value to add + */ + public void addAt(int column, int row, String value) { + grow(row); + Vector rowVector = (Vector) matrix.get(row); + if (column >= rowVector.size()) rowVector.setSize(column); + rowVector.add(column, value); + } + /** * Adds a whole vector to the end of the row indicated * @param value : The vector to be added * @param row : The row to @@ -233,11 +248,13 @@ public class StringMatrix { * @param row : 0-index column * @return */ - private String get(int col, int row){ + public String get(int col, int row){ if (col < 0 || row < 0) return null; Vector rowVector = (Vector) matrix.get(row); if (rowVector == null) return null; - return (String) rowVector.get(col); + if (col < rowVector.size()) + return (String) rowVector.get(col); + else return null; } // Generic interfaces @@ -275,14 +292,28 @@ public class StringMatrix { public int size() { return matrix.size(); } + /** + * @return The number of columns of the StringMatrix + */ public int getNumColumns() { return header.size(); } + /** + * @param i + * @return The name of the header column in the "i" position. Null if no such position. + */ public String getHeaderColumn(int i){ - return (String) header.get(i); + if (i < header.size()) + return (String) header.get(i); + return null; } + /** + * Deletes the row number i + * @param i + */ public void deleteRow(int i){ - matrix.remove(i); + if (i < matrix.size()) + matrix.remove(i); } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/sql/SQLInstructionBuilder.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/sql/SQLInstructionBuilder.java new file mode 100644 index 0000000..63ae94e --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/sql/SQLInstructionBuilder.java @@ -0,0 +1,218 @@ +/* + * Created on 12.08.2004 + * + */ +package com.quantum.util.sql; + +import java.sql.SQLException; + +import com.quantum.adapters.DatabaseAdapter; +import com.quantum.model.Bookmark; +import com.quantum.model.Column; +import com.quantum.model.Entity; +import com.quantum.model.NotConnectedException; +import com.quantum.util.StringMatrix; + +/** + * Functions to build SQL instructions adapted to the particular database + * + * @author Julen + */ +public class SQLInstructionBuilder { + + /** + * Generates an Insert SQL instruction for each row of data in an StrigMatrix + * @param entity The entity to generate the instruction for + * @param columns A StringMatrix holding the names and values of the columns to insert + * @return A String with the insert sentences generated + */ + public static String buildInsert(Entity entity, StringMatrix columns) + { + if (entity == null || columns == null ) return ""; + StringBuffer valuesClause = new StringBuffer(); + StringBuffer namesClause = new StringBuffer(); + String insertSentences = ""; + + // We generate an update sentence for each row in the StringMatrix + for (int iRow = 0; iRow < columns.size(); iRow++) { + for (int iCol = 0; iCol < columns.getNumColumns(); iCol++) { + if (iCol > 0) { + namesClause.append(", "); //$NON-NLS-1$ + valuesClause.append(", "); //$NON-NLS-1$ + } + namesClause.append(columns.getHeaderColumn(iCol)); + valuesClause.append(quoteValue( entity, columns.getHeaderColumn(iCol), columns.get(iCol, iRow))); + } + if (iRow > 0) insertSentences += ";\n"; + insertSentences += "INSERT INTO " + entity.getQuotedTableName(); //$NON-NLS-1$ + insertSentences += "(" + namesClause + " )"; //$NON-NLS-1$ + insertSentences += " VALUES " + " ( " + valuesClause + " )" ; //$NON-NLS-1$ + } + return insertSentences; + } + + /** + * Generates an UPDATE SQL instruction for each row of data in an StrigMatrix + * @param entity The entity to generate the instruction for + * @param columns A StringMatrix holding the names and values of the columns to insert + * @param key A StringMatrix holding the names and values of the columns of the key + * @return A String with the insert sentences generated + */ + public static String buildUpdate(Entity entity, StringMatrix columns, StringMatrix key) + { + if (entity == null || columns == null ) return ""; + StringBuffer setClause = new StringBuffer(); + String whereClause = ""; + String updateSentences = ""; + + // We generate an update sentence for each row in the StringMatrix + for (int iRow = 0; iRow < columns.size(); iRow++) { + for (int iCol = 0; iCol < columns.getNumColumns(); iCol++) { + if (iCol > 0) setClause.append(", "); //$NON-NLS-1$ + setClause.append(columns.getHeaderColumn(iCol)); + setClause.append(" = "); //$NON-NLS-1$ + setClause.append(quoteValue( entity, columns.getHeaderColumn(iCol), columns.get(iCol, iRow))); + } + if (key != null && iRow < key.size()) { + whereClause = getWhereClause(entity, key, iRow); + } + if (iRow > 0) updateSentences += ";\n"; + updateSentences += "UPDATE " + entity.getQuotedTableName(); //$NON-NLS-1$ + updateSentences += " SET " + setClause.toString(); //$NON-NLS-1$ + if (whereClause.length() > 0) + updateSentences += " WHERE " + whereClause; //$NON-NLS-1$ + } + return updateSentences; + } + /** + * @param entity + * @param key + * @return + */ + public static String buildDelete(Entity entity, StringMatrix key) + { + if (entity == null ) return ""; + String deleteSentences = ""; + String whereClause = ""; + + // We generate an update sentence for each row in the StringMatrix + if (key == null) return "DELETE FROM " + entity.getQuotedTableName(); //$NON-NLS-1$ + + for (int iRow = 0; iRow < key.size(); iRow++) { + if (key != null && iRow < key.size()) { + whereClause = getWhereClause(entity, key, iRow); + } + if (iRow > 0) deleteSentences += ";\n"; + deleteSentences += "DELETE FROM " + entity.getQuotedTableName(); //$NON-NLS-1$ + if (whereClause.length() > 0) + deleteSentences += " WHERE " + whereClause; //$NON-NLS-1$ + } + return deleteSentences; + } + /** + * Builds a Select query with all columns and no rows (useful for structure querying) + * @param entity + * @return + */ + public static String buildSelectAllColumnsNoRows(Entity entity) { + return "SELECT * FROM " + entity.getQuotedTableName() + " WHERE (1 = 0)"; //$NON-NLS-1$ //$NON-NLS-2$ + } + /** + * Builds a Select query with all columns and no rows (useful for structure querying) + * @param entity + * @return + */ + public static String buildSelectAllColumnsAllRows(Entity entity) { + return "SELECT * FROM " + entity.getQuotedTableName() ; //$NON-NLS-1$ //$NON-NLS-2$ + } + /** + * Builds a Select query with the selected columns and the selected rows (useful for structure querying) + * @param entity + * @param columns Selected columns. + * @param key Selected key and values, in row 0. Only 1 select query will be generated. + * @return + */ + public static String buildSelect(Entity entity, Column[] columns, StringMatrix key) { + if (entity == null || columns == null ) return ""; + StringBuffer columnsList = new StringBuffer(); + String whereClause = ""; + String selectQuery = ""; + + for (int iCol = 0; iCol < columns.length; iCol++) { + if (iCol > 0) columnsList.append(", "); //$NON-NLS-1$ + columnsList.append(columns[iCol].getName()); + } + if (key != null) { + whereClause = getWhereClause(entity, key, 0); + } + selectQuery += "SELECT " + columnsList; //$NON-NLS-1$ + selectQuery += " FROM " + entity.getQuotedTableName(); //$NON-NLS-1$ + if (whereClause.length() > 0) + selectQuery += " WHERE " + whereClause; //$NON-NLS-1$ + + return selectQuery; + + } + + /** + * @param entity The entity to get the where clause for + * @param key A StringMatrix with the colums that form the key and rows with the values + * @param iRow The key to the row that contains the values we are interested in + * @return A String with where clause (without the 'WHERE' reserved word), adapted to the database of the entity + */ + public static String getWhereClause(Entity entity, StringMatrix key, int iRow) { + StringBuffer whereClause = new StringBuffer(); + for (int iKey = 0; iKey < key.getNumColumns(); iKey++) { + if (iKey > 0) whereClause.append(" AND "); //$NON-NLS-1$ + whereClause.append("("); //$NON-NLS-1$ + whereClause.append(key.getHeaderColumn(iKey)); + whereClause.append(" = "); //$NON-NLS-1$ + whereClause.append(quoteValue( entity, key.getHeaderColumn(iKey), key.get(iKey, iRow))); + whereClause.append(")"); //$NON-NLS-1$ + } + return whereClause.toString(); + } + /** + * Default-value function. + * Generates a whereClause adapted to the entity´s database + * with the data of the first row of the StringMatrix (row 0). + * @see com.quantum.util.sql.SQLInstructionBuilder#getWhereClause + */ + public static String getWhereClause(Entity entity, StringMatrix key) { + return getWhereClause(entity, key, 0); + } + + /** + * Quotes the 'value' according with the type of the column and the database + * @param entity Entity + * @param columnName Name of the column in the Entity + * @param value Value of the column, to be quoted + */ + public static String quoteValue(Entity entity, String columnName, String value) { + Bookmark bookmark = entity.getBookmark(); + DatabaseAdapter adapter = bookmark.getAdapter(); + + if (adapter != null && entity != null && getColumn(entity, columnName) != null) { + Column column = getColumn(entity, columnName); + return adapter.quote(value, column.getType(), column.getTypeName()); + } else { + return value; + } +} + /** + * Wrapper function to avoid exception handling + * @param entity The entity that has the column + * @param columnName The column name + * @return A Column object from that entity, with the given name. null if not found or not connected. + */ + public static Column getColumn(Entity entity, String columnName) { + try { + return entity == null ? null : entity.getColumn(columnName); + } catch (NotConnectedException e) { + return null; + } catch (SQLException e) { + return null; + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/sql/TypesHelper.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/sql/TypesHelper.java index 2b39182..b43c227 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/sql/TypesHelper.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/sql/TypesHelper.java @@ -114,7 +114,8 @@ public class TypesHelper { * @return */ public static boolean isText(int type) { - return (type == CLOB || type == VARBINARY || type ==VARCHAR - || type == CHAR || type == LONGVARCHAR ); + return ( type == CHAR || type == VARCHAR || type == LONGVARCHAR + || type == BINARY || type == VARBINARY || type == LONGVARBINARY + || type == CLOB || type == BLOB); } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/versioning/VersioningHelper.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/versioning/VersioningHelper.java index bbc2979..de069b9 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/versioning/VersioningHelper.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/versioning/VersioningHelper.java @@ -15,6 +15,7 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.actions.ExportResourcesAction; +import org.eclipse.ui.actions.ImportResourcesAction; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.part.WorkbenchPart; @@ -112,6 +113,35 @@ public class VersioningHelper { return action; } + public static ImportResourcesAction createImportResourcesAction(IWorkbenchWindow window) { + ImportResourcesAction action = null; + + try { + if (isEclipse21OrHigher()) { + Constructor constructor = ImportResourcesAction.class.getConstructor( + new Class[] { IWorkbenchWindow.class }); + action = (ImportResourcesAction) constructor.newInstance( + new Object[] { window }); + } else { + Constructor constructor = ImportResourcesAction.class.getConstructor( + new Class[] { IWorkbench.class }); + action = (ImportResourcesAction) constructor.newInstance( + new Object[] { window.getWorkbench() }); + } + } catch (NoSuchMethodException e) { + // should not happen + } catch (IllegalArgumentException e) { + // should not happen + } catch (IllegalAccessException e) { + // should not happen + } catch (InvocationTargetException e) { + // should not happen + } catch (InstantiationException e) { + // should not happen + } + return action; + } + public static void registerActionToKeyBindingService( IWorkbenchPartSite site, String[] scopes, IAction action) { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/SQLQueryView.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/SQLQueryView.java index fd3348e..a438d7f 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/SQLQueryView.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/SQLQueryView.java @@ -5,26 +5,6 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.NoSuchElementException; -import java.util.Vector; - -import com.quantum.ImageStore; -import com.quantum.Messages; -import com.quantum.PluginPreferences; -import com.quantum.QuantumPlugin; -import com.quantum.actions.ExecuteAction; -import com.quantum.actions.ExportQueryAction; -import com.quantum.actions.ImportQueryAction; -import com.quantum.editors.ColorManager; -import com.quantum.model.Bookmark; -import com.quantum.model.BookmarkCollection; -import com.quantum.model.NotConnectedException; -import com.quantum.sql.MultiSQLServer; -import com.quantum.sql.SQLGrammar; -import com.quantum.sql.parser.SQLLexx; -import com.quantum.sql.parser.Token; -import com.quantum.ui.dialog.ExceptionDisplayDialog; -import com.quantum.ui.dialog.SQLExceptionDialog; -import com.quantum.util.versioning.VersioningHelper; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IToolBarManager; @@ -42,8 +22,6 @@ import org.eclipse.swt.custom.ExtendedModifyEvent; import org.eclipse.swt.custom.ExtendedModifyListener; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TransferData; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; @@ -56,6 +34,25 @@ import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.part.ViewPart; +import com.quantum.ImageStore; +import com.quantum.Messages; +import com.quantum.PluginPreferences; +import com.quantum.QuantumPlugin; +import com.quantum.actions.ExecuteAction; +import com.quantum.actions.ExportQueryAction; +import com.quantum.actions.ImportQueryAction; +import com.quantum.editors.ColorManager; +import com.quantum.model.Bookmark; +import com.quantum.model.BookmarkCollection; +import com.quantum.model.NotConnectedException; +import com.quantum.sql.MultiSQLServer; +import com.quantum.sql.SQLGrammar; +import com.quantum.sql.parser.SQLLexx; +import com.quantum.sql.parser.Token; +import com.quantum.ui.dialog.ExceptionDisplayDialog; +import com.quantum.ui.dialog.SQLExceptionDialog; +import com.quantum.util.versioning.VersioningHelper; + public class SQLQueryView extends ViewPart { private class ClearAction extends Action { @@ -230,9 +227,6 @@ public class SQLQueryView extends ViewPart { this.executeAction); } - /** - * @param widget2 - */ private void setFont() { FontData font = PreferenceConverter.getFontData( QuantumPlugin.getDefault().getPreferenceStore(), @@ -279,8 +273,21 @@ public class SQLQueryView extends ViewPart { actionBars.getMenuManager().add(this.commitAction); } + /** + * Returns the query to be executed. The query is either 1) the + * text currently highlighted/selected in the editor or 2) all of + * the text in the editor. + * @return query string to be executed + */ public String getQuery() { - return widget.getText(); + String query; + + if (widget.getSelectionText().length() > 0) + query = widget.getSelectionText(); + else + query = widget.getText(); + + return query; } public void setQuery(String text) { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/BookmarkView.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/BookmarkView.java index e266cb4..c4e2e13 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/BookmarkView.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/BookmarkView.java @@ -13,6 +13,7 @@ import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.IOpenListener; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.OpenEvent; import org.eclipse.jface.viewers.StructuredSelection; @@ -183,21 +184,21 @@ public class BookmarkView extends ViewPart implements PropertyChangeListener { IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore(); String text1 = store.getString("customCopyName1"); if (text1 != null && text1.trim().length() > 0) { - this.customCopyAction1 = new CustomCopyAction(this,1); // 1 is unused, just in case more custom copies are defined + this.customCopyAction1 = new CustomCopyAction(1); // 1 is unused, just in case more custom copies are defined this.customCopyAction1.setText(text1); //$NON-NLS-1$ this.customCopyAction1.setImageDescriptor( ImageStore.getImageDescriptor(ImageStore.COPY)); //$NON-NLS-1$ } String text2 = store.getString("customCopyName2"); if (text2 != null && text1.trim().length() > 0) { - this.customCopyAction2 = new CustomCopyAction(this,2); // 1 is unused, just in case more custom copies are defined + this.customCopyAction2 = new CustomCopyAction(2); // 1 is unused, just in case more custom copies are defined this.customCopyAction2.setText(text2); //$NON-NLS-1$ this.customCopyAction2.setImageDescriptor( ImageStore.getImageDescriptor(ImageStore.COPY)); //$NON-NLS-1$ } String text3 = store.getString("customCopyName3"); if (text3 != null && text1.trim().length() > 0) { - this.customCopyAction3 = new CustomCopyAction(this,3); // 1 is unused, just in case more custom copies are defined + this.customCopyAction3 = new CustomCopyAction(3); // 1 is unused, just in case more custom copies are defined this.customCopyAction3.setText(text3); //$NON-NLS-1$ this.customCopyAction3.setImageDescriptor( ImageStore.getImageDescriptor(ImageStore.COPY)); //$NON-NLS-1$ @@ -251,12 +252,15 @@ public class BookmarkView extends ViewPart implements PropertyChangeListener { mgr.add(new Separator()); MenuManager subMenu = new MenuManager(Messages.getString("bookmarkview.customCopyAction")); if (this.customCopyAction1 != null) { + customCopyAction1.selectionChanged(selection); subMenu.add(customCopyAction1); } if (this.customCopyAction2 != null) { + customCopyAction2.selectionChanged(selection); subMenu.add(customCopyAction2); } if (this.customCopyAction3 != null) { + customCopyAction3.selectionChanged(selection); subMenu.add(customCopyAction3); } mgr.add(subMenu); @@ -274,12 +278,15 @@ public class BookmarkView extends ViewPart implements PropertyChangeListener { || this.customCopyAction3 != null)) { MenuManager subMenu = new MenuManager(Messages.getString("bookmarkview.customCopyAction")); if (this.customCopyAction1 != null) { - subMenu.add(customCopyAction1); + customCopyAction1.selectionChanged(selection); + subMenu.add(customCopyAction1); } if (this.customCopyAction2 != null) { + customCopyAction2.selectionChanged(selection); subMenu.add(customCopyAction2); } if (this.customCopyAction3 != null) { + customCopyAction3.selectionChanged(selection); subMenu.add(customCopyAction3); } mgr.add(subMenu); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/BookmarkViewActionGroup.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/BookmarkViewActionGroup.java index 2cd661c..ad120a6 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/BookmarkViewActionGroup.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/BookmarkViewActionGroup.java @@ -17,6 +17,7 @@ import com.quantum.actions.RemoveFromQuickListAction; import com.quantum.actions.ViewTableAction; import com.quantum.actions.ViewTableDetailsAction; import com.quantum.model.Bookmark; +import com.quantum.model.Entity; import com.quantum.util.versioning.VersioningHelper; import org.eclipse.jface.action.Action; @@ -38,6 +39,7 @@ import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.actions.ExportResourcesAction; +import org.eclipse.ui.actions.ImportResourcesAction; import org.eclipse.ui.actions.SelectionListenerAction; import org.eclipse.ui.actions.SelectionProviderAction; import org.eclipse.ui.dialogs.PropertyDialogAction; @@ -111,6 +113,7 @@ public class BookmarkViewActionGroup extends ActionGroup private SelectionListenerAction renameAction; private ExportResourcesAction exportAction; + private ImportResourcesAction importAction; private SelectionProviderAction propertiesAction; @@ -152,6 +155,9 @@ public class BookmarkViewActionGroup extends ActionGroup this.exportAction = VersioningHelper.createExportResourcesAction( this.viewPart.getViewSite().getWorkbenchWindow()); this.exportAction.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.EXPORT)); + this.importAction = VersioningHelper.createImportResourcesAction( + this.viewPart.getViewSite().getWorkbenchWindow()); + this.importAction.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.IMPORT)); this.dropAction = new DropEntityAction(this.viewPart); @@ -199,11 +205,12 @@ public class BookmarkViewActionGroup extends ActionGroup this.exportAction.selectionChanged(getStructuredSelection()); menu.add(this.exportAction); } - - if (getStructuredSelection().size() == 1 && - isEverySelectionInstanceof(BookmarkNode.class)) { + if (this.importAction != null) { + this.importAction.selectionChanged(getStructuredSelection()); + menu.add(this.importAction); } + if (isEverySelectionInstanceof(QueryNode.class)) { if (getStructuredSelection().size() == 1) { addToMenu(menu, this.openQueryAction); @@ -285,6 +292,38 @@ public class BookmarkViewActionGroup extends ActionGroup return result; } + private boolean isEverySelectedGroupOfType(String type) { + boolean result = true; + IStructuredSelection selection = getStructuredSelection(); + for (Iterator i = selection.iterator(); result && i.hasNext(); ) { + Object object = i.next(); + result &= (( object instanceof GroupNode ) && + ((GroupNode)object).getType().equals(type)); + } + + return result; + } + private boolean isEverySelectedEntityTable() { + boolean result = true; + IStructuredSelection selection = getStructuredSelection(); + for (Iterator i = selection.iterator(); result && i.hasNext(); ) { + Object object = i.next(); + result &= (( object instanceof EntityNode ) && + ((EntityNode)object).isTable()); + } + + return result; + } + private boolean isEverySelectedEntityView() { + boolean result = true; + IStructuredSelection selection = getStructuredSelection(); + for (Iterator i = selection.iterator(); result && i.hasNext(); ) { + Object object = i.next(); + result &= (( object instanceof EntityNode ) && + ((EntityNode)object).isView()); + } + return result; + } public IAction getOpenAction() { if (isEverySelectionInstanceof(BookmarkNode.class)) { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/ColumnNode.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/ColumnNode.java index d1f53af..3455de3 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/ColumnNode.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/ColumnNode.java @@ -34,14 +34,14 @@ public class ColumnNode extends TreeNode { String label = getName() + " : " + this.column.getTypeName(); //$NON-NLS-1$ if (this.column.isNumeric()) { if (this.column.getSize() > 0 || this.column.getNumberOfFractionalDigits() > 0) { - label += "(" + Integer.toString(this.column.getSize()); //$NON-NLS-1$ + label += "(" + Long.toString(this.column.getSize()); //$NON-NLS-1$ if (this.column.getNumberOfFractionalDigits() > 0) { label += "," + Integer.toString(this.column.getNumberOfFractionalDigits()); //$NON-NLS-1$ } label += ")"; //$NON-NLS-1$ } } else if (this.column.getSize() > 0) { - label += "(" + Integer.toString(this.column.getSize()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + label += "(" + Long.toString(this.column.getSize()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } return label; } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/EntityNode.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/EntityNode.java index 9d59f71..b45d6b8 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/EntityNode.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/EntityNode.java @@ -126,8 +126,15 @@ public class EntityNode extends TreeNode implements EntityHolder { } else if (isView()) { return "view.gif"; } else { - return (this.entity.exists() == null || this.entity.exists().booleanValue()) - ? "bigtable.gif" : "missingtable.gif"; + if (this.entity.exists() == null || this.entity.exists().booleanValue()){ + if (this.entity.isSynonym()) + return "big_syn_table.gif"; + else + return "bigtable.gif"; + } else + return "missingtable.gif"; + + } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/subset/EntitySubset.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/subset/EntitySubset.java index 853d135..0189a31 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/subset/EntitySubset.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/subset/EntitySubset.java @@ -123,4 +123,11 @@ public class EntitySubset implements Entity { // TODO Auto-generated method stub return null; } + + /* (non-Javadoc) + * @see com.quantum.model.Entity#isSynonym() + */ + public boolean isSynonym() { + return false; + } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/subset/SubsetView.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/subset/SubsetView.java index 09cd2c1..da4ad58 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/subset/SubsetView.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/subset/SubsetView.java @@ -267,7 +267,7 @@ public class SubsetView extends ViewPart { ImageStore.getImageDescriptor(ImageStore.XML)); exportXMLAction.init(this); - this.customCopyAction = new CustomCopyAction(this,1); // 1 is unused, just in case more custom copies are defined + this.customCopyAction = new CustomCopyAction(1); // 1 is unused, just in case more custom copies are defined this.customCopyAction.setText(Messages.getString("bookmarkview.customCopyAction")); //$NON-NLS-1$ this.customCopyAction.setImageDescriptor( ImageStore.getImageDescriptor(ImageStore.COPY)); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ChangeEncodingAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ChangeEncodingAction.java index 713f980..315b733 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ChangeEncodingAction.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ChangeEncodingAction.java @@ -23,8 +23,8 @@ public class ChangeEncodingAction extends ResultSetAction { public ChangeEncodingAction(IViewPart view, ISelectionProvider selectionProvider, String encoding, String key) { super(view, selectionProvider); this.encoding = encoding; - setText(Messages.getString(getClass(), key)); - setToolTipText(Messages.getString(getClass(), key)); + setText(key + " " + Messages.getString(getClass(), "encoding")); + setToolTipText(key + " " + Messages.getString(getClass(), "encoding")); } /* (non-Javadoc) diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BaseSQLPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BaseSQLPage.java index 435f0cc..bdeea07 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BaseSQLPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BaseSQLPage.java @@ -1,7 +1,6 @@ package com.quantum.wizards; import java.sql.SQLException; -import java.util.Arrays; import com.quantum.adapters.DatabaseAdapter; import com.quantum.model.Bookmark; @@ -15,12 +14,9 @@ import com.quantum.ui.dialog.SQLExceptionDialog; import com.quantum.util.connection.ConnectionUtil; import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; /** * @author BC Holmes - * @author Sirkware */ public abstract class BaseSQLPage extends WizardPage implements SQLPage { @@ -74,25 +70,4 @@ public abstract class BaseSQLPage extends WizardPage implements SQLPage { this.results = results; this.row = row; } - - /** - * @param table - * @param colName - * @param style - * @param pos - * @param width - */ - protected void createTableColumn(Table table, String colName, int style, int pos, int width) { - TableColumn column = new TableColumn(table, style, pos); - column.setText(colName); - column.setWidth(width); - } - - /** - * @param columnNames - * @return - */ - protected java.util.List getColumnNamesAsList(String[] columnNames) { - return Arrays.asList(columnNames); - } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java index e76daaf..3acbcfe 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java @@ -225,8 +225,9 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage { boolean complete = true; complete &= (this.connectionURL != null && this.connectionURL.trim().length() > 0); - complete &= (this.userid != null - && this.userid.trim().length() > 0); + // Some databases don't use user id + //complete &= (this.userid != null + // && this.userid.trim().length() > 0); setPageComplete(complete); } /** diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/CommonWizardUI.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/CommonWizardUI.java new file mode 100644 index 0000000..bda7fde --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/CommonWizardUI.java @@ -0,0 +1,72 @@ +package com.quantum.wizards; + +import java.util.Arrays; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; + +/** + * @author Elvin E. Ebora + */ + +public class CommonWizardUI { + + /** + * constructor + */ + public CommonWizardUI() {} + + /** + * Creates a standard Table UI for wizard implementation + * @param composite + * @return Table + */ + protected Table createTablePage(Composite composite) { + int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION; + Table table = new Table(composite, style); + table.setHeaderVisible(true); + table.setLinesVisible(true); + table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING)); + return table; + } + + /** + * Creates a standard TableColumn UI for wizard implementation + * @param table + * @param colName + * @param style + * @param pos + * @param width + */ + protected void createTableColumn(Table table, String colName, int style, int pos, int width) { + TableColumn column = new TableColumn(table, style, pos); + column.setText(colName); + column.setWidth(width); + } + + /** + * Creates a standard GridData UI for wizard implementation + * @param horzSpan + * @param alignment + * @return GridData + */ + protected GridData createGridData(int horzSpan, int alignment) { + GridData gridData = new GridData(); + gridData.horizontalSpan = horzSpan; + gridData.horizontalAlignment = alignment; + gridData.verticalAlignment = alignment; + return gridData; + } + + /** + * Returns a List implementation of an array of string input + * @param columnNames + * @return java.util.List + */ + protected java.util.List getColumnNamesAsList(String[] columnNames) { + return Arrays.asList(columnNames); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/DeleteRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/DeleteRowPage.java index 10d1fda..59e8cf3 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/DeleteRowPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/DeleteRowPage.java @@ -1,28 +1,193 @@ package com.quantum.wizards; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.CheckboxCellEditor; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import com.quantum.ImageStore; import com.quantum.Messages; -import com.quantum.adapters.DatabaseAdapter; -import com.quantum.model.Bookmark; import com.quantum.model.Column; import com.quantum.model.Entity; +import com.quantum.util.StringMatrix; +import com.quantum.util.sql.SQLInstructionBuilder; +/** + * @author BC Holmes + * @author Elvin E. Ebora + */ public class DeleteRowPage extends BaseSQLPage implements SQLPage { + + class DeleteRowPageValues { + private String sColNames = null; + private String sValues = null; + private boolean bPrimary = false; + + public DeleteRowPageValues() { + } + /** + * @return Returns the bPrimary. + */ + public boolean isBPrimary() { + return bPrimary; + } + /** + * @param primary The bPrimary to set. + */ + public void setBPrimary(boolean primary) { + bPrimary = primary; + } + /** + * @return Returns the sColNames. + */ + public String getSColNames() { + return sColNames; + } + /** + * @param colNames The sColNames to set. + */ + public void setSColNames(String colNames) { + sColNames = colNames; + } + /** + * @return Returns the sValues. + */ + public String getSValues() { + return sValues; + } + /** + * @param values The sValues to set. + */ + public void setSValues(String values) { + sValues = values; + } + } + + class LabelProviderImpl implements ITableLabelProvider { + public Image getColumnImage(Object element, int columnIndex) { + if (columnIndex == 2) { + return ((DeleteRowPageValues)element).isBPrimary() ? imgCheck : imgUncheck; + } else { + return null; + } + } + public String getColumnText(Object element, int columnIndex) { + String sReturn = ""; + DeleteRowPageValues deleteRow = (DeleteRowPageValues)element; + switch (columnIndex) { + case 0: // column names + sReturn = deleteRow.getSColNames(); + break; + case 1: // values + sReturn = deleteRow.getSValues(); + break; + case 2: // set checkbox + break; + default: + break; + } + return sReturn; + } + public void addListener(ILabelProviderListener listener) {} + public void dispose() {} + public boolean isLabelProperty(Object element, String property) { + return false; + } + public void removeListener(ILabelProviderListener listener) {} + } + + class ContentProviderImpl implements IStructuredContentProvider { + public Object[] getElements(Object inputElement) { + return deleteTable; + } + + public void dispose() {} + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + } + + class CellModifierImpl implements ICellModifier { + + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + System.out.println("getValue called"); + + // Find the index of the column + int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property); + System.out.println("colIndx : " + colIndx); + + Object rResult = null; + DeleteRowPageValues deleteVal = (DeleteRowPageValues)element; + + switch (colIndx) { + case 0: // column names + rResult = deleteVal.getSColNames(); + break; + case 1: // values + rResult = deleteVal.getSValues(); + break; + case 2: // checkbox + rResult = new Boolean(deleteVal.isBPrimary()); + break; + default: + break; + } + + return rResult; + } + + public void modify(Object element, String property, Object value) { + int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property); + + TableItem item = (TableItem) element; + DeleteRowPageValues deleteVal = (DeleteRowPageValues)item.getData(); + + switch (colIndx) { + case 0: // column names + break; + case 1: // values + deleteVal.setSValues(value.toString()); + break; + case 2: // checkbox + deleteVal.setBPrimary(((Boolean)value).booleanValue()); + break; + default: + break; + } + + updateView(); + updateQuery(); + } + } + String[] columnNames; - Text[] values; - Button[] whereValues; - Text query; + String[] colNames; + Label query; + DeleteRowPageValues[] deleteTable = null; + CommonWizardUI comUI; + TableViewer tableViewer = null; + static Image imgCheck = null; + static Image imgUncheck = null; + + static { + imgCheck = ImageStore.getImage(ImageStore.CHECKED); + imgUncheck = ImageStore.getImage(ImageStore.UNCHECKED); + } public DeleteRowPage(String pageName) { super(pageName); @@ -30,56 +195,34 @@ public class DeleteRowPage extends BaseSQLPage implements SQLPage { public void createControl(Composite parent) { System.out.println("page create control"); //$NON-NLS-1$ - Composite container = new Composite(parent, SWT.V_SCROLL); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - layout.numColumns = 3; + Composite container = new Composite(parent, SWT.NULL); + container.setLayout(new GridLayout()); + container.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING)); Entity entity = this.results.getEntity(); + + comUI = new CommonWizardUI(); + + // init values to be displayed on the table columnNames = this.results.getColumnNames(); - - values = new Text[columnNames.length]; - whereValues = new Button[columnNames.length]; - new Label(container, SWT.NULL).setText(Messages.getString("DeleteRowPage.ColumnName")); //$NON-NLS-1$ - new Label(container, SWT.NULL).setText(Messages.getString("DeleteRowPage.Value")); //$NON-NLS-1$ - new Label(container, SWT.NULL).setText(Messages.getString("DeleteRowPage.IncludeIn")); //$NON-NLS-1$ - for (int i = 0; i < columnNames.length; i++) { - Label label = new Label(container, SWT.NULL); - label.setText(columnNames[i]); - values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - Object object = this.row == null ? null : this.row.get(i+1); - values[i].setText(object == null ? "" : object.toString()); - GridData gridData = new GridData(GridData.FILL_HORIZONTAL); - gridData.widthHint = 150; - values[i].setLayoutData(gridData); - values[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent event) { - updateQuery(); - } - }); - - whereValues[i] = new Button(container, SWT.CHECK); - whereValues[i].setText(Messages.getString("DeleteRowPage.WhereClause")); //$NON-NLS-1$ - // we check if it's a primary key to select it in the WHERE clause - Column column = getColumn(entity, columnNames[i]); - whereValues[i].setSelection(column == null ? false : column.isPrimaryKey()); - whereValues[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); + int nLen = columnNames.length; + deleteTable = new DeleteRowPageValues[nLen]; + + for(int nCtr=0; nCtr 0) whereClause.append(" AND "); //$NON-NLS-1$ - numSelected++; - whereClause.append("("); //$NON-NLS-1$ - whereClause.append(columnNames[i]); - whereClause.append(" = "); //$NON-NLS-1$ - appendColumn(whereClause, entity, columnNames[i], adapter, values[i].getText()); - whereClause.append(")"); //$NON-NLS-1$ + if (deleteTable[i].isBPrimary()) { + key.addHeader( deleteTable[i].getSColNames() ); + key.add( deleteTable[i].getSValues() , 0 ); } } - String query = "DELETE FROM " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$ - if (numSelected > 0) { - query += " WHERE " + whereClause.toString(); //$NON-NLS-1$ - } - if (numSelected > 0) { - setMessage(""); //$NON-NLS-1$ - } else { - setMessage(Messages.getString("DeleteRowPage.WarningNoWhere")); //$NON-NLS-1$ - } - this.query.setText(query); + this.query.setText(SQLInstructionBuilder.buildDelete(this.results.getEntity(), key)); } protected String getQueryText() { return query.getText(); } + + private void updateView() { + this.tableViewer.update(deleteTable, null); + } + + private void createTable(Composite composite) { + System.out.println("Creating table..."); + Table table = comUI.createTablePage(composite); + colNames = new String[] { Messages.getString("DeleteRowPage.ColumnName"), Messages.getString("DeleteRowPage.Value"), "Where" }; + + comUI.createTableColumn(table, colNames[0], SWT.LEFT, 0, 150); + comUI.createTableColumn(table, colNames[1], SWT.LEFT, 1, 300); + comUI.createTableColumn(table, colNames[2], SWT.CENTER, 2, 60); + this.tableViewer = new TableViewer(table); + this.tableViewer.setColumnProperties(colNames); + + CellEditor[] editor = new CellEditor[colNames.length]; + TextCellEditor txtEditorField = new TextCellEditor(table); + txtEditorField.getControl().setEnabled(false); + editor[0] = txtEditorField; + + TextCellEditor txtEditorFieldValue = new TextCellEditor(table); + editor[1] = txtEditorFieldValue; + + editor[2] = new CheckboxCellEditor(table, SWT.NULL); + + this.tableViewer.setCellEditors(editor); + this.tableViewer.setLabelProvider(new LabelProviderImpl()); + this.tableViewer.setContentProvider(new ContentProviderImpl()); + this.tableViewer.setCellModifier(new CellModifierImpl()); + this.tableViewer.setInput(deleteTable); + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/InsertRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/InsertRowPage.java index f25054d..7cb600d 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/InsertRowPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/InsertRowPage.java @@ -1,7 +1,5 @@ package com.quantum.wizards; -import java.util.Arrays; - import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ICellModifier; import org.eclipse.jface.viewers.ILabelProviderListener; @@ -11,24 +9,22 @@ import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TextCellEditor; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Text; import com.quantum.Messages; -import com.quantum.adapters.DatabaseAdapter; -import com.quantum.model.Bookmark; -import com.quantum.model.Entity; -import com.quantum.sql.SQLResultSetResults; +import com.quantum.util.StringMatrix; +import com.quantum.util.sql.SQLInstructionBuilder; +/** + * @author BC Holmes + * @author Elvin E. Ebora + */ public class InsertRowPage extends BaseSQLPage implements SQLPage { class InsertRowTableValues { @@ -109,7 +105,7 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage { System.out.println("getValue called"); // Find the index of the column - int colIndx = getColumnNamesAsList(colNames).indexOf(property); + int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property); System.out.println("colIndx : " + colIndx); Object rResult = null; @@ -131,7 +127,7 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage { } public void modify(Object element, String property, Object value) { - int colIndx = getColumnNamesAsList(colNames).indexOf(property); + int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property); TableItem item = (TableItem) element; InsertRowTableValues insertVal = (InsertRowTableValues)item.getData(); @@ -152,9 +148,9 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage { String[] columnNames; String[] colNames; - Text[] values; Label query; InsertRowTableValues[] insertTable = null; + CommonWizardUI comUI; TableViewer tableViewer = null; int numColumns = 0; @@ -167,6 +163,8 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage { Composite container = new Composite(parent, SWT.NULL); container.setLayout(new GridLayout()); container.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING)); + + comUI = new CommonWizardUI(); // init values to be displayed on the table columnNames = this.results.getColumnNames(); @@ -182,11 +180,7 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage { createTable(container); query = new Label(container, SWT.WRAP); - GridData gridData = new GridData(); - gridData.horizontalSpan = 1; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - query.setLayoutData(gridData); + query.setLayoutData(comUI.createGridData(1, GridData.FILL)); setControl(container); updateQuery(); @@ -195,34 +189,13 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage { } public void updateQuery() { System.out.println("Updating query"); //$NON-NLS-1$ - StringBuffer valuesClause = new StringBuffer(); - StringBuffer namesClause = new StringBuffer(); - Bookmark bookmark = this.results.getBookmark(); - Entity entity = this.results.getEntity(); - DatabaseAdapter adapter = bookmark.getAdapter(); - numColumns = 0; + StringMatrix columns = new StringMatrix(); for (int i = 0; i < columnNames.length; i++) { - String name = insertTable[i].getColNames(); - String value = insertTable[i].getValues(); - if (value != null && value.length() > 0) { - if (numColumns > 0) { - valuesClause.append(", "); //$NON-NLS-1$ - namesClause.append(", "); - } - appendColumn(valuesClause, entity, name, adapter, value); - namesClause.append(name); - numColumns++; - } + columns.addHeader( insertTable[i].getColNames() ); + columns.add( insertTable[i].getValues() , 0 ); } - - String query = "INSERT INTO " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$ - if (numColumns > 0) { - query += " (" + namesClause + ")"; - query += " VALUES " + "(" + valuesClause; //$NON-NLS-1$ - query += " )"; //$NON-NLS-1$ - } - this.query.setText(query); + this.query.setText(SQLInstructionBuilder.buildInsert(this.results.getEntity(), columns)); } /* (non-Javadoc) * @see com.quantum.wizards.BaseSQLPage#getQueryText() @@ -233,16 +206,11 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage { private void createTable(Composite composite) { System.out.println("Creating table..."); - int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION; - Table table = new Table(composite, style); - table.setHeaderVisible(true); - table.setLinesVisible(true); - table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING)); - + Table table = comUI.createTablePage(composite); colNames = new String[] { Messages.getString("InsertRowPage.ColumnName"), Messages.getString("InsertRowPage.Value") }; - createTableColumn(table, colNames[0], SWT.LEFT, 0, 200); - createTableColumn(table, colNames[1], SWT.LEFT, 1, 500); + comUI.createTableColumn(table, colNames[0], SWT.LEFT, 0, 200); + comUI.createTableColumn(table, colNames[1], SWT.LEFT, 1, 500); this.tableViewer = new TableViewer(table); this.tableViewer.setColumnProperties(colNames); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SortFilterPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SortFilterPage.java index e0500bd..0c6b9b4 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SortFilterPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SortFilterPage.java @@ -2,164 +2,356 @@ package com.quantum.wizards; import java.sql.SQLException; +import com.quantum.ImageStore; +import com.quantum.model.Column; +import com.quantum.model.Entity; +import com.quantum.model.NotConnectedException; import com.quantum.sql.FilterSort; import com.quantum.sql.SQLResultSetResults; import com.quantum.ui.dialog.SQLExceptionDialog; import com.quantum.util.connection.ConnectionUtil; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.CheckboxCellEditor; +import org.eclipse.jface.viewers.ComboBoxCellEditor; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; public class SortFilterPage extends WizardPage implements SQLPage { - Button[] filter; - Combo[] operator; - Text[] filterValues; - Button[] stringFlags; - Button[] sort; - Combo[] ascDesc; - private SQLResultSetResults.Row row; + class SortFilterTableValues { + private String colNames = null; + private boolean isWhere = false; + private String operators = ""; + private String values = null; + private boolean isString = false; + private boolean isOrderBy = false; + private String sorter = ""; + + /** + * @return Returns the isOrderBy. + */ + public boolean isOrderBy() { + return isOrderBy; + } + /** + * @param isOrderBy The isOrderBy to set. + */ + public void setOrderBy(boolean isOrderBy) { + this.isOrderBy = isOrderBy; + } + /** + * @return Returns the isString. + */ + public boolean isString() { + return isString; + } + /** + * @param isString The isString to set. + */ + public void setString(boolean isString) { + this.isString = isString; + } + /** + * @return Returns the isWhere. + */ + public boolean isWhere() { + return isWhere; + } + /** + * @param isWhere The isWhere to set. + */ + public void setWhere(boolean isWhere) { + this.isWhere = isWhere; + } + /** + * @return Returns the operators. + */ + public String getOperators() { + return operators; + } + /** + * @param operators The operators to set. + */ + public void setOperators(String operators) { + this.operators = operators; + } + /** + * @return Returns the sorter. + */ + public String getSorter() { + return sorter; + } + /** + * @param sorter The sorter to set. + */ + public void setSorter(String sorter) { + this.sorter = sorter; + } + /** + * @return Returns the values. + */ + public String getValues() { + return values; + } + /** + * @param values The values to set. + */ + public void setValues(String values) { + this.values = values; + } + /** + * @return Returns the colNames. + */ + public String getColNames() { + return colNames; + } + /** + * @param colNames The colNames to set. + */ + public void setColNames(String colNames) { + this.colNames = colNames; + } + } + + class LabelProviderImpl implements ITableLabelProvider { + public Image getColumnImage(Object element, int columnIndex) { + if (columnIndex == 0) { + return ((SortFilterTableValues)element).isWhere() ? imgCheck : imgUncheck; + } else if (columnIndex == 3) { + return ((SortFilterTableValues)element).isString() ? imgCheck : imgUncheck; + } else if (columnIndex == 4) { + return ((SortFilterTableValues)element).isOrderBy() ? imgCheck : imgUncheck; + } else { + return null; + } + } + public String getColumnText(Object element, int columnIndex) { + String sReturn = ""; + SortFilterTableValues sortFilterRow = (SortFilterTableValues)element; + + switch (columnIndex) { + case 0: // isWhere + sReturn = sortFilterRow.getColNames(); + break; + case 1: // operators + sReturn = sortFilterRow.getOperators(); + break; + case 2: // values + sReturn = sortFilterRow.getValues(); + break; + case 3: // isString + break; + case 4: // isOrderBy + sReturn = sortFilterRow.getColNames(); + break; + case 5: // sorter + sReturn = sortFilterRow.getSorter(); + break; + default: + break; + } + return sReturn; + } + public void addListener(ILabelProviderListener listener) {} + public void dispose() {} + public boolean isLabelProperty(Object element, String property) { + return false; + } + public void removeListener(ILabelProviderListener listener) {} + } + + class ContentProviderImpl implements IStructuredContentProvider { + public Object[] getElements(Object inputElement) { + return sortFilterValues; + } + + public void dispose() {} + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + } + + class CellModifierImpl implements ICellModifier { + + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + System.out.println("getValue called"); + + // Find the index of the column + int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property); + System.out.println("colIndx : " + colIndx); + + Object rResult = null; + SortFilterTableValues sortFilterVal = (SortFilterTableValues)element; + + switch (colIndx) { + case 0: // isWhere + rResult = new Boolean(sortFilterVal.isWhere()); + break; + case 1: // operators + String sTemp = sortFilterVal.getOperators(); + int nIndex = comUI.getColumnNamesAsList(oper).indexOf(sTemp); + rResult = new Integer(nIndex); + break; + case 2: // values + rResult = sortFilterVal.getValues(); + break; + case 3: // isString + rResult = new Boolean(sortFilterVal.isString()); + break; + case 4: // isOrderBy + rResult = new Boolean(sortFilterVal.isOrderBy()); + break; + case 5: // sorter + String sTemp2 = sortFilterVal.getSorter(); + int nIndx = comUI.getColumnNamesAsList(order).indexOf(sTemp2); + rResult = new Integer(nIndx); + break; + default: + rResult = ""; + break; + } + + return rResult; + } + + public void modify(Object element, String property, Object value) { + int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property); + + TableItem item = (TableItem) element; + SortFilterTableValues sortFilterVal = (SortFilterTableValues)item.getData(); + + switch (colIndx) { + case 0: // isWhere + sortFilterVal.setWhere(((Boolean)value).booleanValue()); + break; + case 1: // operators + int nIdx = ((Integer)value).intValue(); + if (nIdx != -1) + sortFilterVal.setOperators(oper[nIdx]); + else + sortFilterVal.setOperators(""); + + break; + case 2: // values + sortFilterVal.setValues(value.toString()); + break; + case 3: // isString + sortFilterVal.setString(((Boolean)value).booleanValue()); + break; + case 4: // isOrderBy + sortFilterVal.setOrderBy(((Boolean)value).booleanValue()); + break; + case 5: // sorter + int nId = ((Integer)value).intValue(); + if (nId != -1) + sortFilterVal.setSorter(order[nId]); + else + sortFilterVal.setSorter(""); + + break; + default: + break; + } + + updateView(); + updateQuery(); + } + } + + private SQLResultSetResults.Row row; private ConnectionUtil connectionUtil = new ConnectionUtil(); + CommonWizardUI comUI; + SortFilterTableValues[] sortFilterValues; + TableViewer tableViewer = null; + static Image imgCheck = null; + static Image imgUncheck = null; String columnNames[]; Label query; FilterSort filterSort = new FilterSort(); private SQLResultSetResults results; + + static { + imgCheck = ImageStore.getImage(ImageStore.CHECKED); + imgUncheck = ImageStore.getImage(ImageStore.UNCHECKED); + } + + // constant declarations + String[] colNames = new String[] { "Where", "Operator", "Values", "Is String", "Order By", "Sorter" }; + String[] oper = new String[] { "=", "<>", "<", ">" }; + String[] order = new String[] { "", "ASC", "DESC" }; + public SortFilterPage(String pageName) { super(pageName); } public void init(SQLResultSetResults results, SQLResultSetResults.Row row) { this.results = results; - this.row = row; + this.row = row; } public void createControl(Composite parent) { System.out.println("page create control"); //$NON-NLS-1$ - + Composite container = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - int layoutColumns = 6; - layout.numColumns = layoutColumns; - - columnNames = this.results.getColumnNames(); + container.setLayout(new GridLayout()); + container.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING)); - int size = this.results.getColumnCount(); - filter = new Button[size]; - operator = new Combo[size]; - filterValues = new Text[size]; - stringFlags = new Button[size]; - sort = new Button[size]; - ascDesc = new Combo[size]; - for (int i = 0; i < size; i++) { - filter[i] = new Button(container, SWT.CHECK); - filter[i].setText(columnNames[i]); - filter[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - - operator[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY); - operator[i].add("="); //$NON-NLS-1$ - operator[i].add("<>"); //$NON-NLS-1$ - operator[i].add("<"); //$NON-NLS-1$ - operator[i].add(">"); //$NON-NLS-1$ - operator[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - - filterValues[i] = new Text(container, SWT.BORDER); - Object data = this.row == null ? null : this.row.get(i+1); - filterValues[i].setText(data == null ? "" : data.toString()); - filterValues[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateQuery(); - } - }); - - stringFlags[i] = new Button(container, SWT.CHECK); - stringFlags[i].setText("String"); //$NON-NLS-1$ - stringFlags[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); + comUI = new CommonWizardUI(); + + columnNames = this.results.getColumnNames(); + int nLen = columnNames.length; + sortFilterValues = new SortFilterTableValues[nLen]; + + for (int nCtr = 0; nCtr < nLen; nCtr++) { + sortFilterValues[nCtr] = new SortFilterTableValues(); + sortFilterValues[nCtr].setColNames(columnNames[nCtr]); - final int index = i; - sort[i] = new Button(container, SWT.CHECK); - sort[i].setText(columnNames[i]); - sort[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - if (sort[index].getSelection()) { - filterSort.addSort(columnNames[index], ascDesc[index].getText()); - } else { - filterSort.removeSort(columnNames[index]); - } - updateQuery(); - } - }); - - ascDesc[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY); - ascDesc[i].add(""); //$NON-NLS-1$ - ascDesc[i].add("ASC"); //$NON-NLS-1$ - ascDesc[i].add("DESC"); //$NON-NLS-1$ - ascDesc[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - if (sort[index].getSelection()) { - filterSort.addSort(columnNames[index], ascDesc[index].getText()); - } else { - filterSort.removeSort(columnNames[index]); - } - updateQuery(); - } - }); + Object data = this.row == null ? null : this.row.get(nCtr+1); + sortFilterValues[nCtr].setValues(data == null ? "" : data.toString()); } + + createTable(container); + query = new Label(container, SWT.WRAP); - GridData gridData = new GridData(); - gridData.horizontalSpan = layoutColumns; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - query.setLayoutData(gridData); + query.setLayoutData(comUI.createGridData(1, GridData.FILL)); - setControl(container); - + setControl(container); setPageComplete(true); } public void updateQuery() { filterSort.clearFilters(); - for (int i = 0; i < filter.length; i++) { - if (filter[i].getSelection()) { - filterSort.addFilter(filter[i].getText(), operator[i].getText(), filterValues[i].getText(), stringFlags[i].getSelection()); + + int nLen = columnNames.length; + for (int nCtr = 0; nCtr < nLen; nCtr++) { + if (sortFilterValues[nCtr].isWhere()) { + filterSort.addFilter(columnNames[nCtr], sortFilterValues[nCtr].getOperators(), sortFilterValues[nCtr].getValues(), sortFilterValues[nCtr].isString()); + } + if (sortFilterValues[nCtr].isOrderBy()) { + filterSort.addSort(columnNames[nCtr], sortFilterValues[nCtr].getSorter()); + } else { + filterSort.removeSort(columnNames[nCtr]); } } + query.setText(filterSort.toString()); } @@ -174,4 +366,59 @@ public class SortFilterPage extends WizardPage implements SQLPage { return false; } } + + private void updateView() { + this.tableViewer.update(sortFilterValues, null); + } + + /** + * @param entity + * @param columnName + * @return + * @throws NotConnectedException + * @throws SQLException + */ + protected Column getColumn(Entity entity, String columnName) { + try { + return entity == null ? null : entity.getColumn(columnName); + } catch (NotConnectedException e) { + return null; + } catch (SQLException e) { + return null; + } + } + + private void createTable(Composite composite) { + System.out.println("Creating table..."); + Table table = comUI.createTablePage(composite); + + comUI.createTableColumn(table, colNames[0], SWT.LEFT, 0, 150); // isWhere + comUI.createTableColumn(table, colNames[1], SWT.CENTER, 1, 70); // operator + comUI.createTableColumn(table, colNames[2], SWT.LEFT, 2, 150); // values + comUI.createTableColumn(table, colNames[3], SWT.LEFT, 3, 70); // isString + comUI.createTableColumn(table, colNames[4], SWT.LEFT, 4, 150); // isOrderBy + comUI.createTableColumn(table, colNames[5], SWT.CENTER, 5, 70); // sorter + this.tableViewer = new TableViewer(table); + this.tableViewer.setColumnProperties(colNames); + + CellEditor[] editor = new CellEditor[colNames.length]; + + editor[0] = new CheckboxCellEditor(table, SWT.NULL); + + editor[1] = new ComboBoxCellEditor(table, oper, SWT.READ_ONLY); + + editor[2] = new TextCellEditor(table); + + editor[3] = new CheckboxCellEditor(table, SWT.NULL); + + editor[4] = new CheckboxCellEditor(table, SWT.NULL); + + editor[5] = new ComboBoxCellEditor(table, order, SWT.READ_ONLY); + + this.tableViewer.setCellEditors(editor); + this.tableViewer.setLabelProvider(new LabelProviderImpl()); + this.tableViewer.setContentProvider(new ContentProviderImpl()); + this.tableViewer.setCellModifier(new CellModifierImpl()); + this.tableViewer.setInput(sortFilterValues); + } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/UpdateRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/UpdateRowPage.java index 031ed9f..c1afd51 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/UpdateRowPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/UpdateRowPage.java @@ -1,7 +1,5 @@ package com.quantum.wizards; -import java.util.Arrays; - import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.CheckboxCellEditor; import org.eclipse.jface.viewers.ICellModifier; @@ -12,32 +10,25 @@ import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TextCellEditor; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Text; import com.quantum.ImageStore; import com.quantum.Messages; -import com.quantum.adapters.DatabaseAdapter; -import com.quantum.model.Bookmark; import com.quantum.model.Column; import com.quantum.model.Entity; -import com.quantum.wizards.InsertRowPage.CellModifierImpl; -import com.quantum.wizards.InsertRowPage.ContentProviderImpl; -import com.quantum.wizards.InsertRowPage.InsertRowTableValues; -import com.quantum.wizards.InsertRowPage.LabelProviderImpl; +import com.quantum.util.StringMatrix; +import com.quantum.util.sql.SQLInstructionBuilder; +/** + * @author BC Holmes + * @author Elvin E. Ebora + */ public class UpdateRowPage extends BaseSQLPage implements SQLPage { class UpdateRowTableValues { @@ -170,7 +161,7 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { System.out.println("getValue called"); // Find the index of the column - int colIndx = getColumnNamesAsList(colNames).indexOf(property); + int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property); System.out.println("colIndx : " + colIndx); Object rResult = null; @@ -200,7 +191,7 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { } public void modify(Object element, String property, Object value) { - int colIndx = getColumnNamesAsList(colNames).indexOf(property); + int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property); TableItem item = (TableItem) element; UpdateRowTableValues updateVal = (UpdateRowTableValues)item.getData(); @@ -230,12 +221,9 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { String[] columnNames; String[] colNames; - Text[] oldValues; - Text[] newValues; - Button[] primaryKeys; - Button[] setValues; Label query; UpdateRowTableValues[] updateTable = null; + CommonWizardUI comUI; TableViewer tableViewer = null; static Image imgCheck = null; static Image imgUncheck = null; @@ -257,6 +245,8 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { Entity entity = this.results.getEntity(); + comUI = new CommonWizardUI(); + // init values to be displayed on the table columnNames = this.results.getColumnNames(); int nLen = columnNames.length; @@ -276,12 +266,8 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { createTable(container); - query = new Label(container, SWT.WRAP); - GridData gridData = new GridData(); - gridData.horizontalSpan = 1; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - query.setLayoutData(gridData); + query = new Label(container, SWT.WRAP); + query.setLayoutData(comUI.createGridData(1, GridData.FILL)); setControl(container); updateQuery(); @@ -290,39 +276,23 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { } public void updateQuery() { System.out.println("Updating query"); //$NON-NLS-1$ - StringBuffer setClause = new StringBuffer(); - StringBuffer whereClause = new StringBuffer(); - Bookmark bookmark = this.results.getBookmark(); - Entity entity = this.results.getEntity(); - DatabaseAdapter adapter = bookmark.getAdapter(); - int numValuesSet = 0; - int numValuesWhere = 0; - for (int nCtr = 0; nCtr < columnNames.length; nCtr++) { - if (updateTable[nCtr].isBPrimary()) { - String value = updateTable[nCtr].getSOldValue(); - if (numValuesWhere > 0) whereClause.append(" AND "); //$NON-NLS-1$ - whereClause.append("("); //$NON-NLS-1$ - whereClause.append(updateTable[nCtr].getSColNames()); - whereClause.append(" = "); //$NON-NLS-1$ - appendColumn(whereClause, entity, updateTable[nCtr].getSColNames(), adapter, value); - whereClause.append(")"); //$NON-NLS-1$ - numValuesWhere++; - } - if (updateTable[nCtr].isBSetValue()) { - String value = updateTable[nCtr].getSNewValue(); - if (numValuesSet > 0) setClause.append(", "); //$NON-NLS-1$ - setClause.append(updateTable[nCtr].getSColNames()); - setClause.append(" = "); //$NON-NLS-1$ - appendColumn(setClause, entity, updateTable[nCtr].getSColNames(), adapter, value); - numValuesSet++; + StringMatrix columns = new StringMatrix(); + for (int i = 0; i < columnNames.length; i++) { + if (updateTable[i].isBSetValue()) { + columns.addHeader( updateTable[i].getSColNames() ); + columns.add( updateTable[i].getSNewValue(), 0 ); } } - - String query = "UPDATE " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$ - query += " SET " + setClause.toString(); //$NON-NLS-1$ - query += " WHERE " + whereClause.toString(); //$NON-NLS-1$ - this.query.setText(query); + StringMatrix key = new StringMatrix(); + for (int i = 0; i < columnNames.length; i++) { + if (updateTable[i].isBPrimary()) { + key.addHeader( updateTable[i].getSColNames() ); + // It's an old value because it't the key. + key.add( updateTable[i].getSOldValue() , 0 ); + } + } + this.query.setText(SQLInstructionBuilder.buildUpdate(this.results.getEntity(), columns, key)); } /* (non-Javadoc) @@ -337,21 +307,16 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { } private void createTable(Composite composite) { - System.out.println("Creating table..."); - int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION; - Table table = new Table(composite, style); - table.setHeaderVisible(true); - table.setLinesVisible(true); - table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING)); - + System.out.println("Creating table..."); + Table table = comUI.createTablePage(composite); colNames = new String[] { Messages.getString("UpdateRowPage.ColumnName"), Messages.getString("UpdateRowPage.OldValue"), "Where", Messages.getString("UpdateRowPage.NewValue"), Messages.getString("UpdateRowPage.SetValue") }; - createTableColumn(table, colNames[0], SWT.LEFT, 0, 150); - createTableColumn(table, colNames[1], SWT.LEFT, 1, 300); - createTableColumn(table, colNames[2], SWT.CENTER, 2, 60); - createTableColumn(table, colNames[3], SWT.LEFT, 3, 300); - createTableColumn(table, colNames[4], SWT.CENTER, 4, 70); + comUI.createTableColumn(table, colNames[0], SWT.LEFT, 0, 150); + comUI.createTableColumn(table, colNames[1], SWT.LEFT, 1, 300); + comUI.createTableColumn(table, colNames[2], SWT.CENTER, 2, 60); + comUI.createTableColumn(table, colNames[3], SWT.LEFT, 3, 300); + comUI.createTableColumn(table, colNames[4], SWT.CENTER, 4, 70); this.tableViewer = new TableViewer(table); this.tableViewer.setColumnProperties(colNames); diff --git a/net.sourceforge.phpeclipse.core/plugin.xml b/net.sourceforge.phpeclipse.core/plugin.xml index 64f2b92..fc145ac 100644 --- a/net.sourceforge.phpeclipse.core/plugin.xml +++ b/net.sourceforge.phpeclipse.core/plugin.xml @@ -3,7 +3,7 @@ diff --git a/net.sourceforge.phpeclipse.debug.core/build.xml b/net.sourceforge.phpeclipse.debug.core/build.xml deleted file mode 100644 index a686b93..0000000 --- a/net.sourceforge.phpeclipse.debug.core/build.xml +++ /dev/null @@ -1,198 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/net.sourceforge.phpeclipse.debug.core/plugin.xml b/net.sourceforge.phpeclipse.debug.core/plugin.xml index c384616..ca0ab0c 100644 --- a/net.sourceforge.phpeclipse.debug.core/plugin.xml +++ b/net.sourceforge.phpeclipse.debug.core/plugin.xml @@ -3,7 +3,7 @@ diff --git a/net.sourceforge.phpeclipse.debug.ui/plugin.xml b/net.sourceforge.phpeclipse.debug.ui/plugin.xml index f3f7d1c..c195348 100644 --- a/net.sourceforge.phpeclipse.debug.ui/plugin.xml +++ b/net.sourceforge.phpeclipse.debug.ui/plugin.xml @@ -3,7 +3,7 @@ diff --git a/net.sourceforge.phpeclipse.feature/feature.xml b/net.sourceforge.phpeclipse.feature/feature.xml index 3785364..09d5974 100644 --- a/net.sourceforge.phpeclipse.feature/feature.xml +++ b/net.sourceforge.phpeclipse.feature/feature.xml @@ -2,7 +2,7 @@ @@ -210,73 +210,73 @@ b) in the case of each subsequent Contributor:</FONT></UL> id="net.sourceforge.phpdt.smarty.ui" download-size="0" install-size="0" - version="1.1.0"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + version="2.4.4"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + version="1.1.1"/> + diff --git a/net.sourceforge.phpeclipse.launching/build.xml b/net.sourceforge.phpeclipse.launching/build.xml deleted file mode 100644 index 19a58d8..0000000 --- a/net.sourceforge.phpeclipse.launching/build.xml +++ /dev/null @@ -1,200 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/net.sourceforge.phpeclipse.launching/plugin.xml b/net.sourceforge.phpeclipse.launching/plugin.xml index e3bb186..cff3602 100644 --- a/net.sourceforge.phpeclipse.launching/plugin.xml +++ b/net.sourceforge.phpeclipse.launching/plugin.xml @@ -3,7 +3,7 @@ diff --git a/net.sourceforge.phpeclipse.phphelp/plugin.xml b/net.sourceforge.phpeclipse.phphelp/plugin.xml index a663fbc..63c0f53 100644 --- a/net.sourceforge.phpeclipse.phphelp/plugin.xml +++ b/net.sourceforge.phpeclipse.phphelp/plugin.xml @@ -3,7 +3,7 @@ diff --git a/net.sourceforge.phpeclipse.smarty.ui/build.xml b/net.sourceforge.phpeclipse.smarty.ui/build.xml deleted file mode 100644 index b9d29fe..0000000 --- a/net.sourceforge.phpeclipse.smarty.ui/build.xml +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/net.sourceforge.phpeclipse.smarty.ui/plugin.xml b/net.sourceforge.phpeclipse.smarty.ui/plugin.xml index c17e88d..8222123 100644 --- a/net.sourceforge.phpeclipse.smarty.ui/plugin.xml +++ b/net.sourceforge.phpeclipse.smarty.ui/plugin.xml @@ -3,7 +3,7 @@ diff --git a/net.sourceforge.phpeclipse.webbrowser/plugin.xml b/net.sourceforge.phpeclipse.webbrowser/plugin.xml index 5616079..4b4a865 100644 --- a/net.sourceforge.phpeclipse.webbrowser/plugin.xml +++ b/net.sourceforge.phpeclipse.webbrowser/plugin.xml @@ -3,7 +3,7 @@ diff --git a/net.sourceforge.phpeclipse.xml.core/plugin.xml b/net.sourceforge.phpeclipse.xml.core/plugin.xml index 393a42a..8f29db4 100644 --- a/net.sourceforge.phpeclipse.xml.core/plugin.xml +++ b/net.sourceforge.phpeclipse.xml.core/plugin.xml @@ -3,7 +3,7 @@ diff --git a/net.sourceforge.phpeclipse.xml.ui/plugin.xml b/net.sourceforge.phpeclipse.xml.ui/plugin.xml index dfc4a23..314d7b0 100644 --- a/net.sourceforge.phpeclipse.xml.ui/plugin.xml +++ b/net.sourceforge.phpeclipse.xml.ui/plugin.xml @@ -3,7 +3,7 @@ diff --git a/net.sourceforge.phpeclipse/plugin.xml b/net.sourceforge.phpeclipse/plugin.xml index 5448972..3f94a4f 100644 --- a/net.sourceforge.phpeclipse/plugin.xml +++ b/net.sourceforge.phpeclipse/plugin.xml @@ -3,7 +3,7 @@ @@ -788,7 +788,7 @@ - - + -->