Пример #1
0
  private static String constructGenericOutputPath(Database database, String outputFolder) {
    // Prepares a generic output path string without the table name and csv suffix
    String genericOutputPath = null;

    // An empty string is the default outputFolder, the path of the database file is then used
    if (outputFolder.isEmpty()) {
      try {
        genericOutputPath = database.getFile().getCanonicalPath();
      } catch (IOException ioe) {
        System.out.println(
            "ERROR: unable to construct the canonical path of the "
                + "database file \""
                + database.getFile().getName()
                + "\"");
        closeDatabase(database);
        System.exit(1);
      }
    } else {
      // Ensure that the output folder path always ends with a path separator
      if (!outputFolder.endsWith(File.separator)) {
        outputFolder += File.separator;
      }
      genericOutputPath = outputFolder;
      genericOutputPath += database.getFile().getName();
    }
    return genericOutputPath.substring(0, genericOutputPath.lastIndexOf("."));
  }
Пример #2
0
  private static void doTestCodecHandler(boolean simple) throws Exception {
    for (Database.FileFormat ff : SUPPORTED_FILEFORMATS) {
      Database db = TestUtil.create(ff);
      int pageSize = ((DatabaseImpl) db).getFormat().PAGE_SIZE;
      File dbFile = db.getFile();
      db.close();

      // apply encoding to file
      encodeFile(dbFile, pageSize, simple);

      db =
          new DatabaseBuilder(dbFile)
              .setCodecProvider(simple ? SIMPLE_PROVIDER : FULL_PROVIDER)
              .open();

      Table t1 =
          new TableBuilder("test1")
              .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true))
              .addColumn(new ColumnBuilder("data", DataType.TEXT).setLength(250))
              .setPrimaryKey("id")
              .addIndex(new IndexBuilder("data_idx").addColumns("data"))
              .toTable(db);

      Table t2 =
          new TableBuilder("test2")
              .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true))
              .addColumn(new ColumnBuilder("data", DataType.TEXT).setLength(250))
              .setPrimaryKey("id")
              .addIndex(new IndexBuilder("data_idx").addColumns("data"))
              .toTable(db);

      int autonum = 1;
      for (int i = 1; i < 2; ++i) {
        writeData(t1, t2, autonum, autonum + 100);
        autonum += 100;
      }

      db.close();
    }
  }