Revision: 6593
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6593&view=rev
Author: gerdwagner
Date: 2012-02-28 22:05:08 +0000 (Tue, 28 Feb 2012)
Log Message:
-----------
DBCopy Plugin:
- Offers a new menu item "Paste table as ..." that allows to change the pasted table's name.
This function works if only a single table was copied.
- Tables can now be pasted to arbitrary Schemas.
- In the Plugin preferences the user may choose to append copied data to exisitng tables
Modified Paths:
--------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/schemainfo/SchemaInfo.java
trunk/sql12/doc/src/main/resources/changes.txt
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/DialectUtils.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyExecutor.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyProgressMonitor.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPlugin.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/SessionInfoProvider.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/UICallbacks.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableAction.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/gui/PreferencesPanel.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/prefs/DBCopyPreferenceBean.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/DBUtil.java
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/I18NStrings.properties
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/I18NStrings.properties
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/dbcopy.properties
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/gui/I18NStrings.properties
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/images/copy.gif
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/images/paste.gif
Added Paths:
-----------
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/EditPasteTableNameDlg.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableAsAction.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableUtil.java
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/images/pasteas.gif
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/schemainfo/SchemaInfo.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/schemainfo/SchemaInfo.java 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/schemainfo/SchemaInfo.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -1649,4 +1649,9 @@
throw new RuntimeException(e);
}
}
+
+ public SQLDatabaseMetaData getSQLDatabaseMetaData()
+ {
+ return _dmd;
+ }
}
Modified: trunk/sql12/doc/src/main/resources/changes.txt
===================================================================
--- trunk/sql12/doc/src/main/resources/changes.txt 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/doc/src/main/resources/changes.txt 2012-02-28 22:05:08 UTC (rev 6593)
@@ -9,6 +9,12 @@
Enhancements:
+DBCopy Plugin:
+ - Offers a new menu item "Paste table as ..." that allows to change the pasted table's name.
+ This function works if only a single table was copied.
+ - Tables can now be pasted to arbitrary Schemas.
+ - In the Plugin preferences the user may choose to append copied data to exisitng tables
+
Copy as INSERT-VALUES statement now works on almost any table not just on editable tables. If a table isn't in
a Session scope ";" is used as statement separator instead of the separator defined in Session properties.
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 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/dialects/DialectUtils.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -1875,7 +1875,7 @@
final List<String> constraints = createConstraints(ti, tables, prefs, md);
addConstraintsSQLs(sqls, allconstraints, constraints, prefs);
- final List<String> indexes = createIndexes(ti, md, pkInfos, prefs);
+ final List<String> indexes = createIndexes(ti, ti.getSimpleName(), ti.getSchemaName(), md, pkInfos, prefs);
addConstraintsSQLs(sqls, allconstraints, indexes, prefs);
}
@@ -2441,8 +2441,8 @@
* @param prefs
* @return
*/
- public static List<String> createIndexes(ITableInfo ti, ISQLDatabaseMetaData md,
- List<PrimaryKeyInfo> primaryKeys, CreateScriptPreferences prefs)
+ public static List<String> createIndexes(ITableInfo ti, String destSimpleTableName, String destSchema, ISQLDatabaseMetaData md,
+ List<PrimaryKeyInfo> primaryKeys, CreateScriptPreferences prefs)
{
if (ti == null) { throw new IllegalArgumentException("ti cannot be null"); }
if (md == null) { throw new IllegalArgumentException("md cannot be null"); }
@@ -2527,7 +2527,7 @@
indexSQL.append(ix.ixName);
indexSQL.append(" ON ");
- indexSQL.append(formatQualifIntern(ix.table, ix.tableSchema, prefs));
+ indexSQL.append(formatQualifIntern(destSimpleTableName, destSchema, prefs));
if (ix.cols.size() == 1)
{
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyExecutor.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyExecutor.java 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyExecutor.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -34,14 +34,7 @@
import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
import net.sourceforge.squirrel_sql.fw.dialects.DialectUtils;
import net.sourceforge.squirrel_sql.fw.dialects.UserCancelledOperationException;
-import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
-import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
-import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
-import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
-import net.sourceforge.squirrel_sql.fw.sql.PrimaryKeyInfo;
-import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
-import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
-import net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo;
+import net.sourceforge.squirrel_sql.fw.sql.*;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
import net.sourceforge.squirrel_sql.plugins.dbcopy.event.AnalysisEvent;
@@ -142,7 +135,7 @@
}
/**
- * Performs the table copy operation.
+ * Performs the table copy operation.
*/
private void _execute() {
start = System.currentTimeMillis();
@@ -155,36 +148,41 @@
List<IDatabaseObjectInfo> sourceObjs = prov.getSourceDatabaseObjects();
int[] counts = getTableCounts();
sendCopyStarted(counts);
- String destSchema = prov.getDestDatabaseObject().getSimpleName();
- String destCatalog = prov.getDestDatabaseObject().getCatalogName();
-
- int sourceObjectCount = 0;
+
+ //String destSchema = prov.getDestDatabaseObject().getSimpleName(); used to break, when a table was selected
+
+ String destSchema = DBUtil.getSchemaNameFromDbObject(prov.getDestDatabaseObject());
+
+ String destCatalog = prov.getDestDatabaseObject().getCatalogName();
+
+ TableInfo pasteToTableInfo = prov.getPasteToTableInfo(destConn, destSchema, destCatalog);
+
+ int sourceObjectCount = 0;
for (IDatabaseObjectInfo info : sourceObjs) {
if (! (info instanceof ITableInfo)) {
continue;
}
ITableInfo sourceTI = (ITableInfo)info;
- sendTableCopyStarted(sourceTI, sourceObjectCount+1);
+ sendTableCopyStarted(chooseDestTableInfo(sourceTI, pasteToTableInfo), sourceObjectCount+1);
try {
int destTableCount = DBUtil.getTableCount(destSession,
destCatalog,
- destSchema,
- sourceTI.getSimpleName(),
+ destSchema,
+ chooseDestTableInfo(sourceTI, pasteToTableInfo).getSimpleName(),
DialectFactory.DEST_TYPE);
if (destTableCount == -1) {
- createTable(sourceTI);
+ createTable(sourceTI, chooseDestTableInfo(sourceTI, pasteToTableInfo).getSimpleName(), destSchema, destCatalog);
}
if (destTableCount > 0) {
try {
- String t = sourceTI.getSimpleName();
- if (pref.appendRecordsToExisting(t)) {
+ if (pref.appendRecordsToExisting()) {
/* Do nothing */
- } else if (pref.deleteTableData(sourceTI.getSimpleName())) {
+ } else if (pref.deleteTableData(chooseDestTableInfo(sourceTI, pasteToTableInfo).getSimpleName())) {
// Yes || Yes to all
DBUtil.deleteDataInExistingTable(destSession,
destCatalog,
destSchema,
- sourceTI.getSimpleName());
+ chooseDestTableInfo(sourceTI, pasteToTableInfo).getSimpleName());
} else {
continue; // skip this table, try the next.
}
@@ -195,7 +193,7 @@
}
}
- copyTable(sourceTI, counts[sourceObjectCount]);
+ copyTable(sourceTI, pasteToTableInfo, counts[sourceObjectCount]);
if (sourceObjectCount == sourceObjs.size() - 1 && !cancelled) {
// We just copied the last table. Now it is safe to copy the
@@ -207,7 +205,7 @@
copyConstraints(sourceObjs);
}
if (!cancelled) {
- sendTableCopyFinished(sourceTI, sourceObjectCount+1);
+ sendTableCopyFinished(chooseDestTableInfo(sourceTI, pasteToTableInfo), sourceObjectCount+1);
sleep(prefs.getTableDelayMillis());
}
} catch (SQLException e) {
@@ -240,14 +238,26 @@
ISession session = prov.getDestSession();
if (session.getSessionSheet() != null) {
- session.getSchemaInfo().reload(prov.getDestDatabaseObject());
+ session.getSchemaInfo().reload(DBUtil.getSchemaFromDbObject(prov.getDestDatabaseObject(), session.getSchemaInfo()));
session.getSchemaInfo().fireSchemaInfoUpdate();
}
notifyCopyFinished();
}
-
- /**
+
+ private ITableInfo chooseDestTableInfo(ITableInfo sourceTI, TableInfo pasteToTableInfo)
+ {
+ if (null == pasteToTableInfo)
+ {
+ return sourceTI;
+ }
+ else
+ {
+ return pasteToTableInfo;
+ }
+ }
+
+ /**
* Registers the specified listener to receive copy events from this class.
*
* @param listener
@@ -287,7 +297,7 @@
* @return true if the tables can be created in the destination database;
* false is returned otherwise.
*/
- private boolean analyzeTables() {
+ private boolean analyzeTables() {
boolean result = true;
if (!prefs.isTestColumnNames()) {
return true;
@@ -516,12 +526,13 @@
/**
*
+ *
* @param sourceTableInfo
- * @param sourceTableCount
- * @throws MappingException
+ * @param pasteToTableInfo
+ *@param sourceTableCount @throws MappingException
* @throws SQLException
*/
- private void copyTable(ITableInfo sourceTableInfo, int sourceTableCount)
+ private void copyTable(ITableInfo sourceTableInfo, TableInfo pasteToTableInfo, int sourceTableCount)
throws MappingException, SQLException, UserCancelledOperationException
{
PreparedStatement insertStmt = null;
@@ -537,12 +548,12 @@
SQLDatabaseMetaData sourceMetaData = sourceConn.getSQLMetaData();
SQLDatabaseMetaData destMetaData = destConn.getSQLMetaData();
try {
- String destSchema =
- prov.getDestDatabaseObject().getSimpleName();
- ITableInfo destTableInfo =
+ String destSchema = DBUtil.getSchemaNameFromDbObject(prov.getDestDatabaseObject());
+
+ ITableInfo destTableInfo =
DBUtil.getTableInfo(prov.getDestSession(),
destSchema,
- sourceTableInfo.getSimpleName());
+ chooseDestTableInfo(sourceTableInfo, pasteToTableInfo).getSimpleName());
TableColumnInfo[] sourceInfos = sourceMetaData.getColumnInfo(sourceTableInfo);
TableColumnInfo[] destInfos = destMetaData.getColumnInfo(destTableInfo);
@@ -558,8 +569,8 @@
String selectSQL = DBUtil.getSelectQuery(prov,
sourceColList,
sourceTableInfo);
- String insertSQL = DBUtil.getInsertSQL(prov, destColList,
- sourceTableInfo,
+ String insertSQL = DBUtil.getInsertSQL(prov, destColList,
+ destTableInfo,
destInfos.length);
insertStmt = destConn.prepareStatement(insertSQL);
@@ -785,14 +796,14 @@
}
}
- private void createTable(ITableInfo ti)
+ private void createTable(ITableInfo ti, String destTableName, String destSchema, String destCatalog)
throws SQLException, UserCancelledOperationException, MappingException
{
if (cancelled) {
return;
}
ISQLConnection destCon = prov.getDestSession().getSQLConnection();
- String createTableSql = DBUtil.getCreateTableSql(prov, ti);
+ String createTableSql = DBUtil.getCreateTableSql(prov, ti, destTableName, destSchema, destCatalog);
if (log.isDebugEnabled()) {
log.debug("Creating table in dest db with SQL: "+createTableSql);
@@ -804,15 +815,18 @@
commitConnection(destCon);
}
- if (prefs.isCopyIndexDefs()) {
+ if (prefs.isCopyIndexDefs() && (null == prov.getPasteToTableName() || false == prov.isCopiedFormDestinationSession() ) ) {
Collection<String> indices = null;
ISQLDatabaseMetaData sqlmd = sourceSession.getMetaData();
- if (prefs.isCopyPrimaryKeys()) {
+ CreateScriptPreferences prefs = new CreateScriptPreferences();
+ prefs.setQualifyTableNames(null != destSchema);
+
+ if (this.prefs.isCopyPrimaryKeys()) {
PrimaryKeyInfo[] pkList = sqlmd.getPrimaryKey(ti);
List<PrimaryKeyInfo> pkList2 = Arrays.asList(pkList);
- indices = DialectUtils.createIndexes(ti, sqlmd, pkList2, new CreateScriptPreferences());
+ indices = DialectUtils.createIndexes(ti, destTableName, destSchema, sqlmd, pkList2, prefs);
} else {
- indices = DialectUtils.createIndexes(ti, sqlmd, null, new CreateScriptPreferences());
+ indices = DialectUtils.createIndexes(ti, destTableName, destSchema, sqlmd, null, prefs);
}
Iterator<String> i = indices.iterator();
while (i.hasNext()) {
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyProgressMonitor.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyProgressMonitor.java 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyProgressMonitor.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -42,6 +42,7 @@
import net.sourceforge.squirrel_sql.plugins.dbcopy.event.StatementEvent;
import net.sourceforge.squirrel_sql.plugins.dbcopy.event.TableEvent;
import net.sourceforge.squirrel_sql.plugins.dbcopy.gui.DualProgressBarDialog;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.PreferencesManager;
import net.sourceforge.squirrel_sql.plugins.dbcopy.util.DBUtil;
/**
@@ -147,16 +148,21 @@
* @see net.sourceforge.squirrel_sql.plugins.dbcopy.event.CopyTableListener#copyFinished(int)
*/
public void copyFinished(int seconds) {
- DualProgressBarDialog.stopTimer();
- DualProgressBarDialog.setVisible(false);
- DualProgressBarDialog.dispose();
+ closeProgress();
String title = getMessage("CopyProgressMonitor.successTitle");
String message = getMessage("CopyProgressMonitor.successMessage",
seconds);
showMessageDialog(message, title, JOptionPane.INFORMATION_MESSAGE);
}
- private String wordWrap(String data, int length) {
+ private void closeProgress()
+ {
+ DualProgressBarDialog.stopTimer();
+ DualProgressBarDialog.setVisible(false);
+ DualProgressBarDialog.dispose();
+ }
+
+ private String wordWrap(String data, int length) {
String result = "";
if (data.length() > length) {
String[] parts = data.split("\\s");
@@ -262,6 +268,7 @@
// let them fix it. Then allow them to retry the operation, starting
// from the point at which the previous operation failed.
+ closeProgress();
}
private String getMappingExceptionMessage(Exception e) {
@@ -437,10 +444,9 @@
return false;
}
- public boolean appendRecordsToExisting(String tableName) {
- // TODO: Maybe prompt the user to ask to append the records,
- // ignoring errors for constraint violations?
- return false;
+ public boolean appendRecordsToExisting() {
+
+ return PreferencesManager.getPreferences().isAppendRecordsToExisting();
}
class ConfirmMessageResult {
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPlugin.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPlugin.java 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPlugin.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -35,10 +35,13 @@
import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
+import net.sourceforge.squirrel_sql.fw.sql.TableInfo;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
import net.sourceforge.squirrel_sql.plugins.dbcopy.actions.CopyTableAction;
import net.sourceforge.squirrel_sql.plugins.dbcopy.actions.PasteTableAction;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.actions.PasteTableAsAction;
import net.sourceforge.squirrel_sql.plugins.dbcopy.gui.DBCopyGlobalPreferencesTab;
import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.PreferencesManager;
@@ -63,8 +66,9 @@
private List<IDatabaseObjectInfo> selectedDatabaseObjects = null;
private IDatabaseObjectInfo selectedDestDatabaseObject = null;
+ private String _pasteToTableName;
- /**
+ /**
* @see net.sourceforge.squirrel_sql.client.plugin.ISessionPlugin#sessionStarted(net.sourceforge.squirrel_sql.client.session.ISession)
*/
public PluginSessionCallback sessionStarted(final ISession session)
@@ -175,11 +179,10 @@
IApplication app = getApplication();
ActionCollection coll = app.getActionCollection();
- PasteTableAction pasteTableAction = new PasteTableAction(app, _resources, this);
+ coll.add(new CopyTableAction(app, _resources, this));
+ coll.add(new PasteTableAction(app, _resources, this));
+ coll.add(new PasteTableAsAction(app, _resources, this));
- coll.add(new CopyTableAction(app, _resources, this));
- coll.add(pasteTableAction);
-
setPasteMenuEnabled(false);
}
@@ -291,19 +294,23 @@
api.addToPopup(DatabaseObjectType.TABLE_TYPE_DBO, coll.get(CopyTableAction.class));
api.addToPopup(DatabaseObjectType.TABLE_TYPE_DBO, coll.get(PasteTableAction.class));
+ api.addToPopup(DatabaseObjectType.TABLE_TYPE_DBO, coll.get(PasteTableAsAction.class));
// Copy action object tree types
api.addToPopup(DatabaseObjectType.TABLE, coll.get(CopyTableAction.class));
api.addToPopup(DatabaseObjectType.TABLE, coll.get(PasteTableAction.class));
+ api.addToPopup(DatabaseObjectType.TABLE, coll.get(PasteTableAsAction.class));
// Paste action object tree types
api.addToPopup(DatabaseObjectType.SCHEMA, coll.get(PasteTableAction.class));
+ api.addToPopup(DatabaseObjectType.SCHEMA, coll.get(PasteTableAsAction.class));
// MySQL shows databases as "CATALOGS" not "SCHEMAS"
api.addToPopup(DatabaseObjectType.CATALOG, coll.get(PasteTableAction.class));
+ api.addToPopup(DatabaseObjectType.CATALOG, coll.get(PasteTableAsAction.class));
- api.addToPopup(DatabaseObjectType.SESSION, coll.get(PasteTableAction.class));
+ api.addToPopup(DatabaseObjectType.SESSION, coll.get(PasteTableAsAction.class));
}
@@ -342,7 +349,42 @@
return copyDestSession;
}
- /**
+ @Override
+ public void setPasteToTableName(String pasteToTableName)
+ {
+ _pasteToTableName = pasteToTableName;
+ }
+
+ @Override
+ public String getPasteToTableName()
+ {
+ return _pasteToTableName;
+ }
+
+ @Override
+ public TableInfo getPasteToTableInfo(ISQLConnection destConn, String destSchema, String destCatalog)
+ {
+ if(null == _pasteToTableName)
+ {
+ return null;
+ }
+
+ if(1 != selectedDatabaseObjects.size() || false == selectedDatabaseObjects.get(0) instanceof TableInfo)
+ {
+ throw new IllegalStateException("Invalid paste table as state");
+ }
+
+ TableInfo ret = new TableInfo(destCatalog, destSchema, _pasteToTableName, "TABLE", null, destConn.getSQLMetaData());
+ return ret;
+ }
+
+ @Override
+ public boolean isCopiedFormDestinationSession()
+ {
+ return copyDestSession.equals(copySourceSession);
+ }
+
+ /**
* @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#setDestSession(net.sourceforge.squirrel_sql.client.session.ISession)
*/
public void setDestSession(ISession session)
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/SessionInfoProvider.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/SessionInfoProvider.java 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/SessionInfoProvider.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -22,6 +22,8 @@
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
+import net.sourceforge.squirrel_sql.fw.sql.TableInfo;
/**
* This is implemented in order to pass needed info along to copy executor.
@@ -44,4 +46,12 @@
public void setDestSession(ISession session);
public ISession getDestSession();
+
+ void setPasteToTableName(String pasteToTableName);
+
+ String getPasteToTableName();
+
+ TableInfo getPasteToTableInfo(ISQLConnection destConn, String destSchema, String destCatalog);
+
+ boolean isCopiedFormDestinationSession();
}
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/UICallbacks.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/UICallbacks.java 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/UICallbacks.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -40,10 +40,9 @@
* Ask the user whether or not to append the new records to existing records
* in the specified table.
*
- * @param tableName
* @return
* @throws UserCancelledOperationException
*/
- public boolean appendRecordsToExisting(String tableName)
+ public boolean appendRecordsToExisting()
throws UserCancelledOperationException;
}
Copied: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/EditPasteTableNameDlg.java (from rev 6590, trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/db/EditAliasFolderDlg.java)
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/EditPasteTableNameDlg.java (rev 0)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/EditPasteTableNameDlg.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -0,0 +1,128 @@
+package net.sourceforge.squirrel_sql.plugins.dbcopy.actions;
+
+import com.jidesoft.swing.MultilineLabel;
+import net.sourceforge.squirrel_sql.client.gui.mainframe.MainFrame;
+import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+public class EditPasteTableNameDlg extends JDialog
+{
+ private static final StringManager s_stringMgr =
+ StringManagerFactory.getStringManager(EditPasteTableNameDlg.class);
+
+
+
+ private JTextField _txtFolderName = new JTextField();
+
+ private JButton _btnOK = new JButton(s_stringMgr.getString("EditPasteTableNameDlg.OK"));
+ private JButton _btnCancel = new JButton(s_stringMgr.getString("EditPasteTableNameDlg.Cancel"));
+
+ private String _tableName;
+
+
+ public EditPasteTableNameDlg(MainFrame mainFrame)
+ {
+ super(mainFrame, s_stringMgr.getString("EditPasteTableNameDlg.title"), true);
+ createUI();
+
+ _btnOK.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ onOK();
+ }
+ });
+
+ getRootPane().setDefaultButton(_btnOK);
+
+ _btnCancel.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ onCancel();
+ }
+ });
+
+
+ GUIUtils.enableCloseByEscape(this);
+
+
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ _txtFolderName.requestFocus();
+ }
+ });
+
+ setSize(400, 150);
+
+ }
+
+ private void onCancel()
+ {
+ close();
+ }
+
+ private void close()
+ {
+ setVisible(false);
+ dispose();
+ }
+
+ private void onOK()
+ {
+ if(null == _txtFolderName.getText() || 0 == _txtFolderName.getText().trim().length())
+ {
+ JOptionPane.showMessageDialog(this,s_stringMgr.getString("EditPasteTableNameDlg.TableNameEmpty"));
+ return;
+ }
+
+ _tableName = _txtFolderName.getText();
+
+ close();
+ }
+
+
+ private void createUI()
+ {
+ getContentPane().setLayout(new GridBagLayout());
+
+ GridBagConstraints gbc;
+
+ gbc = new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5,5,5,5), 0,0);
+ getContentPane().add(new MultilineLabel(s_stringMgr.getString("EditPasteTableNameDlg.text")), gbc);
+
+ gbc = new GridBagConstraints(0,1,1,1,1,0,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5,5,5,5), 0,0);
+ getContentPane().add(_txtFolderName, gbc);
+
+ gbc = new GridBagConstraints(0,2,1,1,1,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,5,5,5), 0,0);
+ getContentPane().add(createButtonPanel(), gbc);
+ }
+
+ private JPanel createButtonPanel()
+ {
+ JPanel ret = new JPanel(new GridBagLayout());
+
+ GridBagConstraints gbc;
+
+ gbc = new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,5,5,5), 0,0);
+ ret.add(_btnOK, gbc);
+
+ gbc = new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,5,5,5), 0,0);
+ ret.add(_btnCancel, gbc);
+
+ return ret;
+ }
+
+ public String getTableName()
+ {
+ return _tableName;
+ }
+}
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableAction.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableAction.java 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableAction.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -21,25 +21,11 @@
import net.sourceforge.squirrel_sql.client.IApplication;
import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
-import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.client.session.action.ISessionAction;
-import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
-import net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect;
-import net.sourceforge.squirrel_sql.fw.dialects.UserCancelledOperationException;
-import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
-import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
-import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
-import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
-import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
import net.sourceforge.squirrel_sql.fw.util.Resources;
-import net.sourceforge.squirrel_sql.fw.util.StringManager;
-import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
-import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
-import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
import net.sourceforge.squirrel_sql.plugins.dbcopy.DBCopyPlugin;
import net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider;
-import net.sourceforge.squirrel_sql.plugins.dbcopy.commands.PasteTableCommand;
public class PasteTableAction extends SquirrelAction
@@ -53,14 +39,6 @@
/** The IApplication that we can use to display error dialogs */
private IApplication app = null;
- /** Logger for this class. */
- private final static ILogger log =
- LoggerController.createLogger(PasteTableAction.class);
-
- /** Internationalized strings for this class */
- private static final StringManager s_stringMgr =
- StringManagerFactory.getStringManager(PasteTableAction.class);
-
/**
* Creates a new SQuirreL action that gets fired whenever the user chooses
* the paste operation.
@@ -80,70 +58,10 @@
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent evt) {
- ISession destSession = sessionInfoProv.getDestSession();
- IObjectTreeAPI api =
- destSession.getObjectTreeAPIOfActiveSessionWindow();
- if (api == null) {
- return;
- }
- IDatabaseObjectInfo[] dbObjs = api.getSelectedDatabaseObjects();
- if (dbObjs.length > 1) {
- sessionInfoProv.setDestDatabaseObject(null);
- //i18n[PasteTableAction.error.multischemapaste=The paste
- //operation may only be applied to one schema at a time]
- String msg =
- s_stringMgr.getString("PasteTableAction.error.multischemapaste");
- app.showErrorDialog(msg);
-
- return;
- } else {
- // When the user pastes on a TABLE label which is located under a
- // schema/catalog, build the schema DatabaseObjectInfo.
- if (DatabaseObjectType.TABLE_TYPE_DBO.equals(dbObjs[0].getDatabaseObjectType())) {
- IDatabaseObjectInfo tableLabelInfo = dbObjs[0];
- ISQLConnection destCon = destSession.getSQLConnection();
- SQLDatabaseMetaData md = null;
- if (destCon != null) {
- md = destCon.getSQLMetaData();
- }
- IDatabaseObjectInfo schema =
- new DatabaseObjectInfo(null,
- tableLabelInfo.getSchemaName(),
- tableLabelInfo.getSchemaName(),
- DatabaseObjectType.SCHEMA,
- md);
- sessionInfoProv.setDestDatabaseObject(schema);
- } else {
- sessionInfoProv.setDestDatabaseObject(dbObjs[0]);
- }
-
- }
-
- try {
- IDatabaseObjectInfo info
- = sessionInfoProv.getDestDatabaseObject();
- if (info == null || destSession == null) {
- return;
- }
- if (!checkSession(destSession, info)) {
- return;
- }
- } catch (UserCancelledOperationException e) {
- return;
- }
- if (sessionInfoProv.getSourceSession() == null) {
- return;
- }
- if (!sourceDestSchemasDiffer()) {
- // TODO: tell the user that the selected destination schema is
- // the same as the source schema.
- //monitor.showMessageDialog(...)
- return;
- }
- new PasteTableCommand(sessionInfoProv).execute();
+ PasteTableUtil.excePasteTable(sessionInfoProv, app, null);
}
- /**
+ /**
* Set the current session.
*
* @param session The current session.
@@ -151,63 +69,5 @@
public void setSession(ISession session) {
sessionInfoProv.setDestSession(session);
}
-
- /**
- * This a work-around for the fact that some databases in SQuirreL show
- * "schemas" as catalogs (MySQL) while most others show them as "schemas".
- * If we restrict the Paste menu-item to schemas, then it won't appear in
- * the context menu in the MySQL object tree. However, if add catalogs to
- * the list of database objects that the paste menu item appears in, then
- * we must be careful not to attempt the copy operation on databases where
- * schema != catalog.(Otherwise the copy operation will fail as the qualified
- * name will be [catalog].[tablename] instead of [schema].[tablename]
- *
- * @param session
- * @param dbObjs
- *
- * @return true if it is ok to proceed with the copy operation; false otherwise.
- */
- private boolean checkSession(ISession session, IDatabaseObjectInfo dbObj)
- throws UserCancelledOperationException
- {
- if (session == null || dbObj == null) {
- return true;
- }
- String typeName = dbObj.getDatabaseObjectType().getName();
-
- log.debug("PasteTableAction.checkSession: dbObj type="+typeName+
- " name="+dbObj.getSimpleName());
- HibernateDialect d =
- DialectFactory.getDialect(DialectFactory.DEST_TYPE,
- session.getApplication().getMainFrame(),
- session.getMetaData());
- if (!d.canPasteTo(dbObj)) {
- //i18n[PasteTableAction.error.destdbobj=The destination database
- //doesn't support copying tables into '{0}' objects.\n Please
- //select a schema to paste into.]
- String errmsg =
- s_stringMgr.getString("PasteTableAction.error.destdbobj",
- new Object[] { typeName });
- app.showErrorDialog(errmsg);
- return false;
- }
- return true;
- }
-
- /**
- * Returns a boolean value indicating whether or not the source and
- * destination sessions refer to the same schema.
- *
- * @return
- */
- private boolean sourceDestSchemasDiffer() {
- //ISession sourceSession = sessionInfoProv.getCopySourceSession();
- //ISession destSession = sessionInfoProv.getCopyDestSession();
-
- // TODO: check to be sure that the source and destination schemas are
- // different. Abort if they are the same and inform the user.
-
- return true;
- }
}
Copied: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableAsAction.java (from rev 6590, trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableAction.java)
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableAsAction.java (rev 0)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableAsAction.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -0,0 +1,116 @@
+package net.sourceforge.squirrel_sql.plugins.dbcopy.actions;
+/*
+ * Copyright (C) 2005 Rob Manning
+ * man...@us...
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
+import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.client.session.action.ISessionAction;
+import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
+import net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect;
+import net.sourceforge.squirrel_sql.fw.dialects.UserCancelledOperationException;
+import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
+import net.sourceforge.squirrel_sql.fw.sql.*;
+import net.sourceforge.squirrel_sql.fw.util.Resources;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
+import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.DBCopyPlugin;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.commands.PasteTableCommand;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+
+
+public class PasteTableAsAction extends SquirrelAction
+ implements ISessionAction {
+
+ /** Current plugin. */
+ private final SessionInfoProvider sessionInfoProv;
+
+ /** The IApplication that we can use to display error dialogs */
+ private IApplication app = null;
+
+ /** Logger for this class. */
+ private final static ILogger log =
+ LoggerController.createLogger(PasteTableAsAction.class);
+
+ /** Internationalized strings for this class */
+ private static final StringManager s_stringMgr =
+ StringManagerFactory.getStringManager(PasteTableAsAction.class);
+
+ /**
+ * Creates a new SQuirreL action that gets fired whenever the user chooses
+ * the paste operation.
+ *
+ * @param app
+ * @param rsrc
+ * @param plugin
+ */
+ public PasteTableAsAction(IApplication app, Resources rsrc,
+ DBCopyPlugin plugin) {
+ super(app, rsrc);
+ this.app = app;
+ sessionInfoProv = plugin;
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ public void actionPerformed(ActionEvent evt) {
+
+ if(null == sessionInfoProv.getSourceDatabaseObjects())
+ {
+ return;
+ }
+
+ if(1 != sessionInfoProv.getSourceDatabaseObjects().size())
+ {
+ JOptionPane.showMessageDialog(app.getMainFrame(), s_stringMgr.getString("EditPasteTableNameDlg.onlyOneTableMsg"));
+ return;
+ }
+
+ EditPasteTableNameDlg dlg = new EditPasteTableNameDlg(app.getMainFrame());
+ GUIUtils.centerWithinParent(dlg);
+ dlg.setVisible(true);
+
+ if(null == dlg.getTableName())
+ {
+ return;
+ }
+
+ PasteTableUtil.excePasteTable(sessionInfoProv, app, dlg.getTableName());
+
+
+ System.out.println("dlg.getTableName() = " + dlg.getTableName());
+
+ }
+
+ /**
+ * Set the current session.
+ *
+ * @param session The current session.
+ */
+ public void setSession(ISession session) {
+ sessionInfoProv.setDestSession(session);
+ }
+}
Added: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableUtil.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableUtil.java (rev 0)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableUtil.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -0,0 +1,149 @@
+package net.sourceforge.squirrel_sql.plugins.dbcopy.actions;
+
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
+import net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect;
+import net.sourceforge.squirrel_sql.fw.dialects.UserCancelledOperationException;
+import net.sourceforge.squirrel_sql.fw.sql.*;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
+import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.commands.PasteTableCommand;
+
+public class PasteTableUtil
+{
+ private final static ILogger log = LoggerController.createLogger(PasteTableUtil.class);
+ private static final StringManager s_stringMgr = StringManagerFactory.getStringManager(PasteTableUtil.class);
+
+
+ public static void excePasteTable(SessionInfoProvider sessionInfoProv, IApplication app1, String pasteToTableName)
+ {
+ ISession destSession = sessionInfoProv.getDestSession();
+ IObjectTreeAPI api =
+ destSession.getObjectTreeAPIOfActiveSessionWindow();
+ if (api == null) {
+ return;
+ }
+ IDatabaseObjectInfo[] dbObjs = api.getSelectedDatabaseObjects();
+ if (dbObjs.length > 1) {
+ sessionInfoProv.setDestDatabaseObject(null);
+ //i18n[PasteTableAction.error.multischemapaste=The paste
+ //operation may only be applied to one schema at a time]
+ String msg =
+ s_stringMgr.getString("PasteTableAction.error.multischemapaste");
+ app1.showErrorDialog(msg);
+
+ return;
+ } else {
+ // When the user pastes on a TABLE label which is located under a
+ // schema/catalog, build the schema DatabaseObjectInfo.
+ if (DatabaseObjectType.TABLE_TYPE_DBO.equals(dbObjs[0].getDatabaseObjectType())) {
+ IDatabaseObjectInfo tableLabelInfo = dbObjs[0];
+ ISQLConnection destCon = destSession.getSQLConnection();
+ SQLDatabaseMetaData md = null;
+ if (destCon != null) {
+ md = destCon.getSQLMetaData();
+ }
+ IDatabaseObjectInfo schema =
+ new DatabaseObjectInfo(null,
+ tableLabelInfo.getSchemaName(),
+ tableLabelInfo.getSchemaName(),
+ DatabaseObjectType.SCHEMA,
+ md);
+ sessionInfoProv.setDestDatabaseObject(schema);
+ } else {
+ sessionInfoProv.setDestDatabaseObject(dbObjs[0]);
+ }
+
+ sessionInfoProv.setPasteToTableName(pasteToTableName);
+
+ }
+
+ try {
+ IDatabaseObjectInfo info
+ = sessionInfoProv.getDestDatabaseObject();
+ if (info == null || destSession == null) {
+ return;
+ }
+ if (!checkSession(destSession, info, app1)) {
+ return;
+ }
+ } catch (UserCancelledOperationException e) {
+ return;
+ }
+ if (sessionInfoProv.getSourceSession() == null) {
+ return;
+ }
+ if (!sourceDestSchemasDiffer()) {
+ // TODO: tell the user that the selected destination schema is
+ // the same as the source schema.
+ //monitor.showMessageDialog(...)
+ return;
+ }
+ new PasteTableCommand(sessionInfoProv).execute();
+ }
+
+ /**
+ * This a work-around for the fact that some databases in SQuirreL show
+ * "schemas" as catalogs (MySQL) while most others show them as "schemas".
+ * If we restrict the Paste menu-item to schemas, then it won't appear in
+ * the context menu in the MySQL object tree. However, if add catalogs to
+ * the list of database objects that the paste menu item appears in, then
+ * we must be careful not to attempt the copy operation on databases where
+ * schema != catalog.(Otherwise the copy operation will fail as the qualified
+ * name will be [catalog].[tablename] instead of [schema].[tablename]
+ *
+ * @param app1
+ * @param session
+ * @param dbObjs
+ *
+ * @return true if it is ok to proceed with the copy operation; false otherwise.
+ */
+ private static boolean checkSession(ISession session, IDatabaseObjectInfo dbObj, IApplication app1)
+ throws UserCancelledOperationException
+ {
+ if (session == null || dbObj == null) {
+ return true;
+ }
+ String typeName = dbObj.getDatabaseObjectType().getName();
+
+ log.debug("PasteTableAction.checkSession: dbObj type="+typeName+
+ " name="+dbObj.getSimpleName());
+
+ HibernateDialect d =
+ DialectFactory.getDialect(DialectFactory.DEST_TYPE,
+ session.getApplication().getMainFrame(),
+ session.getMetaData());
+ if (!d.canPasteTo(dbObj)) {
+ //i18n[PasteTableAction.error.destdbobj=The destination database
+ //doesn't support copying tables into '{0}' objects.\n Please
+ //select a schema to paste into.]
+ String errmsg =
+ s_stringMgr.getString("PasteTableAction.error.destdbobj",
+ new Object[] { typeName });
+ app1.showErrorDialog(errmsg);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns a boolean value indicating whether or not the source and
+ * destination sessions refer to the same schema.
+ *
+ * @return
+ */
+ private static boolean sourceDestSchemasDiffer() {
+ //ISession sourceSession = sessionInfoProv.getCopySourceSession();
+ //ISession destSession = sessionInfoProv.getCopyDestSession();
+
+ // TODO: check to be sure that the source and destination schemas are
+ // different. Abort if they are the same and inform the user.
+
+ return true;
+ }
+}
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/gui/PreferencesPanel.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/gui/PreferencesPanel.java 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/gui/PreferencesPanel.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -74,7 +74,9 @@
JCheckBox pruneDuplicateIndexDefs = null;
JCheckBox writeScriptCheckBox = null;
-
+
+ JCheckBox appendRecordsToExistingCheckBox = null;
+
JCheckBox promptForHibernateCheckBox = null;
JCheckBox checkKeywordsCheckBox = null;
@@ -167,7 +169,8 @@
addDelayRecordsTextField(result, 1, 14);
addWriteScriptCheckBox(result, 0, 15);
-
+ addAppendRecordsToExistingCheckBox(result, 0, 16);
+
return result;
}
@@ -203,13 +206,31 @@
writeScriptCheckBox.setToolTipText(toolTipText);
panel.add(writeScriptCheckBox, c);
}
-
+
+ private void addAppendRecordsToExistingCheckBox(JPanel panel, int col, int row) {
+ GridBagConstraints c = new GridBagConstraints();
+ c.gridx = col;
+ c.gridy = row;
+ c.gridwidth = 2; // Span across two columns
+ c.insets = new Insets(10,0,0,0);
+ c.anchor = GridBagConstraints.WEST;
+ String cbLabelStr =
+ s_stringMgr.getString("PreferencesPanel.appendRecordsToExistingCheckBox");
+ String toolTipText =
+ s_stringMgr.getString("PreferencesPanel.appendRecordsToExistingCheckBoxToolTip");
+ appendRecordsToExistingCheckBox = new JCheckBox(cbLabelStr);
+ appendRecordsToExistingCheckBox.setToolTipText(toolTipText);
+ panel.add(appendRecordsToExistingCheckBox, c);
+ }
+
private void addUseTruncateCheckBox(JPanel panel, int col, int row) {
GridBagConstraints c = new GridBagConstraints();
c.gridx = col;
c.gridy = row;
c.gridwidth = 2; // Span across two columns
- String cbToolTipText =
+ c.insets = new Insets(10,0,0,0);
+ c.anchor = GridBagConstraints.WEST;
+ String cbToolTipText =
s_stringMgr.getString("PreferencesPanel.truncateLabelTipText");
truncateCheckBox.setToolTipText(cbToolTipText);
panel.add(truncateCheckBox, c);
@@ -628,6 +649,7 @@
copyForeignKeys.setSelected(_prefs.isCopyForeignKeys());
copyPrimaryKeys.setSelected(_prefs.isCopyPrimaryKeys());
writeScriptCheckBox.setSelected(_prefs.isWriteScript());
+ appendRecordsToExistingCheckBox.setSelected(_prefs.isAppendRecordsToExisting());
pruneDuplicateIndexDefs.setSelected(_prefs.isPruneDuplicateIndexDefs());
commitAfterCreateTableCheckBox.setSelected(_prefs.isCommitAfterTableDefs());
promptForHibernateCheckBox.setSelected(_prefs.isPromptForDialect());
@@ -651,6 +673,7 @@
_prefs.setCopyForeignKeys(copyForeignKeys.isSelected());
_prefs.setCopyPrimaryKeys(copyPrimaryKeys.isSelected());
_prefs.setWriteScript(writeScriptCheckBox.isSelected());
+ _prefs.setAppendRecordsToExisting(appendRecordsToExistingCheckBox.isSelected());
_prefs.setPruneDuplicateIndexDefs(pruneDuplicateIndexDefs.isSelected());
_prefs.setCommitAfterTableDefs(commitAfterCreateTableCheckBox.isSelected());
_prefs.setPromptForDialect(promptForHibernateCheckBox.isSelected());
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/prefs/DBCopyPreferenceBean.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/prefs/DBCopyPreferenceBean.java 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/prefs/DBCopyPreferenceBean.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -60,7 +60,7 @@
private boolean copyForeignKeys = true;
/** whether or not to copy the primary keys */
- private boolean copyPrimaryKeys = true;
+ private boolean copyPrimaryKeys = false;
/** whether or not to discard logically identical index defs */
private boolean pruneDuplicateIndexDefs = true;
@@ -88,8 +88,10 @@
/** default number of milliseconds to wait between copying records */
private long recordDelayMillis = 0;
-
- public DBCopyPreferenceBean() {
+
+ private boolean _appendRecordsToExisting;
+
+ public DBCopyPreferenceBean() {
super();
}
@@ -411,6 +413,15 @@
public boolean isDelayBetweenObjects() {
return delayBetweenObjects;
}
-
+
+ public boolean isAppendRecordsToExisting()
+ {
+ return _appendRecordsToExisting;
+ }
+
+ public void setAppendRecordsToExisting(boolean appendRecordsToExisting)
+ {
+ _appendRecordsToExisting = appendRecordsToExisting;
+ }
}
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/DBUtil.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/DBUtil.java 2012-02-25 19:13:36 UTC (rev 6592)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/DBUtil.java 2012-02-28 22:05:08 UTC (rev 6593)
@@ -49,15 +49,7 @@
import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
import net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect;
import net.sourceforge.squirrel_sql.fw.dialects.UserCancelledOperationException;
-import net.sourceforge.squirrel_sql.fw.sql.ForeignKeyInfo;
-import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
-import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
-import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
-import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
-import net.sourceforge.squirrel_sql.fw.sql.JDBCTypeMapper;
-import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
-import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
-import net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo;
+import net.sourceforge.squirrel_sql.fw.sql.*;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
@@ -1411,7 +1403,7 @@
}
}
- public static String getCreateTableSql(SessionInfoProvider prov, ITableInfo ti) throws SQLException,
+ public static String getCreateTableSql(SessionInfoProvider prov, ITableInfo ti, String destTableName, String destSchema, String destCatalog) throws SQLException,
MappingException, UserCancelledOperationException
{
@@ -1421,10 +1413,10 @@
String sourceTableName = getQualifiedObjectName(
sourceSession, sourceCatalog, sourceSchema, ti.getSimpleName(), DialectFactory.SOURCE_TYPE);
ISession destSession = prov.getDestSession();
- String destSchema = prov.getDestDatabaseObject().getSimpleName();
- String destCatalog = prov.getDestDatabaseObject().getCatalogName();
+// String destSchema = getSchemaNameFromDbObject(prov.getDestDatabaseObject());
+// String destCatalog = prov.getDestDatabaseObject().getCatalogName();
String destinationTableName = getQualifiedObjectName(
- destSession, destCatalog, destSchema, ti.getSimpleName(), DialectFactory.DEST_TYPE);
+ destSession, destCatalog, destSchema, destTableName, DialectFactory.DEST_TYPE);
StringBuilder result = new StringBuilder("CREATE TABLE ");
result.append(destinationTableName);
result.append(" ( ");
@@ -1514,13 +1506,13 @@
* Uses the column type mapper to get the column type and appends that to the name with an optional not
* null modifier.
*
- * @param colInfo
- * @return
- * @throws UserCancelledOperationException
+ *
+ * @param colInfo
+ * @throws UserCancelledOperationException
* @throws MappingException
*/
public static String getColumnSql(SessionInfoProvider prov, TableColumnInfo colInfo,
- String sourceTableName, String destTableName) throws UserCancelledOperationException,
+ String sourceTableName, String destTableName) throws UserCancelledOperationException,
MappingException
{
String columnName = colInfo.getColumnName();
@@ -1641,7 +1633,7 @@
{
StringBuilder result = new StringBuilder();
result.append("insert into ");
- String destSchema = prov.getDestDatabaseObject().getSimpleName();
+ String destSchema = DBUtil.getSchemaNameFromDbObject(prov.getDestDatabaseObject());
String destCatalog = prov.getDestDatabaseObject().getCatalogName();
ISession destSession = prov.getDestSession();
result.append(getQualifiedObjectName(
@@ -2060,5 +2052,36 @@
}
return result;
}
-
+
+ public static String getSchemaNameFromDbObject(IDatabaseObjectInfo dbObject)
+ {
+ String destSchema;
+
+ if (dbObject.getDatabaseObjectType().equals(DatabaseObjectType.SCHEMA))
+ {
+ destSchema = dbObject.getSimpleName();
+ }
+ else
+ {
+ destSchema = dbObject.getSchemaName();
+ }
+ return destSchema;
+ }
+
+ public static IDatabaseObjectInfo getSchemaFromDbObject(IDatabaseObjectInfo dbObject, SchemaInfo schemaInfo)
+ {
+ if (dbObject.getDatabaseObjectType().equals(DatabaseObjectType.SCHEMA))
+ {
+ return dbObject;
+ }
+ else
+ {
+ return new DatabaseObjectInfo(dbObject.getCatalogName(),
+ dbObject.getSchemaName(),
+ dbObject.getSimpleName(),
+ DatabaseObjectType.SCHEMA,
+ schemaInfo.getSQLDatabaseMetaData());
+
+ }
+ }
}
Modified: trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/I18NStrings.properties
==...
[truncated message content] |