public File getFile() {
   String filename = getFilename();
   if (StringUtils.isNullOrEmpty(filename)) {
     return null;
   }
   return new File(filename);
 }
  /**
   * Gets an output column by name.
   *
   * @see #getOutputColumns()
   * @param name
   * @return
   */
  public MutableInputColumn<?> getOutputColumnByName(String name) {
    if (StringUtils.isNullOrEmpty(name)) {
      return null;
    }

    final List<MutableInputColumn<?>> outputColumns = getOutputColumns();
    for (MutableInputColumn<?> inputColumn : outputColumns) {
      if (name.equals(inputColumn.getName())) {
        return inputColumn;
      }
    }
    return null;
  }
 @Override
 protected String getJdbcUrl(
     String hostname,
     int port,
     String database,
     String param1,
     String param2,
     String param3,
     String param4) {
   if (_radioSid.isSelected()) {
     return replaceParameters(URL_SID_BASED, hostname, port, database, param1, param2, param3);
   } else if (_radioServiceName.isSelected()) {
     if (!StringUtils.isNullOrEmpty(database)) {
       return replaceParameters(
           URL_SERVICE_NAME_BASED, hostname, port, database, param1, param2, param3);
     }
   }
   return replaceParameters(URL_FALLBACK, hostname, port, database, param1, param2, param3);
 }
  public static String safeName(String str) {
    if (StringUtils.isNullOrEmpty(str)) {
      throw new IllegalArgumentException("Cannot create safe name from empty/null string: " + str);
    }

    CharIterator ci = new CharIterator(str);
    while (ci.hasNext()) {
      ci.next();
      if (!ci.isLetter() && !ci.isDigit()) {
        // replaces unexpected chars with underscore
        ci.set('_');
      }
    }

    str = ci.toString();
    if (!Character.isLetter(str.charAt(0))) {
      str = "db" + str;
    }
    return str;
  }
示例#5
0
 @Override
 protected UsageAwareDatastoreConnection<UpdateableDataContext> createDatastoreConnection() {
   if (StringUtils.isNullOrEmpty(_datasourceJndiUrl)) {
     if (isMultipleConnections()) {
       final DataSource dataSource = createDataSource();
       return new DataSourceDatastoreConnection(dataSource, getTableTypes(), _catalogName, this);
     } else {
       final Connection connection = createConnection();
       final UpdateableDataContext dataContext =
           new JdbcDataContext(connection, getTableTypes(), _catalogName);
       return new UpdateableDatastoreConnectionImpl<UpdateableDataContext>(dataContext, this);
     }
   } else {
     try {
       Context initialContext = getJndiNamingContext();
       DataSource dataSource = (DataSource) initialContext.lookup(_datasourceJndiUrl);
       return new DataSourceDatastoreConnection(dataSource, getTableTypes(), _catalogName, this);
     } catch (Exception e) {
       logger.error("Could not retrieve DataSource '{}'", _datasourceJndiUrl);
       throw new IllegalStateException(e);
     }
   }
 }
  /**
   * Gets the output column of this transformation with it's current configuration.
   *
   * @return
   */
  public List<MutableInputColumn<?>> getOutputColumns() {
    final Component component = getComponentInstanceForQuestioning();
    if (component == null) {
      // as long as the transformer is not configured, just return an
      // empty list
      return Collections.emptyList();
    }

    final Transformer transformer = (Transformer) component;

    final OutputColumns outputColumns = transformer.getOutputColumns();
    if (outputColumns == null) {
      throw new IllegalStateException(
          "getOutputColumns() returned null on transformer: " + transformer);
    }
    boolean changed = false;

    // adjust the amount of output columns
    final int expectedCols = outputColumns.getColumnCount();
    final int existingCols = _outputColumns.size();
    if (expectedCols != existingCols) {
      changed = true;
      int colDiff = expectedCols - existingCols;
      if (colDiff > 0) {
        for (int i = 0; i < colDiff; i++) {
          final int nextIndex = _outputColumns.size();
          final String name = getColumnName(outputColumns, nextIndex);
          final String id = _id + "-" + _idGenerator.nextId();
          _outputColumns.add(new TransformedInputColumn<Object>(name, id));
          _automaticOutputColumnNames.add(name);
        }
      } else if (colDiff < 0) {
        for (int i = 0; i < Math.abs(colDiff); i++) {
          // remove from the tail
          _outputColumns.remove(_outputColumns.size() - 1);
          _automaticOutputColumnNames.remove(_automaticOutputColumnNames.size() - 1);
        }
      }

      // reset the names when the number of output columns change and the
      // initial name has changed
      for (int i = 0; i < expectedCols; i++) {
        final MutableInputColumn<?> column = _outputColumns.get(i);
        final String previousProposedName = column.getInitialName();
        final String newProposedName = outputColumns.getColumnName(i);
        if (newProposedName != null && !newProposedName.equals(previousProposedName)) {
          column.setName(newProposedName);
        }
      }
    }

    // automatically update names and types of columns if they have not been
    // manually set
    for (int i = 0; i < expectedCols; i++) {
      final String proposedName = getColumnName(outputColumns, i);
      final Class<?> dataType = outputColumns.getColumnType(i);

      final TransformedInputColumn<?> col = (TransformedInputColumn<?>) _outputColumns.get(i);
      col.setInitialName(proposedName);
      if (dataType != col.getDataType()) {
        col.setDataType(dataType);
        changed = true;
      }

      final String automaticName = _automaticOutputColumnNames.get(i);
      final String columnName = col.getName();
      if (StringUtils.isNullOrEmpty(columnName) || automaticName.equals(columnName)) {
        if (proposedName != null) {
          col.setName(proposedName);
          _automaticOutputColumnNames.set(i, proposedName);
        }
      }
    }

    if (changed) {
      // notify listeners
      onOutputChanged();
    }

    return Collections.unmodifiableList(_outputColumns);
  }