Exemplo n.º 1
0
    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");
    }