예제 #1
0
  private void exportRelations(long id) {
    U.encode(relations.size(), SER_HELPER);

    for (Entry<String, RWRelation> rel : relations.entrySet()) {
      U.encode(rel.getKey(), SER_HELPER);
      long[] links = rel.getValue().linksFrom(id).toArray();
      U.encode(links.length, SER_HELPER);
      for (long link : links) {
        U.encode(link, SER_HELPER);
      }
    }
  }
예제 #2
0
  private void exportColumns(long id) {
    IdAddress address = ids.get(id);
    boolean exportTableData = address != null;

    U.encode(exportTableData, SER_HELPER);

    if (exportTableData) {
      TableInternals<?> table = (TableInternals<?>) address.table;
      PropertyInfo[] props = table.props();

      U.encode(table.getClazz().getCanonicalName(), SER_HELPER);
      U.encode(props.length, SER_HELPER);

      for (PropertyInfo prop : props) {
        String colName = prop.getName();
        Object colVal = prop.getColumn().get(address.row);
        U.encode(colName, SER_HELPER);
        U.encode(colVal, SER_HELPER);
      }
    }
  }
예제 #3
0
  @Test
  public void shouldPersistToFileMini() throws IOException, TransactionException {
    Db db = Ohm.db(DB_FILE);
    Table<Person> table = db.table(Person.class);

    assert 0 == table.insert(person("a", 100));
    assert 1 == table.insert(person("b", 200));

    db.shutdown();

    /** * READ DB 2 ** */
    Db db2 = Ohm.db(DB_FILE);
    Table<Person> table2 = db2.table(Person.class);

    Transaction txx = db2.startTransaction();

    eq(table2.size(), 2);

    System.out.println("now delete...");
    table2.delete(1);

    eq(table2.size(), 1);

    txx.commit();

    Transaction txx2 = db2.startTransaction();

    System.out.println("now set name");
    table2.set(0, "name", "z");

    txx2.commit();

    db2.shutdown();

    /** * READ DB 3 ** */
    U.sleep(1000);
    System.out.println("=============================");

    Db db3 = Ohm.db(DB_FILE);

    Table<Person> table3 = db3.table(Person.class);
    eq(table3.size(), 1);
  }
예제 #4
0
 private Object decode() {
   Object val = U.decode(SER_HELPER);
   // System.out.println("DECODE " + val);
   return val;
 }
예제 #5
0
 @Override
 public void update(Object entity) {
   long id = U.getId(entity);
   IdAddress address = address(id);
   ((TableInternals<?>) address.table).updateObj(entity);
 }