コード例 #1
0
ファイル: JDBCEngine.java プロジェクト: josemachino/ontop
  private void connect() throws SQLException {

    String driver = datasource.getParameter(RDBMSourceParameterConstants.DATABASE_DRIVER);
    String url = datasource.getParameter(RDBMSourceParameterConstants.DATABASE_URL);

    log.debug("Connecting to JDBC source: {}", url);

    String username = datasource.getParameter(RDBMSourceParameterConstants.DATABASE_USERNAME);
    String password = datasource.getParameter(RDBMSourceParameterConstants.DATABASE_PASSWORD);
    try {
      Class.forName(driver);
    } catch (Exception e) {
      log.warn(
          "WARNING: JDBC Driver not found exception or may have been already loaded by the system.");
      // log.debug(e.getMessage(), e);
    }
    connection = DriverManager.getConnection(url, username, password);
  }
コード例 #2
0
  private void insertMapping(String target, String source) {
    List<Function> targetQuery = parse(target);
    if (targetQuery != null) {
      final boolean isValid = validator.validate(targetQuery);
      if (isValid) {
        try {
          OBDAModel mapcon = obdaModel;
          URI sourceID = dataSource.getSourceID();
          System.out.println(sourceID.toString() + " \n");

          OBDASQLQuery body = dataFactory.getSQLQuery(source);
          System.out.println(body.toString() + " \n");

          OBDAMappingAxiom newmapping =
              dataFactory.getRDBMSMappingAxiom(txtMappingID.getText().trim(), body, targetQuery);
          System.out.println(newmapping.toString() + " \n");

          if (mapping == null) {
            // Case when we are creating a new mapping
            mapcon.addMapping(sourceID, newmapping);
          } else {
            // Case when we are updating an existing mapping
            mapcon.updateMappingsSourceQuery(sourceID, mapping.getId(), body);
            mapcon.updateTargetQueryMapping(sourceID, mapping.getId(), targetQuery);
            mapcon.updateMapping(sourceID, mapping.getId(), txtMappingID.getText().trim());
          }
        } catch (DuplicateMappingException e) {
          JOptionPane.showMessageDialog(
              this, "Error while inserting mapping: " + e.getMessage() + " is already taken");
          return;
        }
        parent.setVisible(false);
        parent.dispose();

      } else {
        // List of invalid predicates that are found by the validator.
        Vector<String> invalidPredicates = validator.getInvalidPredicates();
        String invalidList = "";
        for (String predicate : invalidPredicates) {
          invalidList += "- " + predicate + "\n";
        }
        JOptionPane.showMessageDialog(
            this,
            "This list of predicates is unknown by the ontology: \n" + invalidList,
            "New Mapping",
            JOptionPane.WARNING_MESSAGE);
      }
    }
  }
コード例 #3
0
ファイル: JDBCEngine.java プロジェクト: josemachino/ontop
  @Override
  public void update(OBDADataSource ds) {
    if (!ds.getParameter(RDBMSourceParameterConstants.DATABASE_DRIVER).equals("org.h2.Driver")) {
      if (connection != null) {
        try {
          disconnect();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
      datasource = ds;

      try {
        connect();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
コード例 #4
0
  @Override
  public void actionPerformed(ActionEvent e) {

    currentOnto = owlManager.getActiveOntology();
    currentModel = modelManager.getActiveOBDAModel();

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    JLabel dsource = new JLabel("Choose a datasource to bootstrap: ");
    dsource.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(dsource);
    List<String> options = new ArrayList<String>();
    for (OBDADataSource source : currentModel.getSources())
      options.add(source.getSourceID().toString());
    JComboBox combo = new JComboBox(options.toArray());
    combo.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(combo);
    Dimension minsize = new Dimension(10, 10);
    panel.add(new Box.Filler(minsize, minsize, minsize));
    JLabel ouri =
        new JLabel("Base URI - the prefix to be used for all generated classes and properties: ");
    ouri.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(ouri);
    JTextField base_uri = new JTextField();
    base_uri.setText(currentModel.getPrefixManager().getDefaultPrefix().replace("#", "/"));
    base_uri.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(base_uri);
    int res =
        JOptionPane.showOptionDialog(
            workspace,
            panel,
            "Bootstrapping",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            null,
            null);
    if (res == JOptionPane.OK_OPTION) {
      int index = combo.getSelectedIndex();
      currentSource = currentModel.getSources().get(index);
      if (currentSource != null) {
        this.baseUri = base_uri.getText().trim();
        if (baseUri.contains("#")) {
          JOptionPane.showMessageDialog(workspace, "Base Uri cannot contain the character '#'");
          throw new RuntimeException("Base URI " + baseUri + " contains '#' character!");
        } else {
          Thread th =
              new Thread(
                  new Runnable() {
                    @Override
                    public void run() {
                      try {
                        OBDAProgessMonitor monitor =
                            new OBDAProgessMonitor("Bootstrapping ontology and mappings...");
                        BootstrapperThread t = new BootstrapperThread();
                        monitor.addProgressListener(t);
                        monitor.start();
                        t.run(baseUri, currentOnto, currentModel, currentSource);
                        currentModel.fireSourceParametersUpdated();
                        monitor.stop();
                        JOptionPane.showMessageDialog(
                            workspace,
                            "Task is completed.",
                            "Done",
                            JOptionPane.INFORMATION_MESSAGE);
                      } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        JOptionPane.showMessageDialog(
                            null, "Error occured during bootstrapping data source.");
                      }
                    }
                  });
          th.start();
        }
      }
    }
  }