Пример #1
0
 private void initGui() {
   this.setLayout(new GridBagLayout());
   this.setBorder(
       new TitledBorder(new EtchedBorder(), dsElement.getAttributeValue(Resources.get("NAME"))));
   // find all partition tables in this dataset
   List<Element> ptList = dsElement.getChildren(Resources.get("PARTITIONTABLE"));
   for (Element ptElement : ptList) {
     List<ArrayList<String>> ptTable = JDomUtils.ptElement2Table(ptElement);
     ptTableMap.put(ptElement.getAttributeValue(Resources.get("NAME")), ptTable);
     // default 0
     ptCurrentIndex.put(ptElement.getAttributeValue(Resources.get("NAME")), 0);
   }
   // find the one has the same user and gui
   HashMap<String, String> conditions = new HashMap<String, String>();
   List<Element> myContainers =
       JDomUtils.findChildElements(dsElement, Resources.get("CONTAINER"), conditions);
   Set<String> ftSet = this.getFlattenPTableName();
   GridBagConstraints c = new GridBagConstraints();
   c.gridy = 0;
   c.gridx = 0;
   c.anchor = GridBagConstraints.FIRST_LINE_START;
   for (Element container : myContainers) {
     if (JDomUtils.isElementHiden(container)) continue;
     // if container is empty, don't add it
     if (!this.isContainerEmpty(container)) {
       this.add(createContainerPanel(container, dsElement, ftSet, false), c);
       c.gridx = c.gridx + 1;
     }
   }
 }
Пример #2
0
 private boolean isContainerEmpty(Element container) {
   if (JDomUtils.searchElement(container, Resources.get("FILTER"), null) == null
       && JDomUtils.searchElement(container, Resources.get("ATTRIBUTE"), null) == null
       && JDomUtils.searchElement(container, Resources.get("ATTRIBUTEPOINTER"), null) == null) {
     return true;
   } else return false;
 }
Пример #3
0
 private List<Element> getFlattenPTable() {
   Map<String, String> conditions = new HashMap<String, String>();
   conditions.put(Resources.get("FLATTEN"), "1");
   List<Element> flatPtList =
       JDomUtils.findDescendentElements(dsElement, Resources.get("PARTITIONTABLE"), conditions);
   return flatPtList;
 }
Пример #4
0
 private boolean isDsColMasked(Element dsTableElement, String dsColName) {
   if (dsTableElement == null) // if it is dragged from other dataset
   return false;
   Element attributeElement =
       JDomUtils.searchElement(dsTableElement, Resources.get("ATTRIBUTE"), dsColName);
   if (attributeElement == null) // check later
   return false;
   String maskStr = attributeElement.getAttributeValue(Resources.get("maskColumnTitle"));
   if ("1".equals(maskStr)) return true;
   else return false;
 }
Пример #5
0
 private Set<String> getFlattenPTableName() {
   Set<String> ptSet = new HashSet<String>();
   List<Element> ptEList = this.getFlattenPTable();
   for (Element ptElement : ptEList) {
     ptSet.add(ptElement.getAttributeValue(Resources.get("DSTABLE")));
   }
   return ptSet;
 }
Пример #6
0
 private void updateLabels() {
   Iterator<Entry<JComponent, Element>> it = this.updateList.entrySet().iterator();
   while (it.hasNext()) {
     Entry<JComponent, Element> entry = it.next();
     String oldName = entry.getValue().getAttributeValue(Resources.get("NAME"));
     String newName = this.renameWithPartitionInfo(oldName, ptTableMap);
     if (entry.getKey().getClass().getName().equals(JLabel.class.getName()))
       ((JLabel) entry.getKey()).setText(newName);
     else ((JCheckBox) entry.getKey()).setText(newName);
   }
 }
Пример #7
0
  /**
   * create a PK for table, if the table has candidate columns, use them, otherwise use keyGuessing
   *
   * @param table
   * @param hasPK
   * @param pkCols
   */
  private void createPKforTable(Table table, List<Column> pkCols) {
    if (table == null) return;
    if (pkCols.isEmpty() && this.isKeyGuessing()) {
      // create PK by keyguessing
      // Did DMD find a PK? If not, which is really unusual but
      // potentially may happen, attempt to find one by looking for a
      // single column with the same name as the table or with '_id'
      // appended if it is source. For the mart, pk is the columns with '_key'.
      // Only do this if we are using key-guessing.
      // Plain version first.
      Column candidateCol = table.getColumnByName(table.getName());
      // Try with '_id' appended if plain version turned up
      // nothing.
      if (candidateCol == null)
        candidateCol = table.getColumnByName(table.getName() + Resources.get("primaryKeySuffix"));
      // Found something? Add it to the primary key columns map,
      // with a dummy key of 1. (Use Short for the key because
      // that
      // is what DMD would have used had it found anything
      // itself).
      if (candidateCol != null) pkCols.add(candidateCol);
    }
    // create PK
    if (!pkCols.isEmpty()) {
      PrimaryKey pkObject;
      try {
        List<Column> columns = new ArrayList<Column>();

        for (Column cc : pkCols) {
          columns.add(cc);
        }
        pkObject = new PrimaryKey(columns);
      } catch (final Throwable th) {
        throw new BioMartError(th);
      }

      try {
        table.setPrimaryKey(pkObject);
      } catch (final Throwable th) {
        throw new BioMartError(th);
      }
    }
  }
Пример #8
0
 private String renamePartitionReference(
     String reference, Map<String, List<ArrayList<String>>> ptTableMap) {
   String[] arr = reference.split(Resources.get("COLPREFIX"));
   String res = "";
   if (arr.length != 2) return res;
   String ptName = arr[0];
   String colStr = arr[1];
   int col = 0;
   try {
     col = Integer.parseInt(colStr);
   } catch (Exception e) {
     return res;
   }
   List<ArrayList<String>> ptTable = ptTableMap.get(ptName);
   int index = ptCurrentIndex.get(ptName);
   try {
     res = "(" + ptTable.get(index).get(col - 1) + ")";
   } catch (Exception e) {
     return res;
   }
   return res;
 }
Пример #9
0
  private void setColor(Element element) {
    // color for dataset
    if (element.getName().equalsIgnoreCase(Resources.get("DATASET"))) {
      // FIXME should have a separate class to handle the XML error
      if (element.getAttributeValue(Resources.get("MATERIALIZED")) != null) {
        if (element.getAttributeValue(Resources.get("MATERIALIZED")).equalsIgnoreCase("true"))
          setForeground(McColorUtils.materializedColor);
      } else setForeground(McColorUtils.nonMaterializedColor);
      //        } else if(element.getName().equalsIgnoreCase(Resources.get("MART"))) {

    } else if (element.getName().equals(Resources.get("MARTREGISTRY"))) {
      setForeground(McColorUtils.nonMaterializedColor);
    } else if (element.getName().equals(Resources.get("LOCATION"))
        || element.getName().equals(Resources.get("MART"))) {
      this.setEnabled(false);
    } else setForeground(McColorUtils.elementColor);

    if (JDomUtils.isElementHiden(element)) setForeground(McColorUtils.hidedColor);
  }
Пример #10
0
  private JPanel createContainerPanel(
      Element e, Element dsElement, Set<String> flattenTableSet, boolean clone) {
    // element is a container element
    boolean hasFlattenAttribute = false;
    List<ArrayList<String>> flattendata = null;
    String dsTableName = "";
    JPanel containerPanel = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.insets = new Insets(0, 5, 0, 5);
    int labelx = 0;
    int tfx = 1;

    int y = 0;
    containerPanel.setBorder(
        new TitledBorder(new EtchedBorder(), e.getAttributeValue(Resources.get("NAME"))));
    List<Element> childList = e.getChildren();
    for (Element child : childList) {
      if (JDomUtils.isElementHiden(child)) continue;
      if (child.getName().equals(Resources.get("CONTAINER"))) {
        if (!this.isContainerEmpty(child)) {
          c.gridx = labelx;
          c.gridy = y;
          containerPanel.add(createContainerPanel(child, dsElement, flattenTableSet, false), c);
          y++;
        }
      } else {
        dsTableName = child.getAttributeValue(Resources.get("DSTABLE"));
        if (flattenTableSet.contains(dsTableName) && hasFlattenAttribute == false) {
          hasFlattenAttribute = true;
          Element ptElement =
              JDomUtils.searchElementWithCondition(
                  dsElement,
                  Resources.get("PARTITIONTABLE"),
                  Resources.get("DSTABLE"),
                  dsTableName);
          flattendata = JDomUtils.ptElement2Table(ptElement);
        }
        String oldLabelName = child.getAttributeValue(Resources.get("NAME"));
        String labelName = this.renameWithPartitionInfo(oldLabelName, ptTableMap);
        // check masked
        Element dsTableElement =
            JDomUtils.searchElement(dsElement, Resources.get("DSTABLE"), dsTableName);
        boolean colMasked = this.isDsColMasked(dsTableElement, oldLabelName);
        if (colMasked) continue;
        if (child.getName().equals(Resources.get("FILTER"))) {
          String ptName = child.getAttributeValue(Resources.get("PARTITIONTABLE"));
          if (!hasFlattenAttribute && ptName != null && !ptName.equals("")) {
            Element ptElement =
                JDomUtils.searchElement(dsElement, Resources.get("PARTITIONTABLE"), ptName);
            List<ArrayList<String>> data = JDomUtils.ptElement2Table(ptElement);
            PartitionedFilterDropDown pfo = new PartitionedFilterDropDown(data, child, this);
            c.gridx = labelx;
            c.gridy = y;
            if (!colMasked) {
              JLabel label = new JLabel(labelName);
              this.updateList.put(label, child);
              containerPanel.add(label, c);
              c.gridx = tfx;
              containerPanel.add(pfo, c);
            }
          } else {
            JLabel label = new JLabel(labelName);
            c.gridx = labelx;
            c.gridy = y;
            containerPanel.add(label, c);
            this.updateList.put(label, child);
            c.gridx = tfx;
            JTextField tf = new JTextField(5);
            containerPanel.add(tf, c);
          }
          y++;
        } else {
          JCheckBox cb = new JCheckBox(labelName);
          this.updateList.put(cb, child);
          c.gridx = labelx;
          c.gridy = y;
          containerPanel.add(cb, c);
          y++;
        }
      }
    }
    if (!clone && hasFlattenAttribute) {
      JPanel panel = new JPanel(new GridLayout(0, 1));
      containerPanel.setBorder(
          new TitledBorder(
              new EtchedBorder(), dsTableName + "(" + flattendata.get(0).get(0) + ")"));
      panel.add(containerPanel);
      for (int i = 1; i < flattendata.size(); i++) {
        // get partitiontable name
        Element pt =
            JDomUtils.searchElementWithCondition(
                dsElement, Resources.get("PARTITIONTABLE"), Resources.get("DSTABLE"), dsTableName);
        this.ptCurrentIndex.put(pt.getAttributeValue(Resources.get("NAME")), i);
        JPanel clonePanel = this.createContainerPanel(e, dsElement, flattenTableSet, true);
        clonePanel.setBorder(
            new TitledBorder(
                new EtchedBorder(), dsTableName + "(" + flattendata.get(i).get(0) + ")"));
        panel.add(clonePanel);
      }
      return panel;
    } else return containerPanel;
  }
Пример #11
0
  public Connection getConnection() throws SQLException {
    // If we are already connected, test to see if we are
    // still connected. If not, reset our connection.
    if (this.connection != null && this.connection.isClosed())
      try {
        Log.debug("Closing dead JDBC connection");
        this.connection.close();
      } catch (final SQLException e) {
        // We don't care. Ignore it.
      } finally {
        this.connection = null;
      }

    // If we are not connected, we should attempt to (re)connect now.
    if (this.connection == null) {
      Log.debug("Establishing JDBC connection");
      // Start out with no driver at all.
      Class loadedDriverClass = null;

      // Try the system class loader instead.
      try {
        loadedDriverClass = Class.forName(this.conObj.getJdbcType().getDriverClassName());
      } catch (final ClassNotFoundException e) {
        final SQLException e2 = new SQLException();
        e2.initCause(e);
        throw e2;
      }

      // Check it really is an instance of Driver.
      if (!Driver.class.isAssignableFrom(loadedDriverClass))
        throw new ClassCastException(Resources.get("driverClassNotJDBCDriver"));

      // Connect!
      final Properties properties = new Properties();
      properties.setProperty("user", this.conObj.getUserName());
      if (!this.conObj.getPassword().equals(""))
        properties.setProperty("password", this.conObj.getPassword());
      properties.setProperty("nullCatalogMeansCurrent", "false");
      /*
       * this.connection = DriverManager.getConnection( overrideDataLinkSchema == null ? this.conObj.getJdbcUrl():
       * (this.conObj.getJdbcUrl()) .replaceAll(this.getDataLinkSchema(), overrideDataLinkSchema), properties);
       */

      this.connection =
          DriverManager.getConnection(
              this.conObj.getJdbcUrl(), conObj.getUserName(), conObj.getPassword());
      // Check the schema name.
      final DatabaseMetaData dmd = this.connection.getMetaData();
      final String catalog = this.connection.getCatalog();
      this.realSchemaName = this.getDataLinkSchema();
      ResultSet rs = dmd.getTables(catalog, this.realSchemaName, "%", null);
      if (!rs.next()) {
        rs = dmd.getTables(catalog, this.realSchemaName.toUpperCase(), "%", null);
        if (rs.next()) this.realSchemaName = this.realSchemaName.toUpperCase();
      }
      if (!rs.next()) {
        rs = dmd.getTables(catalog, this.realSchemaName.toLowerCase(), "%", null);
        if (rs.next()) this.realSchemaName = this.realSchemaName.toLowerCase();
      }
      rs.close();
    }

    // Return the connection.
    return this.connection;
  }