Revision: 6312
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6312&view=rev
Author: manningr
Date: 2011-07-17 00:24:47 +0000 (Sun, 17 Jul 2011)
Log Message:
-----------
Feature request # 3291501 (Scriptable command-line execution of the DBCopy plugin)
Modified Paths:
--------------
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/CopyScripter.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/actions/PasteTableAction.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/CopyTableCommand.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/DBUtil.java
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPluginTest.java
Added Paths:
-----------
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionInfoProviderImpl.java
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessorTest.java
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 2011-07-10 18:38:03 UTC (rev 6311)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyExecutor.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -30,10 +30,10 @@
import java.util.Set;
import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.dialects.CreateScriptPreferences;
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.dialects.CreateScriptPreferences;
import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
@@ -42,8 +42,6 @@
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.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.event.AnalysisEvent;
@@ -90,11 +88,7 @@
/** Logger for this class. */
private final static ILogger log =
LoggerController.createLogger(CopyExecutor.class);
-
- /** Internationalized strings for this class. */
- private static final StringManager s_stringMgr =
- StringManagerFactory.getStringManager(CopyExecutor.class);
-
+
/** the list of ITableInfos that represent the user's last selection. */
private ArrayList<ITableInfo> selectedTableInfos = null;
@@ -121,8 +115,8 @@
*/
public CopyExecutor(SessionInfoProvider p) {
prov = p;
- sourceSession = prov.getCopySourceSession();
- destSession = prov.getCopyDestSession();
+ sourceSession = prov.getSourceSession();
+ destSession = prov.getDestSession();
}
/**
@@ -158,17 +152,19 @@
return;
}
setupAutoCommit(destConn);
- IDatabaseObjectInfo[] sourceObjs = prov.getSourceSelectedDatabaseObjects();
+ List<IDatabaseObjectInfo> sourceObjs = prov.getSourceDatabaseObjects();
int[] counts = getTableCounts();
sendCopyStarted(counts);
- String destSchema = prov.getDestSelectedDatabaseObject().getSimpleName();
- String destCatalog = prov.getDestSelectedDatabaseObject().getCatalogName();
- for (int i = 0; i < sourceObjs.length; i++) {
- if (false == sourceObjs[i] instanceof ITableInfo) {
+ String destSchema = prov.getDestDatabaseObject().getSimpleName();
+ String destCatalog = prov.getDestDatabaseObject().getCatalogName();
+
+ int sourceObjectCount = 0;
+ for (IDatabaseObjectInfo info : sourceObjs) {
+ if (! (info instanceof ITableInfo)) {
continue;
}
- ITableInfo sourceTI = (ITableInfo)sourceObjs[i];
- sendTableCopyStarted(sourceTI, i+1);
+ ITableInfo sourceTI = (ITableInfo)info;
+ sendTableCopyStarted(sourceTI, sourceObjectCount+1);
try {
int destTableCount = DBUtil.getTableCount(destSession,
destCatalog,
@@ -199,9 +195,9 @@
}
}
- copyTable(sourceTI, counts[i]);
+ copyTable(sourceTI, counts[sourceObjectCount]);
- if (i == sourceObjs.length - 1 && !cancelled) {
+ if (sourceObjectCount == sourceObjs.size() - 1 && !cancelled) {
// We just copied the last table. Now it is safe to copy the
// constraints.(Well, that is, if all FK dependencies are met
// in the group of tables being copied.
@@ -211,7 +207,7 @@
copyConstraints(sourceObjs);
}
if (!cancelled) {
- sendTableCopyFinished(sourceTI, i+1);
+ sendTableCopyFinished(sourceTI, sourceObjectCount+1);
sleep(prefs.getTableDelayMillis());
}
} catch (SQLException e) {
@@ -230,6 +226,7 @@
sendErrorEvent(ErrorEvent.GENERIC_EXCEPTION, e);
break;
}
+ sourceObjectCount++;
}
restoreAutoCommit(destConn);
if (cancelled) {
@@ -241,9 +238,11 @@
}
end = System.currentTimeMillis();
- ISession session = prov.getCopyDestSession();
- session.getSchemaInfo().reload(prov.getDestSelectedDatabaseObject());
- session.getSchemaInfo().fireSchemaInfoUpdate();
+ ISession session = prov.getDestSession();
+ if (session.getSessionSheet() != null) {
+ session.getSchemaInfo().reload(prov.getDestDatabaseObject());
+ session.getSchemaInfo().fireSchemaInfoUpdate();
+ }
notifyCopyFinished();
}
@@ -293,8 +292,8 @@
if (!prefs.isTestColumnNames()) {
return true;
}
- if (DBUtil.sameDatabaseType(prov.getCopySourceSession(),
- prov.getCopyDestSession()))
+ if (DBUtil.sameDatabaseType(prov.getSourceSession(),
+ prov.getDestSession()))
{
// No need to check column name validity when source and dest are
// of the same type of database.
@@ -302,11 +301,13 @@
}
sendAnalysisStarted();
try {
- IDatabaseObjectInfo[] dbObjs = prov.getSourceSelectedDatabaseObjects();
- for (int tableIdx = 0; tableIdx < dbObjs.length; tableIdx++) {
- ITableInfo ti = (ITableInfo)dbObjs[tableIdx];
- sendAnalyzingTable(ti, tableIdx);
+ List<IDatabaseObjectInfo> dbObjs = prov.getSourceDatabaseObjects();
+ int sourceObjectCount = 0;
+ for (IDatabaseObjectInfo info : dbObjs) {
+ ITableInfo ti = (ITableInfo) info;
+ sendAnalyzingTable(ti, sourceObjectCount+1);
DBUtil.validateColumnNames(ti, prov);
+ sourceObjectCount++;
}
} catch (MappingException e) {
sendErrorEvent(ErrorEvent.MAPPING_EXCEPTION_TYPE, e);
@@ -362,21 +363,22 @@
private int[] getTableCounts() {
int[] result = null;
- ISession sourceSession = prov.getCopySourceSession();
- IDatabaseObjectInfo[] dbObjs = prov.getSourceSelectedDatabaseObjects();
+ ISession sourceSession = prov.getSourceSession();
+ List<IDatabaseObjectInfo> dbObjs = prov.getSourceDatabaseObjects();
if (dbObjs != null) {
- result = new int[dbObjs.length];
+ result = new int[dbObjs.size()];
selectedTableInfos = new ArrayList<ITableInfo>();
- for (int i = 0; i < dbObjs.length; i++) {
- if (false == dbObjs[i] instanceof ITableInfo) {
+ int sourceObjectCount = 0;
+ for (IDatabaseObjectInfo info : dbObjs) {
+ if (! (info instanceof ITableInfo)) {
continue;
}
try {
- ITableInfo ti = (ITableInfo) dbObjs[i];
+ ITableInfo ti = (ITableInfo) info;
selectedTableInfos.add(ti);
// This doesn't appear to work for PROGRESS RDBMS
//result[i] = DBUtil.getTableCount(con, ti.getSimpleName());
- result[i] =
+ result[sourceObjectCount] =
DBUtil.getTableCount(sourceSession,
ti.getCatalogName(),
ti.getSchemaName(),
@@ -384,8 +386,9 @@
DialectFactory.SOURCE_TYPE);
} catch (Exception e) {
log.error("",e);
- result[i] = 0;
+ result[sourceObjectCount] = 0;
}
+ sourceObjectCount++;
}
}
return result;
@@ -402,7 +405,7 @@
private void sendAnalyzingTable(ITableInfo ti, int number) {
TableEvent event = new TableEvent(prov);
- event.setTableCount(prov.getSourceSelectedDatabaseObjects().length);
+ event.setTableCount(prov.getSourceDatabaseObjects().size());
event.setTableNumber(number);
Iterator<CopyTableListener> i = listeners.iterator();
event.setTableName(ti.getSimpleName());
@@ -425,7 +428,7 @@
private void sendTableCopyStarted(ITableInfo ti, int number) {
TableEvent event = new TableEvent(prov);
event.setTableNumber(number);
- event.setTableCount(prov.getSourceSelectedDatabaseObjects().length);
+ event.setTableCount(prov.getSourceDatabaseObjects().size());
event.setTableName(ti.getSimpleName());
Iterator<CopyTableListener> i = listeners.iterator();
while (i.hasNext()) {
@@ -437,7 +440,7 @@
private void sendTableCopyFinished(ITableInfo ti, int number) {
TableEvent event = new TableEvent(prov);
event.setTableNumber(number);
- event.setTableCount(prov.getSourceSelectedDatabaseObjects().length);
+ event.setTableCount(prov.getSourceDatabaseObjects().size());
event.setTableName(ti.getSimpleName());
Iterator<CopyTableListener> i = listeners.iterator();
while (i.hasNext()) {
@@ -529,15 +532,15 @@
if (!PreferencesManager.getPreferences().isCopyData()) {
return;
}
- ISQLConnection sourceConn = prov.getCopySourceSession().getSQLConnection();
- ISQLConnection destConn = prov.getCopyDestSession().getSQLConnection();
+ ISQLConnection sourceConn = prov.getSourceSession().getSQLConnection();
+ ISQLConnection destConn = prov.getDestSession().getSQLConnection();
SQLDatabaseMetaData sourceMetaData = sourceConn.getSQLMetaData();
SQLDatabaseMetaData destMetaData = destConn.getSQLMetaData();
try {
String destSchema =
- prov.getDestSelectedDatabaseObject().getSimpleName();
+ prov.getDestDatabaseObject().getSimpleName();
ITableInfo destTableInfo =
- DBUtil.getTableInfo(prov.getCopyDestSession(),
+ DBUtil.getTableInfo(prov.getDestSession(),
destSchema,
sourceTableInfo.getSimpleName());
@@ -568,7 +571,7 @@
boolean foundLOBType = false;
// Loop through source records...
DBUtil.setLastStatement(selectSQL);
- rs = DBUtil.executeQuery(prov.getCopySourceSession(), selectSQL);
+ rs = DBUtil.executeQuery(prov.getSourceSession(), selectSQL);
DBUtil.setLastStatement(insertSQL);
boolean isMysql = DialectFactory.isMySQL(destSession.getMetaData());
boolean isSourceOracle =
@@ -589,14 +592,14 @@
int sourceColType = sourceInfos[i].getDataType();
// If source column is type 1111 (OTHER), try to use the
// column type name to find a type that isn't 1111.
- sourceColType = DBUtil.replaceOtherDataType(sourceInfos[i], prov.getCopySourceSession());
+ sourceColType = DBUtil.replaceOtherDataType(sourceInfos[i], prov.getSourceSession());
sourceColType = getDateReplacement(sourceColType,
isSourceOracle);
int destColType = destInfos[i].getDataType();
// If source column is type 1111 (OTHER), try to use the
// column type name to find a type that isn't 1111.
- destColType = DBUtil.replaceOtherDataType(destInfos[i], prov.getCopyDestSession());
+ destColType = DBUtil.replaceOtherDataType(destInfos[i], prov.getDestSession());
destColType = getDateReplacement(destColType, isDestOracle);
@@ -696,7 +699,7 @@
//source database is {1}, but column count for table {2} in
//destination database is {3}
String msg =
- s_stringMgr.getString("CopyExecutor.tablecolmismatch",
+ getMessage("CopyExecutor.tablecolmismatch",
new Object[] {
sourceTableName,
Integer.valueOf(sourceInfos.length),
@@ -756,16 +759,16 @@
* @param ti
* @throws SQLException
*/
- private void copyConstraints(IDatabaseObjectInfo[] dbObjs)
+ private void copyConstraints(List<IDatabaseObjectInfo> dbObjs)
throws SQLException, UserCancelledOperationException
{
if (!prefs.isCopyForeignKeys()
- || DialectFactory.isAxion(prov.getCopySourceSession().getMetaData())) {
+ || DialectFactory.isAxion(prov.getSourceSession().getMetaData())) {
return;
}
- ISQLConnection destConn = prov.getCopyDestSession().getSQLConnection();
- for (int i = 0; i < dbObjs.length; i++) {
- ITableInfo ti = (ITableInfo) dbObjs[i];
+ ISQLConnection destConn = prov.getDestSession().getSQLConnection();
+ for (IDatabaseObjectInfo info : dbObjs) {
+ ITableInfo ti = (ITableInfo) info;
Set<String> fkStmts =
DBUtil.getForeignKeySQL(prov, ti, selectedTableInfos);
Iterator<String> it = fkStmts.iterator();
@@ -788,7 +791,7 @@
if (cancelled) {
return;
}
- ISQLConnection destCon = prov.getCopyDestSession().getSQLConnection();
+ ISQLConnection destCon = prov.getDestSession().getSQLConnection();
String createTableSql = DBUtil.getCreateTableSql(prov, ti);
DBUtil.executeUpdate(destCon, createTableSql, true);
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 2011-07-10 18:38:03 UTC (rev 6311)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyProgressMonitor.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -82,7 +82,7 @@
public CopyProgressMonitor(SessionInfoProvider provider) {
prov = provider;
- parent = prov.getCopyDestSession().getApplication().getMainFrame();
+ parent = prov.getDestSession().getApplication().getMainFrame();
}
// CopyTableListener interface methods
@@ -95,7 +95,7 @@
pm.setProgress(pm.getMaximum());
}
prov = e.getSessionInfoProvider();
- int numTables = prov.getSourceSelectedDatabaseObjects().length;
+ int numTables = prov.getSourceDatabaseObjects().size();
int[] tableCounts = e.getTableCounts();
createProgressDialog();
@@ -459,7 +459,7 @@
pm.setProgress(e.getTableNumber());
}
- /* (non-Javadoc)
+ /**
* @see net.sourceforge.squirrel_sql.plugins.dbcopy.event.CopyTableListener#tableAnalysisStarted(net.sourceforge.squirrel_sql.plugins.dbcopy.event.AnalysisEvent)
*/
public void tableAnalysisStarted(AnalysisEvent e) {
@@ -469,7 +469,7 @@
"Analyzing column names in tables to be copied",
"",
0,
- prov.getSourceSelectedDatabaseObjects().length);
+ prov.getSourceDatabaseObjects().size());
}
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyScripter.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyScripter.java 2011-07-10 18:38:03 UTC (rev 6311)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyScripter.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -63,8 +63,8 @@
* @param prov
*/
private void initializeScript(SessionInfoProvider prov) {
- ISession source = prov.getCopySourceSession();
- ISession dest = prov.getCopyDestSession();
+ ISession source = prov.getSourceSession();
+ ISession dest = prov.getDestSession();
ScriptWriter.open(source,dest);
}
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 2011-07-10 18:38:03 UTC (rev 6311)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPlugin.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -19,6 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+import java.util.List;
+
import javax.swing.SwingUtilities;
import net.sourceforge.squirrel_sql.client.IApplication;
@@ -58,7 +60,7 @@
private ISession copyDestSession = null;
- private IDatabaseObjectInfo[] selectedDatabaseObjects = null;
+ private List<IDatabaseObjectInfo> selectedDatabaseObjects = null;
private IDatabaseObjectInfo selectedDestDatabaseObject = null;
@@ -172,9 +174,9 @@
IApplication app = getApplication();
ActionCollection coll = app.getActionCollection();
-
+
PasteTableAction pasteTableAction = new PasteTableAction(app, _resources, this);
-
+
coll.add(new CopyTableAction(app, _resources, this));
coll.add(pasteTableAction);
@@ -226,16 +228,18 @@
* @param selectedDatabaseObjects
* The selectedDatabaseObjects to set.
*/
- public void setSelectedDatabaseObjects(IDatabaseObjectInfo[] dbObjArr)
+ public void setSourceDatabaseObjects(List<IDatabaseObjectInfo> dbObjList)
{
- if (dbObjArr != null)
+ if (dbObjList != null)
{
- selectedDatabaseObjects = dbObjArr;
- for (int i = 0; i < dbObjArr.length; i++)
+ selectedDatabaseObjects = dbObjList;
+ int sourceObjectCount = 0;
+ if (s_log.isDebugEnabled())
{
- if (s_log.isDebugEnabled())
+ for (IDatabaseObjectInfo info : dbObjList)
{
- s_log.debug("setSelectedDatabaseObjects: IDatabaseObjectInfo[" + i + "]=" + dbObjArr[i]);
+ s_log.debug("setSelectedDatabaseObjects: IDatabaseObjectInfo[" + (sourceObjectCount++) + "]="
+ + info);
}
}
}
@@ -304,17 +308,17 @@
}
/**
- * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getCopySourceSession()
+ * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getSourceSession()
*/
- public ISession getCopySourceSession()
+ public ISession getSourceSession()
{
return copySourceSession;
}
/**
- * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#setCopySourceSession(net.sourceforge.squirrel_sql.client.session.ISession)
+ * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#setSourceSession(net.sourceforge.squirrel_sql.client.session.ISession)
*/
- public void setCopySourceSession(ISession session)
+ public void setSourceSession(ISession session)
{
if (session != null)
{
@@ -323,41 +327,41 @@
}
/**
- * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getSourceSelectedDatabaseObjects()
+ * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getSourceDatabaseObjects()
*/
- public IDatabaseObjectInfo[] getSourceSelectedDatabaseObjects()
+ public List<IDatabaseObjectInfo> getSourceDatabaseObjects()
{
return selectedDatabaseObjects;
}
/**
- * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getCopyDestSession()
+ * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getDestSession()
*/
- public ISession getCopyDestSession()
+ public ISession getDestSession()
{
return copyDestSession;
}
/**
- * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#setDestCopySession(net.sourceforge.squirrel_sql.client.session.ISession)
+ * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#setDestSession(net.sourceforge.squirrel_sql.client.session.ISession)
*/
- public void setDestCopySession(ISession session)
+ public void setDestSession(ISession session)
{
copyDestSession = session;
}
/**
- * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getDestSelectedDatabaseObject()
+ * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#getDestDatabaseObject()
*/
- public IDatabaseObjectInfo getDestSelectedDatabaseObject()
+ public IDatabaseObjectInfo getDestDatabaseObject()
{
return selectedDestDatabaseObject;
}
/**
- * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#setDestSelectedDatabaseObject(net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo)
+ * @see net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider#setDestDatabaseObject(net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo)
*/
- public void setDestSelectedDatabaseObject(IDatabaseObjectInfo info)
+ public void setDestDatabaseObject(IDatabaseObjectInfo info)
{
selectedDestDatabaseObject = info;
}
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 2011-07-10 18:38:03 UTC (rev 6311)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/SessionInfoProvider.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -18,6 +18,8 @@
*/
package net.sourceforge.squirrel_sql.plugins.dbcopy;
+import java.util.List;
+
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
@@ -27,17 +29,19 @@
*/
public interface SessionInfoProvider {
- public void setCopySourceSession(ISession session);
+ public void setSourceSession(ISession session);
- public ISession getCopySourceSession();
+ public ISession getSourceSession();
- public IDatabaseObjectInfo[] getSourceSelectedDatabaseObjects();
+ public void setSourceDatabaseObjects(List<IDatabaseObjectInfo> dbObjList);
- public IDatabaseObjectInfo getDestSelectedDatabaseObject();
+ public List<IDatabaseObjectInfo> getSourceDatabaseObjects();
- public void setDestSelectedDatabaseObject(IDatabaseObjectInfo info);
+ public IDatabaseObjectInfo getDestDatabaseObject();
- public void setDestCopySession(ISession session);
+ public void setDestDatabaseObject(IDatabaseObjectInfo info);
- public ISession getCopyDestSession();
+ public void setDestSession(ISession session);
+
+ public ISession getDestSession();
}
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 2011-07-10 18:38:03 UTC (rev 6311)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableAction.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -78,7 +78,7 @@
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent evt) {
- ISession destSession = sessionInfoProv.getCopyDestSession();
+ ISession destSession = sessionInfoProv.getDestSession();
IObjectTreeAPI api =
destSession.getObjectTreeAPIOfActiveSessionWindow();
if (api == null) {
@@ -86,7 +86,7 @@
}
IDatabaseObjectInfo[] dbObjs = api.getSelectedDatabaseObjects();
if (dbObjs.length > 1) {
- sessionInfoProv.setDestSelectedDatabaseObject(null);
+ sessionInfoProv.setDestDatabaseObject(null);
//i18n[PasteTableAction.error.multischemapaste=The paste
//operation may only be applied to one schema at a time]
String msg =
@@ -110,16 +110,16 @@
tableLabelInfo.getSchemaName(),
DatabaseObjectType.SCHEMA,
md);
- sessionInfoProv.setDestSelectedDatabaseObject(schema);
+ sessionInfoProv.setDestDatabaseObject(schema);
} else {
- sessionInfoProv.setDestSelectedDatabaseObject(dbObjs[0]);
+ sessionInfoProv.setDestDatabaseObject(dbObjs[0]);
}
}
try {
IDatabaseObjectInfo info
- = sessionInfoProv.getDestSelectedDatabaseObject();
+ = sessionInfoProv.getDestDatabaseObject();
if (info == null || destSession == null) {
return;
}
@@ -129,7 +129,7 @@
} catch (UserCancelledOperationException e) {
return;
}
- if (sessionInfoProv.getCopySourceSession() == null) {
+ if (sessionInfoProv.getSourceSession() == null) {
return;
}
if (!sourceDestSchemasDiffer()) {
@@ -147,7 +147,7 @@
* @param session The current session.
*/
public void setSession(ISession session) {
- sessionInfoProv.setDestCopySession(session);
+ sessionInfoProv.setDestSession(session);
}
/**
Added: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java (rev 0)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -0,0 +1,262 @@
+package net.sourceforge.squirrel_sql.plugins.dbcopy.cli;
+
+import javax.swing.Action;
+import javax.swing.JComponent;
+import javax.swing.JMenu;
+
+import net.sourceforge.squirrel_sql.client.ApplicationListener;
+import net.sourceforge.squirrel_sql.client.FontInfoStore;
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.action.ActionCollection;
+import net.sourceforge.squirrel_sql.client.gui.WindowManager;
+import net.sourceforge.squirrel_sql.client.gui.db.DataCache;
+import net.sourceforge.squirrel_sql.client.gui.desktopcontainer.DesktopStyle;
+import net.sourceforge.squirrel_sql.client.gui.mainframe.MainFrame;
+import net.sourceforge.squirrel_sql.client.plugin.IPlugin;
+import net.sourceforge.squirrel_sql.client.plugin.IPluginManager;
+import net.sourceforge.squirrel_sql.client.preferences.PreferenceType;
+import net.sourceforge.squirrel_sql.client.preferences.SquirrelPreferences;
+import net.sourceforge.squirrel_sql.client.resources.SquirrelResources;
+import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanelFactory;
+import net.sourceforge.squirrel_sql.client.session.SessionManager;
+import net.sourceforge.squirrel_sql.client.session.mainpanel.SQLHistory;
+import net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.IWikiTableConfigurationFactory;
+import net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager;
+import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
+import net.sourceforge.squirrel_sql.fw.util.TaskThreadPool;
+
+public class ApplicationStub implements IApplication
+{
+
+ private SessionManager sessionManager = null;
+
+ private SquirrelPreferences squirrelPreferences = new SquirrelPreferences();
+
+ private TaskThreadPool threadPool = new TaskThreadPool();
+
+ public ApplicationStub()
+ {
+ sessionManager = new SessionManager(this);
+ }
+
+ @Override
+ public void addApplicationListener(ApplicationListener l)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void addToMenu(int menuId, JMenu menu)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void addToMenu(int menuId, Action action)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void addToStatusBar(JComponent comp)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public ActionCollection getActionCollection()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataCache getDataCache()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DesktopStyle getDesktopStyle()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IPlugin getDummyAppPlugin()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public FontInfoStore getFontInfoStore()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public MainFrame getMainFrame()
+ {
+ return null;
+ }
+
+ @Override
+ public IMessageHandler getMessageHandler()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IPluginManager getPluginManager()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SquirrelResources getResources()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SQLDriverManager getSQLDriverManager()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ISQLEntryPanelFactory getSQLEntryPanelFactory()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SQLHistory getSQLHistory()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SessionManager getSessionManager()
+ {
+ return sessionManager;
+ }
+
+ @Override
+ public SquirrelPreferences getSquirrelPreferences()
+ {
+ return squirrelPreferences;
+ }
+
+ @Override
+ public TaskThreadPool getThreadPool()
+ {
+ return threadPool;
+ }
+
+ @Override
+ public IWikiTableConfigurationFactory getWikiTableConfigFactory()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public WindowManager getWindowManager()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void openURL(String url)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void removeApplicationListener(ApplicationListener l)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void removeFromStatusBar(JComponent comp)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void saveApplicationState()
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void savePreferences(PreferenceType preferenceType)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void setSQLEntryPanelFactory(ISQLEntryPanelFactory factory)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void showErrorDialog(String msg)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void showErrorDialog(Throwable th)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void showErrorDialog(String msg, Throwable th)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public boolean shutdown(boolean updateLaunchScript)
+ {
+
+ return false;
+ }
+
+ @Override
+ public void startup()
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+}
Added: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java (rev 0)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -0,0 +1,83 @@
+package net.sourceforge.squirrel_sql.plugins.dbcopy.cli;
+
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.AnalysisEvent;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.CopyEvent;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.CopyTableListener;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.ErrorEvent;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.RecordEvent;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.StatementEvent;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.TableEvent;
+
+public class CLCopyListener implements CopyTableListener
+{
+
+ private boolean copyFinished = false;
+
+ public boolean isCopyFinished() {
+ return copyFinished;
+ }
+
+ @Override
+ public void analyzingTable(TableEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void copyFinished(int seconds)
+ {
+ copyFinished = true;
+ }
+
+ @Override
+ public void copyStarted(CopyEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void handleError(ErrorEvent e)
+ {
+ System.err.println("Encountered the following exception: "+e.getException().getMessage());
+ e.getException().printStackTrace();
+ copyFinished = true;
+ }
+
+ @Override
+ public void recordCopied(RecordEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void statementExecuted(StatementEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void tableAnalysisStarted(AnalysisEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void tableCopyFinished(TableEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void tableCopyStarted(TableEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java (rev 0)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -0,0 +1,21 @@
+package net.sourceforge.squirrel_sql.plugins.dbcopy.cli;
+
+import net.sourceforge.squirrel_sql.fw.dialects.UserCancelledOperationException;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.UICallbacks;
+
+public class CLCopyUICallback implements UICallbacks
+{
+
+ @Override
+ public boolean appendRecordsToExisting(String tableName) throws UserCancelledOperationException
+ {
+ return false;
+ }
+
+ @Override
+ public boolean deleteTableData(String tableName) throws UserCancelledOperationException
+ {
+ return true;
+ }
+
+}
Added: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java (rev 0)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -0,0 +1,192 @@
+package net.sourceforge.squirrel_sql.plugins.dbcopy.cli;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+
+/**
+ * Class that processes arguments that are specific to the DBCopy command-line.
+ */
+public class CommandLineArgumentProcessor
+{
+ public static final String SOURCE_CATALOG = "source-catalog";
+
+ public static final String SOURCE_SCHEMA = "source-schema";
+
+ public static final String DEST_CATALOG = "dest-catalog";
+
+ public static final String DEST_SCHEMA = "dest-schema";
+
+ public static final String TABLE_PATTERN = "table-pattern";
+
+ public static final String TABLE_LIST = "table-list";
+
+ public static final String DEST_SESSION = "dest-alias";
+
+ public static final String SOURCE_SESSION = "source-alias";
+
+ private Options options = new Options();
+
+ private CommandLine cmd = null;
+
+ private boolean valid = true;
+
+ public CommandLineArgumentProcessor(String[] args) throws ParseException
+ {
+ createOptions();
+ CommandLineParser parser = new GnuParser();
+ try {
+ cmd = parser.parse(options, args);
+ } catch (Exception e) {
+ HelpFormatter formatter = new HelpFormatter();
+ System.out.println(e.getMessage());
+ formatter.printHelp("DBCopyCLI", options, true);
+ valid = false;
+ }
+ }
+
+ @SuppressWarnings("static-access")
+ private void createOptions()
+ {
+ Option sourceOption =
+ OptionBuilder.hasArg().isRequired().withLongOpt(SOURCE_SESSION).withDescription(
+ "The name of the source alias to copy tables from").create();
+ options.addOption(sourceOption);
+
+ Option destOption =
+ OptionBuilder.hasArg().isRequired().withLongOpt(DEST_SESSION).withDescription(
+ "The name of the destination alias to copy tables to").create();
+ options.addOption(destOption);
+
+ Option sourceSchemaOption =
+ OptionBuilder.hasArg().withLongOpt(SOURCE_SCHEMA).withDescription(
+ "The source schema to copy tables from").create();
+
+ Option sourceCatalogOption =
+ OptionBuilder.hasArg().withLongOpt(SOURCE_CATALOG).withDescription(
+ "The source catalog to copy tables from").create();
+
+ OptionGroup sourceSchemaGroup = new OptionGroup();
+ sourceSchemaGroup.setRequired(true);
+ sourceSchemaGroup.addOption(sourceSchemaOption);
+ sourceSchemaGroup.addOption(sourceCatalogOption);
+
+ options.addOptionGroup(sourceSchemaGroup);
+
+ Option listOption =
+ OptionBuilder.hasArg().withLongOpt(TABLE_LIST).withDescription(
+ "A comma-delimited list of tables to copy").create();
+ Option patternOption =
+ OptionBuilder.hasArg().withLongOpt(TABLE_PATTERN).withDescription(
+ "A regexp pattern to match source table names").create();
+
+ OptionGroup tableGroup = new OptionGroup();
+ tableGroup.setRequired(true);
+ tableGroup.addOption(listOption);
+ tableGroup.addOption(patternOption);
+
+ options.addOptionGroup(tableGroup);
+
+ Option destSchemaOption =
+ OptionBuilder.hasArg().withLongOpt(DEST_SCHEMA).withDescription(
+ "The destination schema to copy tables into").create();
+
+ Option destCatalogOption =
+ OptionBuilder.hasArg().withLongOpt(DEST_CATALOG).withDescription(
+ "The destination catalog to copy tables into").create();
+
+ OptionGroup destSchemaGroup = new OptionGroup();
+ destSchemaGroup.setRequired(true);
+ destSchemaGroup.addOption(destSchemaOption);
+ destSchemaGroup.addOption(destCatalogOption);
+
+ options.addOptionGroup(destSchemaGroup);
+
+
+ }
+
+ public boolean isValid() {
+ return valid;
+ }
+
+ public void validate()
+ {
+ try
+ {
+ if (!cmd.hasOption(SOURCE_SESSION))
+ {
+ throw new ParseException("Missing " + SOURCE_SESSION);
+ }
+ if (!cmd.hasOption(DEST_SESSION))
+ {
+ throw new ParseException("Missing " + DEST_SESSION);
+ }
+ if (!cmd.hasOption(TABLE_LIST) && !cmd.hasOption(TABLE_PATTERN))
+ {
+ throw new ParseException("Must specify either " + TABLE_LIST + " or " + TABLE_PATTERN);
+ }
+ if (!cmd.hasOption(DEST_SCHEMA))
+ {
+ throw new ParseException("Missing " + DEST_SCHEMA);
+ }
+ }
+ catch (ParseException e)
+ {
+ HelpFormatter formatter = new HelpFormatter();
+ System.out.println(e.getMessage());
+ formatter.printHelp("DBCopyCLI", options, true);
+ System.exit(1);
+
+ }
+ }
+
+ public String getSourceAliasName() {
+ return cmd.getOptionValue(SOURCE_SESSION);
+ }
+
+ public String getDestAliasName() {
+ return cmd.getOptionValue(DEST_SESSION);
+ }
+
+ public String getDestSchemaName() {
+ return cmd.getOptionValue(DEST_SCHEMA);
+ }
+
+ public String getDestCatalogName() {
+ return cmd.getOptionValue(DEST_CATALOG);
+ }
+
+ public String getSourceCatalogName() {
+ return cmd.getOptionValue(SOURCE_CATALOG);
+ }
+
+ public String getSourceSchemaName() {
+ return cmd.getOptionValue(SOURCE_SCHEMA);
+ }
+
+ public List<String> getTableList() {
+ List<String> result = new ArrayList<String>();
+ if (cmd.hasOption(TABLE_LIST)) {
+ String tableListStr = cmd.getOptionValue(TABLE_LIST);
+ if (tableListStr.contains(",")) {
+ String[] parts = tableListStr.split(",");
+ for (String part : parts) {
+ result.add(part);
+ }
+ } else {
+ result.add(tableListStr);
+ }
+ }
+ // TODO: add support for regular expression.
+ return result;
+ }
+}
Added: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java (rev 0)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -0,0 +1,168 @@
+package net.sourceforge.squirrel_sql.plugins.dbcopy.cli;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.lang.StringUtils;
+
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.gui.db.DataCache;
+import net.sourceforge.squirrel_sql.client.gui.db.SQLAlias;
+import net.sourceforge.squirrel_sql.client.resources.SquirrelResources;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.client.session.SessionManager;
+import net.sourceforge.squirrel_sql.client.util.ApplicationFiles;
+import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
+import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLAlias;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLDriver;
+import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
+import net.sourceforge.squirrel_sql.fw.sql.SQLConnection;
+import net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager;
+import net.sourceforge.squirrel_sql.fw.sql.TableInfo;
+import net.sourceforge.squirrel_sql.fw.util.StringUtilities;
+import net.sourceforge.squirrel_sql.fw.util.Utilities;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.CopyExecutor;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.DBCopyPlugin;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.CopyTableListener;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.PreferencesManager;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.util.DBUtil;
+
+/*
+ * Copyright (C) 2011 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+public class DBCopyCLI
+{
+ private static IApplication applicationStub = new ApplicationStub();
+
+ private static ApplicationFiles applicationFiles = new ApplicationFiles();
+
+ private static SquirrelResources squirrelResources =
+ new SquirrelResources(SquirrelResources.BUNDLE_BASE_NAME);
+
+ private static SQLDriverManager sqlDriverManager = new SQLDriverManager();
+
+ private static DataCache dataCache = null;
+
+ private static ISession sourceSession = null;
+
+ // private static ISession destSession = null;
+
+ private static SessionInfoProvider sessionInfoProvider = new SessionInfoProviderImpl();
+
+ private static ArrayList<ITableInfo> tables = new ArrayList<ITableInfo>();
+
+ private static CLCopyListener listener = new CLCopyListener();
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) throws Exception
+ {
+ CommandLineArgumentProcessor argProcessor = new CommandLineArgumentProcessor(args);
+ String sourceSchemaName = argProcessor.getSourceSchemaName();
+ String sourceCatalogName = argProcessor.getSourceCatalogName();
+ String destSchemaName = argProcessor.getDestSchemaName();
+ String destCatalogName = argProcessor.getDestCatalogName();
+ String simpleName = StringUtils.isEmpty(destSchemaName) ? destCatalogName : destSchemaName;
+
+ dataCache =
+ new DataCache(sqlDriverManager, applicationFiles.getDatabaseDriversFile(),
+ applicationFiles.getDatabaseAliasesFile(), squirrelResources.getDefaultDriversUrl(),
+ applicationStub);
+
+ ISession destSession = getSessionForAlias(argProcessor.getDestAliasName());
+
+ sessionInfoProvider.setSourceSession(getSessionForAlias(argProcessor.getSourceAliasName()));
+ sessionInfoProvider.setDestSession(destSession);
+ for (String tableStr : argProcessor.getTableList())
+ {
+ tables.add(getTableInfo(sessionInfoProvider.getSourceSession(), sourceSchemaName, sourceCatalogName,
+ tableStr));
+ }
+
+ sessionInfoProvider.setSourceDatabaseObjects(DBUtil.convertTableToObjectList(tables));
+
+ DatabaseObjectInfo destObject =
+ new DatabaseObjectInfo(destCatalogName, destSchemaName, simpleName, DatabaseObjectType.SCHEMA,
+ destSession.getMetaData());
+ sessionInfoProvider.setDestDatabaseObject(destObject);
+
+ PreferencesManager.initialize(new DBCopyPlugin());
+ DBUtil.setPreferences(PreferencesManager.getPreferences());
+ DialectFactory.isPromptForDialect = false;
+
+ CopyExecutor executor = new CopyExecutor(sessionInfoProvider);
+ executor.addListener(listener);
+ executor.setPref(new CLCopyUICallback());
+ executor.execute();
+
+ while (!listener.isCopyFinished()) {
+ System.out.print(".");
+ Thread.sleep(2000);
+ }
+
+ }
+
+ private static ITableInfo getTableInfo(ISession session, String schemaName, String catalogName,
+ String tableName) throws SQLException
+ {
+ ISQLDatabaseMetaData md = session.getMetaData();
+ ITableInfo[] result = md.getTables(catalogName, schemaName, tableName, new String[] { "TABLE" }, null);
+ return result[0];
+ }
+
+ private static ISession getSessionForAlias(String alias) throws Exception
+ {
+ Iterator<ISQLAlias> i = dataCache.aliases();
+
+ while (i.hasNext())
+ {
+ ISQLAlias sqlAlias = i.next();
+ if (alias.equals(sqlAlias.getName()))
+ {
+
+ ISQLDriver sqlDriver = dataCache.getDriver(sqlAlias.getDriverIdentifier());
+ sqlDriverManager.registerSQLDriver(sqlDriver);
+ SQLConnection conn =
+ sqlDriverManager.getConnection(sqlDriver, sqlAlias, sqlAlias.getUserName(),
+ sqlAlias.getPassword(), sqlAlias.getDriverPropertiesClone());
+
+ // Class.forName(driver.getDriverClassName());
+
+ // Connection con =
+ // DriverManager.getConnection(sqlAlias.getUrl(), sqlAlias.getUserName(), sqlAlias.getPassword());
+
+ // SQLConnection conn = new SQLConnection(con, sqlAlias.getDriverPropertiesClone(), driver);
+ SessionManager sessionManager = applicationStub.getSessionManager();
+ ISession result =
+ sessionManager.createSession(applicationStub, sqlDriver, (SQLAlias) sqlAlias, conn,
+ sqlAlias.getUserName(), sqlAlias.getPassword());
+ return result;
+ }
+ }
+ throw new RuntimeException("Alias (" + alias + ") was not found");
+ }
+}
Added: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionInfoProviderImpl.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionInfoProviderImpl.java (rev 0)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionInfoProviderImpl.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -0,0 +1,67 @@
+package net.sourceforge.squirrel_sql.plugins.dbcopy.cli;
+
+import java.util.List;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider;
+
+public class SessionInfoProviderImpl implements SessionInfoProvider
+{
+
+ private ISession sourceSession = null;
+ private ISession destSession = null;
+ private IDatabaseObjectInfo destSelectedDatabaseObject = null;
+ private List<IDatabaseObjectInfo> sourceSelectedDatabaseObjects = null;
+
+
+
+ @Override
+ public ISession getDestSession()
+ {
+ return destSession;
+ }
+
+ @Override
+ public ISession getSourceSession()
+ {
+ return sourceSession;
+ }
+
+ @Override
+ public IDatabaseObjectInfo getDestDatabaseObject()
+ {
+ return destSelectedDatabaseObject;
+ }
+
+ @Override
+ public List<IDatabaseObjectInfo> getSourceDatabaseObjects()
+ {
+ return sourceSelectedDatabaseObjects;
+ }
+
+ @Override
+ public void setSourceSession(ISession session)
+ {
+ this.sourceSession = session;
+ }
+
+ @Override
+ public void setDestSession(ISession session)
+ {
+ this.destSession = session;
+ }
+
+ @Override
+ public void setDestDatabaseObject(IDatabaseObjectInfo info)
+ {
+ this.destSelectedDatabaseObject = info;
+ }
+
+ @Override
+ public void setSourceDatabaseObjects(List<IDatabaseObjectInfo> dbObjList)
+ {
+ this.sourceSelectedDatabaseObjects = dbObjList;
+ }
+
+}
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/CopyTableCommand.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/CopyTableCommand.java 2011-07-10 18:38:03 UTC (rev 6311)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/CopyTableCommand.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -23,6 +23,9 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.collections.CollectionUtils;
+import org.jboss.util.collection.CollectionsUtil;
+
import net.sourceforge.squirrel_sql.client.gui.IProgressCallBackFactory;
import net.sourceforge.squirrel_sql.client.gui.ProgressCallBackFactory;
import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
@@ -117,7 +120,7 @@
}
}
- _plugin.setCopySourceSession(_session);
+ _plugin.setSourceSession(_session);
final IDatabaseObjectInfo[] fdbObjs = dbObjs;
final SQLDatabaseMetaData md = _session.getSQLConnection().getSQLMetaData();
_session.getApplication().getThreadPool().addTask(new Runnable()
@@ -141,16 +144,11 @@
private void getInsertionOrder(IDatabaseObjectInfo[] dbObjs, SQLDatabaseMetaData md) throws SQLException
{
-
+ List<ITableInfo> selectedTables = DBUtil.convertObjectArrayToTableList(dbObjs);
+
// Only concerned about order when more than one table.
- if (dbObjs.length > 1)
+ if (selectedTables.size() > 1)
{
- List<ITableInfo> selectedTables = new ArrayList<ITableInfo>();
- for (int i = 0; i < dbObjs.length; i++)
- {
- selectedTables.add((ITableInfo) dbObjs[i]);
- }
-
ProgressCallBack cb =
progressCallBackFactory.create(_session.getApplication().getMainFrame(),
i18n.PROGRESS_DIALOG_TITLE, dbObjs.length);
@@ -159,15 +157,13 @@
selectedTables = SQLUtilities.getInsertionOrder(selectedTables, md, cb);
cb.setVisible(false);
cb.dispose();
+ _plugin.setSourceDatabaseObjects(DBUtil.convertTableToObjectList(selectedTables));
- _plugin.setSelectedDatabaseObjects(selectedTables.toArray(new IDatabaseObjectInfo[dbObjs.length]));
-
}
else
{
- _plugin.setSelectedDatabaseObjects(dbObjs);
+ _plugin.setSourceDatabaseObjects(DBUtil.convertTableToObjectList(selectedTables));
}
}
-
}
\ No newline at end of file
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 2011-07-10 18:38:03 UTC (rev 6311)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/DBUtil.java 2011-07-17 00:24:47 UTC (rev 6312)
@@ -223,9 +223,9 @@
continue;
}
- ISession destSession = prov.getCopyDestSession();
- String destSchema = prov.getDestSelectedDatabaseObject().getSimpleName();
- String destCatalog = prov.getDestSelectedDatabaseObject().getCatalogName();
+ ISession destSession = prov.getDestSession();
+ String destSchema = prov.getDestDatabaseObject().getSimpleName();
+ String destCatalog = prov.getDestDatabaseObject().getCatalogName();
if (tableHasForeignKey(destCatalog, destSchema, ti.getSimpleName(), fkInfo, prov))
{
if (log.isInfoEnabled())
@@ -261,7 +261,7 @@
boolean result = false;
try
{
- SQLDatabaseMetaData md = prov.getCopyDestSession().getSQLConnection().getSQLMetaData();
+ SQLDatabaseMetaData md = prov.getDestSession().getSQLConnection().getSQLMetaData();
ITableInfo[] tables = md.getTables(destCatalog, destSchema, destTableName, new String[]
{ "TABLE" }, null);
@@ -1415,14 +1415,14 @@
MappingException, UserCancelledOperationException
{
- ISession sourceSession = prov.getCopySourceSession();
- String sourceSchema = prov.getSourceSelectedDatabaseObjects()[0].getSchemaName();
- String sourceCatalog = prov.getSourceSelectedDatabaseObjects()[0].getCatalogName();
+ ISession sourceSession = prov.getSourceSession();
+ String sourceSchema = prov.getSourceDatabaseObjects().get(0).getSchemaName();
+ String sourceCatalog = prov.getSourceDatabaseObjects().get(0).getCatalogName();
String sourceTableName = getQualifiedObjectName(
sourceSession, sourceCatalog, sourceSchema, ti.getSimpleName(), DialectFactory.SOURCE_TYPE);
- ISession destSession = prov.getCopyDestSession();
- String destSchema = prov.getDestSelectedDatabaseObject().getSimpleName();
- String destCatalog = prov.getDestSelectedDatabaseObject().getCatalogName();
+ ISession destSession = prov.getDestSession();
+ String destSchema = prov.getDestDatabaseObject().getSimpleName();
+ String destCatalog = prov.getDestDatabaseObject().getCatalogName();
String destinationTableName = getQualifiedObjectName(
destSession, destCatalog, destSchema, ti.getSimpleName(), DialectFactory.DEST_TYPE);
StringBuilder result = new StringBuilder("CREATE TABLE ");
@@ -1432,7 +1432,7 @@
TableColumnInfo colInfo = null;
try
{
- ISQLConnection sourceCon = prov.getCopySourceSession().getSQLConnection();
+ ISQLConnection sourceCon = prov.getSourceSession().getSQLConnection();
TableColumnInfo[] colInfoArr = sourceCon.getSQLMetaData().getColumnInfo(ti);
if (colInfoArr.length == 0)
{
@@ -1526,12 +1526,12 @@
String columnName = colInfo.getColumnName();
if (_prefs.isCheckKeywords())
{
- checkKeyword(prov.getCopyDestSession(), destTableName, columnName);
+ checkKeyword(prov.getDestSession(), destTableName, columnName);
}
StringBuilder result = new StringBuilder(columnName);
boolean notNullable = colInfo.isNullable().equalsIgnoreCase("NO");
String typeName = ColTypeMapper.mapColType(
- prov.getCopySourceSession(), prov.getCopyDestSession(), colInfo, sourceTableName, destTableName);
+ prov.getSourceSession(), prov.getDestSession(), colInfo, sourceTableName, destTableName);
result.append(" ");
result.append(typeName);
if (notNullable)
@@ -1539,7 +1539,7 @@
result.append(" NOT NULL");
} else
{
- ISession destSession = prov.getCopyDestSession();
+ ISession destSession = prov.getDestSession();
HibernateDialect d = DialectFactory.getDialect(
DialectFactory.DEST_TYPE, destSession.getApplication().getMainFrame(), destSession.getMetaData());
String nullString = d...
[truncated message content] |