コード例 #1
0
ファイル: CopyForce.java プロジェクト: jgoldfed/sqlforce
    public void startElement(String uri, String localName, String qName, Attributes attributes)
        throws SAXException {

      if ("include".equals(qName)) {
        String name = getAttribute(attributes, "table");
        if (null != name) {

          TableRule rule = new TableRule(name);
          String predicate = getAttribute(attributes, "where");
          if (null != predicate) {
            rule.setPredicate(predicate);
          }

          ruleSet.includeTable(rule);
          trace("Include table " + name);
        }
      }

      if ("exclude".equals(qName)) {
        String name = attributes.getValue("table");
        if (null != name && name.trim().length() > 0) {
          ruleSet.excludeTable(new TableRule(name));
          trace("Exclude table " + name);
        }
      }
    }
コード例 #2
0
ファイル: CopyForce.java プロジェクト: jgoldfed/sqlforce
    private void addCommandLineIncludeRules(String arg) {
      String newRules[] = arg.split("\\s*,\\s*");

      for (String rule : newRules) {
        rules.includeTable(new TableRule(rule, false));
      }
    }
コード例 #3
0
ファイル: CopyForce.java プロジェクト: jgoldfed/sqlforce
    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");
    }