예제 #1
0
  public void testWriteBatchingAndGetObject() throws Exception {
    Address address1 = new Address();
    address1.setAddress("Address 1");

    writer.flushObjectById();
    realOs.flushObjectById();

    try {
      writer.beginTransaction();
      writer.store(address1);
      assertNotNull(writer.getObjectById(address1.getId(), Address.class));
    } finally {
      if (writer.isInTransaction()) {
        writer.abortTransaction();
      }
    }
  }
예제 #2
0
  public void testTransactionsAndCaches() throws Exception {
    Address address1 = new Address();
    address1.setAddress("Address 1");
    Address address2 = new Address();
    address2.setAddress("Address 2");

    writer.flushObjectById();
    realOs.flushObjectById();

    try {
      writer.store(address1);
      Integer id = address1.getId();
      address2.setId(id);

      assertNull(realOs.pilferObjectById(id));
      assertNull(writer.pilferObjectById(id));

      assertNotNull("Looked for id " + id, realOs.getObjectById(id, Address.class));
      assertNull(writer.pilferObjectById(id));
      assertNotNull(realOs.pilferObjectById(id));
      realOs.flushObjectById();

      assertNotNull(writer.getObjectById(id, Address.class));
      assertNotNull(writer.pilferObjectById(id));
      assertNull(realOs.pilferObjectById(id));
      assertNotNull(realOs.getObjectById(id, Address.class));

      writer.store(address2);
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.delete(address2);
      assertNull(writer.getObjectById(id, Address.class));
      assertNull(realOs.getObjectById(id, Address.class));

      writer.store(address1);
      writer.beginTransaction();
      writer.store(address2);
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 1", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.commitTransaction();
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.beginTransaction();
      writer.delete(address1);
      assertNull(writer.getObjectById(id, Address.class));
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.abortTransaction();
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());
    } finally {
      writer.delete(address1);
    }
  }