Пример #1
0
  /**
   * This method returns an array of all the tables referenced in the datastore.
   *
   * @param updateable True if the table list should only include updateable tables and false if it
   *     should include all.
   */
  public String[] getTableList(boolean updateable) {

    DSColumnDescriptor col = null;

    Vector tables = new Vector();
    Vector pkey = new Vector();

    for (int i = 0; i < _desc.getColumnCount(); i++) {
      col = _desc.getColumn(i);
      String tableName = col.getTable();
      if (tableName == null) tableName = _desc.getDefaultTable();

      if ((!updateable) || col.isUpdateable()) {
        boolean found = false;
        for (int j = 0; j < tables.size(); j++) {
          if ((tables.elementAt(j)).equals(tableName)) {
            if (col.isPrimaryKey()) pkey.setElementAt(new Boolean(true), j);
            found = true;
            break;
          }
        }
        if (!found && tableName != null) {
          tables.addElement(tableName);
          pkey.addElement(new Boolean(col.isPrimaryKey()));
        }
      }
    }

    if (updateable) {
      for (int i = pkey.size() - 1; i > -1; i--) {
        if (!((Boolean) pkey.elementAt(i)).booleanValue()) tables.removeElementAt(i);
      }
    } else {
      for (int i = 0; i < getAliasCount(); i++) {
        try {
          String table = getTable(i);
          boolean found = false;
          for (int j = 0; j < tables.size(); j++) {
            if ((tables.elementAt(j)).equals(table)) found = true;
          }
          if (!found && table != null) tables.addElement(table);
        } catch (Exception e) {
        }
      }
    }

    String retVal[] = new String[tables.size()];
    tables.copyInto(retVal);

    return retVal;
  }
Пример #2
0
  /** This method returns whether a column is part of the primary key */
  public boolean isPrimaryKey(int col) throws DataStoreException {
    if (col < 0 || _desc.getColumnCount() == 0)
      throw new DataStoreException("Specified column (" + col + ") does not exist.");

    DSColumnDescriptor c = _desc.getColumn(col);
    return c.isPrimaryKey();
  }