/** * Start a copy from Salesforce. * * @param args command line switches controlling the copy. * @param monitor class used to monitor the progress of the copy. If this parameter is null, it * will be set based on the command line switches. * @throws Exception if anything goes wrong. */ public void execute(String args[], IExtractionMonitor monitor) throws Exception { CommandLineParser parser = new CommandLineParser(cmdSwitches.toArray(new SwitchDef[0])); args = (null == args ? new String[0] : args); parser.parse(args); boolean isGUI = parser.isSet(SW_GUI); boolean isSilent = parser.isSet(SW_SILENT); if (null == monitor) { if (isSilent) { monitor = new DefaultExtractionMonitor(); } else if (isGUI) { monitor = new SwingExtractionMonitor(); } else { monitor = new OutputStreamExtractionMonitor(); } } CopyThread thread = new CopyThread(parser, monitor); thread.start(); // thread.join(); if (null != thread.exception) { throw thread.exception; } }
private void copy() throws Exception { traceMode = parser.isSet(SW_TRACE); salesforceTimeout = parser.getInt(SW_TIMEOUT); salesforceRowBufferMB = parser.getInt(SW_BUFFER); saleforceQueryBatch = parser.getInt(SW_QUERYBATCH); destRowBatchSize = parser.getInt(SW_DESTBATCH); String copyRecordsSince = parser.getString(SW_SINCE); // // Login into Salesforce. // if (!parser.isSet(SW_SALESFORCE)) { throw new Exception("Required switch " + SW_SALESFORCE + " was not specified"); } String connectString = parser.getString(SW_SALESFORCE); trace("Connect to Salesforce - " + connectString); monitor.reportMessage("Connecting to Salesforce"); LoginManager.Session session = connectToSalesforce(connectString); session.setQueryBatchSize(saleforceQueryBatch); // // Determine what should be transferred to the output database. // if (parser.isSet(SW_CONFIG)) { trace("Load extraction rules from " + parser.getString(SW_CONFIG)); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); ConfigSaxHandler handler = new ConfigSaxHandler(rules); saxParser.parse(parser.getFile(SW_CONFIG), handler); } if (parser.isSet(SW_INCLUDE)) { addCommandLineIncludeRules(parser.getString(SW_INCLUDE)); } if (0 == rules.getIncludedTableRules().size()) { rules.includeTable(new TableRule(".*", false)); } if (parser.isSet(SW_EXCLUDE)) { addCommandLineExcludeRules(parser.getString(SW_EXCLUDE)); } // // Connect to the destination database. // monitor.reportMessage("Connecting to destination database"); IDatabaseBuilder builder = getDatabaseBuilder(parser); // // Start the extraction // ExtractionManager mgr = new ExtractionManager(session, builder); mgr.setMaxBytesToBuffer(salesforceRowBufferMB * (1024 * 1024)); mgr.setMaxRowsToBuffer(destRowBatchSize); mgr.setCopyRecordsSince(copyRecordsSince); if (parser.isSet(SW_SCHEMA)) { trace("Start creation of Schema in target database"); mgr.extractSchema(rules, monitor); } trace("Start copy of data from Salesforce to target database"); mgr.extractData(rules, monitor); trace("Finished"); monitor.reportMessage("Copy is Complete"); }