Java Code Examples for com.healthmarketscience.jackcess.Database#FileFormat

The following examples show how to use com.healthmarketscience.jackcess.Database#FileFormat . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UsageMapTest.java    From jackcess with Apache License 2.0 6 votes vote down vote up
public void testRead() throws Exception {
  for (final TestDB testDB : SUPPORTED_DBS_TEST) {
    final int expectedFirstPage;
    final int expectedLastPage;
    final Database.FileFormat expectedFileFormat = testDB.getExpectedFileFormat();
    if (Database.FileFormat.V2000.equals(expectedFileFormat)) {
      expectedFirstPage = 743;
      expectedLastPage = 767;
    } else if (Database.FileFormat.V2003.equals(expectedFileFormat)) {
      expectedFirstPage = 16;
      expectedLastPage = 799;
    } else if (Database.FileFormat.V2007.equals(expectedFileFormat)) {
      expectedFirstPage = 94;
      expectedLastPage = 511;
    } else if (Database.FileFormat.V2010.equals(expectedFileFormat)) {
      expectedFirstPage = 109;
      expectedLastPage = 511;
    } else {
      throw new IllegalAccessException("Unknown file format: " + expectedFileFormat);
    }
    checkUsageMapRead(testDB.getFile(), expectedFirstPage, expectedLastPage);
  }
}
 
Example 2
Source File: CodecHandlerTest.java    From jackcess with Apache License 2.0 5 votes vote down vote up
private static void doTestCodecHandler(boolean simple) throws Exception
{
  for(Database.FileFormat ff : SUPPORTED_FILEFORMATS) {
    Database db = TestUtil.createFile(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();
  }
}
 
Example 3
Source File: JetFormat.java    From jackcess with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String,Database.FileFormat> getPossibleFileFormats()
{
  return PossibleFileFormats.POSSIBLE_VERSION_3;
}
 
Example 4
Source File: JetFormat.java    From jackcess with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String,Database.FileFormat> getPossibleFileFormats()
{
  return PossibleFileFormats.POSSIBLE_VERSION_4;
}
 
Example 5
Source File: JetFormat.java    From jackcess with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String,Database.FileFormat> getPossibleFileFormats()
{
  return PossibleFileFormats.POSSIBLE_VERSION_MSISAM;
}
 
Example 6
Source File: JetFormat.java    From jackcess with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String,Database.FileFormat> getPossibleFileFormats() {
  return PossibleFileFormats.POSSIBLE_VERSION_12;
}
 
Example 7
Source File: JetFormat.java    From jackcess with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String,Database.FileFormat> getPossibleFileFormats() {
  return PossibleFileFormats.POSSIBLE_VERSION_14;
}
 
Example 8
Source File: JetFormat.java    From jackcess with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String,Database.FileFormat> getPossibleFileFormats() {
  return PossibleFileFormats.POSSIBLE_VERSION_16;
}
 
Example 9
Source File: CalcFieldTest.java    From jackcess with Apache License 2.0 4 votes vote down vote up
public void testCreateCalcField() throws Exception {

    ColumnBuilder cb = new ColumnBuilder("calc_data", DataType.TEXT)
      .setCalculatedInfo("[id] & \"_\" & [data]");

    try {
      cb.validate(JetFormat.VERSION_12);
      fail("IllegalArgumentException should have been thrown");
    } catch(IllegalArgumentException e) {
      assertTrue(e.getMessage().contains(""));
    }

    cb.validate(JetFormat.VERSION_14);

    for (final Database.FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
      JetFormat format = DatabaseImpl.getFileFormatDetails(fileFormat).getFormat();
      if(!format.isSupportedCalculatedDataType(DataType.TEXT)) {
        continue;
      }

      Database db = create(fileFormat);

      Table t = new TableBuilder("Test")
        .putProperty("awesome_table", true)
        .addColumn(new ColumnBuilder("id", DataType.LONG)
                   .setAutoNumber(true))
        .addColumn(new ColumnBuilder("data", DataType.TEXT))
        .addColumn(new ColumnBuilder("calc_text", DataType.TEXT)
                   .setCalculatedInfo("[id] & \"_\" & [data]"))
        .addColumn(new ColumnBuilder("calc_memo", DataType.MEMO)
                   .setCalculatedInfo("[id] & \"_\" & [data]"))
        .addColumn(new ColumnBuilder("calc_bool", DataType.BOOLEAN)
                   .setCalculatedInfo("[id] > 0"))
        .addColumn(new ColumnBuilder("calc_long", DataType.LONG)
                   .setCalculatedInfo("[id] + 1"))
        .addColumn(new ColumnBuilder("calc_numeric", DataType.NUMERIC)
                   .setCalculatedInfo("[id] / 0.03"))
        .toTable(db);

      Column col = t.getColumn("calc_text");
      assertTrue(col.isCalculated());
      assertEquals("[id] & \"_\" & [data]", col.getProperties().getValue(
                       PropertyMap.EXPRESSION_PROP));
      assertEquals(DataType.TEXT.getValue(), 
                   col.getProperties().getValue(
                       PropertyMap.RESULT_TYPE_PROP));

      String longStr = createString(1000);
      BigDecimal bd1 = new BigDecimal("-1234.5678");
      BigDecimal bd2 = new BigDecimal("0.0234");

      t.addRow(Column.AUTO_NUMBER, "foo", "1_foo", longStr, true, 2, bd1);
      t.addRow(Column.AUTO_NUMBER, "bar", "2_bar", longStr, false, -37, bd2);
      t.addRow(Column.AUTO_NUMBER, "", "", "", false, 0, BigDecimal.ZERO);
      t.addRow(Column.AUTO_NUMBER, null, null, null, null, null, null);

      List<? extends Map<String, Object>> expectedRows =
        createExpectedTable(
            createExpectedRow(
                "id", 1,
                "data", "foo",
                "calc_text", "1_foo",
                "calc_memo", longStr,
                "calc_bool", true,
                "calc_long", 2,
                "calc_numeric", bd1),
            createExpectedRow(
                "id", 2,
                "data", "bar",
                "calc_text", "2_bar",
                "calc_memo", longStr,
                "calc_bool", false,
                "calc_long", -37,
                "calc_numeric", bd2),
            createExpectedRow(
                "id", 3,
                "data", "",
                "calc_text", "",
                "calc_memo", "",
                "calc_bool", false,
                "calc_long", 0,
                "calc_numeric", BigDecimal.ZERO),
            createExpectedRow(
                "id", 4,
                "data", null,
                "calc_text", null,
                "calc_memo", null,
                "calc_bool", null,
                "calc_long", null,
                "calc_numeric", null));

      assertTable(expectedRows, t);

      db.close();
    }
  }
 
Example 10
Source File: BigIntTest.java    From jackcess with Apache License 2.0 4 votes vote down vote up
public void testBigInt() throws Exception {

    for (final Database.FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
      JetFormat format = DatabaseImpl.getFileFormatDetails(fileFormat)
        .getFormat();

      if(!format.isSupportedDataType(DataType.BIG_INT)) {
        continue;
      }

      Database db = create(fileFormat);

      Table t = new TableBuilder("Test")
        .addColumn(new ColumnBuilder("id", DataType.LONG)
                   .setAutoNumber(true))
        .addColumn(new ColumnBuilder("data1", DataType.TEXT))
        .addColumn(new ColumnBuilder("num1", DataType.BIG_INT))
        .addIndex(new IndexBuilder("idx").addColumns("num1"))
        .toTable(db);

      long[] vals = new long[] {
        0L, -10L, 3844L, -45309590834L, 50392084913L, 65000L, -6489273L};

      List<Map<String, Object>> expectedTable = 
        new ArrayList<Map<String, Object>>();

      int idx = 1;
      for(long lng : vals) {
        t.addRow(Column.AUTO_NUMBER, "" + lng, lng);

        expectedTable.add(createExpectedRow(
                              "id", idx++,
                              "data1", "" + lng,
                              "num1", lng));
      }

      Collections.sort(expectedTable, new Comparator<Map<String, Object>>() {
          public int compare(
              Map<String, Object> r1,
              Map<String, Object> r2) {
            Long l1 = (Long)r1.get("num1");
            Long l2 = (Long)r2.get("num1");
            return l1.compareTo(l2);
          }
        });
      
      Cursor c = new CursorBuilder(t).setIndexByName("idx").toIndexCursor();

      assertCursor(expectedTable, c);

      db.close();
    }
  }
 
Example 11
Source File: JetFormat.java    From jackcess with Apache License 2.0 votes vote down vote up
protected abstract Map<String,Database.FileFormat> getPossibleFileFormats();