Revision: 6161
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6161&view=rev
Author: manningr
Date: 2011-02-21 21:25:17 +0000 (Mon, 21 Feb 2011)
Log Message:
-----------
Added support and preference setting for sorting the column names of a table when generating the create statement for comparison purposes. It may be that the table was created and later altered in a difference order than in another schema and this might not be considered important for comparison purposes. This sort columns setting will eliminate this from appearing as a difference.
Modified Paths:
--------------
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/CommonHibernateDialect.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/DialectUtils.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/HibernateDialect.java
trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/gui/AbstractSideBySideDiffPresentation.java
trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/gui/ExternalToolSideBySideDiffPresentation.java
trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/DBDiffPreferenceBean.java
trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/DBDiffPreferencesPanel.java
trunk/sql12/plugins/dbdiff/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/I18NStrings.properties
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/CommonHibernateDialect.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/CommonHibernateDialect.java 2011-02-17 19:01:06 UTC (rev 6160)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/CommonHibernateDialect.java 2011-02-21 21:25:17 UTC (rev 6161)
@@ -291,6 +291,17 @@
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getCreateTableSQL(java.util.List,
* net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData,
+ * net.sourceforge.squirrel_sql.fw.dialects.CreateScriptPreferences, boolean, boolean)
+ */
+ public List<String> getCreateTableSQL(List<ITableInfo> tables, ISQLDatabaseMetaData md,
+ CreateScriptPreferences prefs, boolean isJdbcOdbc, boolean sortColumns) throws SQLException
+ {
+ return DialectUtils.getCreateTableSQL(tables, md, this, prefs, isJdbcOdbc, sortColumns);
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getCreateTableSQL(java.util.List,
+ * net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData,
* net.sourceforge.squirrel_sql.fw.dialects.CreateScriptPreferences, boolean)
*/
public List<String> getCreateTableSQL(List<ITableInfo> tables, ISQLDatabaseMetaData md,
@@ -298,7 +309,7 @@
{
return DialectUtils.getCreateTableSQL(tables, md, this, prefs, isJdbcOdbc);
}
-
+
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getCreateTableSQL(java.lang.String,
* java.util.List, java.util.List, net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences,
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/DialectUtils.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/DialectUtils.java 2011-02-17 19:01:06 UTC (rev 6160)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/DialectUtils.java 2011-02-21 21:25:17 UTC (rev 6161)
@@ -1780,6 +1780,13 @@
public static List<String> getCreateTableSQL(List<ITableInfo> tables, ISQLDatabaseMetaData md,
HibernateDialect dialect, CreateScriptPreferences prefs, boolean isJdbcOdbc) throws SQLException
{
+ return getCreateTableSQL(tables, md, dialect, prefs, isJdbcOdbc, false);
+ }
+
+ public static List<String> getCreateTableSQL(List<ITableInfo> tables, ISQLDatabaseMetaData md,
+ HibernateDialect dialect, CreateScriptPreferences prefs, boolean isJdbcOdbc, boolean sortColumns)
+ throws SQLException
+ {
final List<String> sqls = new ArrayList<String>();
final List<String> allconstraints = new ArrayList<String>();
@@ -1793,6 +1800,9 @@
final List<PrimaryKeyInfo> pkInfos = getPrimaryKeyInfo(md, ti, isJdbcOdbc);
final List<String> pks = getPKSequenceList(pkInfos);
final TableColumnInfo[] infos = md.getColumnInfo(ti);
+ if (sortColumns) {
+ Arrays.sort(infos);
+ }
for (final TableColumnInfo tcInfo : infos)
{
final String columnName = tcInfo.getColumnName();
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/HibernateDialect.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/HibernateDialect.java 2011-02-17 19:01:06 UTC (rev 6160)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/HibernateDialect.java 2011-02-21 21:25:17 UTC (rev 6161)
@@ -402,7 +402,8 @@
SqlGenerationPreferences prefs);
/**
- * Returns the SQL command to create the specified table.
+ * Returns the SQL command to create the specified table (columns appear in the same order as they are
+ * stored in the database).
*
* @param tables
* the tables to get create statements for
@@ -418,6 +419,26 @@
CreateScriptPreferences prefs, boolean isJdbcOdbc) throws SQLException;
/**
+ * Returns the SQL command to create the specified table. Optionally, if sortColumns is true, colums will
+ * be sorted by column name in ascending order.
+ *
+ * @param tables
+ * the tables to get create statements for
+ * @param md
+ * the metadata from the ISession
+ * @param prefs
+ * preferences about how the resultant SQL commands should be formed.
+ * @param isJdbcOdbc
+ * whether or not the connection is via JDBC-ODBC bridge.
+ * @param sortColumns
+ * whether or not to sort columns according to their column name.
+ *
+ * @return the SQL that is used to create the specified table
+ */
+ List<String> getCreateTableSQL(List<ITableInfo> tables, ISQLDatabaseMetaData md,
+ CreateScriptPreferences prefs, boolean isJdbcOdbc, boolean sortColumns) throws SQLException;
+
+ /**
* Returns the DialectType enum value associated with this dialect.
*
* @return the DialectType
Modified: trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/gui/AbstractSideBySideDiffPresentation.java
===================================================================
--- trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/gui/AbstractSideBySideDiffPresentation.java 2011-02-17 19:01:06 UTC (rev 6160)
+++ trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/gui/AbstractSideBySideDiffPresentation.java 2011-02-21 21:25:17 UTC (rev 6161)
@@ -40,6 +40,7 @@
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
import net.sourceforge.squirrel_sql.plugins.dbdiff.IScriptFileManager;
+import net.sourceforge.squirrel_sql.plugins.dbdiff.prefs.DBDiffPreferenceBean;
/**
* Base class for all DiffPresentation implementations that display a comparison of the contents of two files
@@ -61,6 +62,11 @@
private IDialectFactory dialectFactory = new DialectFactoryImpl();
/**
+ * preferenceBean
+ */
+ protected DBDiffPreferenceBean preferenceBean = null;
+
+ /**
* Sub-class implementations should override this method to provide the implementation for comparing the
* contents of the specified script filenames.
*
@@ -98,13 +104,14 @@
try
{
+
final String script1 =
constructScriptFromList(dialect.getCreateTableSQL(sourcetables, sourceSession.getMetaData(),
- csprefs, false));
+ csprefs, false, preferenceBean.isSortColumnsForSideBySideComparison()));
final String script2 =
constructScriptFromList(dialect.getCreateTableSQL(desttables, destSession.getMetaData(), csprefs,
- false));
+ false, preferenceBean.isSortColumnsForSideBySideComparison()));
final String sourceFilename = scriptFileManager.getOutputFilenameForSession(sourceSession, 1);
final String destFilename = scriptFileManager.getOutputFilenameForSession(destSession, 2);
@@ -186,4 +193,14 @@
this.dialectFactory = dialectFactory;
}
+ /**
+ * @param preferenceBean
+ * the preferenceBean to set
+ */
+ public void setPreferenceBean(DBDiffPreferenceBean preferenceBean)
+ {
+ Utilities.checkNull("setPreferenceBean", preferenceBean, "preferenceBean");
+ this.preferenceBean = preferenceBean;
+ }
+
}
Modified: trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/gui/ExternalToolSideBySideDiffPresentation.java
===================================================================
--- trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/gui/ExternalToolSideBySideDiffPresentation.java 2011-02-17 19:01:06 UTC (rev 6160)
+++ trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/gui/ExternalToolSideBySideDiffPresentation.java 2011-02-21 21:25:17 UTC (rev 6161)
@@ -21,10 +21,8 @@
import java.io.IOException;
-import net.sourceforge.squirrel_sql.fw.util.Utilities;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
-import net.sourceforge.squirrel_sql.plugins.dbdiff.prefs.DBDiffPreferenceBean;
/**
* A DiffPresentation implementation that creates a script from both schemas to be compared, then launches a
@@ -38,11 +36,6 @@
LoggerController.createLogger(ExternalToolSideBySideDiffPresentation.class);
/**
- * preferenceBean
- */
- private DBDiffPreferenceBean preferenceBean = null;
-
- /**
* @see net.sourceforge.squirrel_sql.plugins.dbdiff.gui.AbstractSideBySideDiffPresentation#
* executeDiff(java.lang.String, java.lang.String)
*/
@@ -60,14 +53,4 @@
Runtime.getRuntime().exec(toolCommand);
}
- /**
- * @param preferenceBean
- * the preferenceBean to set
- */
- public void setPreferenceBean(DBDiffPreferenceBean preferenceBean)
- {
- Utilities.checkNull("setPreferenceBean", preferenceBean, "preferenceBean");
- this.preferenceBean = preferenceBean;
- }
-
}
Modified: trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/DBDiffPreferenceBean.java
===================================================================
--- trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/DBDiffPreferenceBean.java 2011-02-17 19:01:06 UTC (rev 6160)
+++ trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/DBDiffPreferenceBean.java 2011-02-21 21:25:17 UTC (rev 6161)
@@ -46,6 +46,9 @@
/** The graphical tool command that launches the diff tool. It should handle two file arguments */
private String graphicalToolCommand = "";
+
+ /** Whether or not to sort columns by column name when generating table definitions */
+ private boolean sortColumnsForSideBySideComparison = false;
public DBDiffPreferenceBean()
{
@@ -161,4 +164,20 @@
return useTabularDiffPresenation;
}
+ /**
+ * @return the sortColumnsForSideBySideComparison
+ */
+ public boolean isSortColumnsForSideBySideComparison()
+ {
+ return sortColumnsForSideBySideComparison;
+ }
+
+ /**
+ * @param sortColumnsForSideBySideComparison the sortColumnsForSideBySideComparison to set
+ */
+ public void setSortColumnsForSideBySideComparison(boolean sortColumnsForSideBySideComparison)
+ {
+ this.sortColumnsForSideBySideComparison = sortColumnsForSideBySideComparison;
+ }
+
}
Modified: trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/DBDiffPreferencesPanel.java
===================================================================
--- trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/DBDiffPreferencesPanel.java 2011-02-17 19:01:06 UTC (rev 6160)
+++ trunk/sql12/plugins/dbdiff/src/main/java/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/DBDiffPreferencesPanel.java 2011-02-21 21:25:17 UTC (rev 6161)
@@ -27,6 +27,7 @@
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
+import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
@@ -65,6 +66,8 @@
JTextField externalDiffToolCommandTextField = null;
+ JCheckBox sortColumnsCheckBox = null;
+
/** Internationalized strings for this class. */
private static final StringManager s_stringMgr =
StringManagerFactory.getStringManager(DBDiffPreferencesPanel.class);
@@ -119,11 +122,30 @@
addexternalDiffToolCommandLabel(result, 0, 3);
addExternalDiffToolCommandTextField(result, 1, 3);
- addTabularPresentationRadioButton(result, 0, 4);
+ addSortColumnsCheckBoxLabel(result, 0, 4);
+
+ addTabularPresentationRadioButton(result, 0, 5);
return result;
}
+ private void addSortColumnsCheckBoxLabel(JPanel panel, int col, int row)
+ {
+ final GridBagConstraints c = new GridBagConstraints();
+ c.gridx = col;
+ c.gridy = row;
+ c.gridwidth = 2; // Span across two columns
+ c.insets = new Insets(5, 20, 0, 0);
+ c.anchor = GridBagConstraints.WEST;
+ final String sortColumnsCheckBoxLabel =
+ s_stringMgr.getString("DBDiffPreferencesPanel.sortColumnsForSideBySideComparisonLabel");
+ final String sortColumnsCheckBoxToolTip =
+ s_stringMgr.getString("DBDiffPreferencesPanel.sortColumnsForSideBySideComparisonToolTip");
+ sortColumnsCheckBox = new JCheckBox(sortColumnsCheckBoxLabel);
+ sortColumnsCheckBox.setToolTipText(sortColumnsCheckBoxToolTip);
+ panel.add(sortColumnsCheckBox, c);
+ }
+
private void addTabularPresentationRadioButton(JPanel panel, int col, int row)
{
final GridBagConstraints c = new GridBagConstraints();
Modified: trunk/sql12/plugins/dbdiff/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/I18NStrings.properties
===================================================================
--- trunk/sql12/plugins/dbdiff/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/I18NStrings.properties 2011-02-17 19:01:06 UTC (rev 6160)
+++ trunk/sql12/plugins/dbdiff/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbdiff/prefs/I18NStrings.properties 2011-02-21 21:25:17 UTC (rev 6161)
@@ -13,6 +13,9 @@
DBDiffPreferencesPanel.sideBySidePresentationRadionButtonLabel=Side-by-Side
DBDiffPreferencesPanel.sideBySidePresentationRadionButtonToolTip=A form of comparison that displays both schema definitions in terms of SQL.
+DBDiffPreferencesPanel.sortColumnsForSideBySideComparisonLabel=Sort Columns for side-by-side comparison
+DBDiffPreferencesPanel.sortColumnsForSideBySideComparisonToolTip=Column ordering differences can be ignored with this preference.
+
DBDiffPreferencesPanel.tabularPresentationRadioButtonLabel=Tabular
DBDiffPreferencesPanel.tabularPresentationRadioButtonToolTipText=Shows differences in a table
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|