Package org.eclipse.datatools.connectivity

Examples of org.eclipse.datatools.connectivity.IConnectionProfile


      UIJob uiJob = new UIJob(getJobName()) {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {

          IConnectionProfile profile = getConnectionProfile();
          IStatus status = Status.OK_STATUS;

          if (profile != null) {
            status = profile.connect();
          }
          else {
            status = CloudFoundryPlugin.getErrorStatus(NLS.bind(Messages.DataToolsTunnelAction_ERROR_CREATE_PROFILE, tunnelDescriptor.getServiceName()));
          }
View Full Code Here


    }
  }

  protected IConnectionProfile getConnectionProfile() {
    // Check if there is an existing profile
    IConnectionProfile profile = null;
    IConnectionProfile[] profiles = ProfileManager.getInstance().getProfiles();

    if (profiles != null) {

      // If a profile exists with the same exact name as given by the
      // CF data source integration, then check credentials. If they
      // match, use it
      // If not, delete and create a new profile. If in the future
      // profiles should also be checked against the provider (e.g.
      // mysql, psql), and a new
      // name given, also check the provider ID
      for (IConnectionProfile prf : profiles) {
        if (
        // prf.getProviderId().equals(descriptor.getDriverProviderID())
        // &&
        prf.getName().equals(descriptor.getProfileName())) {
          profile = prf;
          break;
        }
      }
    }

    // Otherwise create one, and if necessary also create a new driver
    // definition
    if (profile == null) {
      DriverInstance driverInstance = null;

      // See if there is already a driver instance that can be used;
      driverInstance = DriverManager.getInstance().getDriverInstanceByName(descriptor.getDriverName());

      // Prompt for new driver instance
      if (driverInstance == null) {

        TemplateDescriptor[] templates = TemplateDescriptor.getDriverTemplateDescriptors();
        TemplateDescriptor driverTemplate = null;

        if (templates != null) {
          for (TemplateDescriptor temp : templates) {
            String templateID = temp.getId();
            if (templateID.contains(descriptor.getDriverTemplateIdentifier())) {
              driverTemplate = temp;
              break;
            }
          }
        }

        if (driverTemplate != null) {
          IPropertySet properties = new PropertySetImpl(descriptor.getDriverName(), driverTemplate.getName());
          Properties props = new Properties();
          props.setProperty(IDriverMgmtConstants.PROP_DEFN_JARLIST, Messages.DataToolsTunnelAction_PROP_REPLACE);

          props.setProperty(IDriverMgmtConstants.PROP_DEFN_TYPE, driverTemplate.getId());

          // Must set the properties as the driver dialogue
          // throws exceptions if all properties are not set with
          // values
          // Properties get set again later regardless if a driver
          // instance
          // was created or not
          setProperties(props, tunnelDescriptor);

          properties.setBaseProperties(props);

          Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
          if (shell != null) {
            DriverDialog jdbcDriverDialog = new DriverDialog(shell, driverTemplate.getParentCategory());

            jdbcDriverDialog.setPropertySet(properties);
            jdbcDriverDialog.setEditMode(true);
            jdbcDriverDialog.setIsEditable(true);

            if (jdbcDriverDialog.open() == Window.OK) {
              properties = jdbcDriverDialog.getPropertySet();
              if (properties != null) {

                DriverManager.getInstance().addDriverInstance(properties);
                driverInstance = DriverManager.getInstance().getDriverInstanceByName(
                    descriptor.getDriverName());

              }
            }
          }
        }
      }

      if (driverInstance != null) {
        Properties props = driverInstance.getPropertySet().getBaseProperties();
        props.setProperty(DATA_TOOLS_DRIVER_DEFINITION_ID, driverInstance.getId());
        try {
          String providerID = descriptor.getDriverProviderID();
          profile = ProfileManager.getInstance().createProfile(descriptor.getProfileName(),
              CLOUD_FOUNDRY_JDBC_PROFILE_DESCRIPTION, providerID, props);
        }
        catch (ConnectionProfileException e) {
          CloudFoundryPlugin.logError(e);
        }
      }
      else {
        CloudFoundryPlugin.logError("Failed to create driver instance for: " //$NON-NLS-1$
            + CloudUtil.getServiceVendor(descriptor.getCloudService()) + " - " //$NON-NLS-1$
            + tunnelDescriptor.getServiceName());
      }

    }

    // Check if the profile credentials have changed, which may happen if a
    // service
    // in CF server is deleted and then recreated again with the same name
    if (profile != null && !matchesProfile(profile, tunnelDescriptor)) {
      // Different credentials for the same profile, most likely
      // meaning that a new tunnel was created, and the old profile
      // has obsolete credentials.
      if (profile.getConnectionState() == IConnectionProfile.CONNECTED_STATE) {
        IStatus status = profile.disconnect();
        if (!status.isOK()) {
          CloudFoundryPlugin.log(status);
        }
      }

      // Change the properties to reflect changes
      // Set the properties for the tunnel values
      Properties props = profile.getBaseProperties();
      setProperties(props, tunnelDescriptor);
      profile.setBaseProperties(props);

    }

    return profile;
View Full Code Here

TOP

Related Classes of org.eclipse.datatools.connectivity.IConnectionProfile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.