Example #1
0
  public void execute() throws MojoExecutionException, MojoFailureException {

    Log logger = new MavenLogger(this);

    DbImportConfiguration config = toParameters();
    config.setLogger(logger);
    Injector injector = DIBootstrap.createInjector(new ToolsModule(logger), new DbImportModule());

    validateDbImportConfiguration(config, injector);

    try {
      injector.getInstance(DbImportAction.class).execute(config);
    } catch (Exception ex) {
      Throwable th = Util.unwindException(ex);

      String message = "Error importing database schema";

      if (th.getLocalizedMessage() != null) {
        message += ": " + th.getLocalizedMessage();
      }

      getLog().error(message);
      throw new MojoExecutionException(message, th);
    }
  }
Example #2
0
  private void validateDbImportConfiguration(DbImportConfiguration config, Injector injector)
      throws MojoExecutionException {
    DataNodeDescriptor dataNodeDescriptor = config.createDataNodeDescriptor();
    DataSource dataSource = null;
    DbAdapter adapter = null;

    try {
      dataSource = injector.getInstance(DataSourceFactory.class).getDataSource(dataNodeDescriptor);
      adapter =
          injector
              .getInstance(DbAdapterFactory.class)
              .createAdapter(dataNodeDescriptor, dataSource);

      if (!adapter.supportsCatalogsOnReverseEngineering()
          && reverseEngineering.getCatalogs() != null
          && !reverseEngineering.getCatalogs().isEmpty()) {
        String message =
            "Your database does not support catalogs on reverse engineering. "
                + "It allows to connect to only one at the moment. Please don't note catalogs as param.";
        throw new MojoExecutionException(message);
      }
    } catch (Exception e) {
      throw new MojoExecutionException(
          "Error creating DataSource ("
              + dataSource
              + ") or DbAdapter ("
              + adapter
              + ") for DataNodeDescriptor ("
              + dataNodeDescriptor
              + ")",
          e);
    }
  }
Example #3
0
  DbImportConfiguration toParameters() {
    if (config != null) {
      return config;
    }

    config = new DbImportConfiguration();
    config.setAdapter(adapter);
    config.setDefaultPackage(defaultPackage);
    config.setDriver(driver);
    config.setDataMapFile(map);
    config.setMeaningfulPkTables(meaningfulPkTables);
    config.setNamingStrategy(namingStrategy);
    config.setOverwrite(overwrite);
    config.setPassword(password);
    config.setUrl(url);
    config.setUsername(username);
    config.setUsePrimitives(usePrimitives);
    config.setFiltersConfig(
        new FiltersConfigBuilder(reverseEngineering).add(filterBuilder).filtersConfig());
    config.setSkipRelationshipsLoading(reverseEngineering.getSkipRelationshipsLoading());
    config.setSkipPrimaryKeyLoading(reverseEngineering.getSkipPrimaryKeyLoading());
    config.setTableTypes(reverseEngineering.getTableTypes());

    return config;
  }