public JdbcSource helpCreateValidSource() {
   final JdbcSource result = factory.createJdbcSource();
   result.setName("This is a Valid Name With Trailing Spaces   "); // $NON-NLS-1$
   result.setDriverClass(CLASSES2[0]);
   // Set the URL to something valid
   result.setUrl("jdbc:oracle:thin:@slntds01:1521:ds01a"); // $NON-NLS-1$
   result.setDriverName(exactMatchDriver.getName());
   // Create the properties ...
   for (int i = 0; i < SOURCE_PROPERTY_NAMES.length; i++) {
     helpCreateProperty(result, SOURCE_PROPERTY_NAMES[i], SOURCE_PROPERTY_VALUES[i]);
   }
   helpIsValidJdbcSource(result, JdbcManagerImpl.VALID_SOURCE, IStatus.OK);
   return result;
 }
 public JdbcSourceProperty helpCreateProperty(
     final JdbcSource source, final String name, final String value) {
   final JdbcSourceProperty prop = factory.createJdbcSourceProperty();
   prop.setName(name);
   prop.setValue(value);
   source.getProperties().add(prop);
   return prop;
 }
 public void testExcelConnectingWithBadUrl() throws Exception {
   excelSource.setUrl("jdbc:odbc:Driver={MicroSoft Excel Driver (*.xls)}"); // $NON-NLS-1$
   helpTestConnection(excelSource, null, false);
 }
 public void testIsValidJdbcSourceWithInvalidDriverClass4() {
   sampleSource.setName("This is a Valid Name"); // $NON-NLS-1$
   sampleSource.setDriverClass("not.valid class file"); // $NON-NLS-1$
   helpIsValidJdbcSource(sampleSource, JdbcManagerImpl.ILLEGAL_CHAR_IN_CLASS_NAME, IStatus.ERROR);
 }
 public void testIsValidJdbcSourceWithInvalidDriverClass2() {
   sampleSource.setName("This is a Valid Name"); // $NON-NLS-1$
   sampleSource.setDriverClass(""); // $NON-NLS-1$
   helpIsValidJdbcSource(sampleSource, JdbcManagerImpl.MISSING_DRIVER_CLASS, IStatus.ERROR);
 }
 public void testIsValidJdbcSourceWithNameStartingWithNonLetterOrNumber() {
   sampleSource.setName("*Not Valid Name since begins with a non-letter or number"); // $NON-NLS-1$
   helpIsValidJdbcSource(
       sampleSource, JdbcManagerImpl.NAME_MUST_BEGIN_WITH_LETTER_OR_NUMBER, IStatus.ERROR);
 }
 public void testIsValidJdbcSourceWithEmptyName() {
   sampleSource.setName(""); // $NON-NLS-1$
   helpIsValidJdbcSource(sampleSource, JdbcManagerImpl.NAME_NOT_SPECIFIED, IStatus.ERROR);
 }
  /*
   * @see TestCase#setUp()
   */
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    String jar_path =
        SmartTestDesignerSuite.getProjectPath("com.metamatrix.datadirect"); // $NON-NLS-1$

    JAR_FILES2 =
        new String[] {
          (new File(jar_path + "/MJbase.jar")).toURI().toURL().toString(), // $NON-NLS-1$
          (new File(jar_path + "/MJutil.jar")).toURI().toURL().toString(), // $NON-NLS-1$
          (new File(jar_path + "/MJoracle.jar")).toURI().toURL().toString() // $NON-NLS-1$
        };
    JAR_FILES_THAT_DONT_EXIST =
        new String[] {
          SmartTestDesignerSuite.getTestDataFile(getClass(), "/drivers").toURI().toURL().toString()
              + "MJbase.ZIP", //$NON-NLS-1$ //$NON-NLS-2$
          SmartTestDesignerSuite.getTestDataFile(getClass(), "/drivers").toURI().toURL().toString()
              + "MJutil.ZIP", //$NON-NLS-1$ //$NON-NLS-2$
          SmartTestDesignerSuite.getTestDataFile(getClass(), "/drivers").toURI().toURL().toString()
              + "MJoracle.ZIP" //$NON-NLS-1$ //$NON-NLS-2$
        };

    mgr = new JdbcDriverManagerForTesting();
    // mgr.start();
    sampleSource = factory.createJdbcSource();
    sampleDriver = factory.createJdbcDriver();

    // Create the source for the find method tests
    final String matchDriverName = "My Favorite Driver"; // $NON-NLS-1$
    final String matchDriverClass = CLASSES2[0];
    matchSource = factory.createJdbcSource();
    matchSource.setName("My Database"); // $NON-NLS-1$
    matchSource.setDriverName(matchDriverName);
    matchSource.setDriverClass(matchDriverClass);

    // Create a driver that the matchSource will only match by name
    nameMatchDriver = factory.createJdbcDriver();
    nameMatchDriver.setName(matchDriverName);
    nameMatchDriver.setPreferredDriverClassName(CLASSES3[0]);
    nameMatchDriver.getAvailableDriverClassNames().add(CLASSES3[0]);

    // Create a driver that the matchSource will only match by available driver
    availableClassMatchDriver = factory.createJdbcDriver();
    availableClassMatchDriver.setName(matchDriverName + " (no match)"); // $NON-NLS-1$
    availableClassMatchDriver.setPreferredDriverClassName(CLASSES2[2]);
    availableClassMatchDriver.getAvailableDriverClassNames().add(CLASSES2[0]);
    availableClassMatchDriver.getAvailableDriverClassNames().add(CLASSES2[1]);
    availableClassMatchDriver.getAvailableDriverClassNames().add(CLASSES2[2]);
    availableClassMatchDriver.getAvailableDriverClassNames().add(CLASSES2[3]);

    // Create a driver that the matchSource will only match by available driver
    preferredClassMatchDriver = factory.createJdbcDriver();
    preferredClassMatchDriver.setName(matchDriverName + " (no match)"); // $NON-NLS-1$
    preferredClassMatchDriver.setPreferredDriverClassName(matchDriverClass);
    preferredClassMatchDriver.getAvailableDriverClassNames().add(CLASSES2[0]);
    preferredClassMatchDriver.getAvailableDriverClassNames().add(CLASSES2[1]);
    preferredClassMatchDriver.getAvailableDriverClassNames().add(CLASSES2[2]);
    preferredClassMatchDriver.getAvailableDriverClassNames().add(CLASSES2[3]);

    // Create a driver that the matchSource will not match
    noMatchDriver = factory.createJdbcDriver();
    noMatchDriver.setName(matchDriverName + " (no match)"); // $NON-NLS-1$
    noMatchDriver.setPreferredDriverClassName(CLASSES3[0]);
    noMatchDriver.getAvailableDriverClassNames().add(CLASSES3[0]);

    // Create a driver that the matchSource will only match by available driver
    exactMatchDriver = factory.createJdbcDriver();
    exactMatchDriver.setName(matchDriverName);
    exactMatchDriver.setPreferredDriverClassName(matchDriverClass);
    exactMatchDriver.getAvailableDriverClassNames().add(CLASSES2[0]);
    exactMatchDriver.getAvailableDriverClassNames().add(CLASSES2[1]);
    exactMatchDriver.getAvailableDriverClassNames().add(CLASSES2[2]);
    exactMatchDriver.getAvailableDriverClassNames().add(CLASSES2[3]);
    exactMatchDriver.getJarFileUris().add(JAR_FILES2[0]);
    exactMatchDriver.getJarFileUris().add(JAR_FILES2[1]);
    exactMatchDriver.getJarFileUris().add(JAR_FILES2[2]);

    mgr.getJdbcDrivers().add(nameMatchDriver);
    mgr.getJdbcDrivers().add(availableClassMatchDriver);
    mgr.getJdbcDrivers().add(preferredClassMatchDriver);
    mgr.getJdbcDrivers().add(noMatchDriver);
    mgr.getJdbcDrivers().add(exactMatchDriver);

    metamatrixOracleDriver = factory.createJdbcDriver();
    metamatrixOracleDriver.setName("MetaMatrix JDBC for Oracle"); // $NON-NLS-1$
    metamatrixOracleDriver.getAvailableDriverClassNames().add(CLASSES2[0]);
    metamatrixOracleDriver.getAvailableDriverClassNames().add(CLASSES2[2]);
    metamatrixOracleDriver.setPreferredDriverClassName(CLASSES2[0]);
    metamatrixOracleDriver.getJarFileUris().add(JAR_FILES2[0]);
    metamatrixOracleDriver.getJarFileUris().add(JAR_FILES2[1]);
    metamatrixOracleDriver.getJarFileUris().add(JAR_FILES2[2]);

    excelDriver = factory.createJdbcDriver();
    excelDriver.setName("Microsoft Excel"); // $NON-NLS-1$
    excelDriver.getAvailableDriverClassNames().add(CLASSES3[0]);
    excelDriver.setPreferredDriverClassName(CLASSES3[0]);
    // excelDriver.getJarFileUris().add(JAR_FILES1[0]);
    mgr.getJdbcDrivers().add(excelDriver);
    excelSource = factory.createJdbcSource();
    excelSource.setName("Book1 (Excel)"); // $NON-NLS-1$
    excelSource.setDriverClass(CLASSES3[0]);
    excelSource.setDriverName("Microsoft Excel"); // $NON-NLS-1$
    excelSource.setUrl(
        "jdbc:odbc:Driver={MicroSoft Excel Driver (*.xls)};dBQ=testdata/Book1.xls"); //$NON-NLS-1$

    mgr.start();
  }
  private void internalExecute(final Resource resource, final Shell shell) {
    if (resource != null) {
      final JdbcSource source = JdbcUtil.findJdbcSource(resource);
      if (source != null) {
        final List emfTables = RelationalUtil.findTables(resource);
        final Map tblStats = createTableInfos(emfTables);
        if (tblStats != null && tblStats.size() > 0) {
          CostAnalysisDialog dialog =
              new CostAnalysisDialog(
                  shell,
                  InternalModelerJdbcUiPluginConstants.Util.getString(
                      "CostAnalysisAction.taskDescription"), //$NON-NLS-1$
                  InternalModelerJdbcUiPluginConstants.Util.getString(
                      "CostAnalysisAction.passwordPrompt",
                      new Object[] {source.getUrl(), source.getUsername()}),
                  null,
                  null); //$NON-NLS-1$
          dialog.open();

          final String password = dialog.getValue();
          if (password != null) {
            final Job job =
                new Job(
                    InternalModelerJdbcUiPluginConstants.Util.getString(
                        "CostAnalysisAction.jobDescription")) { //$NON-NLS-1$
                  @Override
                  protected IStatus run(IProgressMonitor monitor) {
                    try {
                      monitor.beginTask(
                          InternalModelerJdbcUiPluginConstants.Util.getString(
                              "CostAnalysisAction.taskDescription"),
                          calculateNumberOfWorkIncrements(tblStats.values())); // $NON-NLS-1$

                      CostAnalyzer costAnalyzer =
                          CostAnalyzerFactory.getCostAnalyzerFactory()
                              .getCostAnalyzer(source, password);
                      // log output to standard out
                      // costAnalyzer.setOutputStream(System.out);
                      costAnalyzer.collectStatistics(tblStats, monitor);

                      if (!monitor.isCanceled()) {
                        populateEmfColumnStatistics(emfTables, tblStats);
                      }

                      monitor.done();

                      if (monitor.isCanceled()) {
                        return Status.CANCEL_STATUS;
                      }

                      return new Status(
                          IStatus.OK,
                          ModelerJdbcUiConstants.PLUGIN_ID,
                          IStatus.OK,
                          InternalModelerJdbcUiPluginConstants.Util.getString(
                              "CostAnalysisAction.statusFinished", emfTables.size()),
                          null); //$NON-NLS-1$
                    } catch (Exception e) {
                      InternalModelerJdbcUiPluginConstants.Util.log(e);
                      return new Status(
                          IStatus.ERROR,
                          ModelerJdbcUiConstants.PLUGIN_ID,
                          IStatus.ERROR,
                          InternalModelerJdbcUiPluginConstants.Util.getString(
                              "CostAnalysisAction.errorMessage"),
                          e); //$NON-NLS-1$
                    } finally {
                    }
                  }
                };

            job.setSystem(false);
            job.setUser(true);
            job.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
            // start as soon as possible
            job.schedule();
          }
        } else {
          MessageDialog.openInformation(
              shell,
              InternalModelerJdbcUiPluginConstants.Util.getString(
                  "CostAnalysisAction.taskDescription"),
              InternalModelerJdbcUiPluginConstants.Util.getString(
                  "CostAnalysisAction.noValidTablesMessage")); //$NON-NLS-1$ //$NON-NLS-2$
        }
      }
    }
  }