コード例 #1
0
 protected static TemplateDescriptor getDriverTemplateDescriptor(IServerType serverType) {
   if (usesH2(serverType)) {
     return TemplateDescriptor.getDriverTemplateDescriptor(H2_DRIVER_TEMPLATE_ID);
   } else {
     return TemplateDescriptor.getDriverTemplateDescriptor(HSQL_DRIVER_TEMPLATE_ID);
   }
 }
コード例 #2
0
  private void createDriver2(String jbossASLocation, IServerType serverType)
      throws ConnectionProfileException {
    if (ProfileManager.getInstance().getProfileByName(DEFAULT_DS) != null) {
      // Don't create the driver a few times
      return;
    }
    String driverPath;
    try {
      driverPath = getDriverPath(jbossASLocation, serverType);
    } catch (IOException e) {
      ServerRuntimesIntegrationActivator.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR,
                  ServerRuntimesIntegrationActivator.PLUGIN_ID,
                  Messages.JBossRuntimeStartup_Cannott_create_new_HSQL_DB_Driver,
                  e));
      return;
    }
    if (driverPath == null) {
      ServerRuntimesIntegrationActivator.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR,
                  ServerRuntimesIntegrationActivator.PLUGIN_ID,
                  Messages.JBossRuntimeStartup_Cannot_create_new_DB_Driver));
    }

    DriverInstance driver = getDriver(serverType);
    if (driver == null) {
      TemplateDescriptor descr = getDriverTemplateDescriptor(serverType);
      IPropertySet instance =
          new PropertySetImpl(getDriverName(serverType), getDriverDefinitionId(serverType));
      instance.setName(getDriverName(serverType));
      instance.setID(getDriverDefinitionId(serverType));
      Properties props = new Properties();

      IConfigurationElement[] template = descr.getProperties();
      for (int i = 0; i < template.length; i++) {
        IConfigurationElement prop = template[i];
        String id = prop.getAttribute("id"); // $NON-NLS-1$

        String value = prop.getAttribute("value"); // $NON-NLS-1$
        props.setProperty(id, value == null ? "" : value); // $NON-NLS-1$
      }
      props.setProperty(DTP_DB_URL_PROPERTY_ID, getDriverUrl(serverType));
      props.setProperty(IDriverMgmtConstants.PROP_DEFN_TYPE, descr.getId());
      props.setProperty(IDriverMgmtConstants.PROP_DEFN_JARLIST, driverPath);
      if (usesH2(serverType)) {
        props.setProperty(
            IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID, "org.h2.Driver"); // $NON-NLS-1$
        props.setProperty(
            IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID, "H2 driver"); // $NON-NLS-1$
        props.setProperty(IDBDriverDefinitionConstants.URL_PROP_ID, "jdbc:h2:mem"); // $NON-NLS-1$
        props.setProperty(IDBDriverDefinitionConstants.USERNAME_PROP_ID, "sa"); // $NON-NLS-1$
      }

      instance.setBaseProperties(props);
      DriverManager.getInstance().removeDriverInstance(instance.getID());
      System.gc();
      DriverManager.getInstance().addDriverInstance(instance);
    }

    driver = DriverManager.getInstance().getDriverInstanceByName(getDriverName(serverType));
    if (driver != null && ProfileManager.getInstance().getProfileByName(DEFAULT_DS) == null) {
      // create profile
      Properties props = new Properties();
      props.setProperty(
          ConnectionProfileConstants.PROP_DRIVER_DEFINITION_ID, getDriverDefinitionId(serverType));
      props.setProperty(
          IDBConnectionProfileConstants.CONNECTION_PROPERTIES_PROP_ID, ""); // $NON-NLS-1$
      props.setProperty(
          IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID,
          driver.getProperty(IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID));
      props.setProperty(
          IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID,
          driver.getProperty(IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID));
      props.setProperty(
          IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID,
          driver.getProperty(IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID));
      props.setProperty(
          IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID, "Default"); // $NON-NLS-1$
      props.setProperty(IDBDriverDefinitionConstants.PASSWORD_PROP_ID, ""); // $NON-NLS-1$
      props.setProperty(
          IDBConnectionProfileConstants.SAVE_PASSWORD_PROP_ID, "false"); // $NON-NLS-1$
      props.setProperty(
          IDBDriverDefinitionConstants.USERNAME_PROP_ID,
          driver.getProperty(IDBDriverDefinitionConstants.USERNAME_PROP_ID));
      props.setProperty(
          IDBDriverDefinitionConstants.URL_PROP_ID,
          driver.getProperty(IDBDriverDefinitionConstants.URL_PROP_ID));

      if (usesH2(serverType)) {
        ProfileManager.getInstance()
            .createProfile(
                DEFAULT_DS,
                Messages.JBossRuntimeStartup_The_JBoss_AS_H2_embedded_database,
                H2_PROFILE_ID,
                props,
                "",
                false); //$NON-NLS-1$
      } else {
        ProfileManager.getInstance()
            .createProfile(
                DEFAULT_DS,
                Messages.JBossRuntimeStartup_The_JBoss_AS_Hypersonic_embedded_database,
                HSQL_PROFILE_ID,
                props,
                "",
                false); //$NON-NLS-1$
      }
    }
  }