コード例 #1
0
  @Override
  public List<ConnectionProfile> readProfiles(String filename) {
    LogMgr.logInfo(
        "IniProfileStorage.readProfiles()", "Loading connection profiles from " + filename);
    WbProperties props = new WbProperties(1);
    BufferedReader reader = null;
    List<ConnectionProfile> profiles = new ArrayList<>(25);

    WbFile inifile = new WbFile(filename);

    try {
      File fileDir = inifile.getCanonicalFile().getParentFile();
      reader = new BufferedReader(new FileReader(filename));
      props.loadFromReader(reader);
      Set<String> keys = getProfileKeys(props);
      for (String key : keys) {
        ConnectionProfile profile = readProfile(fileDir, key, props);
        if (profile != null) {
          profiles.add(profile);
        }
      }
    } catch (Exception ex) {
      LogMgr.logError(
          "IniProfileStorage.readProfiles()", "Could not read profiles from: " + filename, ex);
    } finally {
      FileUtil.closeQuietely(reader);
    }
    return profiles;
  }
コード例 #2
0
  @Override
  public void load() throws IOException {
    if (dataFile != null) {
      // do not load the file twice.
      return;
    }

    InputStream in = null;
    try {
      in = new FileInputStream(inputFile);
      if (useXLSX) {
        dataFile = new XSSFWorkbook(in);
      } else {
        dataFile = new HSSFWorkbook(in);
      }
    } finally {
      FileUtil.closeQuietely(in);
    }

    initActiveSheet();

    try {
      if (useXLSX) {
        XSSFFormulaEvaluator.evaluateAllFormulaCells((XSSFWorkbook) dataFile);
      } else {
        HSSFFormulaEvaluator.evaluateAllFormulaCells((HSSFWorkbook) dataFile);
      }
    } catch (Exception ex) {
      LogMgr.logError("ExcelReader.load()", "Could not refresh formulas!", ex);
    }
  }
コード例 #3
0
  @Override
  public void writeFormatFile(DataExporter exporter, RowDataConverter converter) {
    WbFile baseFile = new WbFile(exporter.getFullOutputFilename());
    String dir = baseFile.getParent();

    String tableName = exporter.getTableNameToUse();
    WbFile ctl = new WbFile(dir, "load_" + tableName + ".sql");
    PrintWriter out = null;
    try {
      out = new PrintWriter(new FileWriter(ctl));
      out.print("load data infile '");
      out.print(baseFile.getFullPath());
      out.print("'\n");
      out.print("  into table ");
      out.println(tableName);

      String encoding = exporter.getEncoding();
      if (encoding != null) {
        out.print("  character set " + encoding + "\n");
      }
      String delim =
          StringUtil.escapeText(exporter.getTextDelimiter(), CharacterRange.RANGE_CONTROL);
      out.print("  columns\n");
      out.print("    terminated by '" + delim + "'\n");
      String quote = exporter.getTextQuoteChar();

      if (quote != null) {
        out.print("    ");
        if (!exporter.getQuoteAlways()) {
          out.print("optionally ");
        }
        out.print("enclosed by '" + quote + "'\n");
      }

      if (exporter.getExportHeaders()) {
        out.print("  ignore 1 lines\n");
      }
    } catch (Exception e) {
      LogMgr.logError(
          "PostgresCopyStatementWriter.writeFormatFile()", "Could not write format file", e);
    } finally {
      FileUtil.closeQuietely(out);
    }
  }