Ejemplo n.º 1
0
  private void createEmbeddedDatabase() {
    String paramCreate =
        CommonUtils.toString(
            site.getDriver().getDriverParameter(GenericConstants.PARAM_CREATE_URL_PARAM));

    DataSourceDescriptor dataSource = (DataSourceDescriptor) site.getActiveDataSource();
    final DataSourceDescriptor testDataSource =
        new DataSourceDescriptor(
            site.getDataSourceRegistry(),
            dataSource.getId(),
            dataSource.getDriver(),
            new DBPConnectionConfiguration(dataSource.getConnectionConfiguration()));

    saveSettings(testDataSource);
    DBPConnectionConfiguration cfg = testDataSource.getConnectionConfiguration();
    cfg.setUrl(cfg.getUrl() + paramCreate);
    String databaseName = cfg.getDatabaseName();
    testDataSource.setName(databaseName);

    if (!UIUtils.confirmAction(
        getShell(),
        "Create Database",
        "Are you sure you want to create database '" + databaseName + "'?")) {
      testDataSource.dispose();
      return;
    }

    try {
      site.getRunnableContext()
          .run(
              true,
              true,
              new DBRRunnableWithProgress() {
                @Override
                public void run(DBRProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                  try {
                    createEmbeddedDatabase(monitor, testDataSource);
                  } catch (DBException e1) {
                    throw new InvocationTargetException(e1);
                  }
                }
              });
      MessageDialog.openInformation(
          getShell(), "Database Create", "Database '" + databaseName + "' created!");
    } catch (InvocationTargetException e1) {
      UIUtils.showErrorDialog(
          getShell(), "Create database", "Error creating database", e1.getTargetException());
    } catch (InterruptedException e1) {
      // Just ignore
    }
  }
Ejemplo n.º 2
0
  @Override
  public void saveSettings(DBPDataSourceContainer dataSource) {
    DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
    final Set<String> properties =
        metaURL == null ? Collections.<String>emptySet() : metaURL.getAvailableProperties();

    if (hostText != null && properties.contains(DriverDescriptor.PROP_HOST)) {
      connectionInfo.setHostName(hostText.getText().trim());
    }
    if (portText != null && properties.contains(DriverDescriptor.PROP_PORT)) {
      connectionInfo.setHostPort(portText.getText().trim());
    }
    if (serverText != null && properties.contains(DriverDescriptor.PROP_SERVER)) {
      connectionInfo.setServerName(serverText.getText().trim());
    }
    if (dbText != null && properties.contains(DriverDescriptor.PROP_DATABASE)) {
      connectionInfo.setDatabaseName(dbText.getText().trim());
    }
    if (pathText != null
        && (properties.contains(DriverDescriptor.PROP_FOLDER)
            || properties.contains(DriverDescriptor.PROP_FILE))) {
      connectionInfo.setDatabaseName(pathText.getText().trim());
    }
    if (userNameText != null) {
      connectionInfo.setUserName(userNameText.getText().trim());
    }
    if (passwordText != null) {
      connectionInfo.setUserPassword(passwordText.getText());
    }
    super.saveSettings(dataSource);
    if (isCustom) {
      if (urlText != null) {
        connectionInfo.setUrl(urlText.getText().trim());
      }
    } else {
      if (urlText != null && connectionInfo.getUrl() != null) {
        urlText.setText(connectionInfo.getUrl());
      }
    }
  }